From 6bbbd9ad5669978a3d41313f4dd32367d4700f7c Mon Sep 17 00:00:00 2001 From: redxef Date: Tue, 14 May 2024 20:59:04 +0200 Subject: [PATCH] Don't break if no vfio-devices are passed through. --- qemu-vm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/qemu-vm b/qemu-vm index 8a7b1b3..f93549e 100755 --- a/qemu-vm +++ b/qemu-vm @@ -37,16 +37,24 @@ NET_CONF_FILE="$NET_CONF_FILE" "$SUDO" --preserve-env=PATH,NET_CONF_FILE qemu-vm # rebind devices old_IFS="$IFS" IFS=$'\n' -for device_override in $(< "$CONFIG_PATH/vfio-devices.txt") $(< "$CONFIG_PATH/vfio-devices-$VMNAME.txt"); do - device="$(echo "$device_override" | awk '{print $1}')" - override="$(echo "$device_override" | awk '{print $2}')" +for device_override in $(cat "$CONFIG_PATH/vfio-devices.txt" || true) $(cat "$CONFIG_PATH/vfio-devices-$VMNAME.txt" || true); do + device_override="${device_override%%#*}" + device="$(awk '{print $1}' <<< "$device_override")" + override="$(awk '{print $2}' <<< "$device_override")" + if [[ "$device" = '' ]] || [[ "$override" = '' ]]; then + continue + fi [[ "$override" != 'true' ]] && continue $SUDO --preserve-env=SUDO,PATH qemu-vm-pci vfio_override_device "$device" done $SUDO modprobe vfio-pci -for device_override in $(< "$CONFIG_PATH/vfio-devices.txt") $(< "$CONFIG_PATH/vfio-devices-$VMNAME.txt"); do - device="$(echo "$device_override" | awk '{print $1}')" - override="$(echo "$device_override" | awk '{print $2}')" +for device_override in $(cat "$CONFIG_PATH/vfio-devices.txt" || true) $(cat "$CONFIG_PATH/vfio-devices-$VMNAME.txt" || true); do + device_override="${device_override%%#*}" + device="$(awk '{print $1}' <<< "$device_override")" + override="$(awk '{print $2}' <<< "$device_override")" + if [[ "$device" = '' ]] || [[ "$override" = '' ]]; then + continue + fi $SUDO --preserve-env=SUDO,PATH qemu-vm-pci vfio_rebind_device "$device" "$override" done IFS="$old_IFS"