8c03ec
From a88996cc6c72a6f7fd034c0890747c54cc377484 Mon Sep 17 00:00:00 2001
8c03ec
Message-Id: <a88996cc6c72a6f7fd034c0890747c54cc377484@dist-git>
8c03ec
From: Pavel Hrdina <phrdina@redhat.com>
8c03ec
Date: Fri, 19 Feb 2021 13:33:56 +0100
8c03ec
Subject: [PATCH] vircgroupv1: refactor virCgroupV1DetectPlacement
8c03ec
MIME-Version: 1.0
8c03ec
Content-Type: text/plain; charset=UTF-8
8c03ec
Content-Transfer-Encoding: 8bit
8c03ec
8c03ec
Remove one level of indentation by splitting the condition.
8c03ec
8c03ec
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
8c03ec
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
8c03ec
(cherry picked from commit 5f56dd7c83493f14a471bb9e33415b04329a08bf)
8c03ec
8c03ec
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463
8c03ec
8c03ec
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
8c03ec
Message-Id: <ce477880853d3a9988389789611b68c458834600.1613737828.git.phrdina@redhat.com>
8c03ec
Reviewed-by: Ján Tomko <jtomko@redhat.com>
8c03ec
---
8c03ec
 src/util/vircgroupv1.c | 39 ++++++++++++++++++++++-----------------
8c03ec
 1 file changed, 22 insertions(+), 17 deletions(-)
8c03ec
8c03ec
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
8c03ec
index 7ec8f3a316..09165ece4d 100644
8c03ec
--- a/src/util/vircgroupv1.c
8c03ec
+++ b/src/util/vircgroupv1.c
8c03ec
@@ -339,23 +339,28 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
8c03ec
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
8c03ec
         const char *typestr = virCgroupV1ControllerTypeToString(i);
8c03ec
 
8c03ec
-        if (virCgroupV1MountOptsMatchController(controllers, typestr) &&
8c03ec
-            group->legacy[i].mountPoint != NULL &&
8c03ec
-            group->legacy[i].placement == NULL) {
8c03ec
-            /*
8c03ec
-             * selfpath == "/" + path="" -> "/"
8c03ec
-             * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
8c03ec
-             * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
8c03ec
-             */
8c03ec
-            if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
8c03ec
-                group->legacy[i].placement = g_strdup(selfpath);
8c03ec
-            } else {
8c03ec
-                bool delim = STREQ(selfpath, "/") || STREQ(path, "");
8c03ec
-
8c03ec
-                group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath,
8c03ec
-                                                             delim ? "" : "/",
8c03ec
-                                                             path);
8c03ec
-            }
8c03ec
+        if (!virCgroupV1MountOptsMatchController(controllers, typestr))
8c03ec
+            continue;
8c03ec
+
8c03ec
+        if (!group->legacy[i].mountPoint)
8c03ec
+            continue;
8c03ec
+
8c03ec
+        if (group->legacy[i].placement)
8c03ec
+            continue;
8c03ec
+
8c03ec
+        /*
8c03ec
+         * selfpath == "/" + path="" -> "/"
8c03ec
+         * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
8c03ec
+         * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
8c03ec
+         */
8c03ec
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
8c03ec
+            group->legacy[i].placement = g_strdup(selfpath);
8c03ec
+        } else {
8c03ec
+            bool delim = STREQ(selfpath, "/") || STREQ(path, "");
8c03ec
+
8c03ec
+            group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath,
8c03ec
+                                                         delim ? "" : "/",
8c03ec
+                                                         path);
8c03ec
         }
8c03ec
     }
8c03ec
 
8c03ec
-- 
8c03ec
2.30.0
8c03ec