From: xie xingguo Date: Tue, 11 Jul 2017 08:07:43 +0000 (+0800) Subject: crush: reuse find_roots to implement find_nonshadow_roots X-Git-Tag: v12.1.2~68^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1b87784f493e6c3235d6239474e6cfafa746d5ce;p=ceph.git crush: reuse find_roots to implement find_nonshadow_roots to reduce code redundance... Signed-off-by: xie xingguo --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 11659ccf4408..9830fedb4097 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -315,21 +315,6 @@ void CrushWrapper::find_roots(set& roots) const } } -void CrushWrapper::find_nonshadow_roots(set& 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) diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 459f0b59dc28..1d216b782422 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -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& roots) const; + void find_nonshadow_roots(set& roots) const { + set 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