public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] SCSI: detect missing data for INQUIRY
@ 2008-10-27 16:18 Alan Stern
  2008-10-27 16:37 ` James Bottomley
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Stern @ 2008-10-27 16:18 UTC (permalink / raw)
  To: James Bottomley; +Cc: Örjan Nordlund, SCSI development list

This patch (as1154) fixes a problem in scsi_probe_lun(): The function
doesn't check whether the device has actually sent back any INQUIRY
data!  The patch adds a test to see if the result buffer is still
empty after the command has been executed.

This enables the Thecus N2050 storage device to work.  The firmware on
that device starts up strangely; it sends no data in response to the
initial INQUIRY, and it sends the INQUIRY information in response to
the followup REQUEST SENSE!  But after that it works better, so
retrying the INQUIRY is enough to get it going.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

This should get into 2.6.28.


Index: usb-2.6/drivers/scsi/scsi_scan.c
===================================================================
--- usb-2.6.orig/drivers/scsi/scsi_scan.c
+++ usb-2.6/drivers/scsi/scsi_scan.c
@@ -602,6 +602,13 @@ static int scsi_probe_lun(struct scsi_de
 				    (sshdr.ascq == 0))
 					continue;
 			}
+		} else {
+			/*
+			 * Additional Length and Vendor fields missing
+			 * probably means nothing was transferred.  Try again.
+			 */
+			if (inq_result[4] == 0 && inq_result[8] == 0)
+				continue;
 		}
 		break;
 	}


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

* Re: [PATCH] SCSI: detect missing data for INQUIRY
  2008-10-27 16:18 [PATCH] SCSI: detect missing data for INQUIRY Alan Stern
@ 2008-10-27 16:37 ` James Bottomley
  2008-10-27 17:00   ` Alan Stern
  0 siblings, 1 reply; 13+ messages in thread
From: James Bottomley @ 2008-10-27 16:37 UTC (permalink / raw)
  To: Alan Stern; +Cc: Örjan Nordlund, SCSI development list

On Mon, 2008-10-27 at 12:18 -0400, Alan Stern wrote:
> This patch (as1154) fixes a problem in scsi_probe_lun(): The function
> doesn't check whether the device has actually sent back any INQUIRY
> data!  The patch adds a test to see if the result buffer is still
> empty after the command has been executed.
> 
> This enables the Thecus N2050 storage device to work.  The firmware on
> that device starts up strangely; it sends no data in response to the
> initial INQUIRY, and it sends the INQUIRY information in response to
> the followup REQUEST SENSE!  But after that it works better, so
> retrying the INQUIRY is enough to get it going.
> 
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> 
> ---
> 
> This should get into 2.6.28.
> 
> 
> Index: usb-2.6/drivers/scsi/scsi_scan.c
> ===================================================================
> --- usb-2.6.orig/drivers/scsi/scsi_scan.c
> +++ usb-2.6/drivers/scsi/scsi_scan.c
> @@ -602,6 +602,13 @@ static int scsi_probe_lun(struct scsi_de
>  				    (sshdr.ascq == 0))
>  					continue;
>  			}
> +		} else {
> +			/*
> +			 * Additional Length and Vendor fields missing
> +			 * probably means nothing was transferred.  Try again.
> +			 */
> +			if (inq_result[4] == 0 && inq_result[8] == 0)
> +				continue;

Really, no.

A legitimate minimal response from a device is zero in the additional
length field.  If it does that, then the vendor field is bound to be
zero as well.

About the best we can do is check the first four fields.  For them to be
all zero, it would have to be a minimal response SCSI-1 device (RDF of
zero) ... hopefully they're all dead by now.

James



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

* Re: [PATCH] SCSI: detect missing data for INQUIRY
  2008-10-27 16:37 ` James Bottomley
@ 2008-10-27 17:00   ` Alan Stern
  2008-10-27 17:08     ` James Bottomley
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Stern @ 2008-10-27 17:00 UTC (permalink / raw)
  To: James Bottomley; +Cc: Örjan Nordlund, SCSI development list

On Mon, 27 Oct 2008, James Bottomley wrote:

