An upcoming patch wants to reuse XML parsing of both unix and tcp
network host descriptions in the context of setting up a backup
NBD server. Make that easier by refactoring the existing parser.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
src/conf/domain_conf.h | 2 ++
src/conf/domain_conf.c | 43 ++++++++++++++++++++--------------------
src/libvirt_private.syms | 1 +
3 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e30a4b2fe7..785786c9b9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3143,6 +3143,8 @@ int virDomainDiskInsert(virDomainDefPtr def,
ATTRIBUTE_RETURN_CHECK;
void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
virDomainDiskDefPtr disk);
+int virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
+ virStorageNetHostDefPtr host);
int virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt,
virDomainDiskDefPtr def,
const virDomainDef *vmdef);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e8e0adc819..262383021a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7122,23 +7122,21 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node,
}
-static int
+int
virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
- virStorageNetHostDefPtr *hosts,
- size_t *nhosts)
+ virStorageNetHostDefPtr host)
{
int ret = -1;
char *transport = NULL;
char *port = NULL;
- virStorageNetHostDef host;
- memset(&host, 0, sizeof(host));
- host.transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+ 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) {
+ host->transport = virStorageNetHostTransportTypeFromString(transport);
+ if (host->transport < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown protocol transport type '%s'"),
transport);
@@ -7146,17 +7144,17 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
}
}
- host.socket = virXMLPropString(hostnode, "socket");
+ host->socket = virXMLPropString(hostnode, "socket");
- if (host.transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
- host.socket == NULL) {
+ if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
+ host->socket == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing socket for unix transport"));
goto cleanup;
}
- if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
- host.socket != NULL) {
+ if (host->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
+ host->socket != NULL) {
virReportError(VIR_ERR_XML_ERROR,
_("transport '%s' does not support "
"socket attribute"),
@@ -7164,26 +7162,24 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
goto cleanup;
}
- if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) {
- if (!(host.name = virXMLPropString(hostnode, "name"))) {
+ if (host->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) {
+ if (!(host->name = virXMLPropString(hostnode, "name"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing name for host"));
goto cleanup;
}
if ((port = virXMLPropString(hostnode, "port"))) {
- if (virStringParsePort(port, &host.port) < 0)
+ if (virStringParsePort(port, &host->port) < 0)
goto cleanup;
}
}
- if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0)
- goto cleanup;
-
ret = 0;
cleanup:
- virStorageNetHostDefClear(&host);
+ if (ret < 0)
+ virStorageNetHostDefClear(host);
VIR_FREE(transport);
VIR_FREE(port);
return ret;
@@ -7200,9 +7196,14 @@ virDomainStorageNetworkParseHosts(xmlNodePtr node,
for (child = node->children; child; child = child->next) {
if (child->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(child, "host")) {
+ virStorageNetHostDef host;
- if (virDomainStorageNetworkParseHost(child, hosts, nhosts) < 0)
+ if (virDomainStorageNetworkParseHost(child, &host) < 0)
return -1;
+ if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) {
+ virStorageNetHostDefClear(&host);
+ return -1;
+ }
}
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 335210c31d..eb1ad579d9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -545,6 +545,7 @@ virDomainStateReasonFromString;
virDomainStateReasonToString;
virDomainStateTypeFromString;
virDomainStateTypeToString;
+virDomainStorageNetworkParseHost;
virDomainStorageSourceFormat;
virDomainStorageSourceParse;
virDomainTaintTypeFromString;
--
2.17.2
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list