From d0658dd3cdf072b2a7c2a1986f8785a697c591ee Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 26 May 2015 15:35:10 +0800 Subject: [PATCH] crushtool: enable check against max_id add an argument "max_id" for "--check-names" to check if any item has an id greater or equal to given "max_id" in crush map. Signed-off-by: Kefu Chai --- src/test/cli/crushtool/check-names.max-id.t | 7 +++++++ src/test/cli/crushtool/help.t | 3 ++- src/tools/crushtool.cc | 8 +++++--- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/test/cli/crushtool/check-names.max-id.t diff --git a/src/test/cli/crushtool/check-names.max-id.t b/src/test/cli/crushtool/check-names.max-id.t new file mode 100644 index 000000000000..2f0d729d5939 --- /dev/null +++ b/src/test/cli/crushtool/check-names.max-id.t @@ -0,0 +1,7 @@ + $ crushtool -i "$TESTDIR/simple.template" --add-item 0 1.0 device0 --loc host host0 --loc cluster cluster0 -o check-names.crushmap > /dev/null + $ crushtool -i check-names.crushmap --add-item 1 1.0 device1 --loc host host0 --loc cluster cluster0 -o check-names.crushmap > /dev/null + $ crushtool -i check-names.crushmap --check-names=2 + $ crushtool -i check-names.crushmap --add-item 2 1.0 device2 --loc host host0 --loc cluster cluster0 -o check-names.crushmap > /dev/null + $ crushtool -i check-names.crushmap --check-names=2 + item id too large: item#2 + $ crushtool -i check-names.crushmap --check-names diff --git a/src/test/cli/crushtool/help.t b/src/test/cli/crushtool/help.t index c2a04a626b1b..0f68ac094d6b 100644 --- a/src/test/cli/crushtool/help.t +++ b/src/test/cli/crushtool/help.t @@ -59,7 +59,8 @@ 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 + --check-names [max_id] + 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 b7b11c4bc2b1..9fe9c7d15815 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -165,7 +165,8 @@ 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 << " --check-names [max_id]\n"; + cout << " 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"; @@ -228,6 +229,7 @@ int main(int argc, const char **argv) bool compile = false; bool decompile = false; bool check_names = false; + int max_id = -1; bool test = false; bool display = false; bool tree = false; @@ -313,7 +315,7 @@ 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)) { + } else if (ceph_argparse_witharg(args, i, &max_id, err, "--check-names", (char*)NULL)) { check_names = true; } else if (ceph_argparse_flag(args, i, "-t", "--test", (char*)NULL)) { test = true; @@ -828,7 +830,7 @@ int main(int argc, const char **argv) } if (check_names) { - if (!tester.check_name_maps()) { + if (!tester.check_name_maps(max_id)) { exit(1); } } -- 2.47.3