> > --- usb-2.6.orig/drivers/scsi/scsi_scan.c
> > +++ usb-2.6/drivers/scsi/scsi_scan.c
> > @@ -602,6 +602,13 @@ static int scsi_probe_lun(struct scsi_de
> >  				    (sshdr.ascq == 0))
> >  					continue;
> >  			}
> > +		} else {
> > +			/*
> > +			 * Additional Length and Vendor fields missing
> > +			 * probably means nothing was transferred.  Try again.
> > +			 */
> > +			if (inq_result[4] == 0 && inq_result[8] == 0)
> > +				continue;
> 
> Really, no.
> 
> A legitimate minimal response from a device is zero in the additional
> length field.  If it does that, then the vendor field is bound to be
> zero as well.
> 
> About the best we can do is check the first four fields.  For them to be
> all zero, it would have to be a minimal response SCSI-1 device (RDF of
> zero) ... hopefully they're all dead by now.

Then you're saying that the patch should everything up to
inq_result[8]?  Or maybe even beyond?  I can do that.  Would that be 
acceptable?

Alan Stern


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

* Re: [PATCH] SCSI: detect missing data for INQUIRY
  2008-10-27 17:00   ` Alan Stern
@ 2008-10-27 17:08     ` James Bottomley
  2008-10-27 17:27       ` Alan Stern
  0 siblings, 1 reply; 13+ messages in thread
From: James Bottomley @ 2008-10-27 17:08 UTC (permalink / raw)
  To: Alan Stern; +Cc: Örjan Nordlund, SCSI development list

On Mon, 2008-10-27 at 13:00 -0400, Alan Stern wrote:
> On Mon, 27 Oct 2008, James Bottomley wrote:
> 
> > > --- usb-2.6.orig/drivers/scsi/scsi_scan.c
> > > +++ usb-2.6/drivers/scsi/scsi_scan.c
> > > @@ -602,6 +602,13 @@ static int scsi_probe_lun(struct scsi_de
> > >  				    (sshdr.ascq == 0))
> > >  					continue;
> > >  			}
> > > +		} else {
> > > +			/*
> > > +			 * Additional Length and Vendor fields missing
> > > +			 * probably means nothing was transferred.  Try again.
> > > +			 */
> > > +			if (inq_result[4] == 0 && inq_result[8] == 0)
> > > +				continue;
> > 
> > Really, no.
> > 
> > A legitimate minimal response from a device is zero in the additional
> > length field.  If it does that, then the vendor field is bound to be
> > zero as well.
> > 
> > About the best we can do is check the first four fields.  For them to be
> > all zero, it would have to be a minimal response SCSI-1 device (RDF of
> > zero) ... hopefully they're all dead by now.
> 
> Then you're saying that the patch should everything up to
> inq_result[8]?  Or maybe even beyond?  I can do that.  Would that be 
> acceptable?

No ... "first four fields" means everything up to inq_result[3].
Anything beyond that would be legitimately zero if they were.

James



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

* Re: [PATCH] SCSI: detect missing data for INQUIRY
  2008-10-27 17:08     ` James Bottomley
@ 2008-10-27 17:27       ` Alan Stern
  2008-10-27 17:29         ` James Bottomley
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Stern @ 2008-10-27 17:27 UTC (permalink / raw)
  To: James Bottomley; +Cc: Örjan Nordlund, SCSI development list

On Mon, 27 Oct 2008, James Bottomley wrote:

> > > About the best we can do is check the first four fields.  For them to be
> > > all zero, it would have to be a minimal response SCSI-1 device (RDF of
> > > zero) ... hopefully they're all dead by now.
> > 
> > Then you're saying that the patch should everything up to
> > inq_result[8]?  Or maybe even beyond?  I can do that.  Would that be 
> > acceptable?
> 
> No ... "first four fields" means everything up to inq_result[3].
> Anything beyond that would be legitimately zero if they were.

But what about the case where the first four bytes are zero and some of 
the fields beyond them are nonzero.  Isn't that possible?

Alan Stern


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

* Re: [PATCH] SCSI: detect missing data for INQUIRY
  2008-10-27 17:27       ` Alan Stern
@ 2008-10-27 17:29         ` James Bottomley
  2008-10-27 18:53           ` [PATCH v2] " Alan Stern
  0 siblings, 1 reply; 13+ messages in thread
From: James Bottomley @ 2008-10-27 17:29 UTC (permalink / raw)
  To: Alan Stern; +Cc: Örjan Nordlund, SCSI development list

On Mon, 2008-10-27 at 13:27 -0400, Alan Stern wrote:
> On Mon, 27 Oct 2008, James Bottomley wrote:
> 
> > > > About the best we can do is check the first four fields.  For them to be
> > > > all zero, it would have to be a minimal response SCSI-1 device (RDF of
> > > > zero) ... hopefully they're all dead by now.
> > > 
> > > Then you're saying that the patch should everything up to
> > > inq_result[8]?  Or maybe even beyond?  I can do that.  Would that be 
> > > acceptable?
> > 
> > No ... "first four fields" means everything up to inq_result[3].
> > Anything beyond that would be legitimately zero if they were.
> 
> But what about the case where the first four bytes are zero and some of 
> the fields beyond them are nonzero.  Isn't that possible?

Not if the device conforms to the standard.

James



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

* [PATCH v2] SCSI: detect missing data for INQUIRY
  2008-10-27 17:29         ` James Bottomley
@ 2008-10-27 18:53           ` Alan Stern
  2008-10-28 13:02             ` James Smart
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Stern @ 2008-10-27 18:53 UTC (permalink / raw)
  To: James Bottomley; +Cc: Örjan Nordlund, SCSI development list

This patch (as1154b) fixes a problem in scsi_probe_lun(): The function
doesn't check whether the device has actually sent back any INQUIRY
data!  The patch adds a test to see if the result buffer is still
empty after the command has been executed.

This enables the Thecus N2050 storage device to work.  The firmware on
that device starts up strangely; it sends no data in response to the
initial INQUIRY, and it sends the INQUIRY information in response to
the followup REQUEST SENSE!  But after that it works better, so
retrying the INQUIRY is enough to get it going.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

Index: usb-2.6/drivers/scsi/scsi_scan.c
===================================================================
--- usb-2.6.orig/drivers/scsi/scsi_scan.c
+++ usb-2.6/drivers/scsi/scsi_scan.c
@@ -602,6 +602,14 @@ static int scsi_probe_lun(struct scsi_de
 				    (sshdr.ascq == 0))
 					continue;
 			}
