]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/blkdev: factor get_device_metadata out of mon, osd
authorSage Weil <sage@redhat.com>
Sat, 14 Dec 2019 15:11:20 +0000 (09:11 -0600)
committerYaarit Hatuka <yaarit@redhat.com>
Wed, 4 Mar 2020 03:52:06 +0000 (03:52 +0000)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 0e2d465526dd2a8368656099ff1bfb76a9140fb1)

src/common/blkdev.cc
src/common/blkdev.h
src/mon/Monitor.cc
src/osd/OSD.cc

index c2f2e319f83235f8609b9b4924cc98900e38d67f..6ee8539900369bed46b299c690fda424f5537cd0 100644 (file)
@@ -1229,3 +1229,26 @@ int block_device_run_nvme(const char *device, const char *vendor, int timeout,
 }
 
 #endif
+
+
+void get_device_metadata(
+  const std::set<std::string>& devnames,
+  std::map<std::string,std::string> *pm,
+  std::map<std::string,std::string> *errs)
+{
+  (*pm)["devices"] = stringify(devnames);
+  string &devids = (*pm)["device_ids"];
+  string &devpaths = (*pm)["device_paths"];
+  for (auto& dev : devnames) {
+    string err;
+    string id = get_device_id(dev, &err);
+    if (id.size()) {
+      if (!devids.empty()) {
+       devids += ",";
+      }
+      devids += dev + "=" + id;
+    } else {
+      (*errs)[dev] = " no unique device id for "s + dev + ": " + err;
+    }
+  }
+}
index d471df22dc53e031d830e3bc176dfa6352fd4d51..e0e6d342b1baee99227855c1bb919fbbf770f01a 100644 (file)
@@ -5,6 +5,7 @@
 #define __CEPH_COMMON_BLKDEV_H
 
 #include <set>
+#include <map>
 #include <string>
 #include "json_spirit/json_spirit_value.h"
 
@@ -24,8 +25,15 @@ extern int get_device_by_path(const char *path, char* partition, char* device, s
 
 extern std::string _decode_model_enc(const std::string& in);  // helper, exported only so we can unit test
 
+// get $vendor_$model_$serial style device id
 extern std::string get_device_id(const std::string& devname,
                                 std::string *err=0);
+// populate daemon metadata map with device info
+extern void get_device_metadata(
+  const std::set<std::string>& devnames,
+  std::map<std::string,std::string> *pm,
+  std::map<std::string,std::string> *errs);
+
 extern void get_dm_parents(const std::string& dev, std::set<std::string> *ls);
 extern int block_device_get_metrics(const std::string& devname, int timeout,
                                    json_spirit::mValue *result);
index cd634d349b1ae715da7df809823cc99c50ec0603..cf59867cc29bb450fc53467cbb3176d19002bef8 100644 (file)
@@ -2287,21 +2287,11 @@ void Monitor::collect_metadata(Metadata *m)
   string devname = store->get_devname();
   set<string> devnames;
   get_raw_devices(devname, &devnames);
-  (*m)["devices"] = stringify(devnames);
-  string devids;
-  for (auto& devname : devnames) {
-    string err;
-    string id = get_device_id(devname, &err);
-    if (id.size()) {
-      if (!devids.empty()) {
-       devids += ",";
-      }
-      devids += devname + "=" + id;
-    } else {
-      derr << "failed to get devid for " << devname << ": " << err << dendl;
-    }
+  map<string,string> errs;
+  get_device_metadata(devnames, m, &errs);
+  for (auto& i : errs) {
+    dout(1) << __func__ << " " << i.first << ": " << i.second << dendl;
   }
-  (*m)["device_ids"] = devids;
 }
 
 void Monitor::finish_election()
index f40a233257d12bd671fab26282f69c2fe3882594..d2124bacc2f94314439f38de05ac5609388e47eb 100644 (file)
@@ -6461,23 +6461,11 @@ void OSD::_collect_metadata(map<string,string> *pm)
 
   set<string> devnames;
   store->get_devices(&devnames);
-  (*pm)["devices"] = stringify(devnames);
-  string devids;
-  for (auto& dev : devnames) {
-    string err;
-    string id = get_device_id(dev, &err);
-    if (id.size()) {
-      if (!devids.empty()) {
-       devids += ",";
-      }
-      devids += dev + "=" + id;
-    } else {
-      dout(10) << __func__ << " no unique device id for " << dev << ": "
-              << err << dendl;
-    }
+  map<string,string> errs;
+  get_device_metadata(devnames, pm, &errs);
+  for (auto& i : errs) {
+    dout(1) << __func__ << " " << i.first << ": " << i.second << dendl;
   }
-  (*pm)["device_ids"] = devids;
-
   dout(10) << __func__ << " " << *pm << dendl;
 }