linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] SCSI: Add rumtime pm in the sd_check_events()
@ 2012-02-20  8:49 Lan Tianyu
  2012-02-20 20:41 ` Alan Stern
  0 siblings, 1 reply; 3+ messages in thread
From: Lan Tianyu @ 2012-02-20  8:49 UTC (permalink / raw)
  To: James.Bottomley; +Cc: Lan Tianyu, stern, linux-scsi

The sd_check_event() will be called periodly even when the device is in
the suspended status to check media event. The scsi_test_unit_ready() in
the sd_check_event() will issue scsi cmd request. Issuing scsi request when
the device is in the suspeneded status will cause problem. For example, when
a usb flash disk in the suspended status, scsi_test_unit_ready() issues a
scsi request. The request will be returned as failed because the usb device
is not active. The patch adds scsi_autopm_get_device() and scsi_autopm_put_device()
around scsi_test_unit_ready() in the sd_check_event() to resolve such problem.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 drivers/scsi/sd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index c691fb5..7913bd1 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1183,8 +1183,14 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
 
 	if (scsi_block_when_processing_errors(sdp)) {
 		sshdr  = kzalloc(sizeof(*sshdr), GFP_KERNEL);
+
+		retval = scsi_autopm_get_device(sdp);
+		if (retval)
+			goto out;
+
 		retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
 					      sshdr);
+		scsi_autopm_put_device(sdp);
 	}
 
 	/* failed to execute TUR, assume media not present */
-- 
1.7.6.rc2.8.g28eb


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] SCSI: Add rumtime pm in the sd_check_events()
  2012-02-20  8:49 [PATCH 1/1] SCSI: Add rumtime pm in the sd_check_events() Lan Tianyu
@ 2012-02-20 20:41 ` Alan Stern
  2012-02-21  1:09   ` Lan Tianyu
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Stern @ 2012-02-20 20:41 UTC (permalink / raw)
  To: Lan Tianyu; +Cc: James.Bottomley, linux-scsi

On Mon, 20 Feb 2012, Lan Tianyu wrote:

> The sd_check_event() will be called periodly even when the device is in
> the suspended status to check media event. The scsi_test_unit_ready() in
> the sd_check_event() will issue scsi cmd request. Issuing scsi request when
> the device is in the suspeneded status will cause problem. For example, when
> a usb flash disk in the suspended status, scsi_test_unit_ready() issues a
> scsi request. The request will be returned as failed because the usb device
> is not active. The patch adds scsi_autopm_get_device() and scsi_autopm_put_device()
> around scsi_test_unit_ready() in the sd_check_event() to resolve such problem.
> 
> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
> ---
>  drivers/scsi/sd.c |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index c691fb5..7913bd1 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -1183,8 +1183,14 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
>  
>  	if (scsi_block_when_processing_errors(sdp)) {
>  		sshdr  = kzalloc(sizeof(*sshdr), GFP_KERNEL);
> +
> +		retval = scsi_autopm_get_device(sdp);
> +		if (retval)
> +			goto out;
> +
>  		retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
>  					      sshdr);
> +		scsi_autopm_put_device(sdp);
>  	}
>  
>  	/* failed to execute TUR, assume media not present */

You might as well put the _get_device call before the kzalloc; no point 
in allocating memory if it's not going to be used.

Apart from that, this is fine.  Are there any other places where the
block layer sends I/O requests even when the device isn't open?

Alan Stern


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] SCSI: Add rumtime pm in the sd_check_events()
  2012-02-20 20:41 ` Alan Stern
@ 2012-02-21  1:09   ` Lan Tianyu
  0 siblings, 0 replies; 3+ messages in thread
From: Lan Tianyu @ 2012-02-21  1:09 UTC (permalink / raw)
  To: Alan Stern; +Cc: JBottomley, linux-scsi


Great Thanks for review.

On 2012年02月21日 04:41, Alan Stern wrote:
> On Mon, 20 Feb 2012, Lan Tianyu wrote:
>
>> The sd_check_event() will be called periodly even when the device is in
>> the suspended status to check media event. The scsi_test_unit_ready() in
>> the sd_check_event() will issue scsi cmd request. Issuing scsi request when
>> the device is in the suspeneded status will cause problem. For example, when
>> a usb flash disk in the suspended status, scsi_test_unit_ready() issues a
>> scsi request. The request will be returned as failed because the usb device
>> is not active. The patch adds scsi_autopm_get_device() and scsi_autopm_put_device()
>> around scsi_test_unit_ready() in the sd_check_event() to resolve such problem.
>>
>> Signed-off-by: Lan Tianyu<tianyu.lan@intel.com>
>> ---
>>   drivers/scsi/sd.c |    6 ++++++
>>   1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
>> index c691fb5..7913bd1 100644
>> --- a/drivers/scsi/sd.c
>> +++ b/drivers/scsi/sd.c
>> @@ -1183,8 +1183,14 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
>>
>>   	if (scsi_block_when_processing_errors(sdp)) {
>>   		sshdr  = kzalloc(sizeof(*sshdr), GFP_KERNEL);
>> +
>> +		retval = scsi_autopm_get_device(sdp);
>> +		if (retval)
>> +			goto out;
>> +
>>   		retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
>>   					      sshdr);
>> +		scsi_autopm_put_device(sdp);
>>   	}
>>
>>   	/* failed to execute TUR, assume media not present */
> You might as well put the _get_device call before the kzalloc; no point
> in allocating memory if it's not going to be used.
Yeah. I will update and send out soon.
> Apart from that, this is fine.  Are there any other places where the
> block layer sends I/O requests even when the device isn't open?
Currently, I just find this place.
> Alan Stern
>

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-21  1:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-20  8:49 [PATCH 1/1] SCSI: Add rumtime pm in the sd_check_events() Lan Tianyu
2012-02-20 20:41 ` Alan Stern
2012-02-21  1:09   ` Lan Tianyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).