]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: rework virCgroupNewSelf
authorPavel Hrdina <phrdina@redhat.com>
Wed, 19 Oct 2022 10:57:49 +0000 (12:57 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 19 Oct 2022 14:32:30 +0000 (16:32 +0200)
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>
src/util/vircgroup.c
tests/vircgrouptest.c

index 9918430ccae9d7169bd3c3306d5e75719e09a969..a6a409af3dff6af4b8536abd2a0b6de74f1b2120 100644 (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;
 }
 
 
index e29bc094b135597b2de3eb25e010bae3d1783796..848a9c7bb0628373214d47ebf55af5f2010ee8bf 100644 (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);