]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: domain: Introduce an internal variant of virDomainDiskDefNew
authorPeter Krempa <pkrempa@redhat.com>
Wed, 14 Apr 2021 14:48:53 +0000 (16:48 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Apr 2021 12:43:59 +0000 (14:43 +0200)
The <disk> XML element parser is going to be modified so that the
virStorageSource bits are pre-parsed. Add virDomainDiskDefNewSource,
which uses an existing 'src' pointer.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c

index 57cad6ffdeba897ddf99f7adf010dafedbc4536d..f59d17930bfd30064a345f0ad7050efb19ede25a 100644 (file)
@@ -2230,25 +2230,32 @@ virDomainDefGetVcpusTopology(const virDomainDef *def,
 }
 
 
-virDomainDiskDef *
-virDomainDiskDefNew(virDomainXMLOption *xmlopt)
+static virDomainDiskDef *
+virDomainDiskDefNewSource(virDomainXMLOption *xmlopt,
+                          virStorageSource **src)
 {
+    void *privateData = NULL;
     virDomainDiskDef *ret;
 
-    ret = g_new0(virDomainDiskDef, 1);
-
-    ret->src = virStorageSourceNew();
-
     if (xmlopt &&
         xmlopt->privateData.diskNew &&
-        !(ret->privateData = xmlopt->privateData.diskNew()))
-        goto error;
+        !(privateData = xmlopt->privateData.diskNew()))
+        return NULL;
+
+    ret = g_new0(virDomainDiskDef, 1);
+    ret->src = g_steal_pointer(src);
+    ret->privateData = privateData;
 
     return ret;
+}
 
- error:
-    virDomainDiskDefFree(ret);
-    return NULL;
+
+virDomainDiskDef *
+virDomainDiskDefNew(virDomainXMLOption *xmlopt)
+{
+    g_autoptr(virStorageSource) src = virStorageSourceNew();
+
+    return virDomainDiskDefNewSource(xmlopt, &src);
 }