SCSI: early detection of medium not present, updated
PATCH 14/17 SCSI: early detection of medium not present, updated
From: Alan Stern <[email protected]>
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 <[email protected]>
Cc Alan Stern <[email protected]>
Cc James Bottomley <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Jens Axboe <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
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(-)
drivers/scsi/scsi_ioctl.c renamed from drivers/scsi/scsi_ioctl.c~scsi-early-detection-of-medium-not-present-updated +1 -1
@@ -239,7 +239,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 ;
drivers/scsi/scsi_lib.c renamed from drivers/scsi/scsi_lib.c~scsi-early-detection-of-medium-not-present-updated +18 -2
@@ -1875,15 +1875,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);
@@ -1892,10 +1903,15 @@ scsi_test_unit_ready(struct scsi_deviceif ((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);
drivers/scsi/sd.c renamed from drivers/scsi/sd.c~scsi-early-detection-of-medium-not-present-updated +1 -1
@@ -759,7 +759,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
drivers/scsi/sr.c renamed from drivers/scsi/sr.c~scsi-early-detection-of-medium-not-present-updated +9 -6
@@ -177,18 +177,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 ;
include/scsi/scsi_device.h renamed from include/scsi/scsi_device.h~scsi-early-detection-of-medium-not-present-updated +1 -1
@@ -283,7 +283,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 int scsi_device_event_notify(struct scsi_device *sdev,
_