From: Kefu Chai Date: Tue, 26 May 2015 04:08:36 +0000 (+0800) Subject: crushtool: add the "--check-names" option X-Git-Tag: v9.0.3~196^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d6b46d4c7b722945ce24ac2930381a109b1e3dda;p=ceph.git 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 --- 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 000000000000..6ba00cda997e --- /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 000000000000..9e30790ca316 --- /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 cd7d4a768542..c2a04a626b1b 100644 --- a/src/test/cli/crushtool/help.t +++ b/src/test/cli/crushtool/help.t @@ -59,6 +59,7 @@ Options for the display/test stage --tree print map summary as a tree + --check-names check if any item is referencing an unknown name/type -i mapfn --show-location id show location for given device id -i mapfn --test test a range of inputs on the map diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index 5e53f0a869fb..b7b11c4bc2b1 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -165,6 +165,7 @@ void usage() cout << "Options for the display/test stage\n"; cout << "\n"; cout << " --tree print map summary as a tree\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 << " -i mapfn --test test a range of inputs on the map\n"; @@ -226,6 +227,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; @@ -311,6 +313,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_witharg(args, i, &full_location, err, "--show-location", (char*)NULL)) { @@ -497,7 +501,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; } @@ -505,7 +509,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; @@ -823,6 +827,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())