]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/crushtool: add new Option --bucket-tree to show bucket map tree
authorlinbing <hawkerous@gmail.com>
Wed, 20 Dec 2017 00:52:12 +0000 (08:52 +0800)
committerGreg Farnum <gfarnum@redhat.com>
Wed, 17 Apr 2019 15:28:00 +0000 (08:28 -0700)
Signed-off-by: linbing <linbing@t2cloud.net>
Update the crushtool cli test template for new options.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/test/cli/crushtool/help.t
src/tools/crushtool.cc

index 77460bd2c68e4848c994b1051b7db7e69064436d..f233b9ad49e174c9732b1a2b75cd0aadeafcc2e8 100644 (file)
@@ -84,6 +84,8 @@
                            table, table-kv, html, html-pretty
      --dump                dump the crush map
      --tree                print map summary as a tree
+     --bucket-tree         print bucket map summary as a tree
+     --bucket-name         specify bucket bucket name for bucket-tree
      --check [max_id]      check if any item is referencing an unknown name/type
      -i mapfn --show-location id
                            show location for given device id
index 07b8b79a083a5ede20442ca3289592f48efbba0d..a4defb04890cc325e53a4a7ca5a19ae13a351fd7 100644 (file)
@@ -192,6 +192,8 @@ void usage()
   cout << "                         table, table-kv, html, html-pretty\n";
   cout << "   --dump                dump the crush map\n";
   cout << "   --tree                print map summary as a tree\n";
+  cout << "   --bucket-tree         print bucket map summary as a tree\n";
+  cout << "   --bucket-name         specify bucket bucket name for bucket-tree\n";
   cout << "   --check [max_id]      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";
@@ -374,7 +376,9 @@ int main(int argc, const char **argv)
   }
 
   const char *me = argv[0];
-  std::string infn, srcfn, outfn, add_name, add_type, remove_name, reweight_name;
+
+  std::string infn, srcfn, outfn, add_name, add_type, remove_name,
+    reweight_name, bucket_name;
   std::string move_name;
   bool compile = false;
   bool decompile = false;
@@ -383,6 +387,7 @@ int main(int argc, const char **argv)
   bool test = false;
   bool display = false;
   bool tree = false;
+  bool bucket_tree = false;
   string dump_format = "json-pretty";
   bool dump = false;
   int full_location = -1;
@@ -496,6 +501,10 @@ int main(int argc, const char **argv)
       i = args.erase(i);
     } else if (ceph_argparse_flag(args, i, "--tree", (char*)NULL)) {
       tree = true;
+    } else if (ceph_argparse_flag(args, i, "--bucket-tree", (char*)NULL)) {
+      bucket_tree = true;
+    } else if (ceph_argparse_witharg(args, i, &val, "-b", "--bucket-name", (char*)NULL)) {
+      bucket_name = val;
     } else if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL)) {
       dump_format = val;
     } else if (ceph_argparse_flag(args, i, "--dump", (char*)NULL)) {
@@ -827,8 +836,10 @@ int main(int argc, const char **argv)
   }
   if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && !dump &&
       add_item < 0 && !add_bucket && !move_item && !add_rule && !del_rule && full_location < 0 &&
+      !bucket_tree &&
       !reclassify && !rebuild_class_roots &&
       compare.empty() &&
+
       remove_name.empty() && reweight_name.empty()) {
     cerr << "no action specified; -h for help" << std::endl;
     return EXIT_FAILURE;
@@ -1210,6 +1221,19 @@ int main(int argc, const char **argv)
     crush.dump_tree(&cout, NULL, {}, true);
   }
 
+  if (bucket_tree) {
+    if (bucket_name.empty()) {
+      cerr << ": error bucket_name is empty" << std::endl;
+    }
+    else {
+      set<int> osd_ids;
+      crush.get_leaves(bucket_name.c_str(), &osd_ids);
+      for (auto &id : osd_ids) {
+        cout << "osd." << id << std::endl;
+      }
+    }
+  }
+
   if (dump) {
     boost::scoped_ptr<Formatter> f(Formatter::create(dump_format, "json-pretty", "json-pretty"));
     f->open_object_section("crush_map");