}
#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;
+ }
+ }
+}
#define __CEPH_COMMON_BLKDEV_H
#include <set>
+#include <map>
#include <string>
#include "json_spirit/json_spirit_value.h"
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);
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()
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;
}