[libvirt PATCH 0/2] fix LXC with cgroup libvirt sub-directory

Pavel Hrdina (2): vircgroupmock: fix cgroup v1 mocking vircgroup: rework virCgroupNewSelf src/util/vircgroup.c | 15 ++++++++++++++- tests/vircgroupmock.c | 4 ++-- tests/vircgrouptest.c | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) -- 2.37.3

The `legacy` mode is also valid so we need to take it into account as well. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- tests/vircgroupmock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index 8a0e3aec0f..777d60b152 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -317,7 +317,7 @@ static int make_controller(const char *path, mode_t mode) unified = true; } else if (STREQ(mock, "hybrid")) { hybrid = true; - } else { + } else if (STRNEQ(mock, "legacy")) { fprintf(stderr, "invalid mode '%s'\n", mock); abort(); } @@ -355,7 +355,7 @@ static void init_sysfs(void) unified = true; } else if (STREQ(mock, "hybrid")) { hybrid = true; - } else { + } else if (STRNEQ(mock, "legacy")) { fprintf(stderr, "invalid mode '%s'\n", mock); abort(); } -- 2.37.3

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> --- 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.37.3

On 10/19/22 14:13, Pavel Hrdina wrote:
Pavel Hrdina (2): vircgroupmock: fix cgroup v1 mocking vircgroup: rework virCgroupNewSelf
src/util/vircgroup.c | 15 ++++++++++++++- tests/vircgroupmock.c | 4 ++-- tests/vircgrouptest.c | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Thanks for fixing this! Michal
participants (2)
-
Michal Prívozník
-
Pavel Hrdina