]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushWrapper: fix crush tree json dumper 23979/head
authorsongshuangyang <songshuangyang@baidu.com>
Fri, 14 Sep 2018 06:53:17 +0000 (14:53 +0800)
committersongshuangyang <songshuangyang@baidu.com>
Fri, 14 Sep 2018 06:53:17 +0000 (14:53 +0800)
    The output json string is invalid for 'osd crush tree --format=json'
    command. It contains a array of 'nodes' and a array of 'stray', but
    not in a json object, and the stray array was not implemented.
    Applications which depends on the output of the above MonCommand will
    occur json parse error.

Signed-off-by: Oshyn Song <dualyangsong@gmail.com>
src/crush/CrushWrapper.cc
src/mon/OSDMonitor.cc

index c5be83571371f643c17ae1ce9f9a1de3ed1cede8..5afb36c3c5c7ea601b71866e4df2cc2c707999d4 100644 (file)
@@ -3131,7 +3131,19 @@ public:
     f->open_array_section("nodes");
     Parent::dump(f);
     f->close_section();
+
+    // There is no stray bucket whose id is a negative number, so just get
+    // the max_id and iterate from 0 to max_id to dump stray osds.
     f->open_array_section("stray");
+    int32_t max_id = -1;
+    if (!crush->name_map.empty()) {
+      max_id = crush->name_map.rbegin()->first;
+    }
+    for (int32_t i = 0; i <= max_id; i++) {
+      if (crush->item_exists(i) && !is_touched(i) && should_dump(i)) {
+        dump_item(CrushTreeDumper::Item(i, 0, 0, 0), f);
+      }
+    }
     f->close_section();
   }
 };
index 8aeb565329198b3f6dad4c7af48bd1031694674a..080567070ccc503ae5ee0fc4c393cbdb9d410811 100644 (file)
@@ -5437,10 +5437,12 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
     bool show_shadow = shadow == "--show-shadow";
     boost::scoped_ptr<Formatter> f(Formatter::create(format));
     if (f) {
+      f->open_object_section("crush_tree");
       osdmap.crush->dump_tree(nullptr,
                               f.get(),
                               osdmap.get_pool_names(),
                               show_shadow);
+      f->close_section();
       f->flush(rdata);
     } else {
       ostringstream ss;