]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: reuse find_roots to implement find_nonshadow_roots
authorxie xingguo <xie.xingguo@zte.com.cn>
Tue, 11 Jul 2017 08:07:43 +0000 (16:07 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Wed, 26 Jul 2017 14:34:51 +0000 (22:34 +0800)
to reduce code redundance...

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 11659ccf44089765962056c274ad86604177f21e..9830fedb4097f7bac87334f5f39bffcf67177669 100644 (file)
@@ -315,21 +315,6 @@ void CrushWrapper::find_roots(set<int>& roots) const
   }
 }
 
-void CrushWrapper::find_nonshadow_roots(set<int>& roots) const
-{
-  for (int i = 0; i < crush->max_buckets; i++) {
-    if (!crush->buckets[i])
-      continue;
-    crush_bucket *b = crush->buckets[i];
-    if (_search_item_exists(b->id))
-      continue;
-    const char *name = get_item_name(b->id);
-    if (name && !is_valid_crush_name(name))
-      continue;
-    roots.insert(b->id);
-  }
-}
-
 bool CrushWrapper::subtree_contains(int root, int item) const
 {
   if (root == item)
index 459f0b59dc28f0fcf70f9dfab2083902f9aedae1..1d216b782422934545e3e27b5b3a8599b9963700 100644 (file)
@@ -581,6 +581,10 @@ public:
     if (have_rmaps)
       rule_name_rmap[name] = i;
   }
+  bool is_shadow_item(int id) const {
+    const char *name = get_item_name(id);
+    return name && !is_valid_crush_name(name);
+  }
 
 
   /**
@@ -603,7 +607,15 @@ public:
    * These are parentless nodes in the map that are not shadow
    * items for device classes.
    */
-  void find_nonshadow_roots(set<int>& roots) const;
+  void find_nonshadow_roots(set<int>& roots) const {
+    set<int> all;
+    find_roots(all);
+    for (auto& p: all) {
+      if (!is_shadow_item(p)) {
+        roots.insert(p);
+      }
+    }
+  }
 
   /**
    * see if an item is contained within a subtree