From 7dcd7da3c90b98f5abf34cf3099b2c4d43443b07 Mon Sep 17 00:00:00 2001
From: Helmut Grohne <helmut@subdivi.de>
Date: Tue, 5 Mar 2024 20:01:20 +0100
Subject: debvm-run: skip rngdev for sparc64 via opt_skip

---
 bin/debvm-run | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'bin')

diff --git a/bin/debvm-run b/bin/debvm-run
index aaf870a..3371b79 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -411,7 +411,7 @@ case "$KERNELARCHCPU" in
 	;;
 	sparc64)
 		MAX_SMP=1
-		RNG_DEV=
+		opt_skip rngdev
 	;;
 esac
 
@@ -455,7 +455,7 @@ if test -z "$MAX_SMP" || test "$MAX_SMP" -gt 1; then
 		set -- -smp "$NPROC" "$@"
 	fi
 fi
-if test -n "$RNG_DEV" && ! check_skip rngdev; then
+if ! check_skip rngdev; then
 	set -- \
 		-device "$RNG_DEV" \
 		-object rng-random,filename=/dev/urandom,id=rng0 \
-- 
cgit v1.2.3


From 8fca4b8b94319e663f0d71d199bfe7bfd0fab596 Mon Sep 17 00:00:00 2001
From: Helmut Grohne <helmut@subdivi.de>
Date: Tue, 5 Mar 2024 20:03:25 +0100
Subject: debvm-run: refactor bus management

Depending on the machine type, devices reside on different buses. For
most vms, we use the pci bus, but m68k uses the virtio ("device") bus.
Also if we were to use an x86 microvm, we'd also use virtio. This is
common to all devices and we can abstract it into a $BUS.
---
 bin/debvm-run | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

(limited to 'bin')

diff --git a/bin/debvm-run b/bin/debvm-run
index 3371b79..4dc35d3 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -354,17 +354,6 @@ set -- \
 	-initrd "/proc/self/fd/$INITRDFD" \
 	"$@"
 
-# If the image filename contains a comma, then that comma must be escaped by
-# prefixing it with another comma or otherwise output filenames are able to
-# inject drive options to qemu (and load the wrong file).
-IMAGE_ESCAPED="$(printf "%s" "$IMAGE" | sed 's/,/,,/g')"
-
-if ! check_skip root/dev; then
-	set -- \
-		-drive "media=disk,format=raw,discard=unmap,file=$IMAGE_ESCAPED,if=virtio,cache=unsafe" \
-		"$@"
-fi
-
 # Translate KERNELARCH (a Debian architecture) to a Debian CPU name.
 # This utilizes the QEMU Debian package symlink mapping that ensures that
 # calling qemu-system-${DEB_HOST_ARCH_CPU} will run the QEMU binary providing
@@ -373,9 +362,8 @@ KERNELARCHCPU="$(dpkg-architecture --force --host-arch "$KERNELARCH" --query DEB
 QEMU="qemu-system-$KERNELARCHCPU"
 CPU=
 MACHINE=
+BUS=pci
 MAX_SMP=
-NIC_DEV=virtio-net-pci,netdev=net0
-RNG_DEV=virtio-rng-pci,rng=rng0
 
 case "$KERNELARCHCPU" in
 	amd64)
@@ -393,8 +381,7 @@ case "$KERNELARCHCPU" in
 	m68k)
 		MACHINE="type=virt"
 		MAX_SMP=1
-		NIC_DEV=virtio-net-device,netdev=net0
-		RNG_DEV=virtio-rng-device,rng=rng0
+		BUS=device
 	;;
 	mips64el)
 		CPU=5KEc
@@ -415,6 +402,18 @@ case "$KERNELARCHCPU" in
 	;;
 esac
 
+# If the image filename contains a comma, then that comma must be escaped by
+# prefixing it with another comma or otherwise output filenames are able to
+# inject drive options to qemu (and load the wrong file).
+IMAGE_ESCAPED="$(printf "%s" "$IMAGE" | sed 's/,/,,/g')"
+
+if ! check_skip root/dev; then
+	set -- \
+		-drive "id=root,media=disk,format=raw,discard=unmap,file=$IMAGE_ESCAPED,if=none,cache=unsafe" \
+		-device "virtio-blk-$BUS,drive=root,serial=root" \
+		"$@"
+fi
+
 ENABLE_KVM=no
 if test "$ARCHITECTURE" = "$KERNELARCH"; then
 	ENABLE_KVM=yes
@@ -457,7 +456,7 @@ if test -z "$MAX_SMP" || test "$MAX_SMP" -gt 1; then
 fi
 if ! check_skip rngdev; then
 	set -- \
-		-device "$RNG_DEV" \
+		-device "virtio-rng-$BUS,rng=rng0" \
 		-object rng-random,filename=/dev/urandom,id=rng0 \
 		"$@"
 fi
@@ -479,14 +478,14 @@ else
 		;;
 		*)
 			set -- \
-				-device virtio-gpu-gl-pci \
+				-device "virtio-gpu-gl-$BUS" \
 				-display gtk,gl=on \
 				"$@"
 		;;
 	esac
 	set -- \
-		-device virtio-keyboard-pci \
-		-device virtio-tablet-pci \
+		-device "virtio-keyboard-$BUS" \
+		-device "virtio-tablet-$BUS" \
 		"$@"
 fi
 