+		} else {
+			/*
+			 * If the first four bytes are all 0 then probably
+			 * nothing was transferred.  Try again.
+			 */
+			if ((inq_result[0] | inq_result[1] |
+					inq_result[2] | inq_result[3]) == 0)
+				continue;
 		}
 		break;
 	}


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

* Re: [PATCH v2] SCSI: detect missing data for INQUIRY
  2008-10-27 18:53           ` [PATCH v2] " Alan Stern
@ 2008-10-28 13:02             ` James Smart
  2008-10-28 13:43               ` Alan Stern
  0 siblings, 1 reply; 13+ messages in thread
From: James Smart @ 2008-10-28 13:02 UTC (permalink / raw)
  To: Alan Stern; +Cc: James Bottomley, Örjan Nordlund, SCSI development list

Checking the payload like this is really hokey - but probably works.
Have we lost all notion from the LLDD on what the actual payload length 
was (calculated by expected transfer length and resid) ?  Seems like a 
much better idea than just checking contents.

-- james s

Alan Stern wrote:
> This patch (as1154b) fixes a problem in scsi_probe_lun(): The function
> doesn't check whether the device has actually sent back any INQUIRY
> data!  The patch adds a test to see if the result buffer is still
> empty after the command has been executed.
> 
> This enables the Thecus N2050 storage device to work.  The firmware on
> that device starts up strangely; it sends no data in response to the
> initial INQUIRY, and it sends the INQUIRY information in response to
> the followup REQUEST SENSE!  But after that it works better, so
> retrying the INQUIRY is enough to get it going.
> 
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> 
> ---
> 
> Index: usb-2.6/drivers/scsi/scsi_scan.c
> ===================================================================
> --- usb-2.6.orig/drivers/scsi/scsi_scan.c
> +++ usb-2.6/drivers/scsi/scsi_scan.c
> @@ -602,6 +602,14 @@ static int scsi_probe_lun(struct scsi_de
>                                     (sshdr.ascq == 0))
>                                         continue;
>                         }
> +               } else {
> +                       /*
> +                        * If the first four bytes are all 0 then probably
> +                        * nothing was transferred.  Try again.
> +                        */
> +                       if ((inq_result[0] | inq_result[1] |
> +                                       inq_result[2] | inq_result[3]) == 0)
> +                               continue;
>                 }
>                 break;
>         }
> 
> --
> 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] 13+ messages in thread

* Re: [PATCH v2] SCSI: detect missing data for INQUIRY
  2008-10-28 13:02             ` James Smart
@ 2008-10-28 13:43               ` Alan Stern
  0 siblings, 0 replies; 13+ messages in thread
From: Alan Stern @ 2008-10-28 13:43 UTC (permalink / raw)
  To: James Smart; +Cc: James Bottomley, Örjan Nordlund, SCSI development list

On Tue, 28 Oct 2008, James Smart wrote:

> Checking the payload like this is really hokey - but probably works.

I agree completely; it _is_ hokey.  There is precedent, however -- 
scsi_mode_sense() behaves similarly.

> Have we lost all notion from the LLDD on what the actual payload length 
> was (calculated by expected transfer length and resid) ?

In short: Yes, we have.  That information is discarded by
scsi_execute().

>  Seems like a 
> much better idea than just checking contents.

Again I agree.  The SCSI midlayer simply is not designed around the
idea of LLD's returning an actual transfer length.  I have no idea why
not -- I wasn't there when the SCSI core was initially designed.  :-)

Alan Stern


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

* Re: [PATCH v2] SCSI: detect missing data for INQUIRY
@ 2008-12-03 17:44 Alan Stern
  2008-12-03 18:00 ` James Bottomley
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Stern @ 2008-12-03 17:44 UTC (permalink / raw)
  To: James Bottomley; +Cc: SCSI development list

