Add helper to manage the virStorageSourcePtr allocation for disk->src,
disk->mirror, and disk->src->backingStore.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_conf.c | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fa20840c0..73fd07d68 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1703,6 +1703,27 @@ virDomainDefGetVcpusTopology(const virDomainDef *def,
}
+static virStorageSourcePtr
+virDomainDiskStorageSourceNew(virDomainXMLOptionPtr xmlopt)
+{
+ virStorageSourcePtr src;
+
+ if (VIR_ALLOC(src) < 0)
+ return NULL;
+
+ if (xmlopt &&
+ xmlopt->privateData.diskSrcNew &&
+ !(src->privateData = xmlopt->privateData.diskSrcNew()))
+ goto error;
+
+ return src;
+
+ error:
+ virStorageSourceFree(src);
+ return NULL;
+}
+
+
virDomainDiskDefPtr
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
{
@@ -1711,7 +1732,7 @@ virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
if (VIR_ALLOC(ret) < 0)
return NULL;
- if (VIR_ALLOC(ret->src) < 0)
+ if (!(ret->src = virDomainDiskStorageSourceNew(xmlopt)))
goto error;
if (xmlopt &&
@@ -8234,7 +8255,8 @@ virDomainDiskSourceParse(xmlNodePtr node,
static int
-virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
+virDomainDiskBackingStoreParse(virDomainXMLOptionPtr xmlopt,
+ xmlXPathContextPtr ctxt,
virStorageSourcePtr src)
{
virStorageSourcePtr backingStore = NULL;
@@ -8249,7 +8271,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
goto cleanup;
}
- if (VIR_ALLOC(backingStore) < 0)
+ if (!(backingStore = virDomainDiskStorageSourceNew(xmlopt)))
goto cleanup;
if (!(type = virXMLPropString(ctxt->node, "type"))) {
@@ -8285,7 +8307,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
}
if (virDomainDiskSourceParse(source, ctxt, backingStore) < 0 ||
- virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
+ virDomainDiskBackingStoreParse(xmlopt, ctxt, backingStore) < 0)
goto cleanup;
src->backingStore = backingStore;
@@ -8386,6 +8408,7 @@ virDomainDiskDefIotuneParse(virDomainDiskDefPtr def,
static int
virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
xmlNodePtr cur,
+ virDomainXMLOptionPtr xmlopt,
xmlXPathContextPtr ctxt)
{
xmlNodePtr mirrorNode;
@@ -8395,7 +8418,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
char *blockJob = NULL;
int ret = -1;
- if (VIR_ALLOC(def->mirror) < 0)
+ if (!(def->mirror = virDomainDiskStorageSourceNew(xmlopt)))
goto cleanup;
if ((blockJob = virXMLPropString(cur, "job"))) {
@@ -8910,7 +8933,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
} else if (!def->mirror &&
virXMLNodeNameEqual(cur, "mirror") &&
!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) {
- if (virDomainDiskDefMirrorParse(def, cur, ctxt) < 0)
+ if (virDomainDiskDefMirrorParse(def, cur, xmlopt, ctxt) < 0)
goto error;
} else if (!authdef &&
virXMLNodeNameEqual(cur, "auth")) {
@@ -9174,7 +9197,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
product = NULL;
if (!(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) {
- if (virDomainDiskBackingStoreParse(ctxt, def->src) < 0)
+ if (virDomainDiskBackingStoreParse(xmlopt, ctxt, def->src) < 0)
goto error;
}
--
2.13.5