[PATCH] lxc: controller: Fix container launch on cgroup v1

Cole Robinson posted 1 patch 2 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/820a11af075479ee562e3185939219b7316935ba.1633531847.git.crobinso@redhat.com
src/lxc/lxc_controller.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

[PATCH] lxc: controller: Fix container launch on cgroup v1

Posted by Cole Robinson 2 weeks, 1 day ago
With cgroup v1 I'm seeing LXC container startup failures:

$ sudo virt-install --connect lxc:/// --name test-container --memory 128
--boot init=/bin/sh

Starting install...
ERROR    error from service:
GDBus.Error:org.freedesktop.machine1.NoMachineForPID: PID 2145047 does
not belong to any known machine

libvirt 7.0.0 works but 7.1.0+ does not. The root error seems to predate
that, showing up in syslog, but commit 9c1693eff made it fatal:

commit 9c1693eff427661616ce1bd2795688f87288a412
Author: Pavel Hrdina <phrdina@redhat.com>
Date:   Fri Feb 5 16:17:35 2021 +0100

     vircgroup: use DBus call to systemd for some APIs

The error comes from virSystemdGetMachineByPID. The PID that shows up in
the above error message does not match the leader PID as reported by
machinectl.

This change fixes the error. Things seem to continue to work with
cgroupsv2 after this change.

https://gitlab.com/libvirt/libvirt/-/issues/182

Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
This is from the thread in August, posted as non RFC now

 src/lxc/lxc_controller.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 8953e0c904..444f728af4 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -865,12 +865,12 @@ static int virLXCControllerSetupCgroupLimits(virLXCController *ctrl)
     nodeset = virDomainNumatuneGetNodeset(ctrl->def->numa, auto_nodeset, -1);
 
     if (!(ctrl->cgroup = virLXCCgroupCreate(ctrl->def,
-                                            ctrl->initpid,
+                                            getpid(),
                                             ctrl->nnicindexes,
                                             ctrl->nicindexes)))
         goto cleanup;
 
-    if (virCgroupAddMachineProcess(ctrl->cgroup, getpid()) < 0)
+    if (virCgroupAddMachineProcess(ctrl->cgroup, ctrl->initpid) < 0)
         goto cleanup;
 
     /* Add all qemu-nbd tasks to the cgroup */
-- 
2.31.1

Re: [PATCH] lxc: controller: Fix container launch on cgroup v1

Posted by Jim Fehlig 2 weeks ago
On 10/7/21 09:08, Cole Robinson wrote:
> With cgroup v1 I'm seeing LXC container startup failures:
> 
> $ sudo virt-install --connect lxc:/// --name test-container --memory 128
> --boot init=/bin/sh
> 
> Starting install...
> ERROR    error from service:
> GDBus.Error:org.freedesktop.machine1.NoMachineForPID: PID 2145047 does
> not belong to any known machine
> 
> libvirt 7.0.0 works but 7.1.0+ does not. The root error seems to predate
> that, showing up in syslog, but commit 9c1693eff made it fatal:
> 
> commit 9c1693eff427661616ce1bd2795688f87288a412
> Author: Pavel Hrdina <phrdina@redhat.com>
> Date:   Fri Feb 5 16:17:35 2021 +0100
> 
>       vircgroup: use DBus call to systemd for some APIs
> 
> The error comes from virSystemdGetMachineByPID. The PID that shows up in
> the above error message does not match the leader PID as reported by
> machinectl.
> 
> This change fixes the error. Things seem to continue to work with
> cgroupsv2 after this change.
> 
> https://gitlab.com/libvirt/libvirt/-/issues/182
> 
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
> This is from the thread in August, posted as non RFC now
> 
>   src/lxc/lxc_controller.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Tested-by: Jim Fehlig <jfehlig@suse.com>

Regards,
Jim

> 
> diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
> index 8953e0c904..444f728af4 100644
> --- a/src/lxc/lxc_controller.c
> +++ b/src/lxc/lxc_controller.c
> @@ -865,12 +865,12 @@ static int virLXCControllerSetupCgroupLimits(virLXCController *ctrl)
>       nodeset = virDomainNumatuneGetNodeset(ctrl->def->numa, auto_nodeset, -1);
>   
>       if (!(ctrl->cgroup = virLXCCgroupCreate(ctrl->def,
> -                                            ctrl->initpid,
> +                                            getpid(),
>                                               ctrl->nnicindexes,
>                                               ctrl->nicindexes)))
>           goto cleanup;
>   
> -    if (virCgroupAddMachineProcess(ctrl->cgroup, getpid()) < 0)
> +    if (virCgroupAddMachineProcess(ctrl->cgroup, ctrl->initpid) < 0)
>           goto cleanup;
>   
>       /* Add all qemu-nbd tasks to the cgroup */
> 

Re: [PATCH] lxc: controller: Fix container launch on cgroup v1

Posted by Michal Prívozník 2 weeks ago
On 10/7/21 5:08 PM, Cole Robinson wrote:
> With cgroup v1 I'm seeing LXC container startup failures:
> 
> $ sudo virt-install --connect lxc:/// --name test-container --memory 128
> --boot init=/bin/sh
> 
> Starting install...
> ERROR    error from service:
> GDBus.Error:org.freedesktop.machine1.NoMachineForPID: PID 2145047 does
> not belong to any known machine
> 
> libvirt 7.0.0 works but 7.1.0+ does not. The root error seems to predate
> that, showing up in syslog, but commit 9c1693eff made it fatal:
> 
> commit 9c1693eff427661616ce1bd2795688f87288a412
> Author: Pavel Hrdina <phrdina@redhat.com>
> Date:   Fri Feb 5 16:17:35 2021 +0100
> 
>      vircgroup: use DBus call to systemd for some APIs
> 
> The error comes from virSystemdGetMachineByPID. The PID that shows up in
> the above error message does not match the leader PID as reported by
> machinectl.
> 
> This change fixes the error. Things seem to continue to work with
> cgroupsv2 after this change.
> 
> https://gitlab.com/libvirt/libvirt/-/issues/182
> 
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
> This is from the thread in August, posted as non RFC now
> 
>  src/lxc/lxc_controller.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal