render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From 90ebcae8a87903065233bfc55a607fcfd103c476 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <90ebcae8a87903065233bfc55a607fcfd103c476@dist-git>
3e5111
From: Peter Krempa <pkrempa@redhat.com>
3e5111
Date: Tue, 20 Jun 2017 10:22:44 +0200
3e5111
Subject: [PATCH] util: storage: adapt to changes in JSON format for ssh
3e5111
3e5111
Since qemu 2.9 the options changed from a monolithic string into fine
3e5111
grained options for the json pseudo-protocol object.
3e5111
3e5111
(cherry picked from commit ea2c418ac30628d1db021f351f0ea5440ba5e4e4)
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 | 21 +++++++++++++--------
3e5111
 tests/virstoragetest.c    | 11 +++++++++++
3e5111
 2 files changed, 24 insertions(+), 8 deletions(-)
3e5111
3e5111
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
3e5111
index 68bfdcd0ca..566c4c27c3 100644
3e5111
--- a/src/util/virstoragefile.c
3e5111
+++ b/src/util/virstoragefile.c
3e5111
@@ -3092,10 +3092,11 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
3e5111
     const char *path = virJSONValueObjectGetString(json, "path");
3e5111
     const char *host = virJSONValueObjectGetString(json, "host");
3e5111
     const char *port = virJSONValueObjectGetString(json, "port");
3e5111
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
3e5111
 
3e5111
-    if (!host || !path) {
3e5111
+    if (!(host || server) || !path) {
3e5111
         virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
-                       _("missing host or path of SSH JSON backing "
3e5111
+                       _("missing host/server or path of SSH JSON backing "
3e5111
                          "volume definition"));
3e5111
         return -1;
3e5111
     }
3e5111
@@ -3110,12 +3111,16 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
3e5111
         return -1;
3e5111
     src->nhosts = 1;
3e5111
 
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 (server) {
3e5111
+        if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts,
3e5111
+                                                              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
+            VIR_STRDUP(src->hosts[0].port, port) < 0)
3e5111
+            return -1;
3e5111
+    }
3e5111
 
3e5111
     return 0;
3e5111
 }
3e5111
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
3e5111
index 97eaeab094..9ca927b5e4 100644
3e5111
--- a/tests/virstoragetest.c
3e5111
+++ b/tests/virstoragetest.c
3e5111
@@ -1501,6 +1501,17 @@ mymain(void)
3e5111
                        "<source protocol='ssh' name='blah'>\n"
3e5111
                        "  <host name='example.org' port='6000'/>\n"
3e5111
                        "</source>\n");
3e5111
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"ssh\","
3e5111
+                                       "\"path\":\"blah\","
3e5111
+                                       "\"server\":{ \"host\":\"example.org\","
3e5111
+                                                    "\"port\":\"6000\""
3e5111
+                                                  "},"
3e5111
+                                       "\"user\":\"user\""
3e5111
+                                      "}"
3e5111
+                            "}",
3e5111
+                       "<source protocol='ssh' name='blah'>\n"
3e5111
+                       "  <host name='example.org' port='6000'/>\n"
3e5111
+                       "</source>\n");
3e5111
     TEST_BACKING_PARSE("json:{\"file.driver\":\"rbd\","
3e5111
                              "\"file.filename\":\"rbd:testshare:id=asdf:mon_host=example.com\""
3e5111
                             "}",
3e5111
-- 
3e5111
2.13.1
3e5111