]> asedeno.scripts.mit.edu Git - linux.git/commit
usbip: auto retry for concurrent attach
authorNobuo Iwata <nobuo.iwata@fujixerox.co.jp>
Tue, 29 Aug 2017 02:13:34 +0000 (11:13 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 31 Aug 2017 16:08:45 +0000 (18:08 +0200)
commita38711a88b7e3fd0c0d292a35693e0f608263759
treea345c712d8daeb5e9cec580696a6331091d54a39
parentaa75936544fafc830ac3cc03458b771f3048a50f
usbip: auto retry for concurrent attach

This patch adds recovery from false busy state on concurrent attach
operation.

The procedure of attach operation is as below.
1) Find an unused port in /sys/devices/platform/vhci_hcd/status.
(userspace)
2) Request attach found port to driver through
/sys/devices/platform/vhci_hcd/attach. (userspace)
3) Lock table, reserve requested port and unlock table. (vhci driver)

Attaching more than one remote devices concurrently, same unused port
number will be found in step-1. Then one request will succeed and
others will fail even though there are some unused ports.

With this patch, driver returns EBUSY when requested port has already
been used. In this case, attach command retries from step-1: finding
another unused port. If there's no unused port, the attach operation
will fail in step-1. Otherwise it retries automatically using another
unused port.

vhci-hcd's interface (only errno) is changed as following.

Current errno New errno Condition
EINVAL same as left specified port number is in invalid
range
EAGAIN same as left platform_get_drvdata() failed
EINVAL same as left specified socket fd is not valid
EINVAL EBUSY specified port status is not free

The errno EBUSY was not used in userspace
src/usbip_attach.c:import_device(). It is needed to distinguish the
condition to be able to retry from other unrecoverable errors.

It is possible to avoid this failure by introducing userspace exclusive
control. But it's exaggerated for this special condition. The locking
itself has done in driver.
As an alternate solution, userspace doesn't specify port number, driver
searches unused port and it returns port number to the userspace. With
this solution, the interface is much different than this patch.

Signed-off-by: Nobuo Iwata <nobuo.iwata@fujixerox.co.jp>
Acked-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/usbip/vhci_sysfs.c
tools/usb/usbip/src/usbip_attach.c