]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crush/CrushTreeDumper: allow children to filter results
authorSage Weil <sage@redhat.com>
Thu, 25 May 2017 20:31:52 +0000 (16:31 -0400)
committerSage Weil <sage@redhat.com>
Thu, 25 May 2017 20:31:52 +0000 (16:31 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/crush/CrushTreeDumper.h

index 3286fc72c31850200bb0dd08fd08316c2c50ac60..6bd11abeb7acfacb3a0a5e9926326971e4837e9a 100644 (file)
@@ -76,8 +76,31 @@ namespace CrushTreeDumper {
       clear();
     }
 
+    virtual bool should_dump_leaf(int i) {
+      return true;
+    }
+    virtual bool should_dump_empty_bucket() {
+      return true;
+    }
+
+    bool should_dump(int id) {
+      if (id >= 0)
+       return should_dump_leaf(id);
+      if (should_dump_empty_bucket())
+       return true;
+      int s = crush->get_bucket_size(id);
+      for (int k = s - 1; k >= 0; k--) {
+       int c = crush->get_bucket_item(id, k);
+       if (should_dump(c))
+         return true;
+      }
+      return false;
+    }
+
     bool next(Item &qi) {
       if (empty()) {
+       while (root != roots.end() && !should_dump(*root))
+         ++root;
        if (root == roots.end())
          return false;
        push_back(Item(*root, 0, crush->get_bucket_weightf(*root)));
@@ -93,9 +116,11 @@ namespace CrushTreeDumper {
        int s = crush->get_bucket_size(qi.id);
        for (int k = s - 1; k >= 0; k--) {
          int id = crush->get_bucket_item(qi.id, k);
-         qi.children.push_back(id);
-         push_front(Item(id, qi.depth + 1,
-                         crush->get_bucket_item_weightf(qi.id, k)));
+         if (should_dump(id)) {
+           qi.children.push_back(id);
+           push_front(Item(id, qi.depth + 1,
+                           crush->get_bucket_item_weightf(qi.id, k)));
+         }
        }
       }
       return true;