From: Sage Weil Date: Fri, 11 May 2018 20:21:46 +0000 (-0500) Subject: osd: clean up smart probe code a bit X-Git-Tag: v14.0.0~144^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F21950%2Fhead;p=ceph.git osd: clean up smart probe code a bit Signed-off-by: Sage Weil --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index af085fc8320f..0bf4e7199f4e 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -6257,24 +6257,23 @@ void OSD::probe_smart(ostream& ss) json_spirit::mValue smart_json; for (auto dev : devnames) { - // smartctl works only on physical devices; filter out any logical device - if (dev.find("dm-") == 0) { - continue; - } + // smartctl works only on physical devices; filter out any logical device + if (dev.find("dm-") == 0) { + continue; + } - if (probe_smart_device(("/dev/" + dev).c_str(), smart_timeout, &result)) { - derr << "probe_smart_device failed for /dev/" << dev << ", continuing to next device"<< dendl; - continue; - } + if (probe_smart_device(("/dev/" + dev).c_str(), smart_timeout, &result)) { + dout(10) << "probe_smart_device failed for /dev/" << dev << dendl; + continue; + } - // TODO: change to read_or_throw? - if (!json_spirit::read(result, smart_json)) { - derr << "smartctl JSON output of /dev/" + dev + " is invalid" << dendl; - } - else { //json is valid, assigning - json_map[dev] = smart_json; - } - // no need to result.clear() or clear smart_json + // TODO: change to read_or_throw? + if (!json_spirit::read(result, smart_json)) { + derr << "smartctl JSON output of /dev/" + dev + " is invalid" << dendl; + } else { //json is valid, assigning + json_map[dev] = smart_json; + } + // no need to result.clear() or clear smart_json } json_spirit::write(json_map, ss, json_spirit::pretty_print); } @@ -6282,14 +6281,15 @@ void OSD::probe_smart(ostream& ss) int OSD::probe_smart_device(const char *device, int timeout, std::string *result) { // when using --json, smartctl will report its errors in JSON format to stdout - SubProcessTimed smartctl("sudo", SubProcess::CLOSE, SubProcess::PIPE, SubProcess::CLOSE, timeout); + SubProcessTimed smartctl("sudo", SubProcess::CLOSE, SubProcess::PIPE, SubProcess::CLOSE, + timeout); smartctl.add_cmd_args( - "smartctl", - "-a", - //"-x", - "--json", - device, - NULL); + "smartctl", + "-a", + //"-x", + "--json", + device, + NULL); int ret = smartctl.spawn(); if (ret != 0) { @@ -6302,6 +6302,7 @@ int OSD::probe_smart_device(const char *device, int timeout, std::string *result if (ret < 0) { derr << "failed read from smartctl: " << cpp_strerror(-ret) << dendl; } else { + ret = 0; *result = output.to_str(); dout(10) << "smartctl output is: " << *result << dendl; } @@ -6311,10 +6312,7 @@ int OSD::probe_smart_device(const char *device, int timeout, std::string *result return -EINVAL; } - if (ret < 0) - return ret; - - return 0; + return ret; } bool OSD::heartbeat_dispatch(Message *m)