diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index a460e9ff4f6..d065fccd009 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -259,9 +259,9 @@ bool CrushWrapper::_maybe_remove_last_instance(CephContext *cct, int item, bool return true; } -int CrushWrapper::remove_unused_root(int item) +int CrushWrapper::remove_root(int item, bool unused) { - if (_bucket_is_in_use(item)) + if (unused && _bucket_is_in_use(item)) return 0; crush_bucket *b = get_bucket(item); @@ -271,7 +271,7 @@ int CrushWrapper::remove_unused_root(int item) for (unsigned n = 0; n < b->size; n++) { if (b->items[n] >= 0) continue; - int r = remove_unused_root(b->items[n]); + int r = remove_root(b->items[n], unused); if (r < 0) return r; } @@ -1035,10 +1035,10 @@ int CrushWrapper::populate_classes() int CrushWrapper::cleanup_classes() { - return trim_roots_with_class(); + return trim_roots_with_class(true); } -int CrushWrapper::trim_roots_with_class() +int CrushWrapper::trim_roots_with_class(bool unused) { set roots; find_roots(roots); @@ -1047,7 +1047,7 @@ int CrushWrapper::trim_roots_with_class() continue; if (!id_has_class(r)) continue; - int res = remove_unused_root(r); + int res = remove_root(r, unused); if (res) return res; } diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 49ef1b89f1f..81044aebdfc 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -691,9 +691,10 @@ public: * when a bucket is in use. * * @param item id to remove + * @param unused true if only unused items should be removed * @return 0 on success, negative on error */ - int remove_unused_root(int item); + int remove_root(int item, bool unused); /** * remove all instances of an item nested beneath a certain point from the map @@ -1091,7 +1092,7 @@ public: int device_class_clone(int original, int device_class, int *clone); int populate_classes(); /* remove unused roots generated for class devices */ - int trim_roots_with_class(); + int trim_roots_with_class(bool unused); int cleanup_classes(); void start_choose_profile() { diff --git a/src/test/crush/CrushWrapper.cc b/src/test/crush/CrushWrapper.cc index 6e535ff6089..ac27c719e86 100644 --- a/src/test/crush/CrushWrapper.cc +++ b/src/test/crush/CrushWrapper.cc @@ -966,7 +966,7 @@ TEST(CrushWrapper, remove_unused_root) { ASSERT_TRUE(c.name_exists("default")); ASSERT_TRUE(c.name_exists("r11")); ASSERT_TRUE(c.name_exists("r12")); - ASSERT_EQ(c.remove_unused_root(c.get_item_id("default")), 0); + ASSERT_EQ(c.remove_root(c.get_item_id("default"), true), 0); ASSERT_FALSE(c.name_exists("default")); ASSERT_TRUE(c.name_exists("r11")); ASSERT_FALSE(c.name_exists("r12")); @@ -993,11 +993,11 @@ TEST(CrushWrapper, trim_roots_with_class) { ASSERT_TRUE(c.name_exists("default")); ASSERT_TRUE(c.name_exists("default~ssd")); - c.trim_roots_with_class(); // do nothing because still in use + c.trim_roots_with_class(true); // do nothing because still in use ASSERT_TRUE(c.name_exists("default")); ASSERT_TRUE(c.name_exists("default~ssd")); c.class_bucket.clear(); - c.trim_roots_with_class(); // do nothing because still in use + c.trim_roots_with_class(true); // do nothing because still in use ASSERT_TRUE(c.name_exists("default")); ASSERT_FALSE(c.name_exists("default~ssd")); }