From 84c4ceebcb442ff8fe5fe695008b2cf9be65da57 Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Wed, 19 Nov 2025 18:09:18 +0200 Subject: T7819: VPP do not override driver if it is already done The upstream VPP code already writes the ena device ID to new_id So we can remove `ena` from `override_driver()` The kernel does not provide a reliable way to check whether an ID has already been registered, so we simply attempt the write and ignore the FileExistsError. Any other failure is treated as a warning. Fixes this case: Traceback (most recent call last): File "/usr/libexec/vyos/services/vyos-configd", line 156, in run_script script.apply(c) File "/usr/libexec/vyos/conf_mode/vpp.py", line 613, in apply control_host.override_driver( File "/usr/lib/python3/dist-packages/vyos/vpp/control_host.py", line 138, in override_driver Path('/sys/module/vfio_pci/drivers/pci:vfio-pci/new_id').write_text( File "/usr/lib/python3.11/pathlib.py", line 1079, in write_text with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f: FileExistsError: [Errno 17] File exists --- python/vyos/vpp/control_host.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/vyos/vpp/control_host.py b/python/vyos/vpp/control_host.py index 2ebfd180b..f284cbb7d 100644 --- a/python/vyos/vpp/control_host.py +++ b/python/vyos/vpp/control_host.py @@ -133,13 +133,22 @@ def override_driver(bus_id: str, device_id: str, driver_name: str = '') -> None: unbind_driver(bus_id, device_id) - # vfio-pci needs special approach + # vfio-pci requires a different workflow: drivers must be explicitly bound by + # writing the vendor/device IDs to the vfio-pci `new_id` interface. The kernel + # does not provide a reliable way to check whether an ID has already been + # registered, so we simply attempt the write and ignore the FileExistsError. + # Any other failure is treated as a warning. if driver_name == 'vfio-pci': vendor: str = Path(f'{device_resolved}/vendor').read_text() device: str = Path(f'{device_resolved}/device').read_text() - Path('/sys/module/vfio_pci/drivers/pci:vfio-pci/new_id').write_text( - f'{vendor} {device}' - ) + try: + Path('/sys/module/vfio_pci/drivers/pci:vfio-pci/new_id').write_text( + f'{vendor} {device}' + ) + except FileExistsError: + pass + except Exception as e: + print(f"Warning: failed to write new_id for vfio-pci: {e}") # override a driver Path(f'{device_resolved}/driver_override').write_text(f'{driver_name}\n') -- cgit v1.2.3