]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crushtool: add the "--check-names" option
authorKefu Chai <kchai@redhat.com>
Tue, 26 May 2015 04:08:36 +0000 (12:08 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 31 May 2015 17:24:54 +0000 (01:24 +0800)
* 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 <kchai@redhat.com>
src/test/cli/crushtool/check-names.empty.crushmap.txt [new file with mode: 0644]
src/test/cli/crushtool/check-names.empty.t [new file with mode: 0644]
src/test/cli/crushtool/help.t
src/tools/crushtool.cc

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 (file)
index 0000000..6ba00cd
--- /dev/null
@@ -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 (file)
index 0000000..9e30790
--- /dev/null
@@ -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"
index cd7d4a7685421258c5c9a5b393517cbbc2fd51f7..c2a04a626b1b10e67d7aed4407a67150399a522e 100644 (file)
@@ -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
index 5e53f0a869fb9d3d6f16d36007f8983c03b955fe..b7b11c4bc2b191b4f680192ce7f6b4ee1c6ec603 100644 (file)
@@ -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())