The virDomainStorageNetworkParseHost() function uses old style of
parsing XML (virXMLPropString + str2enum conversion). Use
virXMLPropEnumDefault() which encapsulates those steps.

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 src/conf/domain_conf.c                        | 19 +++++++------------
 src/conf/storage_source_conf.h                |  2 +-
 src/qemu/qemu_backup.c                        |  2 +-
 src/qemu/qemu_block.c                         |  2 +-
 src/qemu/qemu_command.c                       |  2 ++
 src/qemu/qemu_monitor_json.c                  |  2 +-
 .../storage_file_backend_gluster.c            |  2 +-
 .../storage_source_backingstore.c             | 16 ++++++++++------
 8 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a9c424e71d..17ac74abcd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7006,22 +7006,17 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
                                  virStorageNetHostDef *host)
 {
     int ret = -1;
-    g_autofree char *transport = NULL;
     g_autofree char *port = NULL;
 
     memset(host, 0, sizeof(*host));
-    host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
 
     /* transport can be tcp (default), unix or rdma.  */
-    if ((transport = virXMLPropString(hostnode, "transport"))) {
-        host->transport = virStorageNetHostTransportTypeFromString(transport);
-        if (host->transport < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown protocol transport type '%s'"),
-                           transport);
-            goto cleanup;
-        }
-    }
+    if (virXMLPropEnumDefault(hostnode, "transport",
+                              virStorageNetHostTransportTypeFromString,
+                              VIR_XML_PROP_NONE,
+                              &host->transport,
+                              VIR_STORAGE_NET_HOST_TRANS_TCP) < 0)
+        goto cleanup;
 
     host->socket = virXMLPropString(hostnode, "socket");
 
@@ -7037,7 +7032,7 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
         virReportError(VIR_ERR_XML_ERROR,
                        _("transport '%s' does not support "
                          "socket attribute"),
-                       transport);
+                       
virStorageNetHostTransportTypeToString(host->transport));
         goto cleanup;
     }
 
diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h
index f2440cec6a..3afad96bdb 100644
--- a/src/conf/storage_source_conf.h
+++ b/src/conf/storage_source_conf.h
@@ -150,7 +150,7 @@ typedef struct _virStorageNetHostDef virStorageNetHostDef;
 struct _virStorageNetHostDef {
     char *name;
     unsigned int port;
-    int transport; /* virStorageNetHostTransport */
+    virStorageNetHostTransport transport;
     char *socket;  /* path to unix socket */
 };
 
diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
index 427c090dd8..ef87f99177 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -73,7 +73,7 @@ qemuBackupPrepare(virDomainBackupDef *def)
             def->server->name = g_strdup("localhost");
         }
 
-        switch ((virStorageNetHostTransport) def->server->transport) {
+        switch (def->server->transport) {
         case VIR_STORAGE_NET_HOST_TRANS_TCP:
             /* TODO: Update qemu.conf to provide a port range,
              * probably starting at 10809, for obtaining automatic
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 877c66d62b..ba5e5ef625 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -452,7 +452,7 @@ 
qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDef *host,
     const char *field;
     g_autofree char *port = NULL;
 
-    switch ((virStorageNetHostTransport) host->transport) {
+    switch (host->transport) {
     case VIR_STORAGE_NET_HOST_TRANS_TCP:
         if (legacy)
             transport = "tcp";
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7eb7def747..dac8aabad4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1619,6 +1619,8 @@ qemuBuildNetworkDriveStr(virStorageSource *src,
                     virBufferAsprintf(&buf, "unix:%s", src->hosts->socket);
                     break;
 
+                case VIR_STORAGE_NET_HOST_TRANS_RDMA:
+                case VIR_STORAGE_NET_HOST_TRANS_LAST:
                 default:
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    _("nbd does not support transport '%s'"),
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index dc05dfd047..afe45c415b 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6499,7 +6499,7 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon,
     g_autoptr(virJSONValue) addr = NULL;
     g_autofree char *port_str = NULL;
 
-    switch ((virStorageNetHostTransport)server->transport) {
+    switch (server->transport) {
     case VIR_STORAGE_NET_HOST_TRANS_TCP:
         port_str = g_strdup_printf("%u", server->port);
         addr = qemuMonitorJSONBuildInetSocketAddress(server->name, port_str);
diff --git a/src/storage_file/storage_file_backend_gluster.c 
b/src/storage_file/storage_file_backend_gluster.c
index 2aee61bf33..cd16a6c40c 100644
--- a/src/storage_file/storage_file_backend_gluster.c
+++ b/src/storage_file/storage_file_backend_gluster.c
@@ -65,7 +65,7 @@ 
virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPriv *priv,
     const char *hoststr = NULL;
     int port = 0;
 
-    switch ((virStorageNetHostTransport) host->transport) {
+    switch (host->transport) {
     case VIR_STORAGE_NET_HOST_TRANS_RDMA:
     case VIR_STORAGE_NET_HOST_TRANS_TCP:
         hoststr = host->name;
diff --git a/src/storage_file/storage_source_backingstore.c 
b/src/storage_file/storage_source_backingstore.c
index e48ae725ab..71c5eca13c 100644
--- a/src/storage_file/storage_source_backingstore.c
+++ b/src/storage_file/storage_source_backingstore.c
@@ -65,12 +65,16 @@ virStorageSourceParseBackingURI(virStorageSource *src,
         return -1;
     }
 
-    if (scheme[1] &&
-        (src->hosts->transport = 
virStorageNetHostTransportTypeFromString(scheme[1])) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("invalid protocol transport type '%s'"),
-                       scheme[1]);
-        return -1;
+    if (scheme[1]) {
+        int transport;
+        if ((transport = virStorageNetHostTransportTypeFromString(scheme[1])) 
< 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("invalid protocol transport type '%s'"),
+                           scheme[1]);
+            return -1;
+        }
+
+        src->hosts->transport = transport;
     }
 
     if (uri->query) {
-- 
2.35.1

Reply via email to