Blame SOURCES/libvirt-util-storage-Split-out-parsing-of-TCP-network-host-from-JSON-pseudoprotocol.patch

6d3351
From 663456f9a380912ee4659616074c091cb973a330 Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <663456f9a380912ee4659616074c091cb973a330@dist-git>
6d3351
From: Peter Krempa <pkrempa@redhat.com>
6d3351
Date: Tue, 20 Jun 2017 10:22:39 +0200
6d3351
Subject: [PATCH] util: storage: Split out parsing of TCP network host from
6d3351
 JSON pseudoprotocol
6d3351
6d3351
Few backing protocols support only TCP. Split out the function which
6d3351
will correspond to parsing qemu's InetSocketAddressBase.
6d3351
6d3351
(cherry picked from commit 49ed98a4579744568b5c57f65ae08034d5c9568f)
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 | 38 +++++++++++++++++++++++++-------------
6d3351
 1 file changed, 25 insertions(+), 13 deletions(-)
6d3351
6d3351
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
6d3351
index 3c06685d6b..f67e714e3c 100644
6d3351
--- a/src/util/virstoragefile.c
6d3351
+++ b/src/util/virstoragefile.c
6d3351
@@ -2800,12 +2800,34 @@ virStorageSourceParseBackingJSONUri(virStorageSourcePtr src,
6d3351
 
6d3351
 
6d3351
 static int
6d3351
+virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr host,
6d3351
+                                                  virJSONValuePtr json)
6d3351
+{
6d3351
+    const char *hostname = virJSONValueObjectGetString(json, "host");
6d3351
+    const char *port = virJSONValueObjectGetString(json, "port");
6d3351
+
6d3351
+    if (!hostname) {
6d3351
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
6d3351
+                       _("missing hostname for tcp backing server in "
6d3351
+                         "JSON backing volume definition"));
6d3351
+        return -1;
6d3351
+    }
6d3351
+
6d3351
+    host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
6d3351
+
6d3351
+    if (VIR_STRDUP(host->name, hostname) < 0 ||
6d3351
+        VIR_STRDUP(host->port, port) < 0)
6d3351
+        return -1;
6d3351
+
6d3351
+    return 0;
6d3351
+}
6d3351
+
6d3351
+
6d3351
+static int
6d3351
 virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
6d3351
                                               virJSONValuePtr json)
6d3351
 {
6d3351
     const char *type = virJSONValueObjectGetString(json, "type");
6d3351
-    const char *hostname = virJSONValueObjectGetString(json, "host");
6d3351
-    const char *port = virJSONValueObjectGetString(json, "port");
6d3351
     const char *socket = virJSONValueObjectGetString(json, "socket");
6d3351
 
6d3351
     if (!type) {
6d3351
@@ -2816,18 +2838,8 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
6d3351
     }
6d3351
 
6d3351
     if (STREQ(type, "tcp") || STREQ(type, "inet")) {
6d3351
-        host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
6d3351
+        return virStorageSourceParseBackingJSONInetSocketAddress(host, json);
6d3351
 
6d3351
-        if (!hostname) {
6d3351
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
6d3351
-                           _("missing hostname for tcp backing server in "
6d3351
-                             "JSON backing volume definition"));
6d3351
-            return -1;
6d3351
-        }
6d3351
-
6d3351
-        if (VIR_STRDUP(host->name, hostname) < 0 ||
6d3351
-            VIR_STRDUP(host->port, port) < 0)
6d3351
-            return -1;
6d3351
     } else if (STREQ(type, "unix")) {
6d3351
         host->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
6d3351
 
6d3351
-- 
6d3351
2.13.1
6d3351