]> xenbits.xensource.com Git - libvirt.git/commitdiff
nwfilter_driver: Statically initialize mutex
authorTim Wiederhake <twiederh@redhat.com>
Tue, 15 Feb 2022 12:17:21 +0000 (13:17 +0100)
committerTim Wiederhake <twiederh@redhat.com>
Thu, 17 Mar 2022 15:44:46 +0000 (16:44 +0100)
This enables a later patch to simplify locking during initialization
and cleanup of virNWFilterDriverState.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/virnwfilterobj.h
src/nwfilter/nwfilter_driver.c

index 44ba31f732d6d8fba44734723b4ce88f7963fbf6..c365d0f28af9b15398cc440ffa039138befd2478 100644 (file)
@@ -30,7 +30,6 @@ typedef struct _virNWFilterObjList virNWFilterObjList;
 
 typedef struct _virNWFilterDriverState virNWFilterDriverState;
 struct _virNWFilterDriverState {
-    virMutex lock;
     bool privileged;
 
     /* pid file FD, ensures two copies of the driver can't use the same root */
index a493205c8013bd9ee00463bb6761365b3f64c673..0591f55e39b46c7cd8941615b541d3c7b20e22af 100644 (file)
@@ -57,13 +57,15 @@ static int nwfilterStateCleanup(void);
 
 static int nwfilterStateReload(void);
 
+static virMutex driverMutex = VIR_MUTEX_INITIALIZER;
+
 static void nwfilterDriverLock(void)
 {
-    virMutexLock(&driver->lock);
+    virMutexLock(&driverMutex);
 }
 static void nwfilterDriverUnlock(void)
 {
-    virMutexUnlock(&driver->lock);
+    virMutexUnlock(&driverMutex);
 }
 
 #ifdef WITH_FIREWALLD
@@ -174,10 +176,8 @@ nwfilterStateInitialize(bool privileged,
     driver = g_new0(virNWFilterDriverState, 1);
 
     driver->lockFD = -1;
-    if (virMutexInit(&driver->lock) < 0)
-        goto err_free_driverstate;
-
     driver->privileged = privileged;
+
     if (!(driver->nwfilters = virNWFilterObjListNew()))
         goto error;
 
@@ -343,7 +343,6 @@ nwfilterStateCleanup(void)
     /* free inactive nwfilters */
     virNWFilterObjListFree(driver->nwfilters);
 
-    virMutexDestroy(&driver->lock);
     g_clear_pointer(&driver, g_free);
 
     return 0;