]> 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)
committerSage Weil <sage@redhat.com>
Mon, 16 Dec 2019 13:16:44 +0000 (07:16 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/blkdev.cc
src/common/blkdev.h
src/mon/Monitor.cc
src/osd/OSD.cc

index 4241bccab8db923bd8a3701ac63fcbe2f9e21a56..165829129cf808dd11467db8e41fa65f50f56a9b 100644 (file)
@@ -1208,3 +1208,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 1e5f9469f4c79ae582226fde55503e25c7f1f9df..31c6c7f10bcca3a031291c01ca11f7431c60afbf 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 27ea54b0b327f3711ac81665bca4764719bb88e9..24b4982a50780190aebb5fff5d93e6ff1cec4238 100644 (file)
@@ -2336,21 +2336,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 fcdc14fda0b539df2ba3c88e34d4d1a591bac117..fdd04b860f8b04f822072f571a810867bcbe9ac4 100644 (file)
@@ -6573,23 +6573,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;
 }