]> 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)
committerKonstantin Shalygin <k0ste@k0ste.ru>
Wed, 26 Feb 2020 01:39:17 +0000 (08:39 +0700)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 7ac955e5ddc106a7e04fd4f580377bd104706d30)

src/common/blkdev.cc

index e01ad3c62e41a84a584634952c922c542aa65223..6f8958eafac314e07f74d29832f7aded5930e20e 100644 (file)
@@ -706,6 +706,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)
 {
@@ -719,10 +730,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)) {