From 18abfb2486cdd900dafcf2a9501bcbcb0d14cb3f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 8 Jun 2018 17:45:43 -0500 Subject: [PATCH] osd: optionally query smart for a single devid Signed-off-by: Sage Weil --- src/osd/OSD.cc | 23 ++++++++++++++++------- src/osd/OSD.h | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 46d1ae68358..810d5bb8fa3 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2243,7 +2243,9 @@ will start to track new ops received afterwards."; } f->close_section(); } else if (admin_command == "smart") { - probe_smart(ss); + string devid; + cmd_getval(cct, cmdmap, "devid", devid); + probe_smart(devid, ss); } else if (admin_command == "list_devices") { set devnames; store->get_devices(&devnames); @@ -2813,7 +2815,7 @@ void OSD::final_init() assert(r == 0); - r = admin_socket->register_command("smart", "smart", + r = admin_socket->register_command("smart", "smart name=devid,type=CephString,req=False", asok_hook, "probe OSD devices for SMART data."); @@ -5733,7 +5735,7 @@ COMMAND("compact", "compact object store's omap. " "WARNING: Compaction probably slows your requests", "osd", "rw", "cli,rest") -COMMAND("smart", +COMMAND("smart name=devid,type=CephString,req=False", "runs smartctl on this osd devices. ", "osd", "rw", "cli,rest") }; @@ -6171,7 +6173,9 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector& cmd, buffe } else if (prefix == "smart") { - probe_smart(ds); + string devid; + cmd_getval(cct, cmdmap, "devid", devid); + probe_smart(devid, ds); } else { @@ -6192,13 +6196,12 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector& cmd, buffe } } -void OSD::probe_smart(ostream& ss) +void OSD::probe_smart(const string& only_devid, ostream& ss) { set devnames; store->get_devices(&devnames); uint64_t smart_timeout = cct->_conf->get_val( "osd_smart_report_timeout"); - std::string result; // == typedef std::map mObject; json_spirit::mObject json_map; @@ -6216,9 +6219,15 @@ void OSD::probe_smart(ostream& ss) << dendl; continue; } + if (only_devid.size() && devid != only_devid) { + continue; + } + + std::string result; if (probe_smart_device(("/dev/" + dev).c_str(), smart_timeout, &result)) { dout(10) << "probe_smart_device failed for /dev/" << dev << dendl; - continue; + //continue; + result = "{\"error\": \"smartctl failed\", \"dev\": \"" + dev + "\"}"; } // TODO: change to read_or_throw? diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 7f0afb96eb5..c4cf9fcea95 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -2208,7 +2208,7 @@ private: float get_osd_recovery_sleep(); - void probe_smart(ostream& ss); + void probe_smart(const string& devid, ostream& ss); int probe_smart_device(const char *device, int timeout, std::string *result); public: -- 2.39.5