[libvirt PATCH 04/12] nwfilter_gentech: Use automatic mutex management

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/nwfilter/nwfilter_gentech_driver.c | 34 +++++++++-----------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 7bbf1e12fb..3f888ce873 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -717,9 +717,7 @@ virNWFilterInstantiateFilterInternal(virNWFilterDriverState *driver,
                                      bool *foundNewFilter)
 {
     int ifindex;
-    int rc;
-
-    virMutexLock(&updateMutex);
+    VIR_LOCK_GUARD lock = virLockGuardLock(&updateMutex);
 
     /* after grabbing the filter update lock check for the interface; if
        it's not there anymore its filters will be or are being removed
@@ -729,20 +727,14 @@ virNWFilterInstantiateFilterInternal(virNWFilterDriverState *driver,
         /* interfaces / VMs can disappear during filter instantiation;
            don't mark it as an error */
         virResetLastError();
-        rc = 0;
-        goto cleanup;
+        return 0;
     }
 
-    rc = virNWFilterInstantiateFilterUpdate(driver, teardownOld,
-                                            binding,
-                                            ifindex,
-                                            useNewFilter,
-                                            false, foundNewFilter);
-
- cleanup:
-    virMutexUnlock(&updateMutex);
-
-    return rc;
+    return virNWFilterInstantiateFilterUpdate(driver, teardownOld,
+                                              binding,
+                                              ifindex,
+                                              useNewFilter,
+                                              false, foundNewFilter);
 }
 
 
@@ -753,9 +745,10 @@ virNWFilterInstantiateFilterLate(virNWFilterDriverState *driver,
 {
     int rc;
     bool foundNewFilter = false;
+    VIR_LOCK_GUARD lock = { NULL };
 
     virNWFilterReadLockFilterUpdates();
-    virMutexLock(&updateMutex);
+    lock = virLockGuardLock(&updateMutex);
 
     rc = virNWFilterInstantiateFilterUpdate(driver, true,
                                             binding, ifindex,
@@ -772,7 +765,6 @@ virNWFilterInstantiateFilterLate(virNWFilterDriverState *driver,
     }
 
     virNWFilterUnlockFilterUpdates();
-    virMutexUnlock(&updateMutex);
 
     return rc;
 }
@@ -894,11 +886,9 @@ _virNWFilterTeardownFilter(const char *ifname)
 int
 virNWFilterTeardownFilter(virNWFilterBindingDef *binding)
 {
-    int ret;
-    virMutexLock(&updateMutex);
-    ret = _virNWFilterTeardownFilter(binding->portdevname);
-    virMutexUnlock(&updateMutex);
-    return ret;
+    VIR_LOCK_GUARD lock = virLockGuardLock(&updateMutex);
+
+    return _virNWFilterTeardownFilter(binding->portdevname);
 }
 
 enum {
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux