From 397a2987a7a414d9d7f53d7899fdad07ab78456f Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 26 Jul 2017 20:07:53 +0800 Subject: [PATCH] crush: implement find_shadow_roots Signed-off-by: xie xingguo --- src/crush/CrushWrapper.cc | 8 ++------ src/crush/CrushWrapper.h | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 8b7b758110044..2e5bfac6e1f8c 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1393,12 +1393,10 @@ bool CrushWrapper::class_is_in_use(int class_id, ostream *ss) int CrushWrapper::populate_classes() { set 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 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; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 1d216b7824229..f69357efa8aa4 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -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& roots) const; + + /** + * find tree roots that contain shadow (device class) items only + */ + void find_shadow_roots(set& roots) const { + set 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 * -- 2.39.5