]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/blkdev: identify VDO devices beneath LVM
authorSage Weil <sage@redhat.com>
Wed, 21 Feb 2018 21:10:04 +0000 (15:10 -0600)
committerSage Weil <sage@redhat.com>
Mon, 2 Apr 2018 20:19:19 +0000 (15:19 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/blkdev.cc

index 3d3f1e30705c4e38b23111e6dbf87a976e550059..e88c9e69c10553e5623422b10681c0284dc73294 100644 (file)
 #include "include/uuid.h"
 #include "blkdev.h"
 
-
 #ifdef __linux__
 #include <linux/fs.h>
 #include <blkid/blkid.h>
 
+#include <set>
+
+
 #define UUID_LEN 36
 
 static const char *sandbox_dir = "";
@@ -300,7 +302,7 @@ void get_dm_parents(const std::string& dev, std::set<std::string> *ls)
   }
 }
 
-int get_vdo_stats_handle(const char *devname, std::string *vdo_name)
+int _get_vdo_stats_handle(const char *devname, std::string *vdo_name)
 {
   int vdo_fd = -1;
 
@@ -323,7 +325,7 @@ int get_vdo_stats_handle(const char *devname, std::string *vdo_name)
     target[r] = 0;
     if (expect == target) {
       snprintf(fn, sizeof(fn), "/sys/kvdo/%s/statistics", de->d_name);
-      vdo_fd = ::open(fn, O_DIRECTORY);
+      vdo_fd = ::open(fn, O_RDONLY); //DIRECTORY);
       if (vdo_fd >= 0) {
        *vdo_name = de->d_name;
        break;
@@ -334,6 +336,25 @@ int get_vdo_stats_handle(const char *devname, std::string *vdo_name)
   return vdo_fd;
 }
 
+int get_vdo_stats_handle(const char *devname, std::string *vdo_name)
+{
+  std::set<std::string> devs = { devname };
+  while (!devs.empty()) {
+    std::string dev = *devs.begin();
+    devs.erase(devs.begin());
+    int fd = _get_vdo_stats_handle(dev.c_str(), vdo_name);
+    if (fd >= 0) {
+      // yay, it's vdo
+      return fd;
+    }
+    // ok, see if there are constituent devices
+    if (dev.find("dm-") == 0) {
+      get_dm_parents(dev, &devs);
+    }
+  }
+  return -1;
+}
+
 int64_t get_vdo_stat(int vdo_fd, const char *property)
 {
   int64_t ret = 0;