c401cc
From 7bfd3d12b0886983dc96d451fc68e9d99badc412 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <7bfd3d12b0886983dc96d451fc68e9d99badc412@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:10 +0100
c401cc
Subject: [PATCH] conf: Refactor virDomainDiskSourcePoolDefParse
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
For some strange reason virDomainDiskSourcePoolDefParse accessed def of
c401cc
the disk and allocated the pool object in it. To avoid the need to carry
c401cc
over the disk definition object, refactor this function to return the
c401cc
allocated object instead.
c401cc
c401cc
(cherry picked from commit 6e037015a41a31534aca5fde207dc81b94497456)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/conf/domain_conf.c | 41 ++++++++++++++++++++---------------------
c401cc
 1 file changed, 20 insertions(+), 21 deletions(-)
c401cc
c401cc
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c401cc
index 9456758..96185ca 100644
c401cc
--- a/src/conf/domain_conf.c
c401cc
+++ b/src/conf/domain_conf.c
c401cc
@@ -4785,49 +4785,48 @@ cleanup:
c401cc
 
c401cc
 static int
c401cc
 virDomainDiskSourcePoolDefParse(xmlNodePtr node,
c401cc
-                                virDomainDiskDefPtr def)
c401cc
+                                virDomainDiskSourcePoolDefPtr *srcpool)
c401cc
 {
c401cc
-    char *pool = NULL;
c401cc
-    char *volume = NULL;
c401cc
     char *mode = NULL;
c401cc
+    virDomainDiskSourcePoolDefPtr source;
c401cc
     int ret = -1;
c401cc
 
c401cc
-    pool = virXMLPropString(node, "pool");
c401cc
-    volume = virXMLPropString(node, "volume");
c401cc
+    *srcpool = NULL;
c401cc
+
c401cc
+    if (VIR_ALLOC(source) < 0)
c401cc
+        return -1;
c401cc
+
c401cc
+    source->pool = virXMLPropString(node, "pool");
c401cc
+    source->volume = virXMLPropString(node, "volume");
c401cc
     mode = virXMLPropString(node, "mode");
c401cc
 
c401cc
     /* CD-ROM and Floppy allows no source */
c401cc
-    if (!pool && !volume)
c401cc
-        return 0;
c401cc
+    if (!source->pool && !source->volume) {
c401cc
+        ret = 0;
c401cc
+        goto cleanup;
c401cc
+    }
c401cc
 
c401cc
-    if (!pool || !volume) {
c401cc
+    if (!source->pool || !source->volume) {
c401cc
         virReportError(VIR_ERR_XML_ERROR, "%s",
c401cc
                        _("'pool' and 'volume' must be specified together "
c401cc
                          "for 'pool' type source"));
c401cc
         goto cleanup;
c401cc
     }
c401cc
 
c401cc
-    if (VIR_ALLOC(def->srcpool) < 0)
c401cc
-        goto cleanup;
c401cc
-
c401cc
-    if (mode && (def->srcpool->mode =
c401cc
-                 virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) {
c401cc
+    if (mode &&
c401cc
+        (source->mode = virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) {
c401cc
         virReportError(VIR_ERR_XML_ERROR,
c401cc
                        _("unknown source mode '%s' for volume type disk"),
c401cc
                        mode);
c401cc
         goto cleanup;
c401cc
     }
c401cc
 
c401cc
-    def->srcpool->pool = pool;
c401cc
-    pool = NULL;
c401cc
-    def->srcpool->volume = volume;
c401cc
-    volume = NULL;
c401cc
-
c401cc
+    *srcpool = source;
c401cc
+    source = NULL;
c401cc
     ret = 0;
c401cc
 
c401cc
 cleanup:
c401cc
-    VIR_FREE(pool);
c401cc
-    VIR_FREE(volume);
c401cc
+    virDomainDiskSourcePoolDefFree(source);
c401cc
     VIR_FREE(mode);
c401cc
     return ret;
c401cc
 }
c401cc
@@ -5017,7 +5016,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
c401cc
                     }
c401cc
                     break;
c401cc
                 case VIR_DOMAIN_DISK_TYPE_VOLUME:
c401cc
-                    if (virDomainDiskSourcePoolDefParse(cur, def) < 0)
c401cc
+                    if (virDomainDiskSourcePoolDefParse(cur, &def->srcpool) < 0)
c401cc
                         goto error;
c401cc
                     break;
c401cc
                 default:
c401cc
-- 
c401cc
1.9.0
c401cc