From 4ff990fa25a96c7c4a108d3afbb736e876419b4f Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Tue, 5 Mar 2019 17:10:41 +0800 Subject: [PATCH] mon/OSDMonitor: add 'osd crush get-device-class' command which should work as a good complementation of the existing **set-device-class** and "rm-device-class" command family. Signed-off-by: xie xingguo --- src/mon/MonCommands.h | 4 ++++ src/mon/OSDMonitor.cc | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 9fe22de7394ed..66ae64f8dc5df 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -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 ", \ "osd", "r") +COMMAND("osd crush get-device-class " \ + "name=ids,type=CephString,n=N", \ + "get classes of specified osd(s) [...]", \ + "osd", "r") COMMAND("osd crush weight-set ls", "list crush weight sets", "osd", "r") diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 00d3227202643..e52e4817022fd 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -5858,6 +5858,50 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) } rdata.append(ds); } + } else if (prefix == "osd crush get-device-class") { + vector idvec; + cmd_getval(cct, cmdmap, "ids", idvec); + map 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) -- 2.39.5