virStorageNetHostDef: Convert 'transport' field to proper enum type

Convert the field and adjust the XML parsers to use
virXMLPropEnumDefault().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2023-09-13 18:21:21 +02:00
parent 2dd6369477
commit 452695926d
7 changed files with 20 additions and 21 deletions

View File

@ -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");

View File

@ -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 */
};

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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) {