return true;
}
-int CrushWrapper::remove_root(int item, bool unused)
+int CrushWrapper::remove_root(int item)
{
- if (unused && _bucket_is_in_use(item))
- return 0;
-
crush_bucket *b = get_bucket(item);
if (IS_ERR(b)) {
// should be idempotent
for (unsigned n = 0; n < b->size; n++) {
if (b->items[n] >= 0)
continue;
- int r = remove_root(b->items[n], unused);
+ int r = remove_root(b->items[n]);
if (r < 0)
return r;
}
return 0;
}
-int CrushWrapper::trim_roots_with_class(bool unused)
+int CrushWrapper::trim_roots_with_class()
{
set<int> roots;
find_shadow_roots(roots);
for (auto &r : roots) {
if (r >= 0)
continue;
- int res = remove_root(r, unused);
+ int res = remove_root(r);
if (res)
return res;
}
{
std::map<int32_t, map<int32_t, int32_t> > old_class_bucket = class_bucket;
cleanup_dead_classes();
- int r = trim_roots_with_class(false);
+ int r = trim_roots_with_class();
if (r < 0)
return r;
class_bucket.clear();
* 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_root(int item, bool unused);
+ int remove_root(int item);
/**
* remove all instances of an item nested beneath a certain point from the map
void cleanup_dead_classes();
int rebuild_roots_with_classes();
/* remove unused roots generated for class devices */
- int trim_roots_with_class(bool unused);
+ int trim_roots_with_class();
void start_choose_profile() {
free(crush->choose_tries);
}
}
-TEST(CrushWrapper, remove_unused_root) {
+TEST(CrushWrapper, remove_root) {
CrushWrapper c;
c.create();
c.set_type_name(1, "host");
ASSERT_TRUE(c.name_exists("default"));
ASSERT_TRUE(c.name_exists("r11"));
ASSERT_TRUE(c.name_exists("r12"));
- ASSERT_EQ(c.remove_root(c.get_item_id("default"), true), 0);
+ ASSERT_EQ(c.remove_root(c.get_item_id("default")), 0);
ASSERT_FALSE(c.name_exists("default"));
- ASSERT_TRUE(c.name_exists("r11"));
+ ASSERT_FALSE(c.name_exists("r11"));
ASSERT_FALSE(c.name_exists("r12"));
}
ASSERT_TRUE(c.name_exists("default"));
ASSERT_TRUE(c.name_exists("default~ssd"));
- 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(true); // do nothing because still in use
+ c.trim_roots_with_class();
ASSERT_TRUE(c.name_exists("default"));
ASSERT_FALSE(c.name_exists("default~ssd"));
}