]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: storage: adapt to changes in JSON format for NBD
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 2.9 the host and port for NBD are no longer directly under the
json pseudo-protocol object, but rather belong to a sub-object called
'server'.

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

index 8e6631b459de6ce6afdfd056c36c39258e7cfcdd..b0dc92942eae19a989e0d2fed457e228eb9fb7c1 100644 (file)
@@ -3014,11 +3014,12 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
     const char *host = virJSONValueObjectGetString(json, "host");
     const char *port = virJSONValueObjectGetString(json, "port");
     const char *export = virJSONValueObjectGetString(json, "export");
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
 
-    if (!path && !host) {
+    if (!path && !host && !server) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("missing path or host of NBD server in JSON backing "
-                         "volume definition"));
+                       _("missing host specification of NBD server in JSON "
+                         "backing volume definition"));
         return -1;
     }
 
@@ -3032,17 +3033,22 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
         return -1;
     src->nhosts = 1;
 
-    if (path) {
-        src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
-        if (VIR_STRDUP(src->hosts[0].socket, path) < 0)
+    if (server) {
+        if (virStorageSourceParseBackingJSONSocketAddress(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)
-            return -1;
+        if (path) {
+            src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
+            if (VIR_STRDUP(src->hosts[0].socket, path) < 0)
+                return -1;
+        } else {
+            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 (VIR_STRDUP(src->hosts[0].port, port) < 0)
+                return -1;
+        }
     }
 
     return 0;
index 894f78ba9bfb3a336f3036362361f3cc1f4924f0..ca2601de706b30788fd084431637e281948cc81f 100644 (file)
@@ -1471,6 +1471,17 @@ mymain(void)
                        "<source protocol='nbd' name='blah'>\n"
                        "  <host name='example.org' port='6000'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"nbd\","
+                                       "\"export\":\"blah\","
+                                       "\"server\": { \"type\":\"inet\","
+                                                     "\"host\":\"example.org\","
+                                                     "\"port\":\"6000\""
+                                                   "}"
+                                      "}"
+                            "}",
+                       "<source protocol='nbd' name='blah'>\n"
+                       "  <host name='example.org' port='6000'/>\n"
+                       "</source>\n");
     TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"ssh\","
                                        "\"host\":\"example.org\","
                                        "\"port\":\"6000\","