[libvirt PATCH 04/11] lxc: Prepare virLXCDriverGetCapabilities for automatic mutex management

Tim Wiederhake twiederh at redhat.com
Mon Feb 7 13:12:07 UTC 2022


No functional change intended. This change makes the recfatoring to
automatic mutex management easier to follow.

Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/lxc/lxc_conf.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 8955578d54..cf6679711a 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -156,28 +156,28 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
 virCaps *virLXCDriverGetCapabilities(virLXCDriver *driver,
                                        bool refresh)
 {
-    virCaps *ret;
-    if (refresh) {
-        virCaps *caps = NULL;
-        if ((caps = virLXCDriverCapsInit(driver)) == NULL)
-            return NULL;
+    virCaps *ret = NULL;
+    virCaps *caps = NULL;
+
+    lxcDriverLock(driver);
+    if (!refresh && !driver->caps) {
+        VIR_DEBUG("Capabilities didn't detect any guests. Forcing a refresh.");
+        refresh = true;
+    }
+    lxcDriverUnlock(driver);
 
-        lxcDriverLock(driver);
+    if (refresh && !(caps = virLXCDriverCapsInit(driver)))
+        return NULL;
+
+    lxcDriverLock(driver);
+    if (refresh) {
         virObjectUnref(driver->caps);
         driver->caps = caps;
-    } else {
-        lxcDriverLock(driver);
-
-        if (driver->caps == NULL) {
-            VIR_DEBUG("Capabilities didn't detect any guests. Forcing a "
-                      "refresh.");
-            lxcDriverUnlock(driver);
-            return virLXCDriverGetCapabilities(driver, true);
-        }
     }
 
     ret = virObjectRef(driver->caps);
     lxcDriverUnlock(driver);
+
     return ret;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list