From: Alan S. <st...@ro...> - 2010-10-07 14:46:09
|
On Thu, 7 Oct 2010, Michael Plante wrote: > Xiaofan Chen wrote: > >> I mean it would be good to extend the following two API > >> or new APIs. > >> > >> 1) libusb_kernel_driver_active() can have options to return > >> the driver name, just like the 0.1 API usb_get_driver_np(). > >> Or we can have new API for this purpose. I think extending > >> this API is probably better. > >> > >> 2) libusb_attach_kernel_driver() can be extended to take the driver > >> name as a parameter so that user can specify the > >> driver they want the kernel to attach. > > It's not clear if you're suggesting in #2 something that changes an IOCTL or > modifies an existing one, as opposed to a user-mode change only. > > If you are suggesting a kernel change, I would suggest an additional one. > libusb_detach_kernel_driver() should pass the name of a driver never to > detach, namely "usbfs". I believe the ability to do that would probably > eliminate the race I mentioned. The underlying IOCTL would atomically > decide if the string matches the driver, and, if not, it would detach it, > else it would fail and do nothing. We would then pass "usbfs" as the name, > such that usbfs is never detached. > > Of course, I've not seen any comments on this race, so maybe I'm imagining > it? A related topic has been discussed on a kernel mailing list (this was some time ago and I don't have a pointer to the emails). The feeling was that cooperating programs should have their own techniques for avoiding these races and the kernel shouldn't get involved. Such a technique could be implemented easily enough within libusb (some sort of exclusive open, perhaps). Alan Stern |