From: Hans de Goede <hdegoede@redhat.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Tejun Heo <htejun@gmail.com>,
SCSI development list <linux-scsi@vger.kernel.org>
Subject: Re: [RFC] Pass information about device open/close to low-level driver
Date: Tue, 27 Sep 2011 09:19:30 +0200 [thread overview]
Message-ID: <4E817902.3050605@redhat.com> (raw)
In-Reply-To: <20110926201216.GA18666@infradead.org>
Hi,
On 09/26/2011 10:12 PM, Christoph Hellwig wrote:
> On Mon, Sep 26, 2011 at 04:10:32PM -0400, Alan Stern wrote:
>> James:
>>
>> Something like the patch below has been requested by the virtualization
>> people.
>
> Who are "the virtualization people"?
>
> Either way this idea is a really bad one, and if you check history long
> enough you'd notice we had all that crap in kernel before 2.6 and got
> rid of it all.
That would be me. A small correction to Alan's reply to this I'm not
in contact with vmware about this although I'm sure they would like to
have this functionality too.
The problem these patches try to address is that currently it is possible
to disconnect a usb device driver from a usb device through usbfs / the unbind
sysfs attribute, making the device driver see the device in essence get
unplugged. There is no way for the driver to cancel this, since it is just
like a real unplug.
However since this is a software disconnect not a hardware disconnect it
would be very convenient if the driver could say, no not right now I'm busy.
The use case for this is redirection of usb devices to virtual machines. I'm
working on this for qemu and qemu+spice, when a usb device on a linux host /
linux spice client gets redirected to a vm, we currently start by making
a disconnect ioctl to the usbfs device node, to detach the kernel driver
so that qemu or the spice client can take over the device. This causes
problems when a user first copies a bunch of large files to a usb stick, and
then immediately afterwards selects redirect this usb stick to the vm.
Usually the user does this without first unmounting the stick. So the usb mass
storage driver (and the scsi subsystem after it) see a device disconnect while
some buffered writes still needed flushing -> not good!
For use cases where userspace takes over from a kernel device driver it would
be very nice if userspace could ask the kernel driver nicely to disconnect,
for this a new try_disconnect ioctl would be added to the usbfs ioctls.
In order for the usb mass storage driver to implement this try_disconnect, it
needs to know if its "downstream" scsi devices are in use or not, that is what
this patch is for.
There have already been a lot of discussions on other lists about this, so
let me try to address this biggest complaint against this patch set so far:
"why not do this in userspace".
4 reasons:
1) This is hardware resource management, hw resource management is the kernels task
2) It cannot be done race free in userspace, one can parse sysfs, figure out which
block devices belong to the usb device, and see if they are mounted, but between
the check and the disconnect ioctl they may get mounted
3) One needs to not only check for mounts but also for fsck / mkfs / fdisk on
the block device nodes, this means parsing lsof output for all processes,
something the userspace process in question likely will not have the rights
for
4) If you look at the entirety of the patchset Alan posted for this it is quite small
the code to implement 2 + 3 *which won't even work properly* will be one or more
orders larger and more complex
Thanks & Regards,
Hans
prev parent reply other threads:[~2011-09-27 7:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-26 20:10 [RFC] Pass information about device open/close to low-level driver Alan Stern
2011-09-26 20:12 ` Christoph Hellwig
2011-09-27 1:39 ` Alan Stern
2011-09-27 7:19 ` Hans de Goede [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E817902.3050605@redhat.com \
--to=hdegoede@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=hch@infradead.org \
--cc=htejun@gmail.com \
--cc=linux-scsi@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox