]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Don't update volume objs list before we successfully create one
authorErik Skultety <eskultet@redhat.com>
Thu, 28 May 2015 15:00:01 +0000 (17:00 +0200)
committerErik Skultety <eskultet@redhat.com>
Tue, 2 Jun 2015 13:02:02 +0000 (15:02 +0200)
We do update pool volume object list before we actually create any
volume. If buildVol fails, we then try to delete the volume in the
storage as well as remove it from our structures. The problem is, that
any backend that supports both buildVol and deleteVol would fail in this
case which is completely unnecessary. This patch causes the update to
take place after we know a volume has been created successfully, thus no
removal in case of a buildVol failure is necessary.

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

src/storage/storage_driver.c

index 394e4d4553bc18798cf78a7df06cfbe5f0d37c1a..ab8675db8179db0e92c397ed4513a3a2016f1171 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * storage_driver.c: core driver for storage APIs
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2015 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -1808,9 +1808,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,
@@ -1825,14 +1822,6 @@ storageVolCreateXML(virStoragePoolPtr obj,
     if (backend->createVol(obj->conn, pool, voldef) < 0)
         goto cleanup;
 
-    pool->volumes.objs[pool->volumes.count++] = voldef;
-    volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name,
-                              voldef->key, NULL, NULL);
-    if (!volobj) {
-        pool->volumes.count--;
-        goto cleanup;
-    }
-
     if (VIR_ALLOC(buildvoldef) < 0) {
         voldef = NULL;
         goto cleanup;
@@ -1861,16 +1850,19 @@ storageVolCreateXML(virStoragePoolPtr obj,
         voldef->building = false;
         pool->asyncjobs--;
 
-        if (buildret < 0) {
-            VIR_FREE(buildvoldef);
-            storageVolDeleteInternal(volobj, backend, pool, voldef,
-                                     0, false);
-            voldef = NULL;
+        if (buildret < 0)
             goto cleanup;
-        }
-
     }
 
+    if (VIR_REALLOC_N(pool->volumes.objs,
+                      pool->volumes.count+1) < 0)
+        goto cleanup;
+
+    pool->volumes.objs[pool->volumes.count++] = voldef;
+    if (!(volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name,
+                                    voldef->key, NULL, NULL)))
+        goto cleanup;
+
     if (backend->refreshVol &&
         backend->refreshVol(obj->conn, pool, voldef) < 0)
         goto cleanup;