]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: driver: Split out code fixing pool state after deactivation
authorPeter Krempa <pkrempa@redhat.com>
Thu, 30 Mar 2017 11:45:45 +0000 (13:45 +0200)
committerCole Robinson <crobinso@redhat.com>
Wed, 10 May 2017 19:42:45 +0000 (15:42 -0400)
After a pool is made inactive the definition objects need to be updated
(if a new definition is prepared) and transient pools need to be
completely removed. Split out the code doing these steps into a separate
function for later reuse.

(cherry picked from commit aced6b23560b7d697069b0d81cfab230e2b20c47)

src/storage/storage_driver.c

index 6f1e3727d6e880b5288163cee2b1575063f8db4c..df3d78ca1318ac6e792a75ea9133404c0da1ea50 100644 (file)
@@ -76,6 +76,31 @@ static void storageDriverUnlock(void)
     virMutexUnlock(&driver->lock);
 }
 
+
+/**
+ * virStoragePoolUpdateInactive:
+ * @poolptr: pointer to a variable holding the pool object pointer
+ *
+ * This function is supposed to be called after a pool becomes inactive. The
+ * function switches to the new config object for persistent pools. Inactive
+ * pools are removed.
+ */
+static void
+virStoragePoolUpdateInactive(virStoragePoolObjPtr *poolptr)
+{
+    virStoragePoolObjPtr pool = *poolptr;
+
+    if (pool->configFile == NULL) {
+        virStoragePoolObjRemove(&driver->pools, pool);
+        *poolptr = NULL;
+    } else if (pool->newDef) {
+        virStoragePoolDefFree(pool->def);
+        pool->def = pool->newDef;
+        pool->newDef = NULL;
+    }
+}
+
+
 static void
 storagePoolUpdateState(virStoragePoolObjPtr pool)
 {
@@ -1067,14 +1092,7 @@ storagePoolDestroy(virStoragePoolPtr obj)
 
     pool->active = false;
 
-    if (pool->configFile == NULL) {
-        virStoragePoolObjRemove(&driver->pools, pool);
-        pool = NULL;
-    } else if (pool->newDef) {
-        virStoragePoolDefFree(pool->def);
-        pool->def = pool->newDef;
-        pool->newDef = NULL;
-    }
+    virStoragePoolUpdateInactive(&pool);
 
     ret = 0;
 
@@ -1196,10 +1214,8 @@ storagePoolRefresh(virStoragePoolPtr obj,
                                                 0);
         pool->active = false;
 
-        if (pool->configFile == NULL) {
-            virStoragePoolObjRemove(&driver->pools, pool);
-            pool = NULL;
-        }
+        virStoragePoolUpdateInactive(&pool);
+
         goto cleanup;
     }