From a88996cc6c72a6f7fd034c0890747c54cc377484 Mon Sep 17 00:00:00 2001 Message-Id: From: Pavel Hrdina Date: Fri, 19 Feb 2021 13:33:56 +0100 Subject: [PATCH] vircgroupv1: refactor virCgroupV1DetectPlacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove one level of indentation by splitting the condition. Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik (cherry picked from commit 5f56dd7c83493f14a471bb9e33415b04329a08bf) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463 Signed-off-by: Pavel Hrdina Message-Id: Reviewed-by: Ján Tomko --- src/util/vircgroupv1.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 7ec8f3a316..09165ece4d 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, ""); - - group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath, - delim ? "" : "/", - path); - } + if (!virCgroupV1MountOptsMatchController(controllers, typestr)) + continue; + + 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.30.0