]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: add 'osd crush get-device-class' command
authorxie xingguo <xie.xingguo@zte.com.cn>
Tue, 5 Mar 2019 09:10:41 +0000 (17:10 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Tue, 5 Mar 2019 09:21:08 +0000 (17:21 +0800)
which should work as a good complementation of
the existing **set-device-class** and "rm-device-class"
command family.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/mon/MonCommands.h
src/mon/OSDMonitor.cc

index 9fe22de7394edc295dd8e09ae2f744b30d895c74..66ae64f8dc5dffc08b976289d8e5fbf2cfdd6d96 100644 (file)
@@ -694,6 +694,10 @@ COMMAND("osd crush class ls-osd " \
         "name=class,type=CephString,goodchars=[A-Za-z0-9-_]", \
         "list all osds belonging to the specific <class>", \
         "osd", "r")
+COMMAND("osd crush get-device-class " \
+        "name=ids,type=CephString,n=N", \
+        "get classes of specified osd(s) <id> [<id>...]", \
+        "osd", "r")
 COMMAND("osd crush weight-set ls",
        "list crush weight sets",
        "osd", "r")
index 00d3227202643306c80ec8398dfad4c1520d9c9b..e52e4817022fd84a819304e678fe745efd100c13 100644 (file)
@@ -5858,6 +5858,50 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
       }
       rdata.append(ds);
     }
+  } else if (prefix == "osd crush get-device-class") {
+    vector<string> idvec;
+    cmd_getval(cct, cmdmap, "ids", idvec);
+    map<int, string> class_by_osd;
+    for (auto& id : idvec) {
+      ostringstream ts;
+      long osd = parse_osd_id(id.c_str(), &ts);
+      if (osd < 0) {
+        ss << "unable to parse osd id:'" << id << "'";
+        r = -EINVAL;
+        goto reply;
+      }
+      auto device_class = osdmap.crush->get_item_class(osd);
+      if (device_class)
+        class_by_osd[osd] = device_class;
+      else
+        class_by_osd[osd] = ""; // no class
+    }
+    if (f) {
+      f->open_array_section("osd_device_classes");
+      for (auto& i : class_by_osd) {
+        f->open_object_section("osd_device_class");
+        f->dump_int("osd", i.first);
+        f->dump_string("device_class", i.second);
+        f->close_section();
+      }
+      f->close_section();
+      f->flush(rdata);
+    } else {
+      if (class_by_osd.size() == 1) {
+        // for single input, make a clean output
+        ds << class_by_osd.begin()->second;
+      } else {
+        // note that we do not group osds by class here
+        for (auto it = class_by_osd.begin();
+             it != class_by_osd.end();
+             it++) {
+          ds << "osd." << it->first << ' ' << it->second;
+          if (next(it) != class_by_osd.end())
+            ds << '\n';
+        }
+      }
+      rdata.append(ds);
+    }
   } else if (prefix == "osd erasure-code-profile ls") {
     const auto &profiles = osdmap.get_erasure_code_profiles();
     if (f)