[libvirt] [PATCH 5/6] storage: Unlink stateFile in storagePoolSetInactive

Cole Robinson crobinso at redhat.com
Thu Jun 23 00:12:15 UTC 2016


There are several places in the storage driver where a runtime
stateFile is not being unlinked when the pool is shutdown. Move
the unlinking to storagePoolSetInactive to fix those locations

One minor semantic change is that we no longer fail PoolDestroy
if we fail to build the stateFile path string, but I don't think
that matters.
---
 src/storage/storage_driver.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 9e97f62..8f8d098 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -89,6 +89,13 @@ storagePoolSetInactive(virStoragePoolObjPtr pool)
 {
     bool ret = false;
     pool->active = false;
+    char *stateFile;
+
+    stateFile = virFileBuildPath(driver->stateDir, pool->def->name, ".xml");
+    if (stateFile) {
+        unlink(stateFile);
+        VIR_FREE(stateFile);
+    }
 
     if (pool->configFile == NULL) {
         virStoragePoolObjRemove(&driver->pools, pool);
@@ -112,11 +119,6 @@ storagePoolUpdateState(virStoragePoolObjPtr pool)
     bool active = false;
     virStorageBackendPtr backend;
     bool ret = false;
-    char *stateFile;
-
-    if (!(stateFile = virFileBuildPath(driver->stateDir,
-                                       pool->def->name, ".xml")))
-        goto error;
 
     if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -153,12 +155,8 @@ storagePoolUpdateState(virStoragePoolObjPtr pool)
 
     pool->active = active;
  error:
-    if (!active) {
+    if (!active)
         ret = storagePoolSetInactive(pool);
-        if (stateFile)
-            unlink(stateFile);
-    }
-    VIR_FREE(stateFile);
 
     return ret;
 }
@@ -210,8 +208,6 @@ storageDriverAutostartPool(virConnectPtr conn,
     if (!stateFile ||
         virStoragePoolSaveState(stateFile, pool->def) < 0 ||
         backend->refreshPool(conn, pool) < 0) {
-        if (stateFile)
-            unlink(stateFile);
         if (backend->stopPool)
             backend->stopPool(conn, pool);
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -774,8 +770,6 @@ storagePoolCreateXML(virConnectPtr conn,
     virStoragePoolObjClearVols(pool);
     if (!stateFile || virStoragePoolSaveState(stateFile, pool->def) < 0 ||
         backend->refreshPool(conn, pool) < 0) {
-        if (stateFile)
-            unlink(stateFile);
         if (backend->stopPool)
             backend->stopPool(conn, pool);
         if (storagePoolSetInactive(pool))
@@ -991,8 +985,6 @@ storagePoolCreate(virStoragePoolPtr obj,
     virStoragePoolObjClearVols(pool);
     if (!stateFile || virStoragePoolSaveState(stateFile, pool->def) < 0 ||
         backend->refreshPool(obj->conn, pool) < 0) {
-        if (stateFile)
-            unlink(stateFile);
         if (backend->stopPool)
             backend->stopPool(obj->conn, pool);
 
@@ -1060,7 +1052,6 @@ storagePoolDestroy(virStoragePoolPtr obj)
     virStoragePoolObjPtr pool;
     virStorageBackendPtr backend;
     virObjectEventPtr event = NULL;
-    char *stateFile = NULL;
     int ret = -1;
 
     storageDriverLock();
@@ -1094,13 +1085,6 @@ storagePoolDestroy(virStoragePoolPtr obj)
         goto cleanup;
     }
 
-    if (!(stateFile = virFileBuildPath(driver->stateDir,
-                                       pool->def->name,
-                                       ".xml")))
-        goto cleanup;
-
-    unlink(stateFile);
-    VIR_FREE(stateFile);
 
     if (backend->stopPool &&
         backend->stopPool(obj->conn, pool) < 0)
-- 
2.7.4




More information about the libvir-list mailing list