Blame SOURCES/libvirt-util-storage-Add-support-for-type-inet-in-virStorageSourceParseBackingJSONSocketAddress.patch

3e5111
From bc2eb8e377c02190ee96a78ba0f1ede84ec65c72 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <bc2eb8e377c02190ee96a78ba0f1ede84ec65c72@dist-git>
3e5111
From: Peter Krempa <pkrempa@redhat.com>
3e5111
Date: Tue, 20 Jun 2017 10:22:38 +0200
3e5111
Subject: [PATCH] util: storage: Add support for type 'inet' in
3e5111
 virStorageSourceParseBackingJSONSocketAddress
3e5111
3e5111
'SocketAddress' structure was changed to contain 'inet' instead of
3e5111
'tcp' since qemu commit c5f1ae3ae7b. Existing entries have a backward
3e5111
compatibility layer.
3e5111
3e5111
Libvirt will parse 'inet' and 'tcp' as equivalents.
3e5111
3e5111
(cherry picked from commit 1f915d40a220c6bb05d8630507eed045cabfba34)
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 | 23 +++++++++--------------
3e5111
 tests/virstoragetest.c    |  2 +-
3e5111
 2 files changed, 10 insertions(+), 15 deletions(-)
3e5111
3e5111
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
3e5111
index b8aced5055..3c06685d6b 100644
3e5111
--- a/src/util/virstoragefile.c
3e5111
+++ b/src/util/virstoragefile.c
3e5111
@@ -2807,18 +2807,17 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
3e5111
     const char *hostname = virJSONValueObjectGetString(json, "host");
3e5111
     const char *port = virJSONValueObjectGetString(json, "port");
3e5111
     const char *socket = virJSONValueObjectGetString(json, "socket");
3e5111
-    int transport;
3e5111
 
3e5111
-    if ((transport = virStorageNetHostTransportTypeFromString(type)) < 0) {
3e5111
-        virReportError(VIR_ERR_INTERNAL_ERROR,
3e5111
-                       _("unknown backing store transport protocol '%s'"), type);
3e5111
+    if (!type) {
3e5111
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
+                       _("missing socket address type in "
3e5111
+                         "JSON backing volume definition"));
3e5111
         return -1;
3e5111
     }
3e5111
 
3e5111
-    host->transport = transport;
3e5111
+    if (STREQ(type, "tcp") || STREQ(type, "inet")) {
3e5111
+        host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
3e5111
 
3e5111
-    switch ((virStorageNetHostTransport) transport) {
3e5111
-    case VIR_STORAGE_NET_HOST_TRANS_TCP:
3e5111
         if (!hostname) {
3e5111
             virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
                            _("missing hostname for tcp backing server in "
3e5111
@@ -2829,9 +2828,9 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
3e5111
         if (VIR_STRDUP(host->name, hostname) < 0 ||
3e5111
             VIR_STRDUP(host->port, port) < 0)
3e5111
             return -1;
3e5111
-        break;
3e5111
+    } else if (STREQ(type, "unix")) {
3e5111
+        host->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
3e5111
 
3e5111
-    case VIR_STORAGE_NET_HOST_TRANS_UNIX:
3e5111
         if (!socket) {
3e5111
             virReportError(VIR_ERR_INVALID_ARG, "%s",
3e5111
                            _("missing socket path for udp backing server in "
3e5111
@@ -2839,13 +2838,9 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
3e5111
             return -1;
3e5111
         }
3e5111
 
3e5111
-
3e5111
         if (VIR_STRDUP(host->socket, socket) < 0)
3e5111
             return -1;
3e5111
-        break;
3e5111
-
3e5111
-    case VIR_STORAGE_NET_HOST_TRANS_RDMA:
3e5111
-    case VIR_STORAGE_NET_HOST_TRANS_LAST:
3e5111
+    } else {
3e5111
         virReportError(VIR_ERR_INTERNAL_ERROR,
3e5111
                        _("backing store protocol '%s' is not yet supported"),
3e5111
                        type);
3e5111
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
3e5111
index 984994d8e7..4a1d4d0923 100644
3e5111
--- a/tests/virstoragetest.c
3e5111
+++ b/tests/virstoragetest.c
3e5111
@@ -1431,7 +1431,7 @@ mymain(void)
3e5111
                                                "{ \"type\":\"unix\","
3e5111
                                                  "\"socket\":\"/path/socket\""
3e5111
                                                "},"
3e5111
-                                               "{ \"type\":\"tcp\","
3e5111
+                                               "{ \"type\":\"inet\","
3e5111
                                                  "\"host\":\"example.com\""
3e5111
                                                "}"
3e5111
                                              "]"
3e5111
-- 
3e5111
2.13.1
3e5111