From 44f459c7754bbbafd85fc0af21f12bd3e3c76bbf Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 23 Jun 2011 12:40:41 -0300 Subject: [RHEL6 qemu-kvm PATCH 008/115] usb-linux: Store devpath into USBHostDevice when usb_fs_type == USB_FS_SYS RH-Author: Gerd Hoffmann Message-id: <1308832951-8995-6-git-send-email-kraxel@redhat.com> Patchwork-id: 27854 O-Subject: [RHEL-6.2 kvm PATCH 005/115] usb-linux: Store devpath into USBHostDevice when usb_fs_type == USB_FS_SYS Bugzilla: 561414 632299 645351 711354 RH-Acked-by: Hans de Goede RH-Acked-by: Jes Sorensen This allows us to recreate the sysfspath used during scanning later (which will be used in a later patch in this series). Signed-off-by: Anthony Liguori (cherry picked from commit 0f5160d1ea8bcd69d539f8a87a1b350d98fa5d52) Conflicts: usb-linux.c Signed-off-by: Gerd Hoffmann --- usb-linux.c | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) Signed-off-by: Eduardo Habkost --- usb-linux.c | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 67bb50d..f6849dc 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -62,8 +62,8 @@ struct usb_ctrlrequest { uint16_t wLength; }; -typedef int USBScanFunc(void *opaque, int bus_num, int addr, int class_id, - int vendor_id, int product_id, +typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath, + int class_id, int vendor_id, int product_id, const char *product_name, int speed); //#define DEBUG @@ -141,6 +141,7 @@ typedef struct USBHostDevice { /* Host side address */ int bus_num; int addr; + int devpath; struct USBAutoFilter match; QTAILQ_ENTRY(USBHostDevice) next; @@ -863,7 +864,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s) } static int usb_host_open(USBHostDevice *dev, int bus_num, - int addr, const char *prod_name) + int addr, int devpath, const char *prod_name) { int fd = -1, ret; struct usbdevfs_connectinfo ci; @@ -889,6 +890,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num, dev->bus_num = bus_num; dev->addr = addr; + dev->devpath = devpath; dev->fd = fd; /* read the device description */ @@ -1140,7 +1142,7 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func) if (line[0] == 'T' && line[1] == ':') { if (device_count && (vendor_id || product_id)) { /* New device. Add the previously discovered device. */ - ret = func(opaque, bus_num, addr, class_id, vendor_id, + ret = func(opaque, bus_num, addr, 0, class_id, vendor_id, product_id, product_name, speed); if (ret) goto the_end; @@ -1184,7 +1186,7 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func) } if (device_count && (vendor_id || product_id)) { /* Add the last device. */ - ret = func(opaque, bus_num, addr, class_id, vendor_id, + ret = func(opaque, bus_num, addr, 0, class_id, vendor_id, product_id, product_name, speed); } the_end: @@ -1231,7 +1233,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func) { DIR *dir = NULL; char line[1024]; - int bus_num, addr, speed, class_id, product_id, vendor_id; + int bus_num, addr, devpath, speed, class_id, product_id, vendor_id; int ret = 0; char product_name[512]; struct dirent *de; @@ -1245,9 +1247,12 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func) while ((de = readdir(dir))) { if (de->d_name[0] != '.' && !strchr(de->d_name, ':')) { char *tmpstr = de->d_name; - if (!strncmp(de->d_name, "usb", 3)) + if (!strncmp(de->d_name, "usb", 3)) { tmpstr += 3; - bus_num = atoi(tmpstr); + } + if (sscanf(tmpstr, "%d-%d", &bus_num, &devpath) < 1) { + goto the_end; + } if (!usb_host_read_file(line, sizeof(line), "devnum", de->d_name)) goto the_end; @@ -1289,7 +1294,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func) else speed = USB_SPEED_FULL; - ret = func(opaque, bus_num, addr, class_id, vendor_id, + ret = func(opaque, bus_num, addr, devpath, class_id, vendor_id, product_id, product_name, speed); if (ret) goto the_end; @@ -1376,7 +1381,7 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) static QEMUTimer *usb_auto_timer; -static int usb_host_auto_scan(void *opaque, int bus_num, int addr, +static int usb_host_auto_scan(void *opaque, int bus_num, int addr, int devpath, int class_id, int vendor_id, int product_id, const char *product_name, int speed) { @@ -1408,9 +1413,7 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr, if (s->fd != -1) return 0; - dprintf("husb: auto open: bus_num %d addr %d\n", bus_num, addr); - - usb_host_open(s, bus_num, addr, product_name); + usb_host_open(s, bus_num, addr, devpath, product_name); } return 0; @@ -1562,7 +1565,7 @@ static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id, } static int usb_host_info_device(void *opaque, int bus_num, int addr, - int class_id, + int devpath, int class_id, int vendor_id, int product_id, const char *product_name, int speed) -- 1.7.3.2