9954466
From 9cf0574418cc7657618a738dd31337739c635875 Mon Sep 17 00:00:00 2001
9954466
From: Mark McLoughlin <markmc@redhat.com>
9954466
Date: Fri, 3 Jul 2009 09:17:20 +0100
9954466
Subject: [PATCH] Prefer sysfs for USB host devices
9954466
9954466
Scanning for devices via /sys/bus/usb/devices/ and using them via the
9954466
/dev/bus/usb/<bus>/<device> character devices is the prefered method
9954466
on modern kernels, so try that first.
9954466
9954466
When using SELinux and libvirt, qemu will have access to /sys/bus/usb
9954466
but not /proc/bus/usb, so although the current code will work just
9954466
fine, it will generate SELinux AVC warnings.
9954466
9954466
See also:
9954466
9954466
  https://bugzilla.redhat.com/508326
9954466
9954466
Reported-by: Daniel Berrange <berrange@redhat.com>
9954466
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
9954466
---
9954466
 usb-linux.c |   18 +++++++++---------
9954466
 1 files changed, 9 insertions(+), 9 deletions(-)
9954466
9954466
diff --git a/usb-linux.c b/usb-linux.c
9954466
index 67e4acd..3c724ba 100644
9954466
--- a/usb-linux.c
9954466
+++ b/usb-linux.c
9954466
@@ -1265,6 +1265,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
9954466
 
9954466
     /* only check the host once */
9954466
     if (!usb_fs_type) {
9954466
+        dir = opendir(USBSYSBUS_PATH "/devices");
9954466
+        if (dir) {
9954466
+            /* devices found in /dev/bus/usb/ (yes - not a mistake!) */
9954466
+            strcpy(devpath, USBDEVBUS_PATH);
9954466
+            usb_fs_type = USB_FS_SYS;
9954466
+            closedir(dir);
9954466
+            dprintf(USBDBG_DEVOPENED, USBSYSBUS_PATH);
9954466
+            goto found_devices;
9954466
+        }
9954466
         f = fopen(USBPROCBUS_PATH "/devices", "r");
9954466
         if (f) {
9954466
             /* devices found in /proc/bus/usb/ */
9954466
@@ -1284,15 +1293,6 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
9954466
             dprintf(USBDBG_DEVOPENED, USBDEVBUS_PATH);
9954466
             goto found_devices;
9954466
         }
9954466
-        dir = opendir(USBSYSBUS_PATH "/devices");
9954466
-        if (dir) {
9954466
-            /* devices found in /dev/bus/usb/ (yes - not a mistake!) */
9954466
-            strcpy(devpath, USBDEVBUS_PATH);
9954466
-            usb_fs_type = USB_FS_SYS;
9954466
-            closedir(dir);
9954466
-            dprintf(USBDBG_DEVOPENED, USBSYSBUS_PATH);
9954466
-            goto found_devices;
9954466
-        }
9954466
     found_devices:
9954466
         if (!usb_fs_type) {
9954466
             monitor_printf(mon, "husb: unable to access USB devices\n");
9954466
-- 
9954466
1.6.2.5
9954466