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: v15.1.0~399^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0e2d465526dd2a8368656099ff1bfb76a9140fb1;p=ceph.git common/blkdev: factor get_device_metadata out of mon, osd Signed-off-by: Sage Weil --- diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index 4241bccab8d..165829129cf 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -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& 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 1e5f9469f4c..31c6c7f10bc 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 27ea54b0b32..24b4982a507 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2336,21 +2336,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 fcdc14fda0b..fdd04b860f8 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -6573,23 +6573,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; }