[PATCH 1/2] host/rootfs: assign-devices: silence errors
The expected warnings frequently confuse people. Signed-off-by: Alyssa Ross <hi@alyssa.is> --- host/rootfs/image/usr/bin/assign-devices | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/host/rootfs/image/usr/bin/assign-devices b/host/rootfs/image/usr/bin/assign-devices index 1332a40..58dd3cc 100755 --- a/host/rootfs/image/usr/bin/assign-devices +++ b/host/rootfs/image/usr/bin/assign-devices @@ -5,4 +5,9 @@ elglob -0 devices /sys/bus/pci/drivers/vfio-pci/????:??:??.? forx -pE device { $devices } +# This script is designed to be re-entrant and called multiple times. +# This means we expect to sometimes get an error due to the device +# already having been added. If there's a different error, +# cloud-hypervisor will probably log it itself anyway. +redirfd -w 2 /dev/null ch-remote --api-socket /run/vm/by-name/sys.netvm/vmm add-device path=${device} base-commit: e0f5aad7901d150b1abe381ffd99d554e65e758b -- 2.51.0
udev actions needs to be idempotent, so when we switch to udev, we have the choice of making this script idempotent, or doing goto hacks to stop udev running it more than once. I like this better. assign-devices is already idempotent, so all we need to do to achieve idempotency is avoid unbinding and rebinding the driver if it's already the right one. Link: https://spectrum-os.org/lists/archives/spectrum-devel/87ikgxwq0v.fsf@alyssa.... Signed-off-by: Alyssa Ross <hi@alyssa.is> --- host/rootfs/image/etc/mdev/net/add | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/host/rootfs/image/etc/mdev/net/add b/host/rootfs/image/etc/mdev/net/add index f343779..62c152e 100755 --- a/host/rootfs/image/etc/mdev/net/add +++ b/host/rootfs/image/etc/mdev/net/add @@ -1,6 +1,6 @@ #!/bin/execlineb -P # SPDX-License-Identifier: EUPL-1.2+ -# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> +# SPDX-FileCopyrightText: 2021, 2025 Alyssa Ross <hi@alyssa.is> # Assign the whole IOMMU group containing this device to the network # VM. @@ -12,6 +12,13 @@ importas -i devpath DEVPATH foreground { pipeline { ls -1 /sys${devpath}/iommu_group/devices } forstdin -pE device + if -t { + backtick -E driver_name { + backtick -E driver_path { readlink /sys/bus/pci/devices/${device}/driver } + basename -- $driver_path + } + test $driver_name != vfio-pci + } foreground { redirfd -w 2 /dev/null redirfd -w 1 /sys/bus/pci/devices/${device}/driver/unbind -- 2.51.0
On 11/2/25 10:00, Alyssa Ross wrote:
udev actions needs to be idempotent, so when we switch to udev, we have the choice of making this script idempotent, or doing goto hacks to stop udev running it more than once. I like this better.
assign-devices is already idempotent, so all we need to do to achieve idempotency is avoid unbinding and rebinding the driver if it's already the right one.
Link: https://spectrum-os.org/lists/archives/spectrum-devel/87ikgxwq0v.fsf@alyssa.... Signed-off-by: Alyssa Ross <hi@alyssa.is>
Reviewed-by: Demi Marie Obenour <demiobenour@gmail.com>
--- host/rootfs/image/etc/mdev/net/add | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/host/rootfs/image/etc/mdev/net/add b/host/rootfs/image/etc/mdev/net/add index f343779..62c152e 100755 --- a/host/rootfs/image/etc/mdev/net/add +++ b/host/rootfs/image/etc/mdev/net/add @@ -1,6 +1,6 @@ #!/bin/execlineb -P # SPDX-License-Identifier: EUPL-1.2+ -# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> +# SPDX-FileCopyrightText: 2021, 2025 Alyssa Ross <hi@alyssa.is>
# Assign the whole IOMMU group containing this device to the network # VM. @@ -12,6 +12,13 @@ importas -i devpath DEVPATH foreground { pipeline { ls -1 /sys${devpath}/iommu_group/devices } forstdin -pE device + if -t { + backtick -E driver_name { + backtick -E driver_path { readlink /sys/bus/pci/devices/${device}/driver } + basename -- $driver_path + } + test $driver_name != vfio-pci + } foreground { redirfd -w 2 /dev/null redirfd -w 1 /sys/bus/pci/devices/${device}/driver/unbind -- Sincerely, Demi Marie Obenour (she/her/hers)
This patch has been committed as 1d666582892fbdf812662b4490caf7821078eaf9, which can be viewed online at https://spectrum-os.org/git/spectrum/commit/?id=1d666582892fbdf812662b4490ca.... This is an automated message. Send comments/questions/requests to: Alyssa Ross <hi@alyssa.is>
On 11/2/25 10:00, Alyssa Ross wrote:
The expected warnings frequently confuse people.
Ideally there would be a way to suppress only "device already added errors", but since there is not:
Signed-off-by: Alyssa Ross <hi@alyssa.is> --- host/rootfs/image/usr/bin/assign-devices | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/host/rootfs/image/usr/bin/assign-devices b/host/rootfs/image/usr/bin/assign-devices index 1332a40..58dd3cc 100755 --- a/host/rootfs/image/usr/bin/assign-devices +++ b/host/rootfs/image/usr/bin/assign-devices @@ -5,4 +5,9 @@ elglob -0 devices /sys/bus/pci/drivers/vfio-pci/????:??:??.? forx -pE device { $devices }
+# This script is designed to be re-entrant and called multiple times. +# This means we expect to sometimes get an error due to the device +# already having been added. If there's a different error, +# cloud-hypervisor will probably log it itself anyway. +redirfd -w 2 /dev/null ch-remote --api-socket /run/vm/by-name/sys.netvm/vmm add-device path=${device}
base-commit: e0f5aad7901d150b1abe381ffd99d554e65e758b
Reviewed-by: Demi Marie Obenour <demiobenour@gmail.com> -- Sincerely, Demi Marie Obenour (she/her/hers)
This patch has been committed as f202f8d9c55034b9696f20199e7db2db535a0909, which can be viewed online at https://spectrum-os.org/git/spectrum/commit/?id=f202f8d9c55034b9696f20199e7d.... This is an automated message. Send comments/questions/requests to: Alyssa Ross <hi@alyssa.is>
participants (3)
-
Alyssa Ross -
Alyssa Ross -
Demi Marie Obenour