microvm.nix icon indicating copy to clipboard operation
microvm.nix copied to clipboard

Implement vmm.notify_socket

Open bouk opened this issue 1 year ago • 1 comments

Systemd supports receiving a vmm.notify_socket credential so it can notify the host when the VM has finished loading: https://www.freedesktop.org/software/systemd/man/latest/systemd.system-credentials.html#vmm.notify_socket

If we implement this then the microvm@ service can accurately reflect the VM status

bouk avatar Feb 21 '24 10:02 bouk

This might actually be surprisingly easy, for cloud hypervisor the interface is that you create a unix socket on the host and then that gets bound to a vsock on the guest: https://github.com/cloud-hypervisor/cloud-hypervisor/blob/845bdfb1b24a6a86d1ab7e819ca155faf314c9f7/docs/vsock.md#connecting-from-guest-to-host

The unix socket for Type=notify is passed through $NOTIFY_SOCKET so we need to:

  1. ln -sfn $NOTIFY_SOCKET /tmp/notify.vsock_1234
  2. Pass --vsock cid=3,socket=/tmp/notify.vsock to cloud-hypervisor
  3. Set vmm.notify_socket to vsock:2:1234 by passing --platform oem_strings=[io.systemd.credential:vmm.notify_socket=vsock:2:1234] to cloud-hypervisor

And then I think it might work?

bouk avatar Feb 21 '24 10:02 bouk

I tried to do this, but unfortunately cloud-hypervisor doesn't support datagram vsock: https://github.com/cloud-hypervisor/cloud-hypervisor/issues/6307 which is what systemd uses for notifications

bouk avatar Mar 19 '24 11:03 bouk

Figured it out, systemd can actually use a vsock-stream: notification socket, see: https://github.com/astro/microvm.nix/pull/219

bouk avatar Mar 19 '24 13:03 bouk

Very cool, thank you!

Of course I am interested in having support for that feature for the other hypervisors. Are you going to add them?

astro avatar Mar 21 '24 22:03 astro

@bouk do you know if this definitely breaks when using different systemd version on the host and in the hypervisor? eg 255 on the host and 256 in the vm?

SuperSandro2000 avatar Aug 18 '24 19:08 SuperSandro2000