@@ -76,6 +76,32 @@ static void storageDriverUnlock(void)
virMutexUnlock(&driver->lock);
}
+/*
+ * storagePoolSetInactive:
+ * Helper for setting a pool object as 'inactive'. Handles reassigning
+ * newDef for persistent pools, and removing and freeing the object
+ * for transient pools.
+ *
+ * Returns true if pool was removed from driver->pools
+ */
+static bool
+storagePoolSetInactive(virStoragePoolObjPtr pool)
+{
+ bool ret = false;
+ pool->active = false;
+
+ if (pool->configFile == NULL) {
+ virStoragePoolObjRemove(&driver->pools, pool);
+ ret = true;
+ } else if (pool->newDef) {
+ virStoragePoolDefFree(pool->def);
+ pool->def = pool->newDef;
+ pool->newDef = NULL;
+ }
+
+ return ret;
+}
+
static void
storagePoolUpdateState(virStoragePoolObjPtr pool)
{
@@ -182,6 +208,10 @@ storageDriverAutostartPool(virConnectPtr conn,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to autostart storage pool '%s': %s"),
pool->def->name, virGetLastErrorMessage());
+
+ /* Don't check the return value, it should never be 'true' here
+ * since this function requires a non-transient pool */
+ storagePoolSetInactive(pool);
goto cleanup;
}
@@ -739,8 +769,8 @@ storagePoolCreateXML(virConnectPtr conn,
unlink(stateFile);
if (backend->stopPool)
backend->stopPool(conn, pool);
- virStoragePoolObjRemove(&driver->pools, pool);
- pool = NULL;
+ if (storagePoolSetInactive(pool))
+ pool = NULL;
goto cleanup;
}
@@ -956,6 +986,10 @@ storagePoolCreate(virStoragePoolPtr obj,
unlink(stateFile);
if (backend->stopPool)
backend->stopPool(obj->conn, pool);
+
+ /* Don't check the return value, it should never be 'true' here
+ * since this function requires a non-transient pool */
+ storagePoolSetInactive(pool);
goto cleanup;
}
@@ -1070,16 +1104,8 @@ storagePoolDestroy(virStoragePoolPtr obj)
VIR_STORAGE_POOL_EVENT_STOPPED,
0);
- pool->active = false;
-
- if (pool->configFile == NULL) {
- virStoragePoolObjRemove(&driver->pools, pool);
+ if (storagePoolSetInactive(pool))
pool = NULL;
- } else if (pool->newDef) {
- virStoragePoolDefFree(pool->def);
- pool->def = pool->newDef;
- pool->newDef = NULL;
- }
ret = 0;
@@ -1199,12 +1225,8 @@ storagePoolRefresh(virStoragePoolPtr obj,
pool->def->uuid,
VIR_STORAGE_POOL_EVENT_STOPPED,
0);
- pool->active = false;
-
- if (pool->configFile == NULL) {
- virStoragePoolObjRemove(&driver->pools, pool);
+ if (storagePoolSetInactive(pool))
pool = NULL;
- }
goto cleanup;
}