]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: add adjust_subtree_weight()
authorSage Weil <sage@inktank.com>
Sun, 11 May 2014 22:35:11 +0000 (15:35 -0700)
committerSage Weil <sage@inktank.com>
Tue, 27 May 2014 22:42:08 +0000 (15:42 -0700)
Adjust the weight for all (leaf) items beneath a subtree.

Signed-off-by: Sage Weil <sage@inktank.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index c0eabe37f51aa149bce0b11f34af2ac4655ed294..5d2067750551391f9f400ec1b873ad065ceabca1 100644 (file)
@@ -653,6 +653,33 @@ int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight)
   return changed;
 }
 
+int CrushWrapper::adjust_subtree_weight(CephContext *cct, int id, int weight)
+{
+  ldout(cct, 5) << "adjust_item_weight " << id << " weight " << weight << dendl;
+  crush_bucket *b = get_bucket(id);
+  if (IS_ERR(b))
+    return PTR_ERR(b);
+  int changed = 0;
+  list<crush_bucket*> q;
+  q.push_back(b);
+  while (!q.empty()) {
+    b = q.front();
+    q.pop_front();
+    for (unsigned i=0; i<b->size; ++i) {
+      int n = b->items[i];
+      if (n >= 0) {
+       crush_bucket_adjust_item_weight(b, n, weight);
+      } else {
+       crush_bucket *sub = get_bucket(n);
+       if (IS_ERR(sub))
+         continue;
+       q.push_back(sub);
+      }
+    }
+  }
+  return changed;
+}
+
 bool CrushWrapper::check_item_present(int id)
 {
   bool found = false;
index 3b2e6e6979ac3cc00201fd5b71984c5d2cfbf1d7..44414821ef195e2f17ee8d907962043171e1bcd8 100644 (file)
@@ -551,6 +551,11 @@ public:
   }
   void reweight(CephContext *cct);
 
+  int adjust_subtree_weight(CephContext *cct, int id, int weight);
+  int adjust_subtree_weightf(CephContext *cct, int id, float weight) {
+    return adjust_subtree_weight(cct, id, (int)(weight * (float)0x10000));
+  }
+
   /// check if item id is present in the map hierarchy
   bool check_item_present(int id);