From 3928ca076fac13572f14c20f38bcf5fb205d7670 Mon Sep 17 00:00:00 2001 Message-Id: <3928ca076fac13572f14c20f38bcf5fb205d7670@dist-git> From: Pavel Hrdina Date: Mon, 1 Jul 2019 17:07:14 +0200 Subject: [PATCH] vircgroup: introduce virCgroupV2ValidateMachineGroup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When reconnecting to a domain we are validating the cgroup name. In case of cgroup v2 we need to validate only the new format for host without systemd '{machinename}.libvirt-{drivername}' or scope name generated by systemd. Signed-off-by: Pavel Hrdina (cherry picked from commit 3a365ef697b8fedb929725c46753481a63ae3de7) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297 Signed-off-by: Pavel Hrdina Message-Id: <97d6369bcfc2943c708fd9bfc94f71ab10e00535.1561993100.git.phrdina@redhat.com> Reviewed-by: Ján Tomko --- src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 4ab9f2b792..02dc4e4686 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -36,6 +36,7 @@ #include "virfile.h" #include "virlog.h" #include "virstring.h" +#include "virsystemd.h" VIR_LOG_INIT("util.cgroup"); @@ -90,10 +91,52 @@ virCgroupV2Available(void) } +static bool +virCgroupV2ValidateMachineGroup(virCgroupPtr group, + const char *name ATTRIBUTE_UNUSED, + const char *drivername, + const char *machinename) +{ + VIR_AUTOFREE(char *) partmachinename = NULL; + VIR_AUTOFREE(char *) scopename = NULL; + char *tmp; + + if (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename, + drivername) < 0) { + return false; + } + + if (virCgroupPartitionEscape(&partmachinename) < 0) + return false; + + if (!(scopename = virSystemdMakeScopeName(machinename, drivername, + false))) { + return false; + } + + if (virCgroupPartitionEscape(&scopename) < 0) + return false; + + if (!(tmp = strrchr(group->unified.placement, '/'))) + return false; + tmp++; + + if (STRNEQ(tmp, partmachinename) && + STRNEQ(tmp, scopename)) { + VIR_DEBUG("Name '%s' for unified does not match '%s' or '%s'", + tmp, partmachinename, scopename); + return false; + } + + return true; +} + + virCgroupBackend virCgroupV2Backend = { .type = VIR_CGROUP_BACKEND_TYPE_V2, .available = virCgroupV2Available, + .validateMachineGroup = virCgroupV2ValidateMachineGroup, }; -- 2.22.0