From dc8f41bf6bb689d86bc91d5aca7fb854a5ef847f Mon Sep 17 00:00:00 2001 Message-Id: From: Pavel Hrdina Date: Mon, 1 Jul 2019 17:05:57 +0200 Subject: [PATCH] vircgroup: Use virCgroupMountOptsMatchController in virCgroupDetectPlacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel Hrdina (cherry picked from commit 801d95d2597572612c346508446320a33aebc50d) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297 Signed-off-by: Pavel Hrdina Message-Id: <9c2bb230e14ced391b0731bc2964155960025aa5.1561993099.git.phrdina@redhat.com> Reviewed-by: Ján Tomko --- src/util/vircgroup.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index ec9994780a..7888dab716 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -598,42 +598,27 @@ virCgroupDetectPlacement(virCgroupPtr group, for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { const char *typestr = virCgroupControllerTypeToString(i); - int typelen = strlen(typestr); - char *tmp = controllers; - - while (tmp) { - char *next = strchr(tmp, ','); - int len; - if (next) { - len = next - tmp; - next++; - } else { - len = strlen(tmp); - } + if (virCgroupMountOptsMatchController(controllers, typestr) && + group->controllers[i].mountPoint != NULL && + group->controllers[i].placement == NULL) { /* * selfpath == "/" + path="" -> "/" * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service" * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo" */ - if (typelen == len && STREQLEN(typestr, tmp, len) && - group->controllers[i].mountPoint != NULL && - group->controllers[i].placement == NULL) { - if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) { - if (VIR_STRDUP(group->controllers[i].placement, - selfpath) < 0) - goto cleanup; - } else { - if (virAsprintf(&group->controllers[i].placement, - "%s%s%s", selfpath, - (STREQ(selfpath, "/") || - STREQ(path, "") ? "" : "/"), - path) < 0) - goto cleanup; - } + if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) { + if (VIR_STRDUP(group->controllers[i].placement, + selfpath) < 0) + goto cleanup; + } else { + if (virAsprintf(&group->controllers[i].placement, + "%s%s%s", selfpath, + (STREQ(selfpath, "/") || + STREQ(path, "") ? "" : "/"), + path) < 0) + goto cleanup; } - - tmp = next; } } } -- 2.22.0