]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushTester: allow testing by ruleset
authorSage Weil <sage@redhat.com>
Fri, 18 Sep 2015 13:40:13 +0000 (09:40 -0400)
committerSage Weil <sage@redhat.com>
Fri, 18 Sep 2015 13:40:13 +0000 (09:40 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/crush/CrushTester.cc
src/crush/CrushTester.h
src/tools/crushtool.cc

index 209d03a9f10193629e9c519b5434ef9c630caa7f..086383385b12099691b79bb9fd2d481588ba9f43 100644 (file)
@@ -355,7 +355,9 @@ void CrushTester::write_integer_indexed_scalar_data_string(vector<string> &dst,
   dst.push_back( data_buffer.str() );
 }
 
-int CrushTester::test_with_crushtool(const char *crushtool_cmd, int max_id, int timeout)
+int CrushTester::test_with_crushtool(const char *crushtool_cmd,
+                                    int max_id, int timeout,
+                                    int ruleset)
 {
   SubProcessTimed crushtool(crushtool_cmd, true, false, true, timeout);
   string opt_max_id = boost::lexical_cast<string>(max_id);
@@ -365,6 +367,12 @@ int CrushTester::test_with_crushtool(const char *crushtool_cmd, int max_id, int
     "--min-x", "1",
     "--max-x", "50",
     NULL);
+  if (ruleset >= 0) {
+    crushtool.add_cmd_args(
+      "--ruleset",
+      stringify(ruleset).c_str(),
+      NULL);
+  }
   int ret = crushtool.spawn();
   if (ret != 0) {
     err << "failed run crushtool: " << crushtool.err();
@@ -491,6 +499,10 @@ int CrushTester::test()
         err << "rule " << r << " dne" << std::endl;
       continue;
     }
+    if (ruleset >= 0 &&
+       crush.get_rule_mask_ruleset(r) != ruleset) {
+      continue;
+    }
     int minr = min_rep, maxr = max_rep;
     if (min_rep < 0 || max_rep < 0) {
       minr = crush.get_rule_mask_min_size(r);
index ed14761462ac903df133e13f76b80d4d60091c62..2f1a2c60e753737ece6ac139d95cde94da9c1f47 100644 (file)
@@ -15,6 +15,7 @@ class CrushTester {
 
   map<int, int> device_weight;
   int min_rule, max_rule;
+  int ruleset;
   int min_x, max_x;
   int min_rep, max_rep;
 
@@ -168,6 +169,7 @@ public:
   CrushTester(CrushWrapper& c, ostream& eo)
     : crush(c), err(eo),
       min_rule(-1), max_rule(-1),
+      ruleset(-1),
       min_x(-1), max_x(-1),
       min_rep(-1), max_rep(-1),
       num_batches(1),
@@ -333,6 +335,10 @@ public:
     min_rule = max_rule = rule;
   }
 
+  void set_ruleset(int rs) {
+    ruleset = rs;
+  }
+
   /**
    * check if any bucket/nodes is referencing an unknown name or type
    * @param max_id rejects any non-bucket items with id less than this number,
@@ -344,7 +350,8 @@ public:
   int test();
   int test_with_crushtool(const char *crushtool_cmd = "crushtool",
                          int max_id = -1,
-                         int timeout = 0);
+                         int timeout = 0,
+                         int ruleset = -1);
 };
 
 #endif
index c7ed691062aeecea45b1373af5976c8a569c11b9..532ffe1aa24b6368308a053d7de269bb265910ab 100644 (file)
@@ -170,7 +170,7 @@ void usage()
   cout << "                         show location for given device id\n";
   cout << "   -i mapfn --test       test a range of inputs on the map\n";
   cout << "      [--min-x x] [--max-x x] [--x x]\n";
-  cout << "      [--min-rule r] [--max-rule r] [--rule r]\n";
+  cout << "      [--min-rule r] [--max-rule r] [--rule r] [--ruleset rs]\n";
   cout << "      [--num-rep n]\n";
   cout << "      [--batches b]      split the CRUSH mapping into b > 1 rounds\n";
   cout << "      [--weight|-w devno weight]\n";
@@ -465,6 +465,12 @@ int main(int argc, const char **argv)
        exit(EXIT_FAILURE);
       }
       tester.set_rule(x);
+    } else if (ceph_argparse_witharg(args, i, &x, err, "--ruleset", (char*)NULL)) {
+      if (!err.str().empty()) {
+       cerr << err.str() << std::endl;
+       exit(EXIT_FAILURE);
+      }
+      tester.set_ruleset(x);
     } else if (ceph_argparse_witharg(args, i, &x, err, "--batches", (char*)NULL)) {
       if (!err.str().empty()) {
        cerr << err.str() << std::endl;