render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From 042cf4d53a2422d998e6715a6c914f61cb345bb9 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <042cf4d53a2422d998e6715a6c914f61cb345bb9@dist-git>
3e5111
From: Peter Krempa <pkrempa@redhat.com>
3e5111
Date: Tue, 20 Jun 2017 10:22:42 +0200
3e5111
Subject: [PATCH] util: storage: adapt to changes in JSON format for NBD
3e5111
3e5111
Since 2.9 the host and port for NBD are no longer directly under the
3e5111
json pseudo-protocol object, but rather belong to a sub-object called
3e5111
'server'.
3e5111
3e5111
(cherry picked from commit 35d23f90b2266adb93079755161515699a401932)
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1461638
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
---
3e5111
 src/util/virstoragefile.c | 28 +++++++++++++++++-----------
3e5111
 tests/virstoragetest.c    | 11 +++++++++++
3e5111
 2 files changed, 28 insertions(+), 11 deletions(-)
3e5111
3e5111
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
3e5111
index 945c3e4198..ef3050711b 100644
3e5111
--- a/src/util/virstoragefile.c
3e5111
+++ b/src/util/virstoragefile.c
3e5111
@@ -3019,11 +3019,12 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
3e5111
     const char *host = virJSONValueObjectGetString(json, "host");
3e5111
     const char *port = virJSONValueObjectGetString(json, "port");
3e5111
     const char *export = virJSONValueObjectGetString(json, "export");
3e5111
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
3e5111
 
3e5111
-    if (!path && !host) {
3e5111
+    if (!path && !host && !server) {
3e5111
         virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
-                       _("missing path or host of NBD server in JSON backing "
3e5111
-                         "volume definition"));
3e5111
+                       _("missing host specification of NBD server in JSON "
3e5111
+                         "backing volume definition"));
3e5111
         return -1;
3e5111
     }
3e5111
 
3e5111
@@ -3037,17 +3038,22 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
3e5111
         return -1;
3e5111
     src->nhosts = 1;
3e5111
 
3e5111
-    if (path) {
3e5111
-        src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
3e5111
-        if (VIR_STRDUP(src->hosts[0].socket, path) < 0)
3e5111
+    if (server) {
3e5111
+        if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, server) < 0)
3e5111
             return -1;
3e5111
     } else {
3e5111
-        src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
3e5111
-        if (VIR_STRDUP(src->hosts[0].name, host) < 0)
3e5111
-            return -1;
3e5111
+        if (path) {
3e5111
+            src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
3e5111
+            if (VIR_STRDUP(src->hosts[0].socket, path) < 0)
3e5111
+                return -1;
3e5111
+        } else {
3e5111
+            src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
3e5111
+            if (VIR_STRDUP(src->hosts[0].name, host) < 0)
3e5111
+                return -1;
3e5111
 
3e5111
-        if (VIR_STRDUP(src->hosts[0].port, port) < 0)
3e5111
-            return -1;
3e5111
+            if (VIR_STRDUP(src->hosts[0].port, port) < 0)
3e5111
+                return -1;
3e5111
+        }
3e5111
     }
3e5111
 
3e5111
     return 0;
3e5111
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
3e5111
index 294e1f6ffb..54f7c849c5 100644
3e5111
--- a/tests/virstoragetest.c
3e5111
+++ b/tests/virstoragetest.c
3e5111
@@ -1471,6 +1471,17 @@ mymain(void)
3e5111
                        "<source protocol='nbd' name='blah'>\n"
3e5111
                        "  <host name='example.org' port='6000'/>\n"
3e5111
                        "</source>\n");
3e5111
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"nbd\","
3e5111
+                                       "\"export\":\"blah\","
3e5111
+                                       "\"server\": { \"type\":\"inet\","
3e5111
+                                                     "\"host\":\"example.org\","
3e5111
+                                                     "\"port\":\"6000\""
3e5111
+                                                   "}"
3e5111
+                                      "}"
3e5111
+                            "}",
3e5111
+                       "<source protocol='nbd' name='blah'>\n"
3e5111
+                       "  <host name='example.org' port='6000'/>\n"
3e5111
+                       "</source>\n");
3e5111
     TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"ssh\","
3e5111
                                        "\"host\":\"example.org\","
3e5111
                                        "\"port\":\"6000\","
3e5111
-- 
3e5111
2.13.1
3e5111