Convert the field and adjust the XML parsers to use
virXMLPropEnumDefault().
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 16 ++++++----------
src/conf/storage_source_conf.h | 2 +-
src/qemu/qemu_backup.c | 2 +-
src/qemu/qemu_block.c | 2 +-
src/qemu/qemu_monitor_json.c | 2 +-
src/storage_file/storage_file_backend_gluster.c | 2 +-
src/storage_file/storage_source_backingstore.c | 15 +++++++++------
7 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a743a0628c..5f4146b4e3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5834,17 +5834,13 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
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
'%1$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");
diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h
index f99579bce2..9791fb25ee 100644
--- a/src/conf/storage_source_conf.h
+++ b/src/conf/storage_source_conf.h
@@ -151,7 +151,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 a94869522d..e4db967e2c 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -68,7 +68,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 d31bbde0f4..97f03002fd 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -130,7 +130,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDef
*host)
g_autoptr(virJSONValue) server = NULL;
g_autofree char *port = NULL;
- switch ((virStorageNetHostTransport) host->transport) {
+ switch (host->transport) {
case VIR_STORAGE_NET_HOST_TRANS_TCP:
port = g_strdup_printf("%u", host->port);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 5b9edadcf7..137cb4e293 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6176,7 +6176,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 d018d5422e..950f8e81fe 100644
--- a/src/storage_file/storage_file_backend_gluster.c
+++ b/src/storage_file/storage_file_backend_gluster.c
@@ -63,7 +63,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 00fcfe9fd7..80681924ea 100644
--- a/src/storage_file/storage_source_backingstore.c
+++ b/src/storage_file/storage_source_backingstore.c
@@ -42,6 +42,7 @@ virStorageSourceParseBackingURI(virStorageSource *src,
{
g_autoptr(virURI) uri = NULL;
const char *path = NULL;
+ int transport = 0;
g_auto(GStrv) scheme = NULL;
if (!(uri = virURIParse(uristr))) {
@@ -65,12 +66,14 @@ virStorageSourceParseBackingURI(virStorageSource *src,
return -1;
}
- if (scheme[1] &&
- (src->hosts->transport =
virStorageNetHostTransportTypeFromString(scheme[1])) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("invalid protocol transport type '%1$s'"),
- scheme[1]);
- return -1;
+ if (scheme[1]) {
+ if ((transport = virStorageNetHostTransportTypeFromString(scheme[1])) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("invalid protocol transport type
'%1$s'"),
+ scheme[1]);
+ return -1;
+ }
+ src->hosts->transport = transport;
}
if (uri->query) {
--
2.41.0