From 6b6fe52aacf645ce3cac08c8bd540691fcc15f8a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 6 Jun 2018 08:44:42 -0500 Subject: [PATCH] mgr: track and report device names too If you're looking at a specific device by its unique id, it's also nice to know what device name (sdb etc) it is and on which host. Signed-off-by: Sage Weil --- src/mgr/DaemonServer.cc | 8 ++++---- src/mgr/DaemonState.cc | 24 +++++++++++++++++------- src/mgr/DaemonState.h | 13 +++++++------ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index 43d6efd866e..d35a0c55dc0 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -1686,15 +1686,15 @@ bool DaemonServer::handle_command(MCommand *m) 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()); } diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 8b7d39a7653..824e606fa36 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -54,7 +54,14 @@ void DeviceState::rm_expected_failure() 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)); @@ -70,7 +77,9 @@ void DeviceState::dump(Formatter *f) const 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 d; for (auto& j : daemons) { d.insert(to_string(j)); @@ -93,10 +102,10 @@ void DaemonStateIndex::insert(DaemonStatePtr dm) 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)); } } @@ -108,10 +117,11 @@ void DaemonStateIndex::_erase(const DaemonKey& dmk) 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); } diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index 81d8cb49ab4..c746d57ca2a 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -129,8 +129,8 @@ class DaemonState // The metadata (hostname, version, etc) sent from the daemon std::map metadata; - /// device ids, derived from metadata[device_ids] - std::set devids; + /// device ids -> devname, derived from metadata[device_ids] + std::map devices; // TODO: this can be generalized to other daemons std::vector daemon_health_metrics; @@ -166,7 +166,7 @@ class DaemonState map devs; get_str_map(p->second, &devs, ",; "); for (auto& i : devs) { - devids.insert(i.second); + devices[i.second] = i.first; } } } @@ -191,7 +191,7 @@ typedef std::map DaemonStateCollection; struct DeviceState : public RefCountedObject { std::string devid; - std::string server; + std::set> devnames; ///< (server,devname) std::set daemons; std::map metadata; ///< persistent metadata @@ -322,8 +322,9 @@ public: 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); + } } } -- 2.39.5