[libvirt] [PATCH 3/4] storageVolCreateXML: Swap order of two operations

Michal Privoznik mprivozn at redhat.com
Wed Feb 10 16:28:56 UTC 2016


Firstly, we realloc internal list to hold new item (=volume that
will be potentially be created) and then we check whether we
actually know how to create it. If we don't we consume more
memory than we really need for no good reason.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/storage/storage_driver.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 8ee2840..e0ded01 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1856,10 +1856,6 @@ storageVolCreateXML(virStoragePoolPtr obj,
         goto cleanup;
     }
 
-    if (VIR_REALLOC_N(pool->volumes.objs,
-                      pool->volumes.count+1) < 0)
-        goto cleanup;
-
     if (!backend->createVol) {
         virReportError(VIR_ERR_NO_SUPPORT,
                        "%s", _("storage pool does not support volume "
@@ -1867,6 +1863,10 @@ storageVolCreateXML(virStoragePoolPtr obj,
         goto cleanup;
     }
 
+    if (VIR_REALLOC_N(pool->volumes.objs,
+                      pool->volumes.count+1) < 0)
+        goto cleanup;
+
     /* Wipe any key the user may have suggested, as volume creation
      * will generate the canonical key.  */
     VIR_FREE(voldef->key);
-- 
2.4.10




More information about the libvir-list mailing list