James:

There hasn't been any feedback on this patch:

	http://marc.info/?l=linux-scsi&m=122513368301598&w=2

It was modified in the way you requested.  Does it need to be revised 
any more?

Alan Stern


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

* Re: [PATCH v2] SCSI: detect missing data for INQUIRY
  2008-12-03 17:44 Alan Stern
@ 2008-12-03 18:00 ` James Bottomley
  2008-12-03 18:18   ` Alan Stern
  0 siblings, 1 reply; 13+ messages in thread
From: James Bottomley @ 2008-12-03 18:00 UTC (permalink / raw)
  To: Alan Stern; +Cc: SCSI development list

On Wed, 2008-12-03 at 12:44 -0500, Alan Stern wrote:
> James:
> 
> There hasn't been any feedback on this patch:
> 
> 	http://marc.info/?l=linux-scsi&m=122513368301598&w=2
> 
> It was modified in the way you requested.  Does it need to be revised 
> any more?

Probably not.  I really dislike a check and retry on something which is
theoretically a legal return, but I suppose I can put it in and see if
anything breaks.

James



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

* Re: [PATCH v2] SCSI: detect missing data for INQUIRY
  2008-12-03 18:00 ` James Bottomley
@ 2008-12-03 18:18   ` Alan Stern
  2008-12-03 18:46     ` Boaz Harrosh
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Stern @ 2008-12-03 18:18 UTC (permalink / raw)
  To: James Bottomley; +Cc: SCSI development list

On Wed, 3 Dec 2008, James Bottomley wrote:

> On Wed, 2008-12-03 at 12:44 -0500, Alan Stern wrote:
> > James:
> > 
> > There hasn't been any feedback on this patch:
> > 
> > 	http://marc.info/?l=linux-scsi&m=122513368301598&w=2
> > 
> > It was modified in the way you requested.  Does it need to be revised 
> > any more?
> 
> Probably not.  I really dislike a check and retry on something which is
> theoretically a legal return, but I suppose I can put it in and see if
> anything breaks.

It's too bad that the scsi_execute_req() interface loses all 
information about how much data the device actually sent.  If that 
information were preserved then it wouldn't be necessary to rely on 
this not-quite-satisfactory sort of test.

Alan Stern


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

* Re: [PATCH v2] SCSI: detect missing data for INQUIRY
  2008-12-03 18:18   ` Alan Stern
@ 2008-12-03 18:46     ` Boaz Harrosh
  0 siblings, 0 replies; 13+ messages in thread
From: Boaz Harrosh @ 2008-12-03 18:46 UTC (permalink / raw)
  To: Alan Stern; +Cc: James Bottomley, SCSI development list

Alan Stern wrote:
> On Wed, 3 Dec 2008, James Bottomley wrote:
> 
>> On Wed, 2008-12-03 at 12:44 -0500, Alan Stern wrote:
>>> James:
>>>
>>> There hasn't been any feedback on this patch:
>>>
>>> 	http://marc.info/?l=linux-scsi&m=122513368301598&w=2
>>>
>>> It was modified in the way you requested.  Does it need to be revised 
>>> any more?
>> Probably not.  I really dislike a check and retry on something which is
>> theoretically a legal return, but I suppose I can put it in and see if
>> anything breaks.
> 
> It's too bad that the scsi_execute_req() interface loses all 
> information about how much data the device actually sent.  If that 
> information were preserved then it wouldn't be necessary to rely on 
> this not-quite-satisfactory sort of test.
> 
> Alan Stern
> 

Just a comment:
You are the third person this week that wanted residual return from
scsi_execute/scsi_execute_req. Perhaps it's time as come ;)

(This is a TODO for me)

Boaz

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

end of thread, other threads:[~2008-12-03 18:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-27 16:18 [PATCH] SCSI: detect missing data for INQUIRY Alan Stern
2008-10-27 16:37 ` James Bottomley
2008-10-27 17:00   ` Alan Stern
2008-10-27 17:08     ` James Bottomley
2008-10-27 17:27       ` Alan Stern
2008-10-27 17:29         ` James Bottomley
2008-10-27 18:53           ` [PATCH v2] " Alan Stern
2008-10-28 13:02             ` James Smart
2008-10-28 13:43               ` Alan Stern
  -- strict thread matches above, loose matches on Subject: below --
2008-12-03 17:44 Alan Stern
2008-12-03 18:00 ` James Bottomley
2008-12-03 18:18   ` Alan Stern
2008-12-03 18:46     ` Boaz Harrosh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox