]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: implement find_shadow_roots
authorxie xingguo <xie.xingguo@zte.com.cn>
Wed, 26 Jul 2017 12:07:53 +0000 (20:07 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Wed, 26 Jul 2017 14:36:25 +0000 (22:36 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 8b7b7581100443f18d60677a4d11e53fd51e5b5b..2e5bfac6e1f8c0e4fcb9db3b9d6c26856cc365e6 100644 (file)
@@ -1393,12 +1393,10 @@ bool CrushWrapper::class_is_in_use(int class_id, ostream *ss)
 int CrushWrapper::populate_classes()
 {
   set<int> roots;
-  find_roots(roots);
+  find_nonshadow_roots(roots);
   for (auto &r : roots) {
     if (r >= 0)
       continue;
-    if (id_has_class(r))
-      continue;
     for (auto &c : class_name) {
       int clone;
       int res = device_class_clone(r, c.first, &clone);
@@ -1417,12 +1415,10 @@ int CrushWrapper::cleanup_classes()
 int CrushWrapper::trim_roots_with_class(bool unused)
 {
   set<int> roots;
-  find_roots(roots);
+  find_shadow_roots(roots);
   for (auto &r : roots) {
     if (r >= 0)
       continue;
-    if (!id_has_class(r))
-      continue;
     int res = remove_root(r, unused);
     if (res)
       return res;
index 1d216b782422934545e3e27b5b3a8599b9963700..f69357efa8aa48697ab3ab00e6e484bb68e673fd 100644 (file)
@@ -443,13 +443,6 @@ public:
       name_rmap[bn] = a;
     }
   }
-  bool id_has_class(int i) {
-    int idout;
-    int classout;
-    if (split_id_class(i, &idout, &classout) != 0)
-      return false;
-    return classout != -1;
-  }
   int split_id_class(int i, int *idout, int *classout) const;
 
   bool class_exists(const string& name) const {
@@ -601,6 +594,20 @@ public:
    */
   void find_roots(set<int>& roots) const;
 
+
+  /**
+   * find tree roots that contain shadow (device class) items only
+   */
+  void find_shadow_roots(set<int>& roots) const {
+    set<int> all;
+    find_roots(all);
+    for (auto& p: all) {
+      if (is_shadow_item(p)) {
+        roots.insert(p);
+      }
+    }
+  }
+
   /**
    * find tree roots that are not shadow (device class) items
    *