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 <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Pavel Hrdina 2022-10-19 12:57:49 +02:00
parent 76ff847386
commit 33178b9e52
2 changed files with 16 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);