Skip to content

fix(core): add libvirt patch for USB startupPolicy in containers#2432

Merged
yaroslavborbat merged 3 commits into
mainfrom
fix/usb/startup-policy-in-containers
Jun 3, 2026
Merged

fix(core): add libvirt patch for USB startupPolicy in containers#2432
yaroslavborbat merged 3 commits into
mainfrom
fix/usb/startup-policy-in-containers

Conversation

@yaroslavborbat

@yaroslavborbat yaroslavborbat commented Jun 1, 2026

Copy link
Copy Markdown
Member

Description

Add a libvirt patch (005-usb-startup-policy-in-containers.patch) that fixes startupPolicy='optional' for USB hostdev in containerized environments.

The patch adds a virFileExists check on the device node path in virUSBDeviceSearch after sysfs discovery. If the /dev/bus/usb/ node is missing, the device is skipped so that callers see an empty result and handle the absence gracefully.

See also:

Why do we need it, and what problem does it solve?

In containers, sysfs (/sys/bus/usb/devices/) is mounted from the host kernel and exposes all USB devices regardless of mount namespace isolation. This causes libvirt's virUSBDeviceSearch to report a device as available even when the corresponding /dev/bus/usb/ node is not present in the container's mount namespace.

As a result, startupPolicy='optional' does not remove the missing USB hostdev from the domain XML during incoming migration, and QEMU fails to start with:

Could not open '/dev/bus/usb/005/002': No such file or directory

This breaks VM live migration when USB devices are attached via hotplug and the target node does not yet have the device node mounted into the virt-launcher pod.

What is the expected result?

  1. Start a VM with a hotplugged USB device on node A.
  2. Migrate the VM to node B where the USB device node is not yet in the pod's mount namespace.
  3. The migration succeeds — libvirt skips the missing USB hostdev due to startupPolicy='optional'.
  4. After migration, the USB device is hotplugged into the VM on the target node.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: core
type: fix
summary: Fix USB startupPolicy='optional' in containers where sysfs exposes host devices but device nodes are absent from the mount namespace.
impact_level: low

@yaroslavborbat yaroslavborbat force-pushed the fix/usb/startup-policy-in-containers branch from 8724900 to bf557f9 Compare June 1, 2026 17:45
@yaroslavborbat yaroslavborbat added this to the v1.9.0 milestone Jun 1, 2026
@yaroslavborbat yaroslavborbat requested a review from Isteb4k as a code owner June 2, 2026 14:44
@yaroslavborbat yaroslavborbat force-pushed the fix/usb/startup-policy-in-containers branch from fd65c11 to 56064f3 Compare June 2, 2026 14:46
Signed-off-by: Yaroslav Borbat <yaroslav.borbat@flant.com>
@yaroslavborbat yaroslavborbat force-pushed the fix/usb/startup-policy-in-containers branch 2 times, most recently from e1b3a01 to c772e3c Compare June 2, 2026 17:27
diafour
diafour previously approved these changes Jun 3, 2026
Signed-off-by: Yaroslav Borbat <yaroslav.borbat@flant.com>
Signed-off-by: Yaroslav Borbat <yaroslav.borbat@flant.com>
@yaroslavborbat yaroslavborbat force-pushed the fix/usb/startup-policy-in-containers branch from e4ac9e2 to cdb4025 Compare June 3, 2026 10:27
@yaroslavborbat yaroslavborbat merged commit 1a6ccb2 into main Jun 3, 2026
28 of 30 checks passed
@yaroslavborbat yaroslavborbat deleted the fix/usb/startup-policy-in-containers branch June 3, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants