]> 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>
Fri, 10 Jul 2015 07:40:00 +0000 (15:40 +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>
(cherry picked from commit d6b46d4c7b722945ce24ac2930381a109b1e3dda)

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 7d549195206bdd2abcfbf7491c094e6c10d6d1e7..784c6275c4fba72ae736e7054c2a1d378f9305fb 100644 (file)
                            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
index f332186fa88f3923f4e5fc09f648aa8ebac7e4e1..c8cf24ce632aca4976d5cc70816e0246aab059ce 100644 (file)
@@ -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())