Skip to content

Commit

Permalink
osd: clean up smart probe code a bit
Browse files Browse the repository at this point in the history
Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed May 11, 2018
1 parent 00c5a30 commit eea18b4
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions src/osd/OSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6257,39 +6257,39 @@ 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);
}

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) {
Expand All @@ -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;
}
Expand All @@ -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)
Expand Down

0 comments on commit eea18b4

Please sign in to comment.