Skip to content

Commit bf557f9

Browse files
fix(core): add libvirt patch for USB startupPolicy in containers
Signed-off-by: Yaroslav Borbat <yaroslav.borbat@flant.com>
1 parent b45d926 commit bf557f9

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/src/util/virusb.c b/src/util/virusb.c
2+
index cf3461f80a..5a92098452 100644
3+
--- a/src/util/virusb.c
4+
+++ b/src/util/virusb.c
5+
@@ -169,6 +169,24 @@ virUSBDeviceSearch(unsigned int vendor,
6+
if (!usb)
7+
goto cleanup;
8+
9+
+ /* In containerized environments sysfs may expose USB devices
10+
+ * from the host kernel while the corresponding device node
11+
+ * under /dev/bus/usb/ is not present in the container's mount
12+
+ * namespace. Skip such devices so that callers relying on
13+
+ * startupPolicy='optional' see an empty result and can handle
14+
+ * the missing device gracefully. */
15+
+ if (virUSBDeviceGetPath(usb) &&
16+
+ !virFileExists(virUSBDeviceGetPath(usb))) {
17+
+ VIR_DEBUG("USB device %03u:%03u found in sysfs but "
18+
+ "device node '%s' is not accessible, skipping",
19+
+ found_bus, found_devno,
20+
+ virUSBDeviceGetPath(usb));
21+
+ g_clear_pointer(&usb, virUSBDeviceFree);
22+
+ if (found)
23+
+ break;
24+
+ continue;
25+
+ }
26+
+
27+
if (virUSBDeviceListAdd(list, &usb) < 0)
28+
goto cleanup;
29+

images/packages/libvirt/patches/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ This feature enhances security by preventing unauthorized access to the socket a
4141
Fixes a non-shared storage migration cancel race in libvirt/QEMU.
4242

4343
After `AbortJob`, mirror block jobs may become `concluded` in QEMU while libvirt still polls synchronous migration mirrors. The patch refreshes monitor job status and drives pending terminal transitions so concluded jobs are dismissed/unregistered and do not block subsequent migrations.
44+
45+
## 005-usb-startup-policy-in-containers.patch
46+
47+
Fixes `startupPolicy='optional'` for USB hostdev in containerized environments.
48+
49+
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 `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 hostdev from the domain XML, and QEMU fails to start.
50+
51+
The patch adds a `virFileExists` check on the device node path after sysfs discovery. If the node is missing, the device is skipped so that callers see an empty result and handle the absence gracefully.

0 commit comments

Comments
 (0)