conf: Split out parsing of network disk source XML elements

virDomainDiskSourceParse got to the point of being an ugly spaghetti
mess by adding more and more stuff into it. Split out parsing of network
disk information into a separate function so that it stays contained.
This commit is contained in:
Peter Krempa 2017-05-09 14:25:02 +02:00
parent 5656596a40
commit 5047524baa

View File

@ -8106,32 +8106,18 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node,
}
int
virDomainDiskSourceParse(xmlNodePtr node,
static int
virDomainDiskSourceNetworkParse(xmlNodePtr node,
xmlXPathContextPtr ctxt,
virStorageSourcePtr src,
unsigned int flags)
{
int ret = -1;
char *protocol = NULL;
xmlNodePtr saveNode = ctxt->node;
char *haveTLS = NULL;
char *tlsCfg = NULL;
int tlsCfgVal;
int ret = -1;
ctxt->node = node;
switch ((virStorageType)src->type) {
case VIR_STORAGE_TYPE_FILE:
src->path = virXMLPropString(node, "file");
break;
case VIR_STORAGE_TYPE_BLOCK:
src->path = virXMLPropString(node, "dev");
break;
case VIR_STORAGE_TYPE_DIR:
src->path = virXMLPropString(node, "dir");
break;
case VIR_STORAGE_TYPE_NETWORK:
if (!(protocol = virXMLPropString(node, "protocol"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing network source protocol type"));
@ -8207,6 +8193,38 @@ virDomainDiskSourceParse(xmlNodePtr node,
virStorageSourceNetworkAssignDefaultPorts(src);
ret = 0;
cleanup:
VIR_FREE(protocol);
return ret;
}
int
virDomainDiskSourceParse(xmlNodePtr node,
xmlXPathContextPtr ctxt,
virStorageSourcePtr src,
unsigned int flags)
{
int ret = -1;
xmlNodePtr saveNode = ctxt->node;
ctxt->node = node;
switch ((virStorageType)src->type) {
case VIR_STORAGE_TYPE_FILE:
src->path = virXMLPropString(node, "file");
break;
case VIR_STORAGE_TYPE_BLOCK:
src->path = virXMLPropString(node, "dev");
break;
case VIR_STORAGE_TYPE_DIR:
src->path = virXMLPropString(node, "dir");
break;
case VIR_STORAGE_TYPE_NETWORK:
if (virDomainDiskSourceNetworkParse(node, ctxt, src, flags) < 0)
goto cleanup;
break;
case VIR_STORAGE_TYPE_VOLUME:
if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0)
@ -8229,9 +8247,6 @@ virDomainDiskSourceParse(xmlNodePtr node,
ret = 0;
cleanup:
VIR_FREE(protocol);
VIR_FREE(haveTLS);
VIR_FREE(tlsCfg);
ctxt->node = saveNode;
return ret;
}