From 33178b9e52176e1e35575133b9daa1e86d5d82ce Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Wed, 19 Oct 2022 12:57:49 +0200 Subject: [PATCH] vircgroup: rework virCgroupNewSelf With the introduction of `libvirt` sub-directory to the cgroup topology some of the cgroup configuration was moved into that sub-directory together with the VM processes. LXC uses virCgroupNewSelf() in the container process to detect cgroups in order to report various data from cgroups inside the container. We need to properly detect the new `libvirt` sub-directory here otherwise LXC will report incorrect data. Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/util/vircgroup.c | 15 ++++++++++++++- tests/vircgrouptest.c | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 9918430cca..a6a409af3d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1024,7 +1024,20 @@ virCgroupNewNested(virCgroup *parent, int virCgroupNewSelf(virCgroup **group) { - return virCgroupNewDetect(-1, -1, group); + g_autoptr(virCgroup) newGroup = NULL; + g_autoptr(virCgroup) nested = NULL; + + if (virCgroupNewDetect(-1, -1, &newGroup) < 0) + return -1; + + if (virCgroupNewNested(newGroup, -1, false, -1, &nested) < 0) + return -1; + + if (virCgroupExists(nested)) + newGroup->nested = g_steal_pointer(&nested); + + *group = g_steal_pointer(&newGroup); + return 0; } diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index e29bc094b1..848a9c7bb0 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -1019,7 +1019,9 @@ mymain(void) DETECT_MOUNTS("cgroups1"); DETECT_MOUNTS("cgroups2"); DETECT_MOUNTS("cgroups3"); + fakerootdir = initFakeFS(NULL, "all-in-one"); DETECT_MOUNTS("all-in-one"); + cleanupFakeFS(fakerootdir); DETECT_MOUNTS_FAIL("no-cgroups"); DETECT_MOUNTS("kubevirt"); fakerootdir = initFakeFS("unified", NULL); -- 2.39.5