Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qemu: wait for process to be in scope before registering with machined #3297

Closed
wants to merge 1 commit into from

Conversation

bluca
Copy link
Member

@bluca bluca commented Dec 22, 2024

Otherwise if we are unlucky with the timing and the process is added to the scope after the register request is processed, machined will register as the unit the user session scope, and it will kill it once the machine goes away, breaking the testbed/user session.

root@host:~# cat /run/systemd/machines/TEST-64-UDEV-STORAGE-long-sysfs-path-1 NAME=TEST-64-UDEV-STORAGE-long-sysfs-path-1
SCOPE=session-2.scope
SERVICE=mkosi
LEADER=23160
CLASS=vm
REALTIME=1734823438361409
MONOTONIC=11697737480
[  340.373454] systemd-machined[21797]: Got message type=method_return sender=org.freedesktop.DBus destination=:1.13 path=n/a interface=n/a member=n/a  cookie=12 reply_cookie=22 signature=u error-name=n/a error>
[  340.373533] systemd-machined[21797]: Sent message type=error sender=n/a destination=:1.24 path=n/a interface=n/a member=n/a cookie=23 reply_cookie=2 signature=s error-name=org.freedesktop.DBus.Error.FileExis>
[  340.373537] systemd-machined[21797]: Failed to process message type=method_call sender=:1.24 destination=org.freedesktop.machine1 path=/org/freedesktop/machine1 interface=org.freedesktop.machine1.Manager mem>
[  340.373657] busctl[21800]: ‣ Type=method_call  Endian=l  Flags=0  Version=1 Cookie=24  Timestamp="Sat 2024-12-21 20:14:40.997553 UTC"
[  340.373657] busctl[21800]:   Sender=:1.13  Destination=org.freedesktop.systemd1  Path=/org/freedesktop/systemd1  Interface=org.freedesktop.systemd1.Manager  Member=StopUnit
[  340.373657] busctl[21800]:   UniqueName=:1.13
[  340.373657] busctl[21800]:   MESSAGE "ss" {
[  340.373657] busctl[21800]:           STRING "session-c1.scope";
[  340.373657] busctl[21800]:           STRING "fail";
[  340.373657] busctl[21800]:   };
[  340.373551] systemd-machined[21797]: Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=StopUnit co>
[  340.380081] systemd[1]: mkosi-TEST-64-UDEV-STORAGE-long-sysfs-path-1.scope: 1 process added to scope's control group.

@bluca bluca force-pushed the qemu_scope_wait branch 2 times, most recently from 2a009ad to 3a8c4a8 Compare December 22, 2024 01:32
Otherwise if we are unlucky with the timing and the process is added to
the scope after the register request is processed, machined will register
as the unit the user session scope, and it will kill it once the machine
goes away, breaking the testbed/user session.

root@host:~# cat /run/systemd/machines/TEST-64-UDEV-STORAGE-long-sysfs-path-1
NAME=TEST-64-UDEV-STORAGE-long-sysfs-path-1
SCOPE=session-2.scope
SERVICE=mkosi
LEADER=23160
CLASS=vm
REALTIME=1734823438361409
MONOTONIC=11697737480

[  340.373454] systemd-machined[21797]: Got message type=method_return sender=org.freedesktop.DBus destination=:1.13 path=n/a interface=n/a member=n/a  cookie=12 reply_cookie=22 signature=u error-name=n/a error>
[  340.373533] systemd-machined[21797]: Sent message type=error sender=n/a destination=:1.24 path=n/a interface=n/a member=n/a cookie=23 reply_cookie=2 signature=s error-name=org.freedesktop.DBus.Error.FileExis>
[  340.373537] systemd-machined[21797]: Failed to process message type=method_call sender=:1.24 destination=org.freedesktop.machine1 path=/org/freedesktop/machine1 interface=org.freedesktop.machine1.Manager mem>
[  340.373657] busctl[21800]: ‣ Type=method_call  Endian=l  Flags=0  Version=1 Cookie=24  Timestamp="Sat 2024-12-21 20:14:40.997553 UTC"
[  340.373657] busctl[21800]:   Sender=:1.13  Destination=org.freedesktop.systemd1  Path=/org/freedesktop/systemd1  Interface=org.freedesktop.systemd1.Manager  Member=StopUnit
[  340.373657] busctl[21800]:   UniqueName=:1.13
[  340.373657] busctl[21800]:   MESSAGE "ss" {
[  340.373657] busctl[21800]:           STRING "session-c1.scope";
[  340.373657] busctl[21800]:           STRING "fail";
[  340.373657] busctl[21800]:   };
[  340.373551] systemd-machined[21797]: Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=StopUnit co>
[  340.380081] systemd[1]: mkosi-TEST-64-UDEV-STORAGE-long-sysfs-path-1.scope: 1 process added to scope's control group.
Copy link
Contributor

@DaanDeMeyer DaanDeMeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should instead pass an exec-fd to mkosi-sandbox and have it close it just before execve() and then wait for that exec fd to be closed by mkosi-sandbox before registering the machine

@bluca
Copy link
Member Author

bluca commented Dec 22, 2024

How are things nested? Is the sandbox running sdrun or the other way around?

@DaanDeMeyer
Copy link
Contributor

sdrun invokes the sandbox which invokes qemu.

@bluca
Copy link
Member Author

bluca commented Dec 22, 2024

masking machined fixes the problem too and doesn't cause any issue, so I'll just do that

@bluca bluca closed this Dec 22, 2024
@bluca bluca deleted the qemu_scope_wait branch December 22, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants