if (dm) {
if (f) {
f->open_array_section("devices");
- for (auto& i : dm->devids) {
- f->dump_string("device", i);
+ for (auto& i : dm->devices) {
+ f->dump_string("device", i.first);
}
f->close_section();
f->flush(cmdctx->odata);
} else {
ostringstream rs;
- for (auto& i : dm->devids) {
- rs << i << "\n";
+ for (auto& i : dm->devices) {
+ rs << i.first << "\n";
}
cmdctx->odata.append(rs.str());
}
void DeviceState::dump(Formatter *f) const
{
f->dump_string("devid", devid);
- f->dump_string("host", server);
+ f->open_array_section("location");
+ for (auto& i : devnames) {
+ f->open_object_section("attachment");
+ f->dump_string("host", i.first);
+ f->dump_string("dev", i.second);
+ f->close_section();
+ }
+ f->close_section();
f->open_array_section("daemons");
for (auto& i : daemons) {
f->dump_string("daemon", to_string(i));
void DeviceState::print(ostream& out) const
{
out << "device " << devid << "\n";
- out << "host " << server << "\n";
+ for (auto& i : devnames) {
+ out << "attachment " << i.first << ":" << i.second << "\n";
+ }
set<string> d;
for (auto& j : daemons) {
d.insert(to_string(j));
by_server[dm->hostname][dm->key] = dm;
all[dm->key] = dm;
- for (auto& devid : dm->devids) {
- auto d = _get_or_create_device(devid);
+ for (auto& i : dm->devices) {
+ auto d = _get_or_create_device(i.first);
d->daemons.insert(dm->key);
- d->server = dm->hostname;
+ d->devnames.insert(make_pair(dm->hostname, i.second));
}
}
assert(to_erase != all.end());
const auto dm = to_erase->second;
- for (auto& devid : dm->devids) {
- auto d = _get_or_create_device(devid);
+ for (auto& i : dm->devices) {
+ auto d = _get_or_create_device(i.first);
assert(d->daemons.count(dmk));
d->daemons.erase(dmk);
+ d->devnames.erase(make_pair(dm->hostname, i.second));
if (d->empty()) {
_erase_device(d);
}
// The metadata (hostname, version, etc) sent from the daemon
std::map<std::string, std::string> metadata;
- /// device ids, derived from metadata[device_ids]
- std::set<std::string> devids;
+ /// device ids -> devname, derived from metadata[device_ids]
+ std::map<std::string,std::string> devices;
// TODO: this can be generalized to other daemons
std::vector<DaemonHealthMetric> daemon_health_metrics;
map<std::string,std::string> devs;
get_str_map(p->second, &devs, ",; ");
for (auto& i : devs) {
- devids.insert(i.second);
+ devices[i.second] = i.first;
}
}
}
struct DeviceState : public RefCountedObject
{
std::string devid;
- std::string server;
+ std::set<pair<std::string,std::string>> devnames; ///< (server,devname)
std::set<DaemonKey> daemons;
std::map<string,string> metadata; ///< persistent metadata
auto m = get_by_server(server);
for (auto& i : m) {
Mutex::Locker l(i.second->lock);
- ls->insert(i.second->devids.begin(),
- i.second->devids.end());
+ for (auto& j : i.second->devices) {
+ ls->insert(j.first);
+ }
}
}