From ff29a7f9dd21505c681881e609183aed9ac3250e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 26 May 2015 12:08:36 +0800 Subject: [PATCH] crushtool: add the "--check-names" option * so one is able to verify that the "ceph osd tree" won't chock on the new crush map because of dangling name/type references Signed-off-by: Kefu Chai (cherry picked from commit d6b46d4c7b722945ce24ac2930381a109b1e3dda) --- .../crushtool/check-names.empty.crushmap.txt | 11 ++++++++++ src/test/cli/crushtool/check-names.empty.t | 4 ++++ src/test/cli/crushtool/help.t | 4 ++++ src/tools/crushtool.cc | 20 ++++++++++++++++--- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/test/cli/crushtool/check-names.empty.crushmap.txt create mode 100644 src/test/cli/crushtool/check-names.empty.t diff --git a/src/test/cli/crushtool/check-names.empty.crushmap.txt b/src/test/cli/crushtool/check-names.empty.crushmap.txt new file mode 100644 index 0000000000000..6ba00cda997ef --- /dev/null +++ b/src/test/cli/crushtool/check-names.empty.crushmap.txt @@ -0,0 +1,11 @@ +# begin crush map + +# devices + +# types + +# buckets + +# rules + +# end crush map diff --git a/src/test/cli/crushtool/check-names.empty.t b/src/test/cli/crushtool/check-names.empty.t new file mode 100644 index 0000000000000..9e30790ca316d --- /dev/null +++ b/src/test/cli/crushtool/check-names.empty.t @@ -0,0 +1,4 @@ + $ crushtool -c "$TESTDIR/check-names.empty.crushmap.txt" -o "$TESTDIR/check-names.empty.crushmap" + $ crushtool -i "$TESTDIR/check-names.empty.crushmap" --check-names + unknown type name: item#0 + $ rm -f "$TESTDIR/check-names.empty.crushmap" diff --git a/src/test/cli/crushtool/help.t b/src/test/cli/crushtool/help.t index 7d549195206bd..784c6275c4fba 100644 --- a/src/test/cli/crushtool/help.t +++ b/src/test/cli/crushtool/help.t @@ -30,6 +30,10 @@ reweight a given item (and adjust ancestor weights as needed) -i mapfn --reweight recalculate all bucket weights + + Options for the display/test stage + + --check-names check if any item is referencing an unknown name/type -i mapfn --show-location id show location for given device id --show-utilization show OSD usage diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index f332186fa88f3..c8cf24ce632ac 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -135,6 +135,10 @@ void usage() cout << " reweight a given item (and adjust ancestor\n" << " weights as needed)\n"; cout << " -i mapfn --reweight recalculate all bucket weights\n"; + cout << "\n"; + cout << "Options for the display/test stage\n"; + cout << "\n"; + cout << " --check-names 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"; cout << " --show-utilization show OSD usage\n"; @@ -191,6 +195,7 @@ int main(int argc, const char **argv) std::string infn, srcfn, outfn, add_name, remove_name, reweight_name; bool compile = false; bool decompile = false; + bool check_names = false; bool test = false; bool display = false; bool tree = false; @@ -276,6 +281,8 @@ int main(int argc, const char **argv) } else if (ceph_argparse_witharg(args, i, &val, "-c", "--compile", (char*)NULL)) { srcfn = val; compile = true; + } else if (ceph_argparse_flag(args, i, "--check-names", (char*)NULL)) { + check_names = true; } else if (ceph_argparse_flag(args, i, "-t", "--test", (char*)NULL)) { test = true; } else if (ceph_argparse_withint(args, i, &full_location, &err, "--show-location", (char*)NULL)) { @@ -462,7 +469,7 @@ int main(int argc, const char **argv) } } - if (test && !display && !write_to_file) { + if (test && !check_name && !display && !write_to_file) { cerr << "WARNING: no output selected; use --output-csv or --show-X" << std::endl; } @@ -470,7 +477,7 @@ int main(int argc, const char **argv) cerr << "cannot specify more than one of compile, decompile, and build" << std::endl; exit(EXIT_FAILURE); } - if (!compile && !decompile && !build && !test && !reweight && !adjust && !tree && + if (!check_names && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && add_item < 0 && full_location < 0 && remove_name.empty() && reweight_name.empty()) { cerr << "no action specified; -h for help" << std::endl; @@ -785,7 +792,8 @@ int main(int argc, const char **argv) crush.set_allowed_bucket_algs(allowed_bucket_algs); modified = true; } - if (modified) { + + if (modified) { crush.finalize(); if (outfn.empty()) { @@ -803,6 +811,12 @@ int main(int argc, const char **argv) } } + if (check_names) { + if (!tester.check_name_maps()) { + exit(1); + } + } + if (test) { if (tester.get_output_utilization_all() || tester.get_output_utilization()) -- 2.39.5