render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 7bfd3d12b0886983dc96d451fc68e9d99badc412 Mon Sep 17 00:00:00 2001
Message-Id: <7bfd3d12b0886983dc96d451fc68e9d99badc412@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:54:10 +0100
Subject: [PATCH] conf: Refactor virDomainDiskSourcePoolDefParse

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

For some strange reason virDomainDiskSourcePoolDefParse accessed def of
the disk and allocated the pool object in it. To avoid the need to carry
over the disk definition object, refactor this function to return the
allocated object instead.

(cherry picked from commit 6e037015a41a31534aca5fde207dc81b94497456)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9456758..96185ca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4785,49 +4785,48 @@ cleanup:
 
 static int
 virDomainDiskSourcePoolDefParse(xmlNodePtr node,
-                                virDomainDiskDefPtr def)
+                                virDomainDiskSourcePoolDefPtr *srcpool)
 {
-    char *pool = NULL;
-    char *volume = NULL;
     char *mode = NULL;
+    virDomainDiskSourcePoolDefPtr source;
     int ret = -1;
 
-    pool = virXMLPropString(node, "pool");
-    volume = virXMLPropString(node, "volume");
+    *srcpool = NULL;
+
+    if (VIR_ALLOC(source) < 0)
+        return -1;
+
+    source->pool = virXMLPropString(node, "pool");
+    source->volume = virXMLPropString(node, "volume");
     mode = virXMLPropString(node, "mode");
 
     /* CD-ROM and Floppy allows no source */
-    if (!pool && !volume)
-        return 0;
+    if (!source->pool && !source->volume) {
+        ret = 0;
+        goto cleanup;
+    }
 
-    if (!pool || !volume) {
+    if (!source->pool || !source->volume) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("'pool' and 'volume' must be specified together "
                          "for 'pool' type source"));
         goto cleanup;
     }
 
-    if (VIR_ALLOC(def->srcpool) < 0)
-        goto cleanup;
-
-    if (mode && (def->srcpool->mode =
-                 virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) {
+    if (mode &&
+        (source->mode = virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("unknown source mode '%s' for volume type disk"),
                        mode);
         goto cleanup;
     }
 
-    def->srcpool->pool = pool;
-    pool = NULL;
-    def->srcpool->volume = volume;
-    volume = NULL;
-
+    *srcpool = source;
+    source = NULL;
     ret = 0;
 
 cleanup:
-    VIR_FREE(pool);
-    VIR_FREE(volume);
+    virDomainDiskSourcePoolDefFree(source);
     VIR_FREE(mode);
     return ret;
 }
@@ -5017,7 +5016,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
                     }
                     break;
                 case VIR_DOMAIN_DISK_TYPE_VOLUME:
-                    if (virDomainDiskSourcePoolDefParse(cur, def) < 0)
+                    if (virDomainDiskSourcePoolDefParse(cur, &def->srcpool) < 0)
                         goto error;
                     break;
                 default:
-- 
1.9.0