]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: implement 'osd crush ls <node>' 16920/head
authorSage Weil <sage@redhat.com>
Tue, 8 Aug 2017 19:56:18 +0000 (15:56 -0400)
committerSage Weil <sage@redhat.com>
Tue, 8 Aug 2017 19:56:18 +0000 (15:56 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
doc/release-notes.rst
src/mon/MonCommands.h
src/mon/OSDMonitor.cc

index ae6de44d2721d87616149f12ef7f173719e762e6..612fc3a42db68ae82290d2abb838cc8ad638eb4a 100644 (file)
@@ -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 <node>`` will list items (OSDs or other CRUSH nodes)
+      directly beneath a given CRUSH node.
     - ``ceph osd crush swap-bucket <src> <dest>`` will swap the
       contents of two CRUSH buckets in the hierarchy while preserving
       the buckets' ids.  This allows an entire subtree of devices to
index c7a5401f229a49f657589643d1b3d9df7558a566..ef3c094b2339e83749eccfcdb6d01d06a504e767 100644 (file)
@@ -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")
index c8596a98ceaa886b5fd6c73e922185166191ee0a..d1c1766c2800cd05685b93985d2d0f6dee19cb71 100644 (file)
@@ -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<int> 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<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty"));
     f->open_array_section("crush_classes");