Blame qemu-prefer-sysfs-for-usb-host-devices.patch

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