Card-Reader Problem continued

Alan Stern stern at rowland.harvard.edu
Sun May 21 14:45:35 PDT 2006


On Sat, 20 May 2006, Christian Haul wrote:

> OK, I've attached a gzip'ed kern.log that covers plugging in the reader
> and removing it after approx. 30 seconds. If the attachment is removed
> by the list software but the mail gets through, you'll find the log at
> 
> http://chaul.bluehash.de/usb/kern.log.gz

Good, that helped a lot.

It turns out that the retries _are_ being done by the kernel.  In the SCSI
disk driver, to be precise.  There's a kernel patch below which should
reduce the number of attempts from 4 to 2 on each loop.

It's not so easy to get rid of the single remaining retry.  They are an 
artifact of the way the kernel detects disk changes and removals.  First 
it checks to see if there has been a change (that's the first TEST UNIT 
READY command), and if there has then it checks to see if there's a disk 
present (that's the second one).  You'd think the two operations could be 
combined into one.

Anyway, it's clear that this is not a problem in hald.  I'll try starting 
a discussion about it on LKML.

Alan Stern



Index: usb-2.6/drivers/scsi/sd.c
===================================================================
--- usb-2.6.orig/drivers/scsi/sd.c
+++ usb-2.6/drivers/scsi/sd.c
@@ -1047,6 +1048,14 @@ sd_spinup_disk(struct scsi_disk *sdkp, c
 						      &sshdr, SD_TIMEOUT,
 						      SD_MAX_RETRIES);
 
+			/*
+			 * If the drive has indicated to us that it
+			 * doesn't have any media in it, don't bother
+			 * with any of the rest of this crap.
+			 */
+			if (media_not_present(sdkp, &sshdr))
+				return;
+
 			if (the_result)
 				sense_valid = scsi_sense_valid(&sshdr);
 			retries++;
@@ -1055,14 +1064,6 @@ sd_spinup_disk(struct scsi_disk *sdkp, c
 			  ((driver_byte(the_result) & DRIVER_SENSE) &&
 			  sense_valid && sshdr.sense_key == UNIT_ATTENTION)));
 
-		/*
-		 * If the drive has indicated to us that it doesn't have
-		 * any media in it, don't bother with any of the rest of
-		 * this crap.
-		 */
-		if (media_not_present(sdkp, &sshdr))
-			return;
-
 		if ((driver_byte(the_result) & DRIVER_SENSE) == 0) {
 			/* no sense, TUR either succeeded or failed
 			 * with a status error */




More information about the hal mailing list