]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushWrapper: add get_parent_of_type
authorSage Weil <sage@redhat.com>
Tue, 2 May 2017 00:45:21 +0000 (19:45 -0500)
committerSage Weil <sage@redhat.com>
Tue, 2 May 2017 00:45:21 +0000 (19:45 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 88471f87458178edb1b94dc697d3abb8c2f4448e..d3a7cd4e0e0c8d4fc8d3e72c8148f84ffb071c7d 100644 (file)
@@ -1044,6 +1044,17 @@ int CrushWrapper::get_immediate_parent_id(int id, int *parent) const
   return -ENOENT;
 }
 
+int CrushWrapper::get_parent_of_type(int item, int type) const
+{
+  do {
+    int r = get_immediate_parent_id(item, &item);
+    if (r < 0) {
+      return 0;
+    }
+  } while (get_bucket_type(item) != type);
+  return item;
+}
+
 bool CrushWrapper::class_is_in_use(int class_id)
 {
   for (auto &i : class_bucket)
index 54fd572f8cc41a4c4fdbbed982bc36a78a9aea18..0775de3feb37fe00cd2c71d906e103ec0822e6da 100644 (file)
@@ -571,6 +571,12 @@ public:
   pair<string,string> get_immediate_parent(int id, int *ret = NULL);
   int get_immediate_parent_id(int id, int *parent) const;
 
+  /**
+   * return ancestor of the given type, or 0 if none
+   * (parent is always a bucket and thus <0)
+   */
+  int get_parent_of_type(int id, int type) const;
+
   /**
    * get the fully qualified location of a device by successively finding
    * parents beginning at ID and ending at highest type number specified in