render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From af9bf10ff9d8a6f0ae9b6d898138144bf7dcd161 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <af9bf10ff9d8a6f0ae9b6d898138144bf7dcd161@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:18 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2DetectPlacement
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
If the placement was copied from parent or set to absolute path
c480ed
there is nothing to do, otherwise set the placement based on
c480ed
process placement from /proc/self/cgroup or /proc/{pid}/cgroup.
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 1efcf202e777d32600e90f3176e0357053341533)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <7fcc9d25385c40df5531e5b7171338a624d0c4fb.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv2.c | 26 ++++++++++++++++++++++++++
c480ed
 1 file changed, 26 insertions(+)
c480ed
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 19a9ba38f8..fb1aa2de0a 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -181,6 +181,31 @@ virCgroupV2DetectMounts(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2DetectPlacement(virCgroupPtr group,
c480ed
+                           const char *path,
c480ed
+                           const char *controllers ATTRIBUTE_UNUSED,
c480ed
+                           const char *selfpath)
c480ed
+{
c480ed
+    if (group->unified.placement)
c480ed
+        return 0;
c480ed
+
c480ed
+    /*
c480ed
+     * selfpath == "/" + path="" -> "/"
c480ed
+     * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
c480ed
+     * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
c480ed
+     */
c480ed
+    if (virAsprintf(&group->unified.placement,
c480ed
+                    "%s%s%s", selfpath,
c480ed
+                    (STREQ(selfpath, "/") ||
c480ed
+                     STREQ(path, "") ? "" : "/"),
c480ed
+                    path) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV2Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
 
c480ed
@@ -189,6 +214,7 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
     .copyMounts = virCgroupV2CopyMounts,
c480ed
     .copyPlacement = virCgroupV2CopyPlacement,
c480ed
     .detectMounts = virCgroupV2DetectMounts,
c480ed
+    .detectPlacement = virCgroupV2DetectPlacement,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed