Blob Blame History Raw
From 90ebcae8a87903065233bfc55a607fcfd103c476 Mon Sep 17 00:00:00 2001
Message-Id: <90ebcae8a87903065233bfc55a607fcfd103c476@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 20 Jun 2017 10:22:44 +0200
Subject: [PATCH] util: storage: adapt to changes in JSON format for ssh

Since qemu 2.9 the options changed from a monolithic string into fine
grained options for the json pseudo-protocol object.

(cherry picked from commit ea2c418ac30628d1db021f351f0ea5440ba5e4e4)

https://bugzilla.redhat.com/show_bug.cgi?id=1461638

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util/virstoragefile.c | 21 +++++++++++++--------
 tests/virstoragetest.c    | 11 +++++++++++
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 68bfdcd0ca..566c4c27c3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3092,10 +3092,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;
     }
@@ -3110,12 +3111,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;
 }
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 97eaeab094..9ca927b5e4 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -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\""
                             "}",
-- 
2.13.1