From 46e0a2c2fb4cc490418e227242da504d0a59e9cb Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Wed, 1 Mar 2017 15:16:28 +0100 Subject: [PATCH] crush: add --dump to crushtool So it can display the same as ceph osd crush dump from a file instead of a live cluster. The default format is json-pretty and can be modified via -f or --format in the same way as the ceph cli. Signed-off-by: Loic Dachary --- src/test/cli/crushtool/help.t | 4 ++++ src/tools/crushtool.cc | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/test/cli/crushtool/help.t b/src/test/cli/crushtool/help.t index 1c9c342ec791..65323c334823 100755 --- a/src/test/cli/crushtool/help.t +++ b/src/test/cli/crushtool/help.t @@ -61,6 +61,10 @@ Options for the display/test stage + -f --format the format of --dump, defaults to json-pretty + can be one of json, json-pretty, xml, xml-pretty, + table, table-kv, html, html-pretty + --dump dump the crush map --tree print map summary as a tree --check [max_id] check if any item is referencing an unknown name/type -i mapfn --show-location id diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index 201147392d18..12eff342fdd9 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -25,6 +25,7 @@ #include "common/debug.h" #include "common/errno.h" #include "common/config.h" +#include "common/Formatter.h" #include "common/ceph_argparse.h" #include "include/stringify.h" @@ -168,6 +169,10 @@ void usage() cout << "\n"; cout << "Options for the display/test stage\n"; cout << "\n"; + cout << " -f --format the format of --dump, defaults to json-pretty\n"; + cout << " can be one of json, json-pretty, xml, xml-pretty,\n"; + 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 << " --check [max_id] check if any item is referencing an unknown name/type\n"; cout << " -i mapfn --show-location id\n"; @@ -237,6 +242,8 @@ int main(int argc, const char **argv) bool test = false; bool display = false; bool tree = false; + string dump_format = "json-pretty"; + bool dump = false; int full_location = -1; bool write_to_file = false; int verbose = 0; @@ -304,6 +311,10 @@ int main(int argc, const char **argv) verbose += 1; } else if (ceph_argparse_flag(args, i, "--tree", (char*)NULL)) { tree = true; + } 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)) { + dump = true; } else if (ceph_argparse_flag(args, i, "--show_utilization", (char*)NULL)) { display = true; tester.set_output_utilization(true); @@ -536,7 +547,7 @@ int main(int argc, const char **argv) cerr << "cannot specify more than one of compile, decompile, and build" << std::endl; return EXIT_FAILURE; } - if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && + if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && !dump && add_item < 0 && full_location < 0 && remove_name.empty() && reweight_name.empty()) { cerr << "no action specified; -h for help" << std::endl; @@ -849,6 +860,15 @@ int main(int argc, const char **argv) crush.dump_tree(&cout, NULL); } + if (dump) { + boost::scoped_ptr f(Formatter::create(dump_format, "json-pretty", "json-pretty")); + f->open_object_section("crush_map"); + crush.dump(f.get()); + f->close_section(); + f->flush(cout); + cout << "\n"; + } + if (decompile) { CrushCompiler cc(crush, cerr, verbose); if (!outfn.empty()) { -- 2.47.3