All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] SCSI: early detection of medium not present, updated
@ 2007-11-29 23:18 Andrew Morton
  2007-11-30  0:04 ` Tejun Heo
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Andrew Morton @ 2007-11-29 23:18 UTC (permalink / raw)
  To: James Bottomley, linux-scsi, Albert Lee, Alan Stern, Tejun Heo,
	Je


Guys, I have this marked as needed-in-2.6.24?





From: Alan Stern <stern@rowland.harvard.edu>

Taken from http://bugzilla.kernel.org/show_bug.cgi?id=8904

An updated (by Albert, I assume) version of the fourteen-month-old patch here:

http://marc.info/?l=linux-kernel&m=115412002912837&w=2

Apparently fixes the bug described at
http://bugzilla.kernel.org/show_bug.cgi?id=8904

Needs some TLC.  Perhaps urgently.

Cc: Albert Lee <albertcc@tw.ibm.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: Tejun Heo <htejun@gmail.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/scsi/scsi_ioctl.c  |    2 +-
 drivers/scsi/scsi_lib.c    |   20 ++++++++++++++++++--
 drivers/scsi/sd.c          |    2 +-
 drivers/scsi/sr.c          |   15 +++++++++------
 include/scsi/scsi_device.h |    2 +-
 5 files changed, 30 insertions(+), 11 deletions(-)

diff -puN drivers/scsi/scsi_ioctl.c~scsi-early-detection-of-medium-not-present-updated drivers/scsi/scsi_ioctl.c
--- a/drivers/scsi/scsi_ioctl.c~scsi-early-detection-of-medium-not-present-updated
+++ a/drivers/scsi/scsi_ioctl.c
@@ -244,7 +244,7 @@ int scsi_ioctl(struct scsi_device *sdev,
 		return scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW);
 	case SCSI_IOCTL_TEST_UNIT_READY:
 		return scsi_test_unit_ready(sdev, IOCTL_NORMAL_TIMEOUT,
-					    NORMAL_RETRIES);
+					    NORMAL_RETRIES, NULL);
 	case SCSI_IOCTL_START_UNIT:
 		scsi_cmd[0] = START_STOP;
 		scsi_cmd[1] = 0;
diff -puN drivers/scsi/scsi_lib.c~scsi-early-detection-of-medium-not-present-updated drivers/scsi/scsi_lib.c
--- a/drivers/scsi/scsi_lib.c~scsi-early-detection-of-medium-not-present-updated
+++ a/drivers/scsi/scsi_lib.c
@@ -2010,15 +2010,26 @@ scsi_mode_sense(struct scsi_device *sdev
 }
 EXPORT_SYMBOL(scsi_mode_sense);
 
+/**
+ *	scsi_test_unit_ready - test if unit is ready
+ *	@sdev:	scsi device to change the state of.
+ *	@timeout: command timeout
+ *	@retries: number of retries before failing
+ *	@media_maybe_present: 1 if media maybe present or not.
+ *		              0 if media not present.
+ *
+ *	Returns zero if unsuccessful or an error if TUR failed.
+ **/
 int
-scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries)
+scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, int *media_maybe_present)
 {
 	char cmd[] = {
 		TEST_UNIT_READY, 0, 0, 0, 0, 0,
 	};
 	struct scsi_sense_hdr sshdr;
 	int result;
-	
+	int maybe_present = 1;
+
 	result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, &sshdr,
 				  timeout, retries);
 
@@ -2027,10 +2038,15 @@ scsi_test_unit_ready(struct scsi_device 
 		if ((scsi_sense_valid(&sshdr)) &&
 		    ((sshdr.sense_key == UNIT_ATTENTION) ||
 		     (sshdr.sense_key == NOT_READY))) {
+			if (sshdr.asc == 0x3A)
+				maybe_present = 0;
 			sdev->changed = 1;
 			result = 0;
 		}
 	}
+
+	if (media_maybe_present)
+		*media_maybe_present = maybe_present;
 	return result;
 }
 EXPORT_SYMBOL(scsi_test_unit_ready);
diff -puN drivers/scsi/sd.c~scsi-early-detection-of-medium-not-present-updated drivers/scsi/sd.c
--- a/drivers/scsi/sd.c~scsi-early-detection-of-medium-not-present-updated
+++ a/drivers/scsi/sd.c
@@ -767,7 +767,7 @@ static int sd_media_changed(struct gendi
 	retval = -ENODEV;
 
 	if (scsi_block_when_processing_errors(sdp))
-		retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES);
+		retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES, NULL);
 
 	/*
 	 * Unable to test, unit probably not ready.   This usually
diff -puN drivers/scsi/sr.c~scsi-early-detection-of-medium-not-present-updated drivers/scsi/sr.c
--- a/drivers/scsi/sr.c~scsi-early-detection-of-medium-not-present-updated
+++ a/drivers/scsi/sr.c
@@ -179,18 +179,21 @@ static int sr_media_change(struct cdrom_
 {
 	struct scsi_cd *cd = cdi->handle;
 	int retval;
+	int media_maybe_present;
 
 	if (CDSL_CURRENT != slot) {
 		/* no changer support */
 		return -EINVAL;
 	}
 
-	retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES);
-	if (retval) {
-		/* Unable to test, unit probably not ready.  This usually
-		 * means there is no disc in the drive.  Mark as changed,
-		 * and we will figure it out later once the drive is
-		 * available again.  */
+	retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES,
+				      &media_maybe_present);
+	if (retval || !media_maybe_present) {
+		/* Media not present or unable to test, unit probably not
+		 * ready. This usually means there is no disc in the drive.
+		 * Mark as changed, and we will figure it out later once
+		 * the drive is available again.
+		 */
 		cd->device->changed = 1;
 		/* This will force a flush, if called from check_disk_change */
 		retval = 1;
diff -puN include/scsi/scsi_device.h~scsi-early-detection-of-medium-not-present-updated include/scsi/scsi_device.h
--- a/include/scsi/scsi_device.h~scsi-early-detection-of-medium-not-present-updated
+++ a/include/scsi/scsi_device.h
@@ -292,7 +292,7 @@ extern int scsi_mode_select(struct scsi_
 			    struct scsi_mode_data *data,
 			    struct scsi_sense_hdr *);
 extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout,
-				int retries);
+				int retries, int *media_maybe_present);
 extern int scsi_device_set_state(struct scsi_device *sdev,
 				 enum scsi_device_state state);
 extern struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type,
_


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [PATCH] SCSI: early detection of medium not present, updated
@ 2006-07-28 20:50 Alan Stern
  0 siblings, 0 replies; 10+ messages in thread
From: Alan Stern @ 2006-07-28 20:50 UTC (permalink / raw)
  To: Andrew Morton; +Cc: James Bottomley, Jens Axboe, Kernel development list

This patch (as757) is meant to apply on top of the
scsi-core-and-sd-early-detection-of-medium-not-present patch currently in
2.6.18-rc2-mm1.  It updates the way the scsi_test_unit_ready() routine
reports medium not present, using the technique recommended by James
Bottomley.

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

---

If James would prefer, I could submit this in a different form: first 
revert the earlier SCSI patch and then add the new stuff from this one.

In a brief conversation during OLS, Jens said that he saw no problem with
allowing the block layer to accept -ENOMEDIUM as a return code from the 
media_changed method.  The patch is already in -mm, named
block-layer-early-detection-of-medium-not-present.

In principle cdrom drivers could use a similar technique to avoid calling 
the revalidate method when no disc is loaded, but that would require more 
far-reaching changes.  For now it's easier to confine this to disk drives.


Index: 2.6.18-rc2-mm1/drivers/scsi/sd.c
===================================================================
--- 2.6.18-rc2-mm1.orig/drivers/scsi/sd.c
+++ 2.6.18-rc2-mm1/drivers/scsi/sd.c
@@ -733,6 +733,7 @@ static int sd_media_changed(struct gendi
 	struct scsi_disk *sdkp = scsi_disk(disk);
 	struct scsi_device *sdp = sdkp->device;
 	int retval;
+	int media_not_present = 0;
 
 	SCSI_LOG_HLQUEUE(3, printk("sd_media_changed: disk=%s\n",
 						disk->disk_name));
@@ -760,7 +761,8 @@ static int sd_media_changed(struct gendi
 	 */
 	retval = -ENODEV;
 	if (scsi_block_when_processing_errors(sdp))
-		retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES);
+		retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
+				&media_not_present);
 
 	/*
 	 * Unable to test, unit probably not ready.   This usually
@@ -768,7 +770,7 @@ static int sd_media_changed(struct gendi
 	 * and we will figure it out later once the drive is
 	 * available again.
 	 */
-	if (retval || sdp->medium_not_present)
+	if (retval || media_not_present)
 		 goto not_present;
 	/*
 	 * For removable scsi disk we have to recognise the presence
Index: 2.6.18-rc2-mm1/include/scsi/scsi_device.h
===================================================================
--- 2.6.18-rc2-mm1.orig/include/scsi/scsi_device.h
+++ 2.6.18-rc2-mm1/include/scsi/scsi_device.h
@@ -92,7 +92,6 @@ struct scsi_device {
 	unsigned writeable:1;
 	unsigned removable:1;
 	unsigned changed:1;	/* Data invalid due to media change */
-	unsigned medium_not_present:1;	/* Set by scsi_test_unit_ready() */
 	unsigned busy:1;	/* Used to prevent races */
 	unsigned lockable:1;	/* Able to prevent media removal */
 	unsigned locked:1;      /* Media removal disabled */
@@ -268,7 +267,7 @@ extern int scsi_mode_select(struct scsi_
 			    struct scsi_mode_data *data,
 			    struct scsi_sense_hdr *);
 extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout,
-				int retries);
+				int retries, int *media_not_present);
 extern int scsi_device_set_state(struct scsi_device *sdev,
 				 enum scsi_device_state state);
 extern int scsi_device_quiesce(struct scsi_device *sdev);
Index: 2.6.18-rc2-mm1/drivers/scsi/sr.c
===================================================================
--- 2.6.18-rc2-mm1.orig/drivers/scsi/sr.c
+++ 2.6.18-rc2-mm1/drivers/scsi/sr.c
@@ -178,14 +178,16 @@ static int sr_media_change(struct cdrom_
 {
 	struct scsi_cd *cd = cdi->handle;
 	int retval;
+	int media_not_present = 0;
 
 	if (CDSL_CURRENT != slot) {
 		/* no changer support */
 		return -EINVAL;
 	}
 
-	retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES);
-	if (retval) {
+	retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES,
+			&media_not_present);
+	if (retval || media_not_present) {
 		/* Unable to test, unit probably not ready.  This usually
 		 * means there is no disc in the drive.  Mark as changed,
 		 * and we will figure it out later once the drive is
Index: 2.6.18-rc2-mm1/drivers/scsi/scsi_lib.c
===================================================================
--- 2.6.18-rc2-mm1.orig/drivers/scsi/scsi_lib.c
+++ 2.6.18-rc2-mm1/drivers/scsi/scsi_lib.c
@@ -1867,7 +1867,8 @@ scsi_mode_sense(struct scsi_device *sdev
 EXPORT_SYMBOL(scsi_mode_sense);
 
 int
-scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries)
+scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries,
+		int *media_not_present)
 {
 	char cmd[] = {
 		TEST_UNIT_READY, 0, 0, 0, 0, 0,
@@ -1878,7 +1879,6 @@ scsi_test_unit_ready(struct scsi_device 
 	result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, &sshdr,
 				  timeout, retries);
 
-	sdev->medium_not_present = 0;
 	if ((driver_byte(result) & DRIVER_SENSE) && sdev->removable) {
 
 		if ((scsi_sense_valid(&sshdr)) &&
@@ -1887,8 +1887,8 @@ scsi_test_unit_ready(struct scsi_device 
 			sdev->changed = 1;
 			result = 0;
 
-			if (sshdr.asc == 0x3A)
-				sdev->medium_not_present = 1;
+			if (sshdr.asc == 0x3A && media_not_present != NULL)
+				*media_not_present = 1;
 		}
 	}
 	return result;
Index: 2.6.18-rc2-mm1/drivers/scsi/scsi_ioctl.c
===================================================================
--- 2.6.18-rc2-mm1.orig/drivers/scsi/scsi_ioctl.c
+++ 2.6.18-rc2-mm1/drivers/scsi/scsi_ioctl.c
@@ -242,7 +242,7 @@ int scsi_ioctl(struct scsi_device *sdev,
 		return scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW);
 	case SCSI_IOCTL_TEST_UNIT_READY:
 		return scsi_test_unit_ready(sdev, IOCTL_NORMAL_TIMEOUT,
-					    NORMAL_RETRIES);
+					    NORMAL_RETRIES, NULL);
 	case SCSI_IOCTL_START_UNIT:
 		scsi_cmd[0] = START_STOP;
 		scsi_cmd[1] = 0;


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

end of thread, other threads:[~2007-12-07 15:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-29 23:18 [patch] SCSI: early detection of medium not present, updated Andrew Morton
2007-11-30  0:04 ` Tejun Heo
2007-11-30  3:26 ` Alan Stern
2007-12-01 14:24 ` James Bottomley
2007-12-01 15:55   ` Alan Stern
2007-12-02 17:10   ` James Bottomley
2007-12-02 20:02     ` Alan Stern
2007-12-05 16:06       ` James Bottomley
2007-12-07 15:51         ` Alan Stern
  -- strict thread matches above, loose matches on Subject: below --
2006-07-28 20:50 [PATCH] " Alan Stern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.