From 2c0fd7d86827aa76b8d923870018365cdae4a6ad Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 15 Dec 2019 10:28:57 -0600 Subject: [PATCH] mgr: report device by-path paths too I'm leaving this out of the 'device ls[-*]' human output because the paths are usually quite long, but it's in the json output and the 'device info' command has it. Signed-off-by: Sage Weil --- src/mgr/DaemonServer.cc | 14 +++++++------- src/mgr/DaemonState.cc | 28 +++++++++++++++++++++------- src/mgr/DaemonState.h | 19 ++++++++++++++++--- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index 8af4a1a76b6..f72ae5cfbc4 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -1985,11 +1985,11 @@ bool DaemonServer::_handle_command( auto now = ceph_clock_now(); daemon_state.with_devices([&tbl, now](const DeviceState& dev) { string h; - for (auto& i : dev.devnames) { + for (auto& i : dev.attachments) { if (h.size()) { h += " "; } - h += i.first + ":" + i.second; + h += std::get<0>(i) + ":" + std::get<1>(i); } string d; for (auto& i : dev.daemons) { @@ -2037,11 +2037,11 @@ bool DaemonServer::_handle_command( daemon_state.with_device( i.first, [&tbl, now] (const DeviceState& dev) { string h; - for (auto& i : dev.devnames) { + for (auto& i : dev.attachments) { if (h.size()) { h += " "; } - h += i.first + ":" + i.second; + h += std::get<0>(i) + ":" + std::get<1>(i); } tbl << dev.devid << h @@ -2083,12 +2083,12 @@ bool DaemonServer::_handle_command( daemon_state.with_device( devid, [&tbl, &host, now] (const DeviceState& dev) { string n; - for (auto& j : dev.devnames) { - if (j.first == host) { + for (auto& j : dev.attachments) { + if (std::get<0>(j) == host) { if (n.size()) { n += " "; } - n += j.second; + n += std::get<1>(j); } } string d; diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 13e42ff1006..87f820bffb7 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -96,10 +96,11 @@ void DeviceState::dump(Formatter *f) const { f->dump_string("devid", devid); f->open_array_section("location"); - for (auto& i : devnames) { + for (auto& i : attachments) { f->open_object_section("attachment"); - f->dump_string("host", i.first); - f->dump_string("dev", i.second); + f->dump_string("host", std::get<0>(i)); + f->dump_string("dev", std::get<1>(i)); + f->dump_string("path", std::get<2>(i)); f->close_section(); } f->close_section(); @@ -119,8 +120,10 @@ void DeviceState::dump(Formatter *f) const void DeviceState::print(ostream& out) const { out << "device " << devid << "\n"; - for (auto& i : devnames) { - out << "attachment " << i.first << ":" << i.second << "\n"; + for (auto& i : attachments) { + out << "attachment " << std::get<0>(i) << " " << std::get<1>(i) << " " + << std::get<2>(i) << "\n"; + out << "\n"; } std::copy(std::begin(daemons), std::end(daemons), std::experimental::make_ostream_joiner(out, ",")); @@ -150,7 +153,13 @@ void DaemonStateIndex::_insert(DaemonStatePtr dm) for (auto& i : dm->devices) { auto d = _get_or_create_device(i.first); d->daemons.insert(dm->key); - d->devnames.insert(make_pair(dm->hostname, i.second)); + auto p = dm->devices_bypath.find(i.first); + if (p != dm->devices_bypath.end()) { + d->attachments.insert(std::make_tuple(dm->hostname, i.second, p->second)); + } else { + d->attachments.insert(std::make_tuple(dm->hostname, i.second, + std::string())); + } } } @@ -166,7 +175,12 @@ void DaemonStateIndex::_erase(const DaemonKey& dmk) auto d = _get_or_create_device(i.first); ceph_assert(d->daemons.count(dmk)); d->daemons.erase(dmk); - d->devnames.erase(make_pair(dm->hostname, i.second)); + auto p = dm->devices_bypath.find(i.first); + if (p != dm->devices_bypath.end()) { + d->attachments.erase(make_tuple(dm->hostname, i.second, p->second)); + } else { + d->attachments.erase(make_tuple(dm->hostname, i.second, std::string())); + } if (d->empty()) { _erase_device(d); } diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index 1d374b225ea..1b9ef543dc3 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -134,6 +134,9 @@ class DaemonState /// device ids -> devname, derived from metadata[device_ids] std::map devices; + /// device ids -> by-path, derived from metadata[device_ids] + std::map devices_bypath; + // TODO: this can be generalized to other daemons std::vector daemon_health_metrics; @@ -164,14 +167,23 @@ class DaemonState void set_metadata(const std::map& m) { devices.clear(); + devices_bypath.clear(); metadata = m; auto p = m.find("device_ids"); if (p != m.end()) { - map devs; + map devs, paths; // devname -> id or path get_str_map(p->second, &devs, ",; "); + auto q = m.find("device_paths"); + if (q != m.end()) { + get_str_map(q->second, &paths, ",; "); + } for (auto& i : devs) { if (i.second.size()) { // skip blank ids - devices[i.second] = i.first; + devices[i.second] = i.first; // id -> devname + auto j = paths.find(i.first); + if (j != paths.end()) { + devices_bypath[i.second] = j->second; // id -> path + } } } } @@ -201,7 +213,8 @@ typedef std::map DaemonStateCollection; struct DeviceState : public RefCountedObject { std::string devid; - std::set> devnames; ///< (server,devname) + /// (server,devname,path) + std::set> attachments; std::set daemons; std::map metadata; ///< persistent metadata -- 2.39.5