The virDomainStorageNetworkParseHost() function uses old style of
parsing XML (virXMLPropString + str2enum conversion). Use
virXMLPropEnumDefault() which encapsulates those steps.
Signed-off-by: Michal Privoznik <mprivozn(a)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 e4d0ee1eb1..451221624e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6970,22 +6970,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");
@@ -7001,7 +6996,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 57bd7d25b2..61a6262213 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 ba2d6496f0..faf18fd6a8 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1586,6 +1586,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 d5622bd6d9..bf3245f7e2 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6529,7 +6529,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