summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-03-05 20:03:25 +0100
committerHelmut Grohne <helmut@subdivi.de>2024-03-05 20:03:25 +0100
commit8fca4b8b94319e663f0d71d199bfe7bfd0fab596 (patch)
tree7d7191f2e5710d1711583beb5d4eba9e1f0606ce /bin
parent7dcd7da3c90b98f5abf34cf3099b2c4d43443b07 (diff)
downloaddebvm-8fca4b8b94319e663f0d71d199bfe7bfd0fab596.tar.gz
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.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/debvm-run42
1 files changed, 22 insertions, 20 deletions
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