[libvirt PATCH 10/11] storage: Move and split up storateStateCleanup

Tim Wiederhake twiederh at redhat.com
Thu Feb 17 13:01:02 UTC 2022


Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/storage/storage_driver.c | 71 +++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 34 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 05675a5539..3bd5d07efb 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -59,8 +59,6 @@ static virStorageDriverState *driver;
 
 static virMutex mutex = VIR_MUTEX_INITIALIZER;
 
-static int storageStateCleanup(void);
-
 typedef struct _virStorageVolStreamInfo virStorageVolStreamInfo;
 struct _virStorageVolStreamInfo {
     char *pool_name;
@@ -248,6 +246,43 @@ storageDriverAutostart(void)
                                  NULL);
 }
 
+static int
+storageStateCleanupLocked(void)
+{
+    if (!driver)
+        return -1;
+
+    virObjectUnref(driver->caps);
+    virObjectUnref(driver->storageEventState);
+
+    /* free inactive pools */
+    virObjectUnref(driver->pools);
+
+    if (driver->lockFD != -1)
+        virPidFileRelease(driver->stateDir, "driver",
+                          driver->lockFD);
+
+    VIR_FREE(driver->configDir);
+    VIR_FREE(driver->autostartDir);
+    VIR_FREE(driver->stateDir);
+    VIR_FREE(driver);
+
+    return 0;
+}
+
+/**
+ * storageStateCleanup
+ *
+ * Shutdown the storage driver, it will stop all active storage pools
+ */
+static int
+storageStateCleanup(void)
+{
+    VIR_LOCK_GUARD lock = virLockGuardLock(&mutex);
+
+    return storageStateCleanupLocked();
+}
+
 /**
  * virStorageStartup:
  *
@@ -363,38 +398,6 @@ storageStateReload(void)
 }
 
 
-/**
- * storageStateCleanup
- *
- * Shutdown the storage driver, it will stop all active storage pools
- */
-static int
-storageStateCleanup(void)
-{
-    if (!driver)
-        return -1;
-
-    storageDriverLock();
-
-    virObjectUnref(driver->caps);
-    virObjectUnref(driver->storageEventState);
-
-    /* free inactive pools */
-    virObjectUnref(driver->pools);
-
-    if (driver->lockFD != -1)
-        virPidFileRelease(driver->stateDir, "driver",
-                          driver->lockFD);
-
-    VIR_FREE(driver->configDir);
-    VIR_FREE(driver->autostartDir);
-    VIR_FREE(driver->stateDir);
-    storageDriverUnlock();
-    VIR_FREE(driver);
-
-    return 0;
-}
-
 static virDrvOpenStatus
 storageConnectOpen(virConnectPtr conn,
                    virConnectAuthPtr auth G_GNUC_UNUSED,
-- 
2.31.1




More information about the libvir-list mailing list