Re: Mass storage suspend questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 13 Jan 2012, Oliver Neukum wrote:

> Now that you mention it, I am wondering about sd.
> 
> 1. sd_open() calls scsi_autopm_get_device(sdev) but only in
> the error case it calls scsi_autopm_put_device(sdev). So any
> mount or open should prevent the device from autosuspending.
> The behavior is certainly correct, but it seems to be in conflict with
> your statement that it suspends after each command.

That was Sarah's statement originally, and she appeared to be talking
about usb-storage, not sd.  Furthermore, unless I misunderstood, she
said merely that it suspends between commands (as opposed to within
commands), not that it suspends after each command.  

In other words, usb-storage's suspend routine waits for any
currently-executing command to finish before returning.  That's what I
meant in my reply to her.

> 2. scsi_autopm_get_device(sdev) is called unconditionally on each open.
> But according to the comment on the top of sd_release(). scsi_autopm_put_device(sdev)
> would be called only for the last close. Doesn't that mean that concurrent
> open calls for a disk disable autosuspend permanently?

There ought to be an analogous comment for sd_open() -- it gets called 
only for the first open.

This means something different from what you're probably thinking.  If
two separate systems calls to open(2) are made (either in the same
process or in different processes), followed by two calls to close(2),
then sd_open and sd_release will each be invoked twice.

However, if open(2) is called once followed by dup(2), and close(2) is
called twice (for both the original fd and the fd returned by dup),
then sd_open and sd_release will both be invoked only once.  Even
though there are two file descriptors, there's only one open file
reference.

BTW, there's one other thing you need to know -- an error in your 
patch.  SCSI doesn't use the same scheme as USB for indicating whether 
a driver supports autosuspend.  Instead it uses PCI's scheme:

	The core initially increments the usage counter for each
	device.

	If a driver wants to support autosuspend, it must decrement
	the usage count in its probe routine and increment the count
	in its remove routine.

Thus, there's a call to scsi_autopm_put_device() at the end of 
sd_probe_async() and a call to scsi_autopm_get_device() at the start of 
sd_remove().  You'll have to do the same thing in sr.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux