From: songshuangyang Date: Fri, 14 Sep 2018 06:53:17 +0000 (+0800) Subject: crush/CrushWrapper: fix crush tree json dumper X-Git-Tag: v14.0.1~217^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=35c0d1f45cd676f201d4031cb8f447f7ea6aee0e;p=ceph.git crush/CrushWrapper: fix crush tree json dumper 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 --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index c5be83571371f..5afb36c3c5c7e 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -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(); } }; diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 8aeb565329198..080567070ccc5 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -5437,10 +5437,12 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) bool show_shadow = shadow == "--show-shadow"; boost::scoped_ptr 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;