]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: optional show-shadow for "crush tree" command
authorxie xingguo <xie.xingguo@zte.com.cn>
Wed, 26 Jul 2017 06:47:07 +0000 (14:47 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Wed, 26 Jul 2017 14:30:04 +0000 (22:30 +0800)
 ./bin/ceph osd crush tree --show-shadow
ID WEIGHT  TYPE NAME
-4 3.00000 root default~ssd
-3 3.00000     host gitbuilder-ceph-rpm-centos7-amd64-basic~ssd
 0 1.00000         osd.0
 1 1.00000         osd.1
 2 1.00000         osd.2
-1 3.00000 root default
-2 3.00000     host gitbuilder-ceph-rpm-centos7-amd64-basic
 0 1.00000         osd.0
 1 1.00000         osd.1
 2 1.00000         osd.2

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/crush/CrushTreeDumper.h
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/mon/MonCommands.h
src/mon/OSDMonitor.cc

index 199b3c39be3ec61f334b56efeb5c4a1ed6089e49..5bfbc14462369064abe66ba1cf07a07a904d4d25 100644 (file)
@@ -71,6 +71,17 @@ namespace CrushTreeDumper {
       crush->find_nonshadow_roots(roots);
       root = roots.begin();
     }
+    explicit Dumper(const CrushWrapper *crush_,
+                    const name_map_t& weight_set_names_,
+                    bool show_shadow)
+      : crush(crush_), weight_set_names(weight_set_names_) {
+      if (show_shadow) {
+        crush->find_roots(roots);
+      } else {
+        crush->find_nonshadow_roots(roots);
+      }
+      root = roots.begin();
+    }
 
     virtual ~Dumper() {}
 
@@ -228,6 +239,10 @@ namespace CrushTreeDumper {
     explicit FormattingDumper(const CrushWrapper *crush,
                              const name_map_t& weight_set_names)
       : Dumper<Formatter>(crush, weight_set_names) {}
+    explicit FormattingDumper(const CrushWrapper *crush,
+                              const name_map_t& weight_set_names,
+                              bool show_shadow)
+      : Dumper<Formatter>(crush, weight_set_names, show_shadow) {}
 
   protected:
     void dump_item(const Item &qi, Formatter *f) override {
index c01856607afdb97cb6536a8bac2b1a34432ac75b..1a35f52e5469e671cb1753faf1c4554fe9a4e2f4 100644 (file)
@@ -2587,6 +2587,11 @@ public:
   explicit CrushTreePlainDumper(const CrushWrapper *crush,
                                const CrushTreeDumper::name_map_t& wsnames)
     : Parent(crush, wsnames) {}
+  explicit CrushTreePlainDumper(const CrushWrapper *crush,
+                                const CrushTreeDumper::name_map_t& wsnames,
+                                bool show_shadow)
+    : Parent(crush, wsnames, show_shadow) {}
+
 
   void dump(TextTable *tbl) {
     tbl->define_column("ID", TextTable::LEFT, TextTable::RIGHT);
@@ -2656,6 +2661,12 @@ public:
     const CrushTreeDumper::name_map_t& wsnames)
     : Parent(crush, wsnames) {}
 
+  explicit CrushTreeFormattingDumper(
+    const CrushWrapper *crush,
+    const CrushTreeDumper::name_map_t& wsnames,
+    bool show_shadow)
+    : Parent(crush, wsnames, show_shadow) {}
+
   void dump(Formatter *f) {
     f->open_array_section("nodes");
     Parent::dump(f);
@@ -2667,16 +2678,18 @@ public:
 
 
 void CrushWrapper::dump_tree(
-  ostream *out, Formatter *f,
-  const CrushTreeDumper::name_map_t& weight_set_names) const
+  ostream *out,
+  Formatter *f,
+  const CrushTreeDumper::name_map_t& weight_set_names,
+  bool show_shadow) const
 {
   if (out) {
     TextTable tbl;
-    CrushTreePlainDumper(this, weight_set_names).dump(&tbl);
+    CrushTreePlainDumper(this, weight_set_names, show_shadow).dump(&tbl);
     *out << tbl;
   }
   if (f) {
-    CrushTreeFormattingDumper(this, weight_set_names).dump(f);
+    CrushTreeFormattingDumper(this, weight_set_names, show_shadow).dump(f);
   }
 }
 
index ec6a9ea85816f1797e34daa96457b8af693dfb4f..02ece73316a66ae9e8ee968c3af16fdd91f91ce6 100644 (file)
@@ -1481,8 +1481,10 @@ public:
   void dump_choose_args(Formatter *f) const;
   void list_rules(Formatter *f) const;
   void list_rules(ostream *ss) const;
-  void dump_tree(ostream *out, Formatter *f,
-                const CrushTreeDumper::name_map_t& ws) const;
+  void dump_tree(ostream *out,
+                 Formatter *f,
+                const CrushTreeDumper::name_map_t& ws,
+                 bool show_shadow = false) const;
   void dump_tree(ostream *out, Formatter *f) {
     dump_tree(out, f, CrushTreeDumper::name_map_t());
   }
index 41e3f79f1175a7e6f3ccb170ae50183b91d8f929..e90e1da9b6e7fe7a6ee4d5349018d15bdf686e2c 100644 (file)
@@ -632,7 +632,8 @@ COMMAND("osd crush rule create-erasure " \
 COMMAND("osd crush rule rm " \
        "name=name,type=CephString,goodchars=[A-Za-z0-9-_.] ",  \
        "remove crush rule <name>", "osd", "rw", "cli,rest")
-COMMAND("osd crush tree",
+COMMAND("osd crush tree "
+        "name=shadow,type=CephChoices,strings=--show-shadow,req=false", \
        "dump crush buckets and items in a tree view",
        "osd", "r", "cli,rest")
 COMMAND("osd crush class create " \
index fd72cd67d1e47588304937d8e8af8946b922ee3f..f802c29a5ed8d04a0450fb00f536cdb588eea962 100644 (file)
@@ -5113,13 +5113,22 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
     rs << "\n";
     rdata.append(rs.str());
   } else if (prefix == "osd crush tree") {
+    string shadow;
+    cmd_getval(g_ceph_context, cmdmap, "shadow", shadow);
+    bool show_shadow = shadow == "--show-shadow";
     boost::scoped_ptr<Formatter> f(Formatter::create(format));
     if (f) {
-      osdmap.crush->dump_tree(nullptr, f.get(), osdmap.get_pool_names());
+      osdmap.crush->dump_tree(nullptr,
+                              f.get(),
+                              osdmap.get_pool_names(),
+                              show_shadow);
       f->flush(rdata);
     } else {
       ostringstream ss;
-      osdmap.crush->dump_tree(&ss, nullptr, osdmap.get_pool_names());
+      osdmap.crush->dump_tree(&ss,
+                              nullptr,
+                              osdmap.get_pool_names(),
+                              show_shadow);
       rdata.append(ss.str());
     }
   } else if (prefix == "osd crush class ls") {