From: songshuangyang Date: Fri, 14 Sep 2018 06:53:17 +0000 (+0800) Subject: crush/CrushWrapper: fix crush tree json dumper X-Git-Tag: v13.2.3~141^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F24481%2Fhead;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 (cherry picked from commit 35c0d1f45cd676f201d4031cb8f447f7ea6aee0e) --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 349b7751be18..b55fe32011fb 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 da55af151949..5a20d3a93f49 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -5433,10 +5433,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;