[libvirt PATCH 11/11] storage: Use automatic mutex management

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


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

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 3bd5d07efb..74c03b4cbf 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -65,16 +65,6 @@ struct _virStorageVolStreamInfo {
     char *vol_path;
 };
 
-static void storageDriverLock(void)
-{
-    virMutexLock(&mutex);
-}
-static void storageDriverUnlock(void)
-{
-    virMutexUnlock(&mutex);
-}
-
-
 static void
 storagePoolRefreshFailCleanup(virStorageBackend *backend,
                               virStoragePoolObj *obj,
@@ -297,6 +287,7 @@ storageStateInitialize(bool privileged,
     g_autofree char *configdir = NULL;
     g_autofree char *rundir = NULL;
     bool autostart = true;
+    VIR_LOCK_GUARD lock = virLockGuardLock(&mutex);
 
     if (root != NULL) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -307,7 +298,6 @@ storageStateInitialize(bool privileged,
     driver = g_new0(virStorageDriverState, 1);
 
     driver->lockFD = -1;
-    storageDriverLock();
 
     if (!(driver->pools = virStoragePoolObjListNew()))
         goto error;
@@ -363,13 +353,10 @@ storageStateInitialize(bool privileged,
     if (!(driver->caps = virStorageBackendGetCapabilities()))
         goto error;
 
-    storageDriverUnlock();
-
     return VIR_DRV_STATE_INIT_COMPLETE;
 
  error:
-    storageDriverUnlock();
-    storageStateCleanup();
+    storageStateCleanupLocked();
     return VIR_DRV_STATE_INIT_ERROR;
 }
 
@@ -382,17 +369,17 @@ storageStateInitialize(bool privileged,
 static int
 storageStateReload(void)
 {
+    VIR_LOCK_GUARD lock = virLockGuardLock(&mutex);
+
     if (!driver)
         return -1;
 
-    storageDriverLock();
     virStoragePoolObjLoadAllState(driver->pools,
                                   driver->stateDir);
     virStoragePoolObjLoadAllConfigs(driver->pools,
                                     driver->configDir,
                                     driver->autostartDir);
     storageDriverAutostart();
-    storageDriverUnlock();
 
     return 0;
 }
-- 
2.31.1




More information about the libvir-list mailing list