Resend of usbip-utils migration patches and various other fixes
cover Resend of usbip-utils migration patches and various other fixes
This is a resend of the patches sent a few days ago, including the migration of USB/IP userspace side to use libudev instead of libsysfs and various other fixes, all ordered in a big patch series.
The patches have been modified according to received feedback.
Valentina Manea (18):
staging: usbip: userspace: migrate usbip_bind to libudev
staging: usbip: userspace: remove useless libsysfs includes
staging: usbip: userspace: migrate usbip_unbind to libudev
staging: usbip: userspace: migrate usbip_list to libudev
staging: usbip: userspace: re-add interface information listing
staging: usbip: userspace: add new list API
staging: usbip: userspace: move sysfs_utils to libsrc
staging: usbip: userspace: migrate usbip_host_driver to libudev
staging: usbip: userspace: remove class device infrastructure in
vhci_driver
staging: usbip: userspace: migrate vhci_driver to libudev
staging: usbip: userspace: remove libsysfs flag and autoconf check
staging: usbip: userspace: update dependencies in README
staging: usbip: userspace: increase version to 2.0
staging: usbip: let client choose device configuration
staging: usbip: trigger driver probing after unbinding from usbip-host
staging: usbip: claim ports used by shared devices
staging: usbip: userspace: don't throw error when trying to read
configuration specific attributes
staging: usbip: userspace: add hwdata as optional dependency in README
drivers/staging/usbip/stub.h | 1 + drivers/staging/usbip/stub_dev.c | 33 +- drivers/staging/usbip/stub_main.c | 39 +++ drivers/staging/usbip/stub_rx.c | 26 +- drivers/staging/usbip/userspace/README | 8 +- drivers/staging/usbip/userspace/configure.ac | 12 +- drivers/staging/usbip/userspace/libsrc/Makefile.am | 3 +- drivers/staging/usbip/userspace/libsrc/list.h | 136 ++++++++ .../staging/usbip/userspace/libsrc/sysfs_utils.c | 31 ++ .../staging/usbip/userspace/libsrc/sysfs_utils.h | 8 + .../staging/usbip/userspace/libsrc/usbip_common.c | 91 +++--- .../staging/usbip/userspace/libsrc/usbip_common.h | 15 +- .../usbip/userspace/libsrc/usbip_host_driver.c | 285 +++++------------ .../usbip/userspace/libsrc/usbip_host_driver.h | 7 +- .../staging/usbip/userspace/libsrc/vhci_driver.c | 346 ++++----------------- .../staging/usbip/userspace/libsrc/vhci_driver.h | 14 +- drivers/staging/usbip/userspace/src/Makefile.am | 1 - drivers/staging/usbip/userspace/src/usbip_attach.c | 1 - drivers/staging/usbip/userspace/src/usbip_bind.c | 149 ++++----- drivers/staging/usbip/userspace/src/usbip_detach.c | 2 - drivers/staging/usbip/userspace/src/usbip_list.c | 153 ++++----- .../staging/usbip/userspace/src/usbip_network.h | 1 - drivers/staging/usbip/userspace/src/usbip_unbind.c | 110 +++---- drivers/staging/usbip/userspace/src/usbipd.c | 30 +- drivers/staging/usbip/userspace/src/utils.c | 48 +-- drivers/usb/core/hub.c | 2 + drivers/usb/core/usb.h | 4 - include/linux/usb.h | 7 + 28 files changed, 676 insertions(+), 887 deletions(-) create mode 100644 drivers/staging/usbip/userspace/libsrc/list.h create mode 100644 drivers/staging/usbip/userspace/libsrc/sysfs_utils.c create mode 100644 drivers/staging/usbip/userspace/libsrc/sysfs_utils.h
Signature · 1 line
1.8.1.2
PATCH 1/18 staging: usbip: userspace: migrate usbip_bind to libudev
This patch adds autoconf check for libudev and migrates usbip_bind to the new library.
libsysfs will still be used until all userspace is modified.
--- drivers/staging/usbip/userspace/configure.ac | 6 + .../staging/usbip/userspace/libsrc/usbip_common.h | 9 ++ drivers/staging/usbip/userspace/src/Makefile.am | 3 +- drivers/staging/usbip/userspace/src/sysfs_utils.c | 31 +++++ drivers/staging/usbip/userspace/src/sysfs_utils.h | 8 ++ drivers/staging/usbip/userspace/src/usbip_bind.c | 149 ++++++++------------- drivers/staging/usbip/userspace/src/utils.c | 48 ++----- 7 files changed, 127 insertions(+), 127 deletions(-) create mode 100644 drivers/staging/usbip/userspace/src/sysfs_utils.c create mode 100644 drivers/staging/usbip/userspace/src/sysfs_utils.h
drivers/staging/usbip/userspace/configure.ac +6 -0
@@ -50,6 +50,12 @@ AC_CHECK_HEADER([sysfs/libsysfs.h], [AC_MSG_ERROR([Missing sysfs2 library!])])], [AC_MSG_ERROR([Missing /usr/include/sysfs/libsysfs.h])]) +AC_CHECK_HEADER([libudev.h], + [AC_CHECK_LIB([udev], [udev_new], + [LIBS="$LIBS -ludev"], + [AC_MSG_ERROR([Missing udev library!])])], + [AC_MSG_ERROR([Missing /usr/include/libudev.h])]) + # Checks for libwrap library. AC_MSG_CHECKING([whether to use the libwrap (TCP wrappers) library]) AC_ARG_WITH([tcp-wrappers],
drivers/staging/usbip/userspace/libsrc/usbip_common.h +9 -0
@@ -30,6 +30,15 @@#define USBIP_HOST_DRV_NAME "usbip-host"#define USBIP_VHCI_DRV_NAME "vhci_hcd" +/* sysfs constants */ +#define SYSFS_MNT_PATH "/sys" +#define SYSFS_BUS_NAME "bus" +#define SYSFS_BUS_TYPE "usb" +#define SYSFS_DRIVERS_NAME "drivers" + +#define SYSFS_PATH_MAX 256 +#define SYSFS_BUS_ID_SIZE 32 +extern int usbip_use_syslog;extern int usbip_use_stderr;extern int usbip_use_debug ;
drivers/staging/usbip/userspace/src/Makefile.am +2 -1
@@ -6,7 +6,8 @@ sbin_PROGRAMS := usbip usbipd usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \ usbip_attach.c usbip_detach.c usbip_list.c \ - usbip_bind.c usbip_unbind.c usbip_port.c + usbip_bind.c usbip_unbind.c usbip_port.c \ + sysfs_utils.c usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
drivers/staging/usbip/userspace/src/sysfs_utils.c new file +31 -0
@@ -0,0 +1,31 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +#include "sysfs_utils.h" +#include "usbip_common.h" + +int write_sysfs_attribute (const char *attr_path,const char *new_value, +size_t len) +{ +int fd; +int length; + + fd =open (attr_path,O_WRONLY ); +if (fd <0 ) { +dbg ("error opening attribute %s" , attr_path); +return -1 ; + } + + length =write (fd, new_value, len); +if (length <0 ) { +dbg ("error writing to attribute %s" , attr_path); +close (fd); +return -1 ; + } + +close (fd); + +return 0 ; +}
drivers/staging/usbip/userspace/src/sysfs_utils.h new file +8 -0
@@ -0,0 +1,8 @@ + +#ifndef __SYSFS_UTILS_H +#define __SYSFS_UTILS_H + +int write_sysfs_attribute (const char *attr_path,const char *new_value, +size_t len); + +#endif
drivers/staging/usbip/userspace/src/usbip_bind.c +59 -90
220 lines not on this page · raw message
drivers/staging/usbip/userspace/src/utils.c +12 -36
73 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 2/18 staging: usbip: userspace: remove useless libsysfs includes
In reply to Valentina ManeaThis patch removes useless libsysfs.h includes in various userspace files.
--- drivers/staging/usbip/userspace/src/usbip_attach.c | 1 - drivers/staging/usbip/userspace/src/usbip_detach.c | 2 -- drivers/staging/usbip/userspace/src/usbip_network.h | 1 - 3 files changed, 4 deletions(-)
drivers/staging/usbip/userspace/src/usbip_attach.c +0 -1
@@ -17,7 +17,6 @@*/ #include <sys/stat.h> -#include <sysfs/libsysfs.h> #include <limits.h> #include <stdint.h>
drivers/staging/usbip/userspace/src/usbip_detach.c +0 -2
@@ -16,8 +16,6 @@* along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <sysfs/libsysfs.h> -#include <ctype.h> #include <limits.h> #include <stdint.h>
drivers/staging/usbip/userspace/src/usbip_network.h +0 -1
@@ -10,7 +10,6 @@#endif #include <sys/types.h> -#include <sysfs/libsysfs.h> #include <stdint.h>
Signature · 1 line
1.8.1.2
PATCH 3/18 staging: usbip: userspace: migrate usbip_unbind to libudev
In reply to Valentina ManeaThis patch modifies usbip_unbind to use libudev.
--- drivers/staging/usbip/userspace/src/usbip_unbind.c | 93 +++++++--------------- 1 file changed, 29 insertions(+), 64 deletions(-)
drivers/staging/usbip/userspace/src/usbip_unbind.c +29 -64
@@ -16,7 +16,7 @@* along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <sysfs/libsysfs.h> +#include <libudev.h> #include <errno.h> #include <stdio.h>
@@ -27,6 +27,7 @@#include "usbip_common.h" #include "utils.h" #include "usbip.h" +#include "sysfs_utils.h" static const char usbip_unbind_usage_string[] ="usbip unbind <args>\n"
@@ -41,92 +42,56 @@ void usbip_unbind_usage(void)static int unbind_device (char *busid) {char bus_type[] ="usb" ; -struct sysfs_driver *usbip_host_drv; -struct sysfs_device *dev; -struct dlist *devlist; -int verified =0 ;int rc, ret =-1 ;char attr_name[] ="unbind" ; -char sysfs_mntpath[SYSFS_PATH_MAX ];char unbind_attr_path[SYSFS_PATH_MAX ]; -struct sysfs_attribute *unbind_attr; - -/* verify the busid device is using usbip-host */ - usbip_host_drv =sysfs_open_driver (bus_type,USBIP_HOST_DRV_NAME ); -if (!usbip_host_drv) { -err ("could not open %s driver: %s" ,USBIP_HOST_DRV_NAME , -strerror (errno)); -return -1 ; - } - devlist =sysfs_get_driver_devices (usbip_host_drv); -if (!devlist) { -err ("%s is not in use by any devices" ,USBIP_HOST_DRV_NAME ); - goto err_close_usbip_host_drv; - } +struct udev *udev; +struct udev_device *dev; +const char *driver; - dlist_for_each_data(devlist, dev, struct sysfs_device) { -if (!strncmp (busid, dev->name,strlen (busid)) && - !strncmp (dev->driver_name,USBIP_HOST_DRV_NAME , -strlen (USBIP_HOST_DRV_NAME ))) { - verified =1 ; -break ; - } - } +/* Create libudev context. */ + udev =udev_new (); -if (!verified) { -err ("device on busid %s is not using %s" , busid, -USBIP_HOST_DRV_NAME ); - goto err_close_usbip_host_drv; +/* Check whether the device with this bus ID exists. */ + dev =udev_device_new_from_subsystem_sysname (udev,"usb" , busid); +if (!dev) { +err ("device with the specified bus ID does not exist" ); + goto err_close_udev; } -/* -* NOTE: A read and write of an attribute value of the device busid -* refers to must be done to start probing. That way a rebind of the -* default driver for the device occurs. -* -* This seems very hackish and adds a lot of pointless code. I think it -* should be done in the kernel by the driver after del_match_busid is -* finished! -*/ - - rc =sysfs_get_mnt_path (sysfs_mntpath,SYSFS_PATH_MAX ); -if (rc <0 ) { -err ("sysfs must be mounted: %s" ,strerror (errno)); -return -1 ; +/* Check whether the device is using usbip-host driver. */ + driver =udev_device_get_driver (dev); +if (!driver ||strcmp (driver,"usbip-host" )) { +err ("device is not bound to usbip-host driver" ); + goto err_close_udev; } +/* Unbind device from driver. */ snprintf (unbind_attr_path,sizeof (unbind_attr_path),"%s/%s/%s/%s/%s/%s" , - sysfs_mntpath,SYSFS_BUS_NAME , bus_type,SYSFS_DRIVERS_NAME , +SYSFS_MNT_PATH ,SYSFS_BUS_NAME , bus_type,SYSFS_DRIVERS_NAME ,USBIP_HOST_DRV_NAME , attr_name); -/* read a device attribute */ - unbind_attr =sysfs_open_attribute (unbind_attr_path); -if (!unbind_attr) { -err ("could not open %s/%s: %s" , busid, attr_name, -strerror (errno)); -return -1 ; + rc =write_sysfs_attribute (unbind_attr_path, busid,strlen (busid)); +if (rc <0 ) { +err ("error unbinding device %s from driver" , busid); + goto err_close_udev; } -/* notify driver of unbind */ +/* Notify driver of unbind. */ rc =modify_match_busid (busid,0 );if (rc <0 ) {err ("unable to unbind device on %s" , busid); + goto err_close_udev; } - rc =sysfs_write_attribute (unbind_attr, busid, -SYSFS_BUS_ID_SIZE ); -if (rc <0 ) { -dbg ("bind driver at %s failed" , busid); - } -sysfs_close_attribute (unbind_attr); - ret =0 ; -printf ("unbind device on busid %s: complete\n" , busid); +info ("unbind device on busid %s: complete" , busid); -err_close_usbip_host_drv: -sysfs_close_driver (usbip_host_drv); +err_close_udev: +udev_device_unref (dev); +udev_unref (udev);return ret; }
Signature · 1 line
1.8.1.2
PATCH 4/18 staging: usbip: userspace: migrate usbip_list to libudev
In reply to Valentina ManeaThis patch modifies usbip_list to use libudev.
--- drivers/staging/usbip/userspace/src/usbip_list.c | 133 +++++++++-------------- 1 file changed, 50 insertions(+), 83 deletions(-)
drivers/staging/usbip/userspace/src/usbip_list.c +50 -83
@@ -17,7 +17,7 @@*/ #include <sys/types.h> -#include <sysfs/libsysfs.h> +#include <libudev.h> #include <errno.h> #include <stdbool.h>
@@ -133,8 +133,8 @@ static int list_exported_devices(char *host)return 0 ; } -static void print_device (char *busid,char *vendor,char *product, -bool parsable) +static void print_device (const char *busid,const char *vendor, +const char *product,bool parsable) {if (parsable)printf ("busid=%s#usbid=%.4s:%.4s#" , busid, vendor, product);
@@ -148,106 +148,73 @@ static void print_product_name(char *product_name, bool parsable)printf (" %s\n" , product_name); } -static void print_interface (char *busid,char *driver,bool parsable) -{ -if (parsable) -printf ("%s=%s#" , busid, driver); -else -printf ("%9s%s -> %s\n" ,"" , busid, driver); -} - -static int is_device (void *x) -{ -struct sysfs_attribute *devpath; -struct sysfs_device *dev = x; -int ret =0 ; - - devpath =sysfs_get_device_attr (dev,"devpath" ); -if (devpath && *devpath->value !='0' ) - ret =1 ; - -return ret; -} - -static int devcmp (void *a,void *b) -{ -return strcmp (a, b); -} -static int list_devices (bool parsable) { -char bus_type[] ="usb" ; -char busid[SYSFS_BUS_ID_SIZE ]; +struct udev *udev; +struct udev_enumerate *enumerate; +struct udev_list_entry *devices, *dev_list_entry; +struct udev_device *dev; +const char *path; +const char *idVendor; +const char *idProduct; +const char *bConfValue; +const char *bNumIntfs; +const char *busid;char product_name[128 ]; -struct sysfs_bus *ubus; -struct sysfs_device *dev; -struct sysfs_device *intf; -struct sysfs_attribute *idVendor; -struct sysfs_attribute *idProduct; -struct sysfs_attribute *bConfValue; -struct sysfs_attribute *bNumIntfs; -struct dlist *devlist; -int i;int ret =-1 ; - ubus =sysfs_open_bus (bus_type); -if (!ubus) { -err ("could not open %s bus: %s" , bus_type,strerror (errno)); -return -1 ; - } - - devlist =sysfs_get_bus_devices (ubus); -if (!devlist) { -err ("could not get %s bus devices: %s" , bus_type, -strerror (errno)); - goto err_out; - } - -/* remove interfaces and root hubs from device list */ -dlist_filter_sort (devlist, is_device, devcmp); - -if (!parsable) { -printf ("Local USB devices\n" ); -printf ("=================\n" ); - } - dlist_for_each_data(devlist, dev, struct sysfs_device) { - idVendor =sysfs_get_device_attr (dev,"idVendor" ); - idProduct =sysfs_get_device_attr (dev,"idProduct" ); - bConfValue =sysfs_get_device_attr (dev,"bConfigurationValue" ); - bNumIntfs =sysfs_get_device_attr (dev,"bNumInterfaces" ); +/* Create libudev context. */ + udev =udev_new (); + +/* Create libudev device enumeration. */ + enumerate =udev_enumerate_new (udev); + +/* Take only USB devices that are not hubs and do not have +* the bInterfaceNumber attribute, i.e. are not interfaces. +*/ +udev_enumerate_add_match_subsystem (enumerate,"usb" ); +udev_enumerate_add_nomatch_sysattr (enumerate,"bDeviceClass" ,"09" ); +udev_enumerate_add_nomatch_sysattr (enumerate,"bInterfaceNumber" ,NULL ); +udev_enumerate_scan_devices (enumerate); + + devices =udev_enumerate_get_list_entry (enumerate); + +/* Show information about each device. */ + udev_list_entry_foreach(dev_list_entry, devices) { + path =udev_list_entry_get_name (dev_list_entry); + dev =udev_device_new_from_syspath (udev, path); + +/* Get device information. */ + idVendor =udev_device_get_sysattr_value (dev,"idVendor" ); + idProduct =udev_device_get_sysattr_value (dev,"idProduct" ); + bConfValue =udev_device_get_sysattr_value (dev,"bConfigurationValue" ); + bNumIntfs =udev_device_get_sysattr_value (dev,"bNumInterfaces" ); + busid =udev_device_get_sysname (dev);if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) {err ("problem getting device attributes: %s" ,strerror (errno)); goto err_out; } -/* get product name */ +/* Get product name. */ usbip_names_get_product (product_name,sizeof (product_name), -strtol (idVendor->value,NULL ,16 ), -strtol (idProduct->value,NULL ,16 )); -print_device (dev->bus_id, idVendor->value, idProduct->value, - parsable); +strtol (idVendor,NULL ,16 ), +strtol (idProduct,NULL ,16 )); + +/* Print information. */ +print_device (busid, idVendor, idProduct, parsable);print_product_name (product_name, parsable); -for (i =0 ; i <atoi (bNumIntfs->value); i++) { -snprintf (busid,sizeof (busid),"%s:%.1s.%d" , - dev->bus_id, bConfValue->value, i); - intf =sysfs_open_device (bus_type, busid); -if (!intf) { -err ("could not open device interface: %s" , -strerror (errno)); - goto err_out; - } -print_interface (busid, intf->driver_name, parsable); -sysfs_close_device (intf); - }printf ("\n" ); + +udev_device_unref (dev); } ret =0 ; err_out: -sysfs_close_bus (ubus); +udev_enumerate_unref (enumerate); +udev_unref (udev);return ret; }
Signature · 1 line
1.8.1.2
PATCH 5/18 staging: usbip: userspace: re-add interface information listing
In reply to Valentina ManeaThis was deleted in the driver conversion patch. It didn't need to be deleted; showing more information is ok.
--- drivers/staging/usbip/userspace/src/usbip_list.c | 20 +++++++++++++++++++- drivers/staging/usbip/userspace/src/usbipd.c | 16 +++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-)
drivers/staging/usbip/userspace/src/usbip_list.c +19 -1
@@ -52,8 +52,9 @@ static int get_exported_devices(char *host, int sockfd)struct op_devlist_reply reply;uint16_t code =OP_REP_DEVLIST ;struct usbip_usb_device udev; +struct usbip_usb_interface uintf;unsigned int i; -int rc; +int rc, j; rc =usbip_net_send_op_common (sockfd,OP_REQ_DEVLIST ,0 );if (rc <0 ) {
@@ -103,6 +104,23 @@ static int get_exported_devices(char *host, int sockfd)printf ("%11s: %s\n" ,"" , udev.path);printf ("%11s: %s\n" ,"" , class_name); +for (j =0 ; j < udev.bNumInterfaces; j++) { + rc =usbip_net_recv (sockfd, &uintf,sizeof (uintf)); +if (rc <0 ) { +err ("usbip_net_recv failed: usbip_usb_intf[%d]" , + j); + +return -1 ; + } +usbip_net_pack_usb_interface (0 , &uintf); + +usbip_names_get_class (class_name,sizeof (class_name), + uintf.bInterfaceClass, + uintf.bInterfaceSubClass, + uintf.bInterfaceProtocol); +printf ("%11s: %2d - %s\n" ,"" , j, class_name); + } +printf ("\n" ); }
drivers/staging/usbip/userspace/src/usbipd.c +15 -1
@@ -159,8 +159,9 @@ static int send_reply_devlist(int connfd) {struct usbip_exported_device *edev;struct usbip_usb_device pdu_udev; +struct usbip_usb_interface pdu_uinf;struct op_devlist_reply reply; -int rc; +int rc, i; reply.ndev =0 ;/* number of exported devices */
@@ -194,6 +195,19 @@ static int send_reply_devlist(int connfd)dbg ("usbip_net_send failed: pdu_udev" );return -1 ; } + +for (i =0 ; i < edev->udev.bNumInterfaces; i++) { +dump_usb_interface (&edev->uinf[i]); +memcpy (&pdu_uinf, &edev->uinf[i],sizeof (pdu_uinf)); +usbip_net_pack_usb_interface (1 , &pdu_uinf); + + rc =usbip_net_send (connfd, &pdu_uinf, +sizeof (pdu_uinf)); +if (rc <0 ) { +err ("usbip_net_send failed: pdu_uinf" ); +return -1 ; + } + } }return 0 ;
Signature · 1 line
1.8.1.2
PATCH 6/18 staging: usbip: userspace: add new list API
In reply to Valentina ManeaTake the linked list implementation from the Linux Kernel and strip it down to what it is needed.
--- drivers/staging/usbip/userspace/libsrc/list.h | 136 ++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 drivers/staging/usbip/userspace/libsrc/list.h
drivers/staging/usbip/userspace/libsrc/list.h new file +136 -0
@@ -0,0 +1,136 @@ +#ifndef _LIST_H +#define _LIST_H + +/* Stripped down implementation of linked list taken +* from the Linux Kernel. +*/ + +/* +* Simple doubly linked list implementation. +* +* Some of the internal functions ("__xxx") are useful when +* manipulating whole lists rather than single entries, as +* sometimes we already know the next/prev entries and we can +* generate better code by using them directly rather than +* using the generic single-entry routines. +*/ + +struct list_head { +struct list_head *next, *prev; +}; + +#define LIST_HEAD_INIT (name) { &(name), &(name) } + +#define LIST_HEAD (name) \ + struct list_head name = LIST_HEAD_INIT(name) + +static inline void INIT_LIST_HEAD (struct list_head *list) +{ + list->next = list; + list->prev = list; +} + +/* +* Insert a new entry between two known consecutive entries. +* +* This is only for internal list manipulation where we know +* the prev/next entries already! +*/ +static inline void __list_add (struct list_head *new, +struct list_head *prev, +struct list_head *next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +/** +* list_add - add a new entry +* @new: new entry to be added +* @head: list head to add it after +* +* Insert a new entry after the specified head. +* This is good for implementing stacks. +*/ +static inline void list_add (struct list_head *new,struct list_head *head) +{ +__list_add (new, head, head->next); +} + +/* +* Delete a list entry by making the prev/next entries +* point to each other. +* +* This is only for internal list manipulation where we know +* the prev/next entries already! +*/ +static inline void __list_del (struct list_head * prev,struct list_head * next) +{ + next->prev = prev; + prev->next = next; +} + +#define POISON_POINTER_DELTA 0 +#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA) +#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA) + +/** +* list_del - deletes entry from list. +* @entry: the element to delete from the list. +* Note: list_empty() on entry does not return true after this, the entry is +* in an undefined state. +*/ +static inline void __list_del_entry (struct list_head *entry) +{ +__list_del (entry->prev, entry->next); +} + +static inline void list_del (struct list_head *entry) +{ +__list_del (entry->prev, entry->next); + entry->next =LIST_POISON1 ; + entry->prev =LIST_POISON2 ; +} + +/** +* list_entry - get the struct for this entry +* @ptr: the &struct list_head pointer. +* @type: the type of the struct this is embedded in. +* @member: the name of the list_struct within the struct. +*/ +#define list_entry (ptr, type, member) \ + container_of(ptr, type, member) +/** +* list_for_each - iterate over a list +* @pos: the &struct list_head to use as a loop cursor. +* @head: the head for your list. +*/ +#define list_for_each (pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +/** +* list_for_each_safe - iterate over a list safe against removal of list entry +* @pos: the &struct list_head to use as a loop cursor. +* @n: another &struct list_head to use as temporary storage +* @head: the head for your list. +*/ +#define list_for_each_safe (pos, n, head) \ + for (pos = (head)->next, n = pos->next; pos != (head); \ + pos = n, n = pos->next) + +#define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER) + +/** +* container_of - cast a member of a structure out to the containing structure +* @ptr: the pointer to the member. +* @type: the type of the container struct this is embedded in. +* @member: the name of the member within the struct. +* +*/ +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#endif
Signature · 1 line
1.8.1.2
PATCH 7/18 staging: usbip: userspace: move sysfs_utils to libsrc
In reply to Valentina ManeaSince it offers a API to both usbip tools and libusbip, it is more appropriate to be place in the library.
--- drivers/staging/usbip/userspace/libsrc/Makefile.am | 3 ++- .../staging/usbip/userspace/libsrc/sysfs_utils.c | 31 ++++++++++++++++++++++ .../staging/usbip/userspace/libsrc/sysfs_utils.h | 8 ++++++ drivers/staging/usbip/userspace/src/Makefile.am | 4 +-- drivers/staging/usbip/userspace/src/sysfs_utils.c | 31 ---------------------- drivers/staging/usbip/userspace/src/sysfs_utils.h | 8 ------ 6 files changed, 42 insertions(+), 43 deletions(-) create mode 100644 drivers/staging/usbip/userspace/libsrc/sysfs_utils.c create mode 100644 drivers/staging/usbip/userspace/libsrc/sysfs_utils.h delete mode 100644 drivers/staging/usbip/userspace/src/sysfs_utils.c delete mode 100644 drivers/staging/usbip/userspace/src/sysfs_utils.h
drivers/staging/usbip/userspace/libsrc/Makefile.am +2 -1
@@ -4,4 +4,5 @@ libusbip_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@ lib_LTLIBRARIES := libusbip.la libusbip_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \ - usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h + usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h \ + sysfs_utils.c sysfs_utils.h
drivers/staging/usbip/userspace/libsrc/sysfs_utils.c new file +31 -0
@@ -0,0 +1,31 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +#include "sysfs_utils.h" +#include "usbip_common.h" + +int write_sysfs_attribute (const char *attr_path,const char *new_value, +size_t len) +{ +int fd; +int length; + + fd =open (attr_path,O_WRONLY ); +if (fd <0 ) { +dbg ("error opening attribute %s" , attr_path); +return -1 ; + } + + length =write (fd, new_value, len); +if (length <0 ) { +dbg ("error writing to attribute %s" , attr_path); +close (fd); +return -1 ; + } + +close (fd); + +return 0 ; +}
drivers/staging/usbip/userspace/libsrc/sysfs_utils.h new file +8 -0
@@ -0,0 +1,8 @@ + +#ifndef __SYSFS_UTILS_H +#define __SYSFS_UTILS_H + +int write_sysfs_attribute (const char *attr_path,const char *new_value, +size_t len); + +#endif
drivers/staging/usbip/userspace/src/Makefile.am +1 -3
@@ -6,8 +6,6 @@ sbin_PROGRAMS := usbip usbipd usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \ usbip_attach.c usbip_detach.c usbip_list.c \ - usbip_bind.c usbip_unbind.c usbip_port.c \ - sysfs_utils.c - + usbip_bind.c usbip_unbind.c usbip_port.c usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
drivers/staging/usbip/userspace/src/sysfs_utils.c deleted +0 -31
@@ -1,31 +0,0 @@ -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> - -#include "sysfs_utils.h" -#include "usbip_common.h" - -int write_sysfs_attribute (const char *attr_path,const char *new_value, -size_t len) -{ -int fd; -int length; - - fd =open (attr_path,O_WRONLY ); -if (fd <0 ) { -dbg ("error opening attribute %s" , attr_path); -return -1 ; - } - - length =write (fd, new_value, len); -if (length <0 ) { -dbg ("error writing to attribute %s" , attr_path); -close (fd); -return -1 ; - } - -close (fd); - -return 0 ; -}
drivers/staging/usbip/userspace/src/sysfs_utils.h deleted +0 -8
@@ -1,8 +0,0 @@ - -#ifndef __SYSFS_UTILS_H -#define __SYSFS_UTILS_H - -int write_sysfs_attribute (const char *attr_path,const char *new_value, -size_t len); - -#endif
Signature · 1 line
1.8.1.2
PATCH 8/18 staging: usbip: userspace: migrate usbip_host_driver to libudev
In reply to Valentina ManeaThis patch modifies usbip_host_driver to use libudev.
--- .../staging/usbip/userspace/libsrc/usbip_common.c | 76 ++---- .../staging/usbip/userspace/libsrc/usbip_common.h | 5 +- .../usbip/userspace/libsrc/usbip_host_driver.c | 285 ++++++--------------- .../usbip/userspace/libsrc/usbip_host_driver.h | 7 +- .../staging/usbip/userspace/libsrc/vhci_driver.c | 22 +- drivers/staging/usbip/userspace/src/usbipd.c | 14 +- 6 files changed, 145 insertions(+), 264 deletions(-)
drivers/staging/usbip/userspace/libsrc/usbip_common.c +27 -49
@@ -2,6 +2,7 @@* Copyright (C) 2005-2007 Takahiro Hirofuchi */ +#include <libudev.h> #include "usbip_common.h" #include "names.h"
@@ -12,6 +13,8 @@ int usbip_use_syslog;int usbip_use_stderr;int usbip_use_debug; +extern struct udev *udev_context; +struct speed_string {int num;char *speed;
@@ -111,75 +114,48 @@ void dump_usb_device(struct usbip_usb_device *udev) } -int read_attr_value (struct sysfs_device *dev,const char *name, +int read_attr_value (struct udev_device *dev,const char *name,const char *format) { -char attrpath[SYSFS_PATH_MAX ]; -struct sysfs_attribute *attr; +const char *attr;int num =0 ;int ret; -snprintf (attrpath,sizeof (attrpath),"%s/%s" , dev->path, name); - - attr =sysfs_open_attribute (attrpath); + attr =udev_device_get_sysattr_value (dev, name);if (!attr) { -dbg ("sysfs_open_attribute failed: %s" , attrpath); -return 0 ; - } - - ret =sysfs_read_attribute (attr); -if (ret <0 ) { -dbg ("sysfs_read_attribute failed" ); +err ("udev_device_get_sysattr_value failed" ); goto err; } - ret =sscanf (attr->value, format, &num); + ret =sscanf (attr, format, &num);if (ret <1 ) { -dbg ("sscanf failed" ); +err ("sscanf failed" ); goto err; } err: -sysfs_close_attribute (attr);return num; } -int read_attr_speed (struct sysfs_device *dev) +int read_attr_speed (struct udev_device *dev) { -char attrpath[SYSFS_PATH_MAX ]; -struct sysfs_attribute *attr; -char speed[100 ]; -int ret; - -snprintf (attrpath,sizeof (attrpath),"%s/%s" , dev->path,"speed" ); - - attr =sysfs_open_attribute (attrpath); -if (!attr) { -dbg ("sysfs_open_attribute failed: %s" , attrpath); -return 0 ; - } +const char *speed; - ret =sysfs_read_attribute (attr); -if (ret <0 ) { -dbg ("sysfs_read_attribute failed" ); + speed =udev_device_get_sysattr_value (dev,"speed" ); +if (!speed) { +err ("udev_device_get_sysattr_value failed" ); goto err; } - ret =sscanf (attr->value,"%99s\n" , speed); -if (ret <1 ) { -dbg ("sscanf failed" ); - goto err; - } -err: -sysfs_close_attribute (attr); -for (int i =0 ; speed_strings[i].speed !=NULL ; i++) {if (!strcmp (speed, speed_strings[i].speed))return speed_strings[i].num; } +err: +return USB_SPEED_UNKNOWN ; }
@@ -190,9 +166,10 @@ err: }while (0 ) -int read_usb_device(struct sysfs_device *sdev, struct usbip_usb_device *udev) +int read_usb_device(struct udev_device *sdev, struct usbip_usb_device *udev) { uint32_t busnum, devnum; +const char *path, *name;READ_ATTR (udev, uint8_t, sdev, bDeviceClass,"%02x\n" );READ_ATTR (udev, uint8_t, sdev, bDeviceSubClass,"%02x\n" );
@@ -209,10 +186,13 @@ int read_usb_device(struct sysfs_device *sdev, struct usbip_usb_device *udev)READ_ATTR (udev, uint8_t, sdev, devnum,"%d\n" ); udev->speed =read_attr_speed (sdev); -strncpy (udev->path, sdev->path,SYSFS_PATH_MAX ); -strncpy (udev->busid, sdev->name,SYSFS_BUS_ID_SIZE ); + path =udev_device_get_syspath (sdev); + name =udev_device_get_sysname (sdev); -sscanf (sdev->name,"%u-%u" , &busnum, &devnum); +strncpy (udev->path, path,SYSFS_PATH_MAX ); +strncpy (udev->busid, name,SYSFS_BUS_ID_SIZE ); + +sscanf (name,"%u-%u" , &busnum, &devnum); udev->busnum = busnum;return 0 ;
@@ -222,13 +202,13 @@ int read_usb_interface(struct usbip_usb_device *udev, int i, struct usbip_usb_interface *uinf) {char busid[SYSFS_BUS_ID_SIZE ]; -struct sysfs_device *sif; +struct udev_device *sif;sprintf (busid,"%s:%d.%d" , udev->busid, udev->bConfigurationValue, i); - sif =sysfs_open_device ("usb" , busid); + sif =udev_device_new_from_subsystem_sysname (udev_context,"usb" , busid);if (!sif) { -dbg ("sysfs_open_device(\"usb\", \"%s\") failed" , busid); +err ("udev_device_new_from_subsystem_sysname %s failed" , busid);return -1 ; }
@@ -236,8 +216,6 @@ int read_usb_interface(struct usbip_usb_device *udev, int i,READ_ATTR (uinf, uint8_t, sif, bInterfaceSubClass,"%02x\n" );READ_ATTR (uinf, uint8_t, sif, bInterfaceProtocol,"%02x\n" ); -sysfs_close_device (sif); -return 0 ; }
drivers/staging/usbip/userspace/libsrc/usbip_common.h +3 -2
@@ -6,6 +6,7 @@#define __USBIP_COMMON_H#include <sysfs/libsysfs.h> +#include <libudev.h> #include <stdint.h> #include <stdio.h>
@@ -118,8 +119,8 @@ struct usbip_usb_device {void dump_usb_interface (struct usbip_usb_interface *);void dump_usb_device (struct usbip_usb_device *); -int read_usb_device (struct sysfs_device *sdev,struct usbip_usb_device *udev); -int read_attr_value (struct sysfs_device *dev,const char *name, +int read_usb_device (struct udev_device *sdev,struct usbip_usb_device *udev); +int read_attr_value (struct udev_device *dev,const char *name,const char *format);int read_usb_interface (struct usbip_usb_device *udev,int i,struct usbip_usb_interface *uinf);
drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c +85 -200
421 lines not on this page · raw message
drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h +4 -3
@@ -21,18 +21,19 @@#include <stdint.h> #include "usbip_common.h" +#include "list.h" struct usbip_host_driver {int ndevs; -struct sysfs_driver *sysfs_driver;/* list of exported device */ -struct dlist *edev_list; +struct list_head edev_list; };struct usbip_exported_device { -struct sysfs_device *sudev; +struct udev_device *sudev;int32_t status;struct usbip_usb_device udev; +struct list_head node;struct usbip_usb_interface uinf[]; };
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +18 -4
@@ -6,24 +6,27 @@#include "vhci_driver.h" #include <limits.h> #include <netdb.h> +#include <libudev.h> #undef PROGNAME#define PROGNAME "libusbip"struct usbip_vhci_driver *vhci_driver; +struct udev *udev_context;static struct usbip_imported_device *imported_device_init (struct usbip_imported_device *idev,char *busid) { -struct sysfs_device *sudev; +struct udev_device *sudev; - sudev =sysfs_open_device ("usb" , busid); + sudev =udev_device_new_from_subsystem_sysname (udev_context, +"usb" , busid);if (!sudev) { -dbg ("sysfs_open_device failed: %s" , busid); +dbg ("udev_device_new_from_subsystem_sysname failed: %s" , busid); goto err; }read_usb_device (sudev, &idev->udev); -sysfs_close_device (sudev); +udev_device_unref (sudev);/* add class devices of this imported device */ struct usbip_class_device *cdev;
@@ -410,6 +413,12 @@ int usbip_vhci_driver_open(void)int ret;char hc_busid[SYSFS_BUS_ID_SIZE ]; + udev_context =udev_new (); +if (!udev_context) { +err ("udev_new failed" ); +return -1 ; + } + vhci_driver = (struct usbip_vhci_driver *)calloc (1 ,sizeof (*vhci_driver));if (!vhci_driver) {dbg ("calloc failed" );
@@ -461,6 +470,9 @@ err:free (vhci_driver); vhci_driver =NULL ; + +udev_unref (udev_context); +return -1 ; }
@@ -483,6 +495,8 @@ void usbip_vhci_driver_close()free (vhci_driver); vhci_driver =NULL ; + +udev_unref (udev_context); }
drivers/staging/usbip/userspace/src/usbipd.c +8 -6
@@ -43,6 +43,7 @@#include "usbip_host_driver.h" #include "usbip_common.h" #include "usbip_network.h" +#include "list.h" #undef PROGNAME#define PROGNAME "usbipd"
@@ -93,6 +94,7 @@ static int recv_request_import(int sockfd)struct op_common reply;struct usbip_exported_device *edev;struct usbip_usb_device pdu_udev; +struct list_head *i;int found =0 ;int error =0 ;int rc;
@@ -107,8 +109,8 @@ static int recv_request_import(int sockfd) }PACK_OP_IMPORT_REQUEST (0 , &req); -dlist_for_each_data (host_driver->edev_list, edev, - struct usbip_exported_device) { +list_for_each (i, &host_driver->edev_list) { + edev = list_entry(i, struct usbip_exported_device, node);if (!strncmp (req.busid, edev->udev.busid,SYSFS_BUS_ID_SIZE )) {info ("found requested device: %s" , req.busid); found =1 ;
@@ -161,12 +163,12 @@ static int send_reply_devlist(int connfd)struct usbip_usb_device pdu_udev;struct usbip_usb_interface pdu_uinf;struct op_devlist_reply reply; +struct list_head *j;int rc, i; reply.ndev =0 ;/* number of exported devices */ -dlist_for_each_data (host_driver->edev_list, edev, - struct usbip_exported_device) { +list_for_each (j, &host_driver->edev_list) { reply.ndev +=1 ; }info ("exportable devices: %d" , reply.ndev);
@@ -184,8 +186,8 @@ static int send_reply_devlist(int connfd)return -1 ; } -dlist_for_each_data (host_driver->edev_list, edev, - struct usbip_exported_device) { +list_for_each (j, &host_driver->edev_list) { + edev = list_entry(j, struct usbip_exported_device, node);dump_usb_device (&edev->udev);memcpy (&pdu_udev, &edev->udev,sizeof (pdu_udev));usbip_net_pack_usb_device (1 , &pdu_udev);
Signature · 1 line
1.8.1.2
PATCH 9/18 staging: usbip: userspace: remove class device infrastructure in vhci_driver
In reply to Valentina ManeaThe class device lists were used only when being initialized, being populated and being destroyed. They had no real meaning and thus the code was useless.
--- .../staging/usbip/userspace/libsrc/vhci_driver.c | 178 --------------------- .../staging/usbip/userspace/libsrc/vhci_driver.h | 9 -- 2 files changed, 187 deletions(-)
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +0 -178
@@ -28,26 +28,6 @@ imported_device_init(struct usbip_imported_device *idev, char *busid)read_usb_device (sudev, &idev->udev);udev_device_unref (sudev); -/* add class devices of this imported device */ -struct usbip_class_device *cdev; -dlist_for_each_data (vhci_driver->cdev_list, cdev, - struct usbip_class_device) { -if (!strncmp (cdev->dev_path, idev->udev.path, -strlen (idev->udev.path))) { -struct usbip_class_device *new_cdev; -/* -* alloc and copy because dlist is linked -* from only one list -*/ - new_cdev =calloc (1 ,sizeof (*new_cdev)); -if (!new_cdev) - goto err; - -memcpy (new_cdev, cdev,sizeof (*new_cdev)); -dlist_unshift (idev->cdev_list, (void *) new_cdev); - } - } -return idev; err:
@@ -103,12 +83,6 @@ static int parse_status(char *value) idev->busnum = (devid >>16 ); idev->devnum = (devid &0x0000ffff ); - idev->cdev_list =dlist_new (sizeof (struct usbip_class_device )); -if (!idev->cdev_list) { -dbg ("dlist_new failed" ); -return -1 ; - } -if (idev->status !=VDEV_ST_NULL && idev->status !=VDEV_ST_NOTASSIGNED ) { idev =imported_device_init (idev, lbusid);
@@ -132,118 +106,6 @@ static int parse_status(char *value)return 0 ; } - -static int check_usbip_device (struct sysfs_class_device *cdev) -{ -/* /sys/class/video4linux/video0/device */ -char class_path[SYSFS_PATH_MAX ]; -/* /sys/devices/platform/vhci_hcd/usb6/6-1:1.1 */ -char dev_path[SYSFS_PATH_MAX ]; -int ret; -struct usbip_class_device *usbip_cdev; - -snprintf (class_path,sizeof (class_path),"%s/device" , cdev->path); - - ret =sysfs_get_link (class_path, dev_path,sizeof (dev_path)); -if (ret ==0 ) { -if (!strncmp (dev_path, vhci_driver->hc_device->path, -strlen (vhci_driver->hc_device->path))) { -/* found usbip device */ - usbip_cdev =calloc (1 ,sizeof (*usbip_cdev)); -if (!usbip_cdev) { -dbg ("calloc failed" ); -return -1 ; - } -dlist_unshift (vhci_driver->cdev_list, usbip_cdev); -strncpy (usbip_cdev->class_path, class_path, -sizeof (usbip_cdev->class_path)); -strncpy (usbip_cdev->dev_path, dev_path, -sizeof (usbip_cdev->dev_path)); -dbg ("found: %s %s" , class_path, dev_path); - } - } - -return 0 ; -} - - -static int search_class_for_usbip_device (char *cname) -{ -struct sysfs_class *class; -struct dlist *cdev_list; -struct sysfs_class_device *cdev; -int ret =0 ; - - class =sysfs_open_class (cname); -if (!class) { -dbg ("sysfs_open_class failed" ); -return -1 ; - } - -dbg ("class: %s" , class->name); - - cdev_list =sysfs_get_class_devices (class); -if (!cdev_list) -/* nothing */ - goto out; - - dlist_for_each_data(cdev_list, cdev, struct sysfs_class_device) { -dbg ("cdev: %s" , cdev->name); - ret =check_usbip_device (cdev); -if (ret <0 ) - goto out; - } - -out: -sysfs_close_class (class); - -return ret; -} - - -static int refresh_class_device_list (void ) -{ -int ret; -struct dlist *cname_list; -char *cname; -char sysfs_mntpath[SYSFS_PATH_MAX ]; -char class_path[SYSFS_PATH_MAX ]; - - ret =sysfs_get_mnt_path (sysfs_mntpath,SYSFS_PATH_MAX ); -if (ret <0 ) { -dbg ("sysfs_get_mnt_path failed" ); -return -1 ; - } - -snprintf (class_path,sizeof (class_path),"%s/%s" , sysfs_mntpath, -SYSFS_CLASS_NAME ); - -/* search under /sys/class */ - cname_list =sysfs_open_directory_list (class_path); -if (!cname_list) { -dbg ("sysfs_open_directory failed" ); -return -1 ; - } - -dlist_for_each_data (cname_list, cname, char) { - ret =search_class_for_usbip_device (cname); -if (ret <0 ) { -sysfs_close_list (cname_list); -return -1 ; - } - } - -sysfs_close_list (cname_list); - -/* search under /sys/block */ - ret =search_class_for_usbip_device (SYSFS_BLOCK_NAME ); -if (ret <0 ) -return -1 ; - -return 0 ; -} - -static int refresh_imported_device_list (void ) {struct sysfs_attribute *attr_status;
@@ -447,13 +309,6 @@ int usbip_vhci_driver_open(void)dbg ("available ports: %d" , vhci_driver->nports); - vhci_driver->cdev_list =dlist_new (sizeof (struct usbip_class_device )); -if (!vhci_driver->cdev_list) - goto err; - -if (refresh_class_device_list ()) - goto err; -if (refresh_imported_device_list ()) goto err;
@@ -462,8 +317,6 @@ int usbip_vhci_driver_open(void) err: -if (vhci_driver->cdev_list) -dlist_destroy (vhci_driver->cdev_list);if (vhci_driver->hc_device)sysfs_close_device (vhci_driver->hc_device);if (vhci_driver)
@@ -482,14 +335,6 @@ void usbip_vhci_driver_close()if (!vhci_driver)return ; -if (vhci_driver->cdev_list) -dlist_destroy (vhci_driver->cdev_list); - -for (int i =0 ; i < vhci_driver->nports; i++) { -if (vhci_driver->idev[i].cdev_list) -dlist_destroy (vhci_driver->idev[i].cdev_list); - } -if (vhci_driver->hc_device)sysfs_close_device (vhci_driver->hc_device);free (vhci_driver);
@@ -502,35 +347,12 @@ void usbip_vhci_driver_close()int usbip_vhci_refresh_device_list (void ) { -if (vhci_driver->cdev_list) -dlist_destroy (vhci_driver->cdev_list); - - -for (int i =0 ; i < vhci_driver->nports; i++) { -if (vhci_driver->idev[i].cdev_list) -dlist_destroy (vhci_driver->idev[i].cdev_list); - } - - vhci_driver->cdev_list =dlist_new (sizeof (struct usbip_class_device )); -if (!vhci_driver->cdev_list) - goto err; - -if (refresh_class_device_list ()) - goto err;if (refresh_imported_device_list ()) goto err;return 0 ; err: -if (vhci_driver->cdev_list) -dlist_destroy (vhci_driver->cdev_list); - -for (int i =0 ; i < vhci_driver->nports; i++) { -if (vhci_driver->idev[i].cdev_list) -dlist_destroy (vhci_driver->idev[i].cdev_list); - } -dbg ("failed to refresh device list" );return -1 ; }
drivers/staging/usbip/userspace/libsrc/vhci_driver.h +0 -9
@@ -13,11 +13,6 @@#define USBIP_VHCI_BUS_TYPE "platform"#define MAXNPORT 128 -struct usbip_class_device { -char class_path[SYSFS_PATH_MAX ]; -char dev_path[SYSFS_PATH_MAX ]; -}; -struct usbip_imported_device {uint8_t port;uint32_t status;
@@ -28,7 +23,6 @@ struct usbip_imported_device {uint8_t devnum;/* usbip_class_device list */ -struct dlist *cdev_list;struct usbip_usb_device udev; };
@@ -38,9 +32,6 @@ struct usbip_vhci_driver {/* /sys/devices/platform/vhci_hcd */ struct sysfs_device *hc_device; -/* usbip_class_device list */ -struct dlist *cdev_list; -int nports;struct usbip_imported_device idev[MAXNPORT ]; };
Signature · 1 line
1.8.1.2
PATCH 10/18 staging: usbip: userspace: migrate vhci_driver to libudev
In reply to Valentina ManeaThis patch migrates vhci_driver to libudev.
--- .../staging/usbip/userspace/libsrc/usbip_common.h | 1 - .../staging/usbip/userspace/libsrc/vhci_driver.c | 154 ++++++--------------- .../staging/usbip/userspace/libsrc/vhci_driver.h | 5 +- 3 files changed, 44 insertions(+), 116 deletions(-)
drivers/staging/usbip/userspace/libsrc/usbip_common.h +0 -1
@@ -5,7 +5,6 @@#ifndef __USBIP_COMMON_H#define __USBIP_COMMON_H -#include <sysfs/libsysfs.h> #include <libudev.h> #include <stdint.h>
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +42 -112
258 lines not on this page · raw message
drivers/staging/usbip/userspace/libsrc/vhci_driver.h +2 -3
@@ -5,7 +5,7 @@#ifndef __VHCI_DRIVER_H#define __VHCI_DRIVER_H -#include <sysfs/libsysfs.h> +#include <libudev.h> #include <stdint.h> #include "usbip_common.h"
@@ -27,10 +27,9 @@ struct usbip_imported_device { };struct usbip_vhci_driver { -char sysfs_mntpath[SYSFS_PATH_MAX ];/* /sys/devices/platform/vhci_hcd */ -struct sysfs_device *hc_device; +struct udev_device *hc_device;int nports;struct usbip_imported_device idev[MAXNPORT ];
Signature · 1 line
1.8.1.2
PATCH 11/18 staging: usbip: userspace: remove libsysfs flag and autoconf check
In reply to Valentina Manealibsysfs is now completely removed from USB/IP.
--- drivers/staging/usbip/userspace/configure.ac | 6 ------ 1 file changed, 6 deletions(-)
drivers/staging/usbip/userspace/configure.ac +0 -6
@@ -44,12 +44,6 @@ AC_FUNC_REALLOC AC_CHECK_FUNCS([memset mkdir regcomp socket strchr strerror strstr dnl strtoul]) -AC_CHECK_HEADER([sysfs/libsysfs.h], - [AC_CHECK_LIB([sysfs], [sysfs_open_directory_list], - [LIBS="$LIBS -lsysfs"], - [AC_MSG_ERROR([Missing sysfs2 library!])])], - [AC_MSG_ERROR([Missing /usr/include/sysfs/libsysfs.h])]) - AC_CHECK_HEADER([libudev.h], [AC_CHECK_LIB([udev], [udev_new], [LIBS="$LIBS -ludev"],
Signature · 1 line
1.8.1.2
PATCH 12/18 staging: usbip: userspace: update dependencies in README
In reply to Valentina ManeaAdd libudev as dependency and remove libsysfs.
--- drivers/staging/usbip/userspace/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/usbip/userspace/README +2 -2
@@ -9,8 +9,8 @@ - USB/IP device drivers Found in the staging directory of the Linux kernel. - - sysfsutils >= 2.0.0 - sysfsutils library + - libudev >= 2.0 + libudev library - libwrap0-dev tcp wrapper library
Signature · 1 line
1.8.1.2
PATCH 13/18 staging: usbip: userspace: increase version to 2.0
In reply to Valentina Manea--- drivers/staging/usbip/userspace/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/usbip/userspace/configure.ac +1 -1
@@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([usbip-utils], [1.1.1], [[email protected]]) +AC_INIT([usbip-utils], [2.0], [[email protected]]) AC_DEFINE([USBIP_VERSION], [0x00000111], [binary-coded decimal version number]) CURRENT=0
Signature · 1 line
1.8.1.2
PATCH 14/18 staging: usbip: let client choose device configuration
In reply to Valentina ManeaSince usbip-host is now a device driver and the client has full access to the shared device, it makes sense to let the client choose device configuration.
--- drivers/staging/usbip/stub_dev.c | 10 +--------- drivers/staging/usbip/stub_rx.c | 26 +++++++------------------- 2 files changed, 8 insertions(+), 28 deletions(-)
drivers/staging/usbip/stub_dev.c +1 -9
@@ -337,7 +337,7 @@ static int stub_probe(struct usb_device *udev) {struct stub_device *sdev =NULL ;const char *udev_busid =dev_name (&udev->dev); -int err =0 , config; +int err =0 ;struct bus_id_priv *busid_priv;dev_dbg (&udev->dev,"Enter\n" );
@@ -383,14 +383,6 @@ static int stub_probe(struct usb_device *udev) busid_priv->shutdown_busid =0 ; - config =usb_choose_configuration (udev); -if (config >=0 ) { - err =usb_set_configuration (udev, config); -if (err && err != -ENODEV ) -dev_err (&udev->dev,"can't set config #%d, error %d\n" , - config, err); - } -/* set private data to usb_device */ dev_set_drvdata (&udev->dev, sdev); busid_priv->sdev = sdev;
drivers/staging/usbip/stub_rx.c +7 -19
@@ -142,31 +142,19 @@ static int tweak_set_interface_cmd(struct urb *urb)static int tweak_set_configuration_cmd (struct urb *urb) { +struct stub_priv *priv = (struct stub_priv *) urb->context; +struct stub_device *sdev = priv->sdev;struct usb_ctrlrequest *req;__u16 config; +int err; req = (struct usb_ctrlrequest *) urb->setup_packet; config =le16_to_cpu (req->wValue); -/* -* I have never seen a multi-config device. Very rare. -* For most devices, this will be called to choose a default -* configuration only once in an initialization phase. -* -* set_configuration may change a device configuration and its device -* drivers will be unbound and assigned for a new device configuration. -* This means this usbip driver will be also unbound when called, then -* eventually reassigned to the device as far as driver matching -* condition is kept. -* -* Unfortunately, an existing usbip connection will be dropped -* due to this driver unbinding. So, skip here. -* A user may need to set a special configuration value before -* exporting the device. -*/ -dev_info (&urb->dev->dev,"usb_set_configuration %d to %s... skip!\n" , - config,dev_name (&urb->dev->dev)); - + err =usb_set_configuration (sdev->udev, config); +if (err && err != -ENODEV ) +dev_err (&sdev->udev->dev,"can't set config #%d, error %d\n" , + config, err);return 0 ; }
Signature · 1 line
1.8.1.2
PATCH 15/18 staging: usbip: trigger driver probing after unbinding from usbip-host
In reply to Valentina ManeaA sysfs attribute is used to announce kernel space that a new driver probing session should be triggered for the just unbinded device.
In order to have the address of struct device associated to this USB device, a new member has been added to struct bus_id_priv.
--- drivers/staging/usbip/stub.h | 1 + drivers/staging/usbip/stub_dev.c | 1 + drivers/staging/usbip/stub_main.c | 39 ++++++++++++++++++++++ drivers/staging/usbip/userspace/src/usbip_unbind.c | 17 ++++++++-- 4 files changed, 56 insertions(+), 2 deletions(-)
drivers/staging/usbip/stub.h +1 -0
@@ -86,6 +86,7 @@ struct bus_id_priv {char status;int interf_count;struct stub_device *sdev; +struct usb_device *udev;char shutdown_busid; };
drivers/staging/usbip/stub_dev.c +1 -0
@@ -386,6 +386,7 @@ static int stub_probe(struct usb_device *udev)/* set private data to usb_device */ dev_set_drvdata (&udev->dev, sdev); busid_priv->sdev = sdev; + busid_priv->udev = udev; err =stub_add_files (&udev->dev);if (err) {
drivers/staging/usbip/stub_main.c +39 -0
@@ -19,6 +19,7 @@#include <linux/string.h> #include <linux/module.h> +#include <linux/device.h> #include "usbip_common.h" #include "stub.h"
@@ -187,6 +188,34 @@ static ssize_t store_match_busid(struct device_driver *dev, const char *buf, static DRIVER_ATTR(match_busid, S_IRUSR | S_IWUSR, show_match_busid, store_match_busid); +static ssize_t rebind_store (struct device_driver *dev,const char *buf, +size_t count) +{ +int ret; +int len; +struct bus_id_priv *bid; + +/* buf length should be less that BUSID_SIZE */ + len =strnlen (buf,BUSID_SIZE ); + +if (!(len <BUSID_SIZE )) +return -EINVAL ; + + bid =get_busid_priv (buf); +if (!bid) +return -ENODEV ; + + ret =device_attach (&bid->udev->dev); +if (ret <0 ) { +dev_err (&bid->udev->dev,"rebind failed\n" ); +return ret; + } + +return count; +} + +static DRIVER_ATTR_WO (rebind); +static struct stub_priv *stub_priv_pop_from_listhead (struct list_head *listhead) {struct stub_priv *priv, *tmp;
@@ -267,6 +296,13 @@ static int __init usbip_host_init(void) goto err_create_file; } + ret =driver_create_file (&stub_driver.drvwrap.driver, + &driver_attr_rebind); +if (ret) { +pr_err ("driver_create_file failed\n" ); + goto err_create_file; + } +pr_info (DRIVER_DESC " v" USBIP_VERSION "\n" );return ret;
@@ -282,6 +318,9 @@ static void __exit usbip_host_exit(void)driver_remove_file (&stub_driver.drvwrap.driver, &driver_attr_match_busid); +driver_remove_file (&stub_driver.drvwrap.driver, + &driver_attr_rebind); +/* * deregister() calls stub_disconnect() for all devices. Device * specific data is cleared in stub_disconnect().
drivers/staging/usbip/userspace/src/usbip_unbind.c +15 -2
@@ -44,8 +44,10 @@ static int unbind_device(char *busid)char bus_type[] ="usb" ;int rc, ret =-1 ; -char attr_name[] ="unbind" ; +char unbind_attr_name[] ="unbind" ;char unbind_attr_path[SYSFS_PATH_MAX ]; +char rebind_attr_name[] ="rebind" ; +char rebind_attr_path[SYSFS_PATH_MAX ];struct udev *udev;struct udev_device *dev;
@@ -71,7 +73,7 @@ static int unbind_device(char *busid)/* Unbind device from driver. */ snprintf (unbind_attr_path,sizeof (unbind_attr_path),"%s/%s/%s/%s/%s/%s" ,SYSFS_MNT_PATH ,SYSFS_BUS_NAME , bus_type,SYSFS_DRIVERS_NAME , -USBIP_HOST_DRV_NAME , attr_name); +USBIP_HOST_DRV_NAME , unbind_attr_name); rc =write_sysfs_attribute (unbind_attr_path, busid,strlen (busid));if (rc <0 ) {
@@ -86,6 +88,17 @@ static int unbind_device(char *busid) goto err_close_udev; } +/* Trigger new probing. */ +snprintf (rebind_attr_path,sizeof (unbind_attr_path),"%s/%s/%s/%s/%s/%s" , +SYSFS_MNT_PATH ,SYSFS_BUS_NAME , bus_type,SYSFS_DRIVERS_NAME , +USBIP_HOST_DRV_NAME , rebind_attr_name); + + rc =write_sysfs_attribute (rebind_attr_path, busid,strlen (busid)); +if (rc <0 ) { +err ("error rebinding" ); + goto err_close_udev; + } + ret =0 ;info ("unbind device on busid %s: complete" , busid);
Signature · 1 line
1.8.1.2
PATCH 16/18 staging: usbip: claim ports used by shared devices
In reply to Valentina ManeaA device should not be able to be used concurrently both by the server and the client. Claiming the port used by the shared device ensures no interface drivers bind to it and that it is not usable from the server.
--- drivers/staging/usbip/stub_dev.c | 22 ++++++++++++++++++++++ drivers/usb/core/hub.c | 2 ++ drivers/usb/core/usb.h | 4 ---- include/linux/usb.h | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-)
drivers/staging/usbip/stub_dev.c +22 -0
@@ -339,6 +339,7 @@ static int stub_probe(struct usb_device *udev)const char *udev_busid =dev_name (&udev->dev);int err =0 ;struct bus_id_priv *busid_priv; +int rc;dev_dbg (&udev->dev,"Enter\n" );
@@ -388,6 +389,18 @@ static int stub_probe(struct usb_device *udev) busid_priv->sdev = sdev; busid_priv->udev = udev; +/* +* Claim this hub port. +* It doesn't matter what value we pass as owner +* (struct dev_state) as long as it is unique. +*/ + rc =usb_hub_claim_port (udev->parent, udev->portnum, + (struct dev_state *) udev); +if (rc) { +dev_dbg (&udev->dev,"unable to claim port\n" ); +return rc; + } + err =stub_add_files (&udev->dev);if (err) {dev_err (&udev->dev,"stub_add_files for %s\n" , udev_busid);
@@ -424,6 +437,7 @@ static void stub_disconnect(struct usb_device *udev)struct stub_device *sdev;const char *udev_busid =dev_name (&udev->dev);struct bus_id_priv *busid_priv; +int rc;dev_dbg (&udev->dev,"Enter\n" );
@@ -448,6 +462,14 @@ static void stub_disconnect(struct usb_device *udev)*/ stub_remove_files (&udev->dev); +/* release port */ + rc =usb_hub_release_port (udev->parent, udev->portnum, + (struct dev_state *) udev); +if (rc) { +dev_dbg (&udev->dev,"unable to release port\n" ); +return ; + } +/* If usb reset is called from event handler */ if (busid_priv->sdev->ud.eh == current)return ;
drivers/usb/core/hub.c +2 -0
@@ -1819,6 +1819,7 @@ int usb_hub_claim_port(struct usb_device *hdev, unsigned port1, *powner = owner;return rc; } +EXPORT_SYMBOL_GPL (usb_hub_claim_port);int usb_hub_release_port (struct usb_device *hdev,unsigned port1,struct dev_state *owner)
@@ -1834,6 +1835,7 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, *powner =NULL ;return rc; } +EXPORT_SYMBOL_GPL (usb_hub_release_port);void usb_hub_release_all_ports (struct usb_device *hdev,struct dev_state *owner) {
drivers/usb/core/usb.h +0 -4
@@ -57,10 +57,6 @@ extern int usb_match_device(struct usb_device *dev,extern void usb_forced_unbind_intf (struct usb_interface *intf);extern void usb_rebind_intf (struct usb_interface *intf); -extern int usb_hub_claim_port (struct usb_device *hdev,unsigned port, -struct dev_state *owner); -extern int usb_hub_release_port (struct usb_device *hdev,unsigned port, -struct dev_state *owner);extern void usb_hub_release_all_ports (struct usb_device *hdev,struct dev_state *owner);extern bool usb_device_is_owned (struct usb_device *udev);
include/linux/usb.h +7 -0
@@ -366,6 +366,8 @@ struct usb_bus {#endif }; +struct dev_state ; +/* ----------------------------------------------------------------------- */ struct usb_tt ;
@@ -749,6 +751,11 @@ extern struct usb_host_interface *usb_find_alt_setting(unsigned int iface_num, unsigned int alt_num); +/* port claiming functions */ +int usb_hub_claim_port (struct usb_device *hdev,unsigned port1, +struct dev_state *owner); +int usb_hub_release_port (struct usb_device *hdev,unsigned port1, +struct dev_state *owner);/** * usb_make_path - returns stable device path in the usb tree
Signature · 1 line
1.8.1.2
PATCH 17/18 staging: usbip: userspace: don't throw error when trying to read configuration specific attributes
In reply to Valentina ManeaWhen a device has just been bound to usbip-host but the client hasn't set a configuration on it, certain attributes will not exist. Don't treat this as an error.
--- drivers/staging/usbip/userspace/libsrc/usbip_common.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/staging/usbip/userspace/libsrc/usbip_common.c +15 -2
@@ -127,10 +127,23 @@ int read_attr_value(struct udev_device *dev, const char *name, goto err; } +/* The client chooses the device configuration +* when attaching it so right after being bound +* to usbip-host on the server the device will +* have no configuration. +* Therefore, attributes such as bConfigurationValue +* and bNumInterfaces will not exist and sscanf will +* fail. Check for these cases and don't treat them +* as errors. +*/ + ret =sscanf (attr, format, &num);if (ret <1 ) { -err ("sscanf failed" ); - goto err; +if (strcmp (name,"bConfigurationValue" ) && +strcmp (name,"bNumInterfaces" )) { +err ("sscanf failed for attribute %s" , name); + goto err; + } } err:
Signature · 1 line
1.8.1.2
PATCH 18/18 staging: usbip: userspace: add hwdata as optional dependency in README
In reply to Valentina ManeaThis is an optional dependency since USB/IP can fully work without it. However, it is needed to display device information such as vendor.
--- drivers/staging/usbip/userspace/README | 4 ++++ 1 file changed, 4 insertions(+)
drivers/staging/usbip/userspace/README +4 -0
@@ -19,6 +19,10 @@ - libtool, automake >= 1.9, autoconf >= 2.5.0, pkg-config +[Optional] + - hwdata + Contains USB device identification data. + [Install] 0. Generate configuration scripts.
Signature · 1 line
1.8.1.2
Greg KH
maintainerQuoted 4 lines · Valentina Manea
This is a resend of the patches sent a few days ago, including the migration of USB/IP userspace side to use libudev instead of libsysfs and various other fixes, all ordered in a big patch series.
Very nice work, thanks so much for doing all of this, it looks great.
Now applied to my tree, you should have gotten the emails about it already.
thanks,
greg k-h
I was notified that one of the patches in the series (staging: usbip:
claim ports used by shared devices) breaks the build.
I take full responsability for this as I haven't compiled the kernel with allyesconfig and I am sorry.
This can be fixed by moving struct dev_state, usb_hub_claim_port() and usb_hub_release_port() declarations from include/linux/usb.h to usbip/stub.h, and leaving the declarations in usb/core/usb.h untouched.
Should the fix come as a separate patch or v2 of the broken one?
Thanks,
Valentina
Greg KH
maintainerQuoted 4 lines · Valentina Manea
I was notified that one of the patches in the series (staging: usbip:
claim ports used by shared devices) breaks the build.
I take full responsability for this as I haven't compiled the kernel with allyesconfig and I am sorry.
No worries, it happens to all of us :)
Quoted 6 lines
This can be fixed by moving struct
dev_state,usb_hub_claim_port()andusb_hub_release_port()declarations frominclude/linux/usb.htousbip/stub.h, and leaving the declarations inusb/core/usb.huntouched.Should the fix come as a separate patch or v2 of the broken one?
No, I can't redo the patch that I've already committed.
As "dev_state" is a very generic term, how about we just rename it to something more USB specific, like usb_dev_state? That way it would fix the build issue, and keep it from being a problem in the future in other drivers.
thanks,
greg k-h