[libvirt] [PATCH v2 07/53] [ACKED] vircgroup: introduce virCgroupV2DetectPlacement

Pavel Hrdina phrdina at redhat.com
Fri Oct 5 12:43:28 UTC 2018


If the placement was copied from parent or set to absolute path
there is nothing to do, otherwise set the placement based on
process placement from /proc/self/cgroup or /proc/{pid}/cgroup.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/util/vircgroupv2.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index f13c5fc669..800fc083f2 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -189,6 +189,31 @@ virCgroupV2DetectMounts(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2DetectPlacement(virCgroupPtr group,
+                           const char *path,
+                           const char *controllers ATTRIBUTE_UNUSED,
+                           const char *selfpath)
+{
+    if (group->unified.placement)
+        return 0;
+
+    /*
+     * selfpath == "/" + path="" -> "/"
+     * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
+     * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
+     */
+    if (virAsprintf(&group->unified.placement,
+                    "%s%s%s", selfpath,
+                    (STREQ(selfpath, "/") ||
+                     STREQ(path, "") ? "" : "/"),
+                    path) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -197,6 +222,7 @@ virCgroupBackend virCgroupV2Backend = {
     .copyMounts = virCgroupV2CopyMounts,
     .copyPlacement = virCgroupV2CopyPlacement,
     .detectMounts = virCgroupV2DetectMounts,
+    .detectPlacement = virCgroupV2DetectPlacement,
 };
 
 
-- 
2.17.1




More information about the libvir-list mailing list