Skip to content

Commit 67b5d3e

Browse files
committed
mgr: parse out devids from daemon metadata
Look for the "device_ids" key in the metadata and parse out a device list. Signed-off-by: Sage Weil <[email protected]>
1 parent de9ddc0 commit 67b5d3e

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

‎src/mgr/DaemonServer.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ bool DaemonServer::handle_open(MMgrOpen *m)
383383
daemon->perf_counters.clear();
384384

385385
if (m->service_daemon) {
386-
daemon->metadata = m->daemon_metadata;
386+
daemon->set_metadata(m->daemon_metadata);
387387
daemon->service_status = m->daemon_status;
388388

389389
utime_t now = ceph_clock_now();
@@ -1885,7 +1885,7 @@ void DaemonServer::got_service_map()
18851885
if (!daemon_state.exists(key)) {
18861886
auto daemon = std::make_shared<DaemonState>(daemon_state.types);
18871887
daemon->key = key;
1888-
daemon->metadata = q.second.metadata;
1888+
daemon->set_metadata(q.second.metadata);
18891889
if (q.second.metadata.count("hostname")) {
18901890
daemon->hostname = q.second.metadata["hostname"];
18911891
}

‎src/mgr/DaemonState.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <boost/circular_buffer.hpp>
2222

2323
#include "common/RWLock.h"
24+
#include "include/str_map.h"
2425

2526
#include "msg/msg_types.h"
2627

@@ -31,6 +32,10 @@
3132
// Unique reference to a daemon within a cluster
3233
typedef std::pair<std::string, std::string> DaemonKey;
3334

35+
static inline std::string to_string(const DaemonKey& dk) {
36+
return dk.first + "." + dk.second;
37+
}
38+
3439
// An instance of a performance counter type, within
3540
// a particular daemon.
3641
class PerfCounterInstance
@@ -121,6 +126,9 @@ class DaemonState
121126
// The metadata (hostname, version, etc) sent from the daemon
122127
std::map<std::string, std::string> metadata;
123128

129+
/// device ids, derived from metadata[device_ids]
130+
std::set<std::string> devids;
131+
124132
// TODO: this can be generalized to other daemons
125133
std::vector<DaemonHealthMetric> daemon_health_metrics;
126134

@@ -148,6 +156,18 @@ class DaemonState
148156
{
149157
}
150158

159+
void set_metadata(const std::map<std::string,std::string>& m) {
160+
metadata = m;
161+
auto p = m.find("device_ids");
162+
if (p != m.end()) {
163+
map<std::string,std::string> devs;
164+
get_str_map(p->second, &devs, ",; ");
165+
for (auto& i : devs) {
166+
devids.insert(i.second);
167+
}
168+
}
169+
}
170+
151171
const std::map<std::string,std::string>& get_config_defaults() {
152172
if (config_defaults.empty() &&
153173
config_defaults_bl.length()) {

‎src/mgr/Mgr.cc‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ void MetadataUpdate::finish(int r)
104104
}
105105
daemon_meta.erase("hostname");
106106
state->metadata.clear();
107+
map<string,string> m;
107108
for (const auto &i : daemon_meta) {
108-
state->metadata[i.first] = i.second.get_str();
109-
}
109+
m[i.first] = i.second.get_str();
110+
}
111+
state->set_metadata(m);
110112
} else {
111113
state = std::make_shared<DaemonState>(daemon_state.types);
112114
state->key = key;
@@ -119,9 +121,11 @@ void MetadataUpdate::finish(int r)
119121
}
120122
daemon_meta.erase("hostname");
121123

124+
map<string,string> m;
122125
for (const auto &i : daemon_meta) {
123-
state->metadata[i.first] = i.second.get_str();
126+
m[i.first] = i.second.get_str();
124127
}
128+
state->set_metadata(m);
125129

126130
daemon_state.insert(state);
127131
}
@@ -349,9 +353,11 @@ void Mgr::load_all_metadata()
349353
osd_metadata.erase("id");
350354
osd_metadata.erase("hostname");
351355

356+
map<string,string> m;
352357
for (const auto &i : osd_metadata) {
353-
dm->metadata[i.first] = i.second.get_str();
358+
m[i.first] = i.second.get_str();
354359
}
360+
dm->set_metadata(m);
355361

356362
daemon_state.insert(dm);
357363
}

0 commit comments

Comments
 (0)