[libvirt] [PATCH v2 1/8] util: storage: Add support for type 'inet' in virStorageSourceParseBackingJSONSocketAddress

Peter Krempa pkrempa at redhat.com
Mon Jun 19 13:58:28 UTC 2017


'SocketAddress' structure was changed to contain 'inet' instead of
'tcp' since qemu commit c5f1ae3ae7b. Existing entries have a backward
compatibility layer.

Libvirt will parse 'inet' and 'tcp' as equivalents.
---
 src/util/virstoragefile.c | 23 +++++++++--------------
 tests/virstoragetest.c    |  2 +-
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 92bc561a2..7f2a50fd1 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2802,18 +2802,17 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
     const char *hostname = virJSONValueObjectGetString(json, "host");
     const char *port = virJSONValueObjectGetString(json, "port");
     const char *socket = virJSONValueObjectGetString(json, "socket");
-    int transport;

-    if ((transport = virStorageNetHostTransportTypeFromString(type)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unknown backing store transport protocol '%s'"), type);
+    if (!type) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing socket address type in "
+                         "JSON backing volume definition"));
         return -1;
     }

-    host->transport = transport;
+    if (STREQ(type, "tcp") || STREQ(type, "inet")) {
+        host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;

-    switch ((virStorageNetHostTransport) transport) {
-    case VIR_STORAGE_NET_HOST_TRANS_TCP:
         if (!hostname) {
             virReportError(VIR_ERR_INVALID_ARG, "%s",
                            _("missing hostname for tcp backing server in "
@@ -2824,9 +2823,9 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
         if (VIR_STRDUP(host->name, hostname) < 0 ||
             VIR_STRDUP(host->port, port) < 0)
             return -1;
-        break;
+    } else if (STREQ(type, "unix")) {
+        host->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;

-    case VIR_STORAGE_NET_HOST_TRANS_UNIX:
         if (!socket) {
             virReportError(VIR_ERR_INVALID_ARG, "%s",
                            _("missing socket path for udp backing server in "
@@ -2834,13 +2833,9 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
             return -1;
         }

-
         if (VIR_STRDUP(host->socket, socket) < 0)
             return -1;
-        break;
-
-    case VIR_STORAGE_NET_HOST_TRANS_RDMA:
-    case VIR_STORAGE_NET_HOST_TRANS_LAST:
+    } else {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("backing store protocol '%s' is not yet supported"),
                        type);
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 70e24a1b7..117208289 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1431,7 +1431,7 @@ mymain(void)
                                                "{ \"type\":\"unix\","
                                                  "\"socket\":\"/path/socket\""
                                                "},"
-                                               "{ \"type\":\"tcp\","
+                                               "{ \"type\":\"inet\","
                                                  "\"host\":\"example.com\""
                                                "}"
                                              "]"
-- 
2.12.2




More information about the libvir-list mailing list