]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/blkdev: include bad json from smartctl when unparseable
authorSage Weil <sage@redhat.com>
Fri, 28 Jun 2019 14:34:23 +0000 (09:34 -0500)
committerSage Weil <sage@redhat.com>
Mon, 1 Jul 2019 22:25:12 +0000 (17:25 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/blkdev.cc

index 074eb2c80c6dd689ef56eae7c1ea62853403d5aa..4ecd1d8d3f48df219263c4b114b619932e53683a 100644 (file)
@@ -708,6 +708,17 @@ static int block_device_run_smartctl(const string& devname, int timeout,
   return ret;
 }
 
+static std::string escape_quotes(const std::string& s)
+{
+  std::string r = s;
+  auto pos = r.find("\"");
+  while (pos != std::string::npos) {
+    r.replace(pos, 1, "\"");
+    pos = r.find("\"", pos + 1);
+  }
+  return r;
+}
+
 int block_device_get_metrics(const string& devname, int timeout,
                             json_spirit::mValue *result)
 {
@@ -721,10 +732,12 @@ int block_device_get_metrics(const string& devname, int timeout,
     s += "\", \"smartctl_error_code\": " + stringify(r);
     s += "\", \"smartctl_output\": \"" + s;
     s += + "\"}";
-  }
-  if (!json_spirit::read(s, *result)) {
+  } else if (!json_spirit::read(s, *result)) {
+    string orig = s;
     s = "{\"error\": \"smartctl returned invalid JSON\", \"dev\": \"/dev/";
     s += devname;
+    s += "\",\"output\":\"";
+    s += escape_quotes(orig);
     s += "\"}";
   }
   if (!json_spirit::read(s, *result)) {