]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: clean up smart probe code a bit 21950/head
authorSage Weil <sage@redhat.com>
Fri, 11 May 2018 20:21:46 +0000 (15:21 -0500)
committerSage Weil <sage@redhat.com>
Fri, 11 May 2018 20:21:46 +0000 (15:21 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/OSD.cc

index af085fc8320f0aac8945f3acbd59e72f1cedbbc4..0bf4e7199f4e1c52488a9c17c42d53ad7864300d 100644 (file)
@@ -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)