From: Sage Weil Date: Sun, 11 May 2014 22:35:11 +0000 (-0700) Subject: crush: add adjust_subtree_weight() X-Git-Tag: v0.83~117^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2916148f54edeb8a6c9a342cdde646beee6df5b7;p=ceph.git crush: add adjust_subtree_weight() Adjust the weight for all (leaf) items beneath a subtree. Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index c0eabe37f51a..5d2067750551 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -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 q; + q.push_back(b); + while (!q.empty()) { + b = q.front(); + q.pop_front(); + for (unsigned i=0; isize; ++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; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 3b2e6e6979ac..44414821ef19 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -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);