[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2] avoid false pool creation discard pool definition



False pool creation will clear previous definition.
This patch roll back to previous definition after pool-creat fails
ref:
http://www.redhat.com/archives/libvir-list/2011-November/msg01152.html
http://www.redhat.com/archives/libvir-list/2011-November/msg01152.html

Signed-off-by: Wen Ruo Lv <lvroyce linux vnet ibm com>
---
 src/conf/storage_conf.c      |   15 +++++++++++++--
 src/conf/storage_conf.h      |    2 +-
 src/libvirt_private.syms     |    1 +
 src/storage/storage_driver.c |   32 ++++++++++++++++++++++----------
 4 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index dadc115..4186036 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1387,15 +1387,17 @@ virStoragePoolObjPtr
 virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
                            virStoragePoolDefPtr def) {
     virStoragePoolObjPtr pool;
+    virStoragePoolDefPtr lastDef;
 
     if ((pool = virStoragePoolObjFindByName(pools, def->name))) {
         if (!virStoragePoolObjIsActive(pool)) {
-            virStoragePoolDefFree(pool->def);
+            lastDef = pool->def;
             pool->def = def;
         } else {
-            virStoragePoolDefFree(pool->newDef);
+            lastDef = pool->newDef;
             pool->newDef = def;
         }
+        def = lastDef;
         return pool;
     }
 
@@ -1413,6 +1415,7 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
     virStoragePoolObjLock(pool);
     pool->active = 0;
     pool->def = def;
+    def = NULL;
 
     if (VIR_REALLOC_N(pools->objs, pools->count+1) < 0) {
         pool->def = NULL;
@@ -1426,6 +1429,14 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
     return pool;
 }
 
+void virStoragePoolObjDefRollBack(virStoragePoolDefPtr def,virStoragePoolDefPtr lastDef)
+{
+    virStoragePoolDefPtr tmpDef;
+
+    tmpDef = def;
+    def = lastDef;
+    lastDef = tmpDef;
+}
 static virStoragePoolObjPtr
 virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
                       const char *file,
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 19bbd2c..bfd8904 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -365,7 +365,7 @@ char *virStorageVolDefFormat(virStoragePoolDefPtr pool,
 
 virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
                                                 virStoragePoolDefPtr def);
-
+void virStoragePoolObjDefRollBack(virStoragePoolDefPtr def,virStoragePoolDefPtr lastDef);
 int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
                              virStoragePoolObjPtr pool,
                              virStoragePoolDefPtr def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0b21cdc..391998c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -975,6 +975,7 @@ virStoragePoolLoadAllConfigs;
 virStoragePoolObjAssignDef;
 virStoragePoolObjClearVols;
 virStoragePoolObjDeleteDef;
+virStoragePoolObjDefRollBack;
 virStoragePoolObjFindByName;
 virStoragePoolObjFindByUUID;
 virStoragePoolObjIsDuplicate;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 8c2d6e1..2e6ae05 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -526,6 +526,7 @@ storagePoolCreate(virConnectPtr conn,
     virStoragePoolObjPtr pool = NULL;
     virStoragePoolPtr ret = NULL;
     virStorageBackendPtr backend;
+    int dupPool;
 
     virCheckFlags(0, NULL);
 
@@ -533,7 +534,7 @@ storagePoolCreate(virConnectPtr conn,
     if (!(def = virStoragePoolDefParseString(xml)))
         goto cleanup;
 
-    if (virStoragePoolObjIsDuplicate(&driver->pools, def, 1) < 0)
+    if ((dupPool = virStoragePoolObjIsDuplicate(&driver->pools, def, 1)) < 0)
         goto cleanup;
 
     if (virStoragePoolSourceFindDuplicate(&driver->pools, def) < 0)
@@ -544,20 +545,27 @@ storagePoolCreate(virConnectPtr conn,
 
     if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def)))
         goto cleanup;
-    def = NULL;
 
     if (backend->startPool &&
         backend->startPool(conn, pool) < 0) {
-        virStoragePoolObjRemove(&driver->pools, pool);
-        pool = NULL;
+        if (dupPool)
+            virStoragePoolObjDefRollBack(pool->def, def);
+        else {
+            virStoragePoolObjRemove(&driver->pools, pool);
+            pool = NULL;
+        }
         goto cleanup;
     }
 
     if (backend->refreshPool(conn, pool) < 0) {
         if (backend->stopPool)
             backend->stopPool(conn, pool);
-        virStoragePoolObjRemove(&driver->pools, pool);
-        pool = NULL;
+        if (dupPool)
+            virStoragePoolObjDefRollBack(pool->def, def);
+        else {
+            virStoragePoolObjRemove(&driver->pools, pool);
+            pool = NULL;
+        }
         goto cleanup;
     }
     VIR_INFO("Creating storage pool '%s'", pool->def->name);
@@ -582,6 +590,7 @@ storagePoolDefine(virConnectPtr conn,
     virStoragePoolDefPtr def;
     virStoragePoolObjPtr pool = NULL;
     virStoragePoolPtr ret = NULL;
+    int dupPool;
 
     virCheckFlags(0, NULL);
 
@@ -589,7 +598,7 @@ storagePoolDefine(virConnectPtr conn,
     if (!(def = virStoragePoolDefParseString(xml)))
         goto cleanup;
 
-    if (virStoragePoolObjIsDuplicate(&driver->pools, def, 0) < 0)
+    if ((dupPool = virStoragePoolObjIsDuplicate(&driver->pools, def, 0)) < 0)
         goto cleanup;
 
     if (virStoragePoolSourceFindDuplicate(&driver->pools, def) < 0)
@@ -602,11 +611,14 @@ storagePoolDefine(virConnectPtr conn,
         goto cleanup;
 
     if (virStoragePoolObjSaveDef(driver, pool, def) < 0) {
-        virStoragePoolObjRemove(&driver->pools, pool);
-        def = NULL;
+        if (dupPool)
+            virStoragePoolObjDefRollBack(pool->def, def);
+        else {
+            virStoragePoolObjRemove(&driver->pools, pool);
+            pool = NULL;
+        }
         goto cleanup;
     }
-    def = NULL;
 
     VIR_INFO("Defining storage pool '%s'", pool->def->name);
     ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
-- 
1.7.4.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]