[PATCH 06/22] img/app: add support for testing virtiofs

Alyssa Ross
2022-10-10T23:32:41Z

.gitignore | 5 ++++-
img/app/Makefile | 19 ++++++++++++++++---
img/app/shell.nix | 6 +++++-
3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index a97f309..802df73 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,10 @@
# SPDX-License-Identifier: CC0-1.0
-# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>

/config.nix
build/
result
result-*
+
+# s6-ipcserver-socketbinder creates lockfiles for sockets.
+*.sock.lock
diff --git a/img/app/Makefile b/img/app/Makefile
index c5a4684..7d8e1c1 100644
--- a/img/app/Makefile
+++ b/img/app/Makefile
@@ -5,7 +5,10 @@
# Nixpkgs. If you don't have qemu-kvm, you'll need to set e.g.
# QEMU_KVM = qemu-system-x86_64 -enable-kvm.
QEMU_KVM = qemu-kvm
+BACKGROUND = background
CLOUD_HYPERVISOR = cloud-hypervisor
+S6_IPCSERVER_SOCKETBINDER = s6-ipcserver-socketbinder
+VIRTIOFSD = virtiofsd

prefix = /usr/local
imgdir = $(prefix)/img
@@ -94,25 +97,35 @@ build/etc/s6-rc: $(VM_S6_RC_FILES)
s6-rc-compile $@ $$dir; \
exit=$$?; rm -r $$dir; exit $$exit

-run-qemu: build/host/appvm/blk/root.img
+start-virtiofsd:
+ $(S6_IPCSERVER_SOCKETBINDER) -B virtiofsd.sock \
+ $(BACKGROUND) $(VIRTIOFSD) --fd 0 --shared-dir . ""
+.PHONY: start-virtiofsd
+
+run-qemu: build/host/appvm/blk/root.img start-virtiofsd
$(QEMU_KVM) -m 128 -cpu host -machine q35,kernel=$(KERNEL) -vga none \
-drive file=build/host/appvm/blk/root.img,if=virtio,format=raw,readonly=on \
-drive file=$(RUN_IMG),if=virtio,format=raw,readonly=on \
-append "console=ttyS0 root=PARTLABEL=root" \
-netdev user,id=net0 \
-device virtio-net,netdev=net0,mac=0A:B3:EC:00:00:00 \
+ -chardev socket,id=virtiofsd,path=virtiofsd.sock \
+ -device vhost-user-fs-pci,chardev=virtiofsd,tag=virtiofs0 \
+ -object memory-backend-memfd,id=mem,size=128M,share=on \
+ -numa node,memdev=mem \
-chardev vc,id=virtiocon0 \
-device virtio-serial-pci \
-device virtconsole,chardev=virtiocon0
.PHONY: run-qemu

-run-cloud-hypervisor: build/host/appvm/blk/root.img
+run-cloud-hypervisor: build/host/appvm/blk/root.img start-virtiofsd
$(CLOUD_HYPERVISOR) \
--api-socket path=vmm.sock \
- --memory size=128M \
+ --memory size=128M,shared=on \
--disk path=build/host/appvm/blk/root.img,readonly=on \
path=$(RUN_IMG),readonly=on \
--net tap=tap0,mac=0A:B3:EC:00:00:00 \
+ --fs tag=virtiofs0,socket=virtiofsd.sock \
--kernel $(KERNEL) \
--cmdline "console=ttyS0 root=PARTLABEL=root" \
--console tty \
diff --git a/img/app/shell.nix b/img/app/shell.nix
index 83dcd76..60ca465 100644
--- a/img/app/shell.nix
+++ b/img/app/shell.nix
@@ -12,7 +12,11 @@ with config.pkgs;

{
nativeBuildInputs = nativeBuildInputs ++ [
- cloud-hypervisor jq qemu_kvm reuse
+ # Both QEMU and virtiofsd come with a virtiofsd executable,
+ # so we have to list virtiofsd first.
+ virtiofsd
+
+ cloud-hypervisor execline jq qemu_kvm reuse s6
];

KERNEL = "${passthru.kernel.dev}/vmlinux";
--
2.37.1