@@ -503,7 +502,10 @@ if test -n "$KERNEL_CMDLINE"; then
 fi
 
 if ! check_skip network; then
-	set -- -netdev "user,id=net0$NETOPTS" -device "$NIC_DEV" "$@"
+	set -- \
+		-netdev "user,id=net0$NETOPTS" \
+		-device "virtio-net-$BUS,netdev=net0" \
+		"$@"
 fi
 
 echo "+ $QEMU $*" 1>&2
-- 
cgit v1.2.3


From d927a5e0cee2a725a1b2380ec2022b3564fc26de Mon Sep 17 00:00:00 2001
From: Helmut Grohne <helmut@subdivi.de>
Date: Tue, 5 Mar 2024 20:41:41 +0100
Subject: debvm-run: add --transport option

What was named bus earlier is called transport in qemu and we should
name it the same way when exposing it.
---
 bin/debvm-run | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

(limited to 'bin')

diff --git a/bin/debvm-run b/bin/debvm-run
index 4dc35d3..352f176 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -56,6 +56,11 @@ The option may be specified multiple times or list multiple tasks to be skipped
 By default, no tasks are skipped.
 The following tasks may be skipped.
 
+=item B<--transport>=I<transport>
+
+When B<debvm> adds devices to B<qemu>, it has to select a transport and it most often guesses B<pci>.
+When specifying a different machine such as B<-machine microvm>, a different transport such as B<device> may be needed.
+
 =over 4
 
 =item B<network>
@@ -155,6 +160,7 @@ CMDLINE_APPEND=
 NETOPTS=
 SKIP=,
 SSHPORT=
+TRANSPORT=
 
 nth_arg() {
 	shift "$1"
@@ -199,6 +205,9 @@ opt_skip() {
 opt_sshport() {
 	SSHPORT=$1
 }
+opt_transport() {
+	TRANSPORT=$1
+}
 
 while getopts :gi:s:-: OPTCHAR; do
 	case "$OPTCHAR" in
@@ -213,12 +222,12 @@ while getopts :gi:s:-: OPTCHAR; do
 				graphical)
 					"opt_$OPTARG"
 				;;
-				append|image|netopt|skip|sshport)
+				append|image|netopt|skip|sshport|transport)
 					test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG"
 					"opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")"
 					OPTIND=$((OPTIND+1))
 				;;
-				append=*|image=*|netopt=*|skip=*|sshport=*)
+				append=*|image=*|netopt=*|skip=*|sshport=*|transport=*)
 					"opt_${OPTARG%%=*}" "${OPTARG#*=}"
 				;;
 				*)
@@ -362,7 +371,6 @@ KERNELARCHCPU="$(dpkg-architecture --force --host-arch "$KERNELARCH" --query DEB
 QEMU="qemu-system-$KERNELARCHCPU"
 CPU=
 MACHINE=
-BUS=pci
 MAX_SMP=
 
 case "$KERNELARCHCPU" in
@@ -381,7 +389,7 @@ case "$KERNELARCHCPU" in
 	m68k)
 		MACHINE="type=virt"
 		MAX_SMP=1
-		BUS=device
+		: "${TRANSPORT:=device}"
 	;;
 	mips64el)
 		CPU=5KEc
@@ -402,6 +410,9 @@ case "$KERNELARCHCPU" in
 	;;
 esac
 
+# Assign the default late to allow both cli and arch-specific overrides.
+: "${TRANSPORT:=pci}"
+
 # If the image filename contains a comma, then that comma must be escaped by
 # prefixing it with another comma or otherwise output filenames are able to
 # inject drive options to qemu (and load the wrong file).
@@ -410,7 +421,7 @@ IMAGE_ESCAPED="$(printf "%s" "$IMAGE" | sed 's/,/,,/g')"
 if ! check_skip root/dev; then
 	set -- \
 		-drive "id=root,media=disk,format=raw,discard=unmap,file=$IMAGE_ESCAPED,if=none,cache=unsafe" \
-		-device "virtio-blk-$BUS,drive=root,serial=root" \
+		-device "virtio-blk-$TRANSPORT,drive=root,serial=root" \
 		"$@"
 fi
 
@@ -456,7 +467,7 @@ if test -z "$MAX_SMP" || test "$MAX_SMP" -gt 1; then
 fi
 if ! check_skip rngdev; then
 	set -- \
-		-device "virtio-rng-$BUS,rng=rng0" \
+		-device "virtio-rng-$TRANSPORT,rng=rng0" \
 		-object rng-random,filename=/dev/urandom,id=rng0 \
 		"$@"
 fi
@@ -478,14 +489,14 @@ else
 		;;
 		*)
 			set -- \
-				-device "virtio-gpu-gl-$BUS" \
+				-device "virtio-gpu-gl-$TRANSPORT" \
 				-display gtk,gl=on \
 				"$@"
 		;;
 	esac
 	set -- \
-		-device "virtio-keyboard-$BUS" \
-		-device "virtio-tablet-$BUS" \
+		-device "virtio-keyboard-$TRANSPORT" \
+		-device "virtio-tablet-$TRANSPORT" \
 		"$@"
 fi
 
@@ -504,7 +515,7 @@ fi
 if ! check_skip network; then
 	set -- \
 		-netdev "user,id=net0$NETOPTS" \
-		-device "virtio-net-$BUS,netdev=net0" \
+		-device "virtio-net-$TRANSPORT,netdev=net0" \
 		"$@"
 fi
 
-- 
cgit v1.2.3