Don't break if no vfio-devices are passed through.

This commit is contained in:
redxef 2024-05-14 20:59:04 +02:00
parent 7f917c29c9
commit 6bbbd9ad56
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

20
qemu-vm
View file

@ -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"