]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: report device by-path paths too
authorSage Weil <sage@redhat.com>
Sun, 15 Dec 2019 16:28:57 +0000 (10:28 -0600)
committerSage Weil <sage@redhat.com>
Mon, 16 Dec 2019 13:16:44 +0000 (07:16 -0600)
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 <sage@redhat.com>
src/mgr/DaemonServer.cc
src/mgr/DaemonState.cc
src/mgr/DaemonState.h

index 8af4a1a76b640ee5ea2e5e8e4036f99dcdd177e4..f72ae5cfbc426e48100e2f423f1d6481e5c68c3e 100644 (file)
@@ -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;
index 13e42ff10069fcc56c6101efa84ee80e6c00b207..87f820bffb7dfdec8e09dec6454fecbeff3f35f4 100644 (file)
@@ -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);
     }
index 1d374b225ea3792d2181fb463f745cf831d19701..1b9ef543dc3b7ef7ed9f025d0e91e7ab6424ae26 100644 (file)
@@ -134,6 +134,9 @@ class DaemonState
   /// device ids -> devname, derived from metadata[device_ids]
   std::map<std::string,std::string> devices;
 
+  /// device ids -> by-path, derived from metadata[device_ids]
+  std::map<std::string,std::string> devices_bypath;
+
   // TODO: this can be generalized to other daemons
   std::vector<DaemonHealthMetric> daemon_health_metrics;
 
@@ -164,14 +167,23 @@ class DaemonState
 
   void set_metadata(const std::map<std::string,std::string>& m) {
     devices.clear();
+    devices_bypath.clear();
     metadata = m;
     auto p = m.find("device_ids");
     if (p != m.end()) {
-      map<std::string,std::string> devs;
+      map<std::string,std::string> 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<DaemonKey, DaemonStatePtr> DaemonStateCollection;
 struct DeviceState : public RefCountedObject
 {
   std::string devid;
-  std::set<pair<std::string,std::string>> devnames; ///< (server,devname)
+  /// (server,devname,path)
+  std::set<std::tuple<std::string,std::string,std::string>> attachments;
   std::set<DaemonKey> daemons;
 
   std::map<string,string> metadata;  ///< persistent metadata