vircgroup: introduce virCgroupV2DetectPlacement

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>
This commit is contained in:
Pavel Hrdina 2018-09-14 23:46:42 +02:00
parent 50f61a46fc
commit 1efcf202e7

View 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,
};