From 2555233efcd10dad3ea48f1e9751882fd3586b7e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 21 Dec 2018 11:20:34 -0600 Subject: [PATCH] common/blkdev: add get_raw_devices helper Signed-off-by: Sage Weil --- src/common/blkdev.cc | 37 +++++++++++++++++++++++++++++++++++++ src/common/blkdev.h | 14 ++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index be5a223419a..f55ddbd3b44 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -310,6 +310,28 @@ void get_dm_parents(const std::string& dev, std::set *ls) } } +void get_raw_devices(const std::string& in, + std::set *ls) +{ + if (in.substr(0, 3) == "dm-") { + std::set o; + get_dm_parents(in, &o); + for (auto& d : o) { + get_raw_devices(d, ls); + } + } else { + BlkDev d(in); + std::string wholedisk; + if (d.wholedisk(&wholedisk) == 0) { + std::cout << " wholedisk of " << in << " is " << wholedisk << std::endl; + ls->insert(wholedisk); + } else { + std::cout << " wholedisk of " << in << " failed" << std::endl; + ls->insert(in); + } + } +} + int _get_vdo_stats_handle(const char *devname, std::string *vdo_name) { int vdo_fd = -1; @@ -641,6 +663,11 @@ void get_dm_parents(const std::string& dev, std::set *ls) { } +void get_raw_devices(const std::string& in, + std::set *ls) +{ +} + int get_vdo_stats_handle(const char *devname, std::string *vdo_name) { return -1; @@ -791,6 +818,11 @@ void get_dm_parents(const std::string& dev, std::set *ls) { } +void get_raw_devices(const std::string& in, + std::set *ls) +{ +} + int get_vdo_stats_handle(const char *devname, std::string *vdo_name) { return -1; @@ -922,6 +954,11 @@ void get_dm_parents(const std::string& dev, std::set *ls) { } +void get_raw_devices(const std::string& in, + std::set *ls) +{ +} + int get_vdo_stats_handle(const char *devname, std::string *vdo_name) { return -1; diff --git a/src/common/blkdev.h b/src/common/blkdev.h index e32d8061956..7dc3e422fc3 100644 --- a/src/common/blkdev.h +++ b/src/common/blkdev.h @@ -29,6 +29,11 @@ extern int block_device_run_smartctl(const char *device, int timeout, extern int block_device_get_metrics(const char *device, int timeout, json_spirit::mValue *result); +// do everything to translate a device to the raw physical devices that +// back it, including partitions -> wholedisks and dm -> constituent devices. +extern void get_raw_devices(const std::string& in, + std::set *ls); + // for VDO /// return an op fd for the sysfs stats dir, if this is a VDO device extern int get_vdo_stats_handle(const char *devname, std::string *vdo_name); @@ -59,6 +64,15 @@ public: /* virtual for testing purposes */ virtual const char *sysfsdir() const; virtual int wholedisk(char* device, size_t max) const; + int wholedisk(std::string *s) const { + char out[PATH_MAX] = {0}; + int r = wholedisk(out, sizeof(out)); + if (r < 0) { + return r; + } + *s = out; + return r; + } protected: int64_t get_int_property(blkdev_prop_t prop) const; -- 2.39.5