From: Loic Dachary Date: Sat, 18 Feb 2017 22:33:39 +0000 (+0100) Subject: crush: implement {populate,cleanup}_classes X-Git-Tag: v12.0.1~135^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9cf9d814b309313d3af22f6571b117ccfd1eb85d;p=ceph.git crush: implement {populate,cleanup}_classes Refs: http://tracker.ceph.com/issues/18943 Signed-off-by: Loic Dachary --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 0e498d6555d..81e08d62b76 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1010,6 +1010,30 @@ int CrushWrapper::get_immediate_parent_id(int id, int *parent) return -ENOENT; } +int CrushWrapper::populate_classes() +{ + set roots; + find_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); + if (res < 0) + return res; + } + } + return 0; +} + +int CrushWrapper::cleanup_classes() +{ + return trim_roots_with_class(); +} + int CrushWrapper::trim_roots_with_class() { set takes; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 7de67b94db0..f81d2b17370 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -1089,8 +1089,11 @@ 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 cleanup_classes(); + void start_choose_profile() { free(crush->choose_tries); /* diff --git a/src/test/crush/CrushWrapper.cc b/src/test/crush/CrushWrapper.cc index ee774e9feef..dd846e7d3fb 100644 --- a/src/test/crush/CrushWrapper.cc +++ b/src/test/crush/CrushWrapper.cc @@ -1070,6 +1070,29 @@ TEST(CrushWrapper, split_id_class) { ASSERT_EQ(-1, retrieved_class_id); } +TEST(CrushWrapper, populate_and_cleanup_classes) { + CrushWrapper c; + c.create(); + c.set_type_name(1, "root"); + + int weight = 1; + map loc; + loc["root"] = "default"; + + int item = 1; + c.insert_item(g_ceph_context, item, weight, "osd.1", loc); + int class_id = c.get_or_create_class_id("ssd"); + c.class_map[item] = class_id; + + ASSERT_EQ(c.populate_classes(), 0); + + ASSERT_TRUE(c.name_exists("default~ssd")); + + c.class_bucket.clear(); + ASSERT_EQ(c.cleanup_classes(), 0); + ASSERT_FALSE(c.name_exists("default~ssd")); +} + int main(int argc, char **argv) { vector args; argv_to_vec(argc, (const char **)argv, args);