From: Sage Weil Date: Sat, 14 Dec 2019 15:11:20 +0000 (-0600) Subject: common/blkdev: factor get_device_metadata out of mon, osd X-Git-Tag: v14.2.10~213^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c8445552f17f07eaba1d15210188ffeb05c2a7c7;p=ceph.git common/blkdev: factor get_device_metadata out of mon, osd Signed-off-by: Sage Weil (cherry picked from commit 0e2d465526dd2a8368656099ff1bfb76a9140fb1) --- diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index c2f2e319f832..6ee853990036 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -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& devnames, + std::map *pm, + std::map *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; + } + } +} diff --git a/src/common/blkdev.h b/src/common/blkdev.h index d471df22dc53..e0e6d342b1ba 100644 --- a/src/common/blkdev.h +++ b/src/common/blkdev.h @@ -5,6 +5,7 @@ #define __CEPH_COMMON_BLKDEV_H #include +#include #include #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& devnames, + std::map *pm, + std::map *errs); + extern void get_dm_parents(const std::string& dev, std::set *ls); extern int block_device_get_metrics(const std::string& devname, int timeout, json_spirit::mValue *result); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index cd634d349b1a..cf59867cc29b 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2287,21 +2287,11 @@ void Monitor::collect_metadata(Metadata *m) string devname = store->get_devname(); set 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 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() diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index f40a233257d1..d2124bacc2f9 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -6461,23 +6461,11 @@ void OSD::_collect_metadata(map *pm) set 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 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; }