[libvirt PATCH 5/9] vircgroupv1: refactor virCgroupV1DetectPlacement

Pavel Hrdina phrdina at redhat.com
Tue Feb 9 13:26:10 UTC 2021


Remove one level of indentation by splitting the condition.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/util/vircgroupv1.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index edb2c23bbc..f4dd20fd73 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -339,23 +339,28 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
         const char *typestr = virCgroupV1ControllerTypeToString(i);
 
-        if (virCgroupV1MountOptsMatchController(controllers, typestr) &&
-            group->legacy[i].mountPoint != NULL &&
-            group->legacy[i].placement == NULL) {
-            /*
-             * selfpath == "/" + path="" -> "/"
-             * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
-             * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
-             */
-            if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
-                group->legacy[i].placement = g_strdup(selfpath);
-            } else {
-                bool delim = STREQ(selfpath, "/") || STREQ(path, "");
+        if (!virCgroupV1MountOptsMatchController(controllers, typestr))
+            continue;
 
-                group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath,
-                                                             delim ? "" : "/",
-                                                             path);
-            }
+        if (!group->legacy[i].mountPoint)
+            continue;
+
+        if (group->legacy[i].placement)
+            continue;
+
+        /*
+         * selfpath == "/" + path="" -> "/"
+         * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
+         * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
+         */
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
+            group->legacy[i].placement = g_strdup(selfpath);
+        } else {
+            bool delim = STREQ(selfpath, "/") || STREQ(path, "");
+
+            group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath,
+                                                         delim ? "" : "/",
+                                                         path);
         }
     }
 
-- 
2.29.2




More information about the libvir-list mailing list