From: Sage Weil Date: Tue, 8 Aug 2017 19:56:18 +0000 (-0400) Subject: mon/OSDMonitor: implement 'osd crush ls ' X-Git-Tag: v13.0.0~176^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F16920%2Fhead;p=ceph.git mon/OSDMonitor: implement 'osd crush ls ' Signed-off-by: Sage Weil --- diff --git a/doc/release-notes.rst b/doc/release-notes.rst index ae6de44d2721d..612fc3a42db68 100644 --- a/doc/release-notes.rst +++ b/doc/release-notes.rst @@ -222,6 +222,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 c7a5401f229a4..ef3c094b2339e 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 c8596a98ceaa8..d1c1766c2800c 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");