render / rpms / libvirt

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