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