Skip to content

Commit 3910e65

Browse files
vikanezrimayaastro
authored andcommitted
qemu: support notify sockets
Copied from existing cloud-hypervisor implementation. Tested by launching a MicroVM on a system that expects MicroVMs to use notify sockets, and additionally using plain socat in a second terminal.
1 parent 870cb18 commit 3910e65

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/runners/qemu.nix

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ let
146146
then "console=ttyAMA0"
147147
else "";
148148

149+
supportsNotifySocket = vsock.cid != null;
149150

150151
in
151152
lib.warnIf (mem == 2048) ''
@@ -154,7 +155,16 @@ lib.warnIf (mem == 2048) ''
154155
<https://github.com/astro/microvm.nix/issues/171>
155156
''
156157
{
157-
inherit tapMultiQueue;
158+
inherit tapMultiQueue supportsNotifySocket;
159+
160+
preStart = ''
161+
${microvmConfig.preStart}
162+
'' + lib.optionalString supportsNotifySocket ''
163+
# Start socat to forward systemd notify socket over vsock
164+
if [ -n "''${NOTIFY_SOCKET-}" ]; then
165+
${pkgs.socat}/bin/socat VSOCK-LISTEN:8888,fork UNIX-SENDTO:$NOTIFY_SOCKET &
166+
fi
167+
'';
158168

159169
command = lib.escapeShellArgs (
160170
[
@@ -300,6 +310,11 @@ lib.warnIf (mem == 2048) ''
300310
lib.optionals (vsock.cid != null) [
301311
"-device"
302312
"vhost-vsock-${devType},guest-cid=${toString vsock.cid}"
313+
# We are *supposed* to use SMBIOS here. But somehow, no matter how much I
314+
# tried, SMBIOS Type 11 entries simply don't work. It looks like it might
315+
# be broken on QEMU side. Why? I don't know.
316+
"-fw_cfg"
317+
"name=opt/io.systemd.credentials/vmm.notify_socket,string=vsock-stream:2:8888"
303318
]
304319
++
305320
extraArgs

0 commit comments

Comments
 (0)