]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: introduce virCgroupV2DetectPlacement
authorPavel Hrdina <phrdina@redhat.com>
Fri, 14 Sep 2018 21:46:42 +0000 (23:46 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 5 Oct 2018 13:53:29 +0000 (15:53 +0200)
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@redhat.com>
src/util/vircgroupv2.c

index a66ef4e89547107f35c8faed943c219ba92f6626..84c29cac5a1ca51eb592842475a8eb4b07ef80e9 100644 (file)
@@ -180,6 +180,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,
 
@@ -188,6 +213,7 @@ virCgroupBackend virCgroupV2Backend = {
     .copyMounts = virCgroupV2CopyMounts,
     .copyPlacement = virCgroupV2CopyPlacement,
     .detectMounts = virCgroupV2DetectMounts,
+    .detectPlacement = virCgroupV2DetectPlacement,
 };