From: Sage Weil Date: Tue, 8 Aug 2017 19:56:18 +0000 (-0400) Subject: mon/OSDMonitor: implement 'osd crush ls ' X-Git-Tag: v12.1.3~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fb4f297feb07da8a1a3df78eb0d6d9428c08f91c;p=ceph.git mon/OSDMonitor: implement 'osd crush ls ' Signed-off-by: Sage Weil (cherry picked from commit aeed87945b7e3af3c76b8e39739725ce6b09ad56) --- diff --git a/doc/release-notes.rst b/doc/release-notes.rst index d87ce436e56..db0dbbc8b04 100644 --- a/doc/release-notes.rst +++ b/doc/release-notes.rst @@ -219,6 +219,8 @@ Major Changes from Kraken disable the named mgr module. The module must be present in the configured `mgr_module_path` on the host(s) where `ceph-mgr` is running. + - ``ceph osd crush ls `` will list items (OSDs or other CRUSH nodes) + directly beneath a given CRUSH node. - ``ceph osd crush swap-bucket `` will swap the contents of two CRUSH buckets in the hierarchy while preserving the buckets' ids. This allows an entire subtree of devices to diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index c7a5401f229..ef3c094b233 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -645,6 +645,9 @@ 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 ls name=node,type=CephString,goodchars=goodchars=[A-Za-z0-9-_.]", + "list items beneath a node in the CRUSH tree", + "osd", "r", "cli,rest") COMMAND("osd crush class ls", \ "list all crush device classes", \ "osd", "r", "cli,rest") diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index c8596a98cea..d1c1766c280 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -4984,6 +4984,43 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) show_shadow); rdata.append(ss.str()); } + } else if (prefix == "osd crush ls") { + string name; + if (!cmd_getval(g_ceph_context, cmdmap, "node", name)) { + ss << "no node specified"; + r = -EINVAL; + goto reply; + } + if (!osdmap.crush->name_exists(name)) { + ss << "node '" << name << "' does not exist"; + r = -ENOENT; + goto reply; + } + int id = osdmap.crush->get_item_id(name); + list result; + if (id >= 0) { + result.push_back(id); + } else { + int num = osdmap.crush->get_bucket_size(id); + for (int i = 0; i < num; ++i) { + result.push_back(osdmap.crush->get_bucket_item(id, i)); + } + } + if (f) { + f->open_array_section("items"); + for (auto i : result) { + f->dump_string("item", osdmap.crush->get_item_name(i)); + } + f->close_section(); + f->flush(rdata); + } else { + ostringstream ss; + for (auto i : result) { + ss << osdmap.crush->get_item_name(i) << "\n"; + } + rdata.append(ss.str()); + } + r = 0; } else if (prefix == "osd crush class ls") { boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json-pretty")); f->open_array_section("crush_classes");