From 1b87784f493e6c3235d6239474e6cfafa746d5ce Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Tue, 11 Jul 2017 16:07:43 +0800 Subject: [PATCH] crush: reuse find_roots to implement find_nonshadow_roots to reduce code redundance... Signed-off-by: xie xingguo --- src/crush/CrushWrapper.cc | 15 --------------- src/crush/CrushWrapper.h | 14 +++++++++++++- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 11659ccf440..9830fedb409 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 459f0b59dc2..1d216b78242 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 -- 2.47.3