From: linbing Date: Wed, 20 Dec 2017 00:52:12 +0000 (+0800) Subject: tools/crushtool: add new Option --bucket-tree to show bucket map tree X-Git-Tag: v15.1.0~2893^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ead88f2460dd92b7d76db52fb8a03c33ae94a210;p=ceph.git tools/crushtool: add new Option --bucket-tree to show bucket map tree Signed-off-by: linbing Update the crushtool cli test template for new options. Signed-off-by: Greg Farnum --- diff --git a/src/test/cli/crushtool/help.t b/src/test/cli/crushtool/help.t index 77460bd2c68e..f233b9ad49e1 100644 --- a/src/test/cli/crushtool/help.t +++ b/src/test/cli/crushtool/help.t @@ -84,6 +84,8 @@ table, table-kv, html, html-pretty --dump dump the crush map --tree print map summary as a tree + --bucket-tree print bucket map summary as a tree + --bucket-name specify bucket bucket name for bucket-tree --check [max_id] check if any item is referencing an unknown name/type -i mapfn --show-location id show location for given device id diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index 07b8b79a083a..a4defb04890c 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -192,6 +192,8 @@ void usage() cout << " table, table-kv, html, html-pretty\n"; cout << " --dump dump the crush map\n"; cout << " --tree print map summary as a tree\n"; + cout << " --bucket-tree print bucket map summary as a tree\n"; + cout << " --bucket-name specify bucket bucket name for bucket-tree\n"; cout << " --check [max_id] check if any item is referencing an unknown name/type\n"; cout << " -i mapfn --show-location id\n"; cout << " show location for given device id\n"; @@ -374,7 +376,9 @@ int main(int argc, const char **argv) } const char *me = argv[0]; - std::string infn, srcfn, outfn, add_name, add_type, remove_name, reweight_name; + + std::string infn, srcfn, outfn, add_name, add_type, remove_name, + reweight_name, bucket_name; std::string move_name; bool compile = false; bool decompile = false; @@ -383,6 +387,7 @@ int main(int argc, const char **argv) bool test = false; bool display = false; bool tree = false; + bool bucket_tree = false; string dump_format = "json-pretty"; bool dump = false; int full_location = -1; @@ -496,6 +501,10 @@ int main(int argc, const char **argv) i = args.erase(i); } else if (ceph_argparse_flag(args, i, "--tree", (char*)NULL)) { tree = true; + } else if (ceph_argparse_flag(args, i, "--bucket-tree", (char*)NULL)) { + bucket_tree = true; + } else if (ceph_argparse_witharg(args, i, &val, "-b", "--bucket-name", (char*)NULL)) { + bucket_name = val; } else if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL)) { dump_format = val; } else if (ceph_argparse_flag(args, i, "--dump", (char*)NULL)) { @@ -827,8 +836,10 @@ int main(int argc, const char **argv) } if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && !dump && add_item < 0 && !add_bucket && !move_item && !add_rule && !del_rule && full_location < 0 && + !bucket_tree && !reclassify && !rebuild_class_roots && compare.empty() && + remove_name.empty() && reweight_name.empty()) { cerr << "no action specified; -h for help" << std::endl; return EXIT_FAILURE; @@ -1210,6 +1221,19 @@ int main(int argc, const char **argv) crush.dump_tree(&cout, NULL, {}, true); } + if (bucket_tree) { + if (bucket_name.empty()) { + cerr << ": error bucket_name is empty" << std::endl; + } + else { + set osd_ids; + crush.get_leaves(bucket_name.c_str(), &osd_ids); + for (auto &id : osd_ids) { + cout << "osd." << id << std::endl; + } + } + } + if (dump) { boost::scoped_ptr f(Formatter::create(dump_format, "json-pretty", "json-pretty")); f->open_object_section("crush_map");