]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: storage: adapt to changes in JSON format for ssh
authorPeter Krempa <pkrempa@redhat.com>
Thu, 15 Jun 2017 15:44:18 +0000 (17:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 20 Jun 2017 06:40:18 +0000 (08:40 +0200)
Since qemu 2.9 the options changed from a monolithic string into fine
grained options for the json pseudo-protocol object.

src/util/virstoragefile.c
tests/virstoragetest.c

index 220a55d9b75d85855f48a7362fc12fea2f97465f..b8a3de85c04ced8dc2a5af9ca0ec4a9ff3def771 100644 (file)
@@ -3087,10 +3087,11 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
     const char *path = virJSONValueObjectGetString(json, "path");
     const char *host = virJSONValueObjectGetString(json, "host");
     const char *port = virJSONValueObjectGetString(json, "port");
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
 
-    if (!host || !path) {
+    if (!(host || server) || !path) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("missing host or path of SSH JSON backing "
+                       _("missing host/server or path of SSH JSON backing "
                          "volume definition"));
         return -1;
     }
@@ -3105,12 +3106,16 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
         return -1;
     src->nhosts = 1;
 
-    src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
-    if (VIR_STRDUP(src->hosts[0].name, host) < 0)
-        return -1;
-
-    if (VIR_STRDUP(src->hosts[0].port, port) < 0)
-        return -1;
+    if (server) {
+        if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts,
+                                                              server) < 0)
+            return -1;
+    } else {
+        src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+        if (VIR_STRDUP(src->hosts[0].name, host) < 0 ||
+            VIR_STRDUP(src->hosts[0].port, port) < 0)
+            return -1;
+    }
 
     return 0;
 }
index 9c7314bfff135af9a907163c8b94f629193c37df..08f6c9003519f849db9f5b6893c67766ddc1dcdf 100644 (file)
@@ -1501,6 +1501,17 @@ mymain(void)
                        "<source protocol='ssh' name='blah'>\n"
                        "  <host name='example.org' port='6000'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"ssh\","
+                                       "\"path\":\"blah\","
+                                       "\"server\":{ \"host\":\"example.org\","
+                                                    "\"port\":\"6000\""
+                                                  "},"
+                                       "\"user\":\"user\""
+                                      "}"
+                            "}",
+                       "<source protocol='ssh' name='blah'>\n"
+                       "  <host name='example.org' port='6000'/>\n"
+                       "</source>\n");
     TEST_BACKING_PARSE("json:{\"file.driver\":\"rbd\","
                              "\"file.filename\":\"rbd:testshare:id=asdf:mon_host=example.com\""
                             "}",