libvirt/SOURCES/libvirt-vircgroup-introduce...

69 lines
2.1 KiB
Diff

From 1cabfada0f1a83ae78b6a7dbb9128512369fd6f4 Mon Sep 17 00:00:00 2001
Message-Id: <1cabfada0f1a83ae78b6a7dbb9128512369fd6f4@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:16 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2CopyPlacement
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 7a86201dd6e8cc7e418ea0891aeb44bacd08a10d)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <70993f08246ff3782d9b4a5bdf9187a0c1b57882.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroupv2.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 5d3c80b309..ed87b35db7 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -140,12 +140,39 @@ virCgroupV2CopyMounts(virCgroupPtr group,
}
+static int
+virCgroupV2CopyPlacement(virCgroupPtr group,
+ const char *path,
+ virCgroupPtr parent)
+{
+ if (path[0] == '/') {
+ if (VIR_STRDUP(group->unified.placement, path) < 0)
+ return -1;
+ } else {
+ /*
+ * parent == "/" + path="" => "/"
+ * parent == "/libvirt.service" + path == "" => "/libvirt.service"
+ * parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
+ */
+ if (virAsprintf(&group->unified.placement, "%s%s%s",
+ parent->unified.placement,
+ (STREQ(parent->unified.placement, "/") ||
+ STREQ(path, "") ? "" : "/"),
+ path) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+
virCgroupBackend virCgroupV2Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V2,
.available = virCgroupV2Available,
.validateMachineGroup = virCgroupV2ValidateMachineGroup,
.copyMounts = virCgroupV2CopyMounts,
+ .copyPlacement = virCgroupV2CopyPlacement,
};
--
2.22.0