Commit 554962405cb18a3e624edf05b6257eaf9273810c

Authored by Mark McLoughlin
Committed by Anthony Liguori
1 parent 1fa63e43

Prefer sysfs for USB host devices

Scanning for devices via /sys/bus/usb/devices/ and using them via the
/dev/bus/usb/<bus>/<device> character devices is the prefered method
on modern kernels, so try that first.

When using SELinux and libvirt, qemu will have access to /sys/bus/usb
but not /proc/bus/usb, so although the current code will work just
fine, it will generate SELinux AVC warnings.

See also:

  https://bugzilla.redhat.com/508326

Reported-by: Daniel Berrange <berrange@redhat.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 9 additions and 9 deletions
usb-linux.c
@@ -1265,6 +1265,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) @@ -1265,6 +1265,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
1265 1265
1266 /* only check the host once */ 1266 /* only check the host once */
1267 if (!usb_fs_type) { 1267 if (!usb_fs_type) {
  1268 + dir = opendir(USBSYSBUS_PATH "/devices");
  1269 + if (dir) {
  1270 + /* devices found in /dev/bus/usb/ (yes - not a mistake!) */
  1271 + strcpy(devpath, USBDEVBUS_PATH);
  1272 + usb_fs_type = USB_FS_SYS;
  1273 + closedir(dir);
  1274 + dprintf(USBDBG_DEVOPENED, USBSYSBUS_PATH);
  1275 + goto found_devices;
  1276 + }
1268 f = fopen(USBPROCBUS_PATH "/devices", "r"); 1277 f = fopen(USBPROCBUS_PATH "/devices", "r");
1269 if (f) { 1278 if (f) {
1270 /* devices found in /proc/bus/usb/ */ 1279 /* devices found in /proc/bus/usb/ */
@@ -1284,15 +1293,6 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) @@ -1284,15 +1293,6 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
1284 dprintf(USBDBG_DEVOPENED, USBDEVBUS_PATH); 1293 dprintf(USBDBG_DEVOPENED, USBDEVBUS_PATH);
1285 goto found_devices; 1294 goto found_devices;
1286 } 1295 }
1287 - dir = opendir(USBSYSBUS_PATH "/devices");  
1288 - if (dir) {  
1289 - /* devices found in /dev/bus/usb/ (yes - not a mistake!) */  
1290 - strcpy(devpath, USBDEVBUS_PATH);  
1291 - usb_fs_type = USB_FS_SYS;  
1292 - closedir(dir);  
1293 - dprintf(USBDBG_DEVOPENED, USBSYSBUS_PATH);  
1294 - goto found_devices;  
1295 - }  
1296 found_devices: 1296 found_devices:
1297 if (!usb_fs_type) { 1297 if (!usb_fs_type) {
1298 monitor_printf(mon, "husb: unable to access USB devices\n"); 1298 monitor_printf(mon, "husb: unable to access USB devices\n");