diff options
author | Tejun Heo <tj@kernel.org> | 2010-12-08 14:57:40 -0500 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2010-12-16 11:53:39 -0500 |
commit | 9f8a2c23c6c1140f515f601265c4dff7522110b7 (patch) | |
tree | 6defb41e4b129c3772e0c6d40b5e8e9a29bea7f0 /drivers | |
parent | 638428ece619495edc9579b1e21493eb00f9687c (diff) |
scsi: replace sr_test_unit_ready() with scsi_test_unit_ready()
The usage of TUR has been confusing involving several different
commits updating different parts over time. Currently, the only
differences between scsi_test_unit_ready() and sr_test_unit_ready()
are,
* scsi_test_unit_ready() also sets sdev->changed on NOT_READY.
* scsi_test_unit_ready() returns 0 if TUR ended with UNIT_ATTENTION or
NOT_READY.
Due to the above two differences, sr is using its own
sr_test_unit_ready(), but sd - the sole user of the above extra
handling - doesn't even need them.
Where scsi_test_unit_ready() is used in sd_media_changed(), the code
is looking for device ready w/ media present state which is true iff
TUR succeeds w/o sense data or UA, and when the device is not ready
for whatever reason sd_media_changed() explicitly marks media as
missing so there's no reason to set sdev->changed automatically from
scsi_test_unit_ready() on NOT_READY.
Drop both special handlings from scsi_test_unit_ready(), which makes
it equivalant to sr_test_unit_ready(), and replace
sr_test_unit_ready() with scsi_test_unit_ready(). Also, drop the
unnecessary explicit NOT_READY check from sd_media_changed().
Checking return value is enough for testing device readiness.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 13 | ||||
-rw-r--r-- | drivers/scsi/sd.c | 10 | ||||
-rw-r--r-- | drivers/scsi/sr.c | 31 | ||||
-rw-r--r-- | drivers/scsi/sr.h | 1 | ||||
-rw-r--r-- | drivers/scsi/sr_ioctl.c | 2 |
5 files changed, 6 insertions, 51 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index eafeeda6e194..13bf89145b18 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -1984,8 +1984,7 @@ EXPORT_SYMBOL(scsi_mode_sense); | |||
1984 | * in. | 1984 | * in. |
1985 | * | 1985 | * |
1986 | * Returns zero if unsuccessful or an error if TUR failed. For | 1986 | * Returns zero if unsuccessful or an error if TUR failed. For |
1987 | * removable media, a return of NOT_READY or UNIT_ATTENTION is | 1987 | * removable media, UNIT_ATTENTION sets ->changed flag. |
1988 | * translated to success, with the ->changed flag updated. | ||
1989 | **/ | 1988 | **/ |
1990 | int | 1989 | int |
1991 | scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, | 1990 | scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, |
@@ -2012,16 +2011,6 @@ scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, | |||
2012 | } while (scsi_sense_valid(sshdr) && | 2011 | } while (scsi_sense_valid(sshdr) && |
2013 | sshdr->sense_key == UNIT_ATTENTION && --retries); | 2012 | sshdr->sense_key == UNIT_ATTENTION && --retries); |
2014 | 2013 | ||
2015 | if (!sshdr) | ||
2016 | /* could not allocate sense buffer, so can't process it */ | ||
2017 | return result; | ||
2018 | |||
2019 | if (sdev->removable && scsi_sense_valid(sshdr) && | ||
2020 | (sshdr->sense_key == UNIT_ATTENTION || | ||
2021 | sshdr->sense_key == NOT_READY)) { | ||
2022 | sdev->changed = 1; | ||
2023 | result = 0; | ||
2024 | } | ||
2025 | if (!sshdr_external) | 2014 | if (!sshdr_external) |
2026 | kfree(sshdr); | 2015 | kfree(sshdr); |
2027 | return result; | 2016 | return result; |
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index b9ab3a590e4b..8d488a9fef00 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -1045,15 +1045,7 @@ static int sd_media_changed(struct gendisk *disk) | |||
1045 | sshdr); | 1045 | sshdr); |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | /* | 1048 | if (retval) { |
1049 | * Unable to test, unit probably not ready. This usually | ||
1050 | * means there is no disc in the drive. Mark as changed, | ||
1051 | * and we will figure it out later once the drive is | ||
1052 | * available again. | ||
1053 | */ | ||
1054 | if (retval || (scsi_sense_valid(sshdr) && | ||
1055 | /* 0x3a is medium not present */ | ||
1056 | sshdr->asc == 0x3a)) { | ||
1057 | set_media_not_present(sdkp); | 1049 | set_media_not_present(sdkp); |
1058 | retval = 1; | 1050 | retval = 1; |
1059 | goto out; | 1051 | goto out; |
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index c7e29bdec2cd..310b3fac6313 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c | |||
@@ -165,32 +165,6 @@ static void scsi_cd_put(struct scsi_cd *cd) | |||
165 | mutex_unlock(&sr_ref_mutex); | 165 | mutex_unlock(&sr_ref_mutex); |
166 | } | 166 | } |
167 | 167 | ||
168 | /* identical to scsi_test_unit_ready except that it doesn't | ||
169 | * eat the NOT_READY returns for removable media */ | ||
170 | int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr) | ||
171 | { | ||
172 | int retries = MAX_RETRIES; | ||
173 | int the_result; | ||
174 | u8 cmd[] = {TEST_UNIT_READY, 0, 0, 0, 0, 0 }; | ||
175 | |||
176 | /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION | ||
177 | * conditions are gone, or a timeout happens | ||
178 | */ | ||
179 | do { | ||
180 | the_result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, | ||
181 | 0, sshdr, SR_TIMEOUT, | ||
182 | retries--, NULL); | ||
183 | if (scsi_sense_valid(sshdr) && | ||
184 | sshdr->sense_key == UNIT_ATTENTION) | ||
185 | sdev->changed = 1; | ||
186 | |||
187 | } while (retries > 0 && | ||
188 | (!scsi_status_is_good(the_result) || | ||
189 | (scsi_sense_valid(sshdr) && | ||
190 | sshdr->sense_key == UNIT_ATTENTION))); | ||
191 | return the_result; | ||
192 | } | ||
193 | |||
194 | /* | 168 | /* |
195 | * This function checks to see if the media has been changed in the | 169 | * This function checks to see if the media has been changed in the |
196 | * CDROM drive. It is possible that we have already sensed a change, | 170 | * CDROM drive. It is possible that we have already sensed a change, |
@@ -213,7 +187,8 @@ static int sr_media_change(struct cdrom_device_info *cdi, int slot) | |||
213 | } | 187 | } |
214 | 188 | ||
215 | sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL); | 189 | sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL); |
216 | retval = sr_test_unit_ready(cd->device, sshdr); | 190 | retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, |
191 | sshdr); | ||
217 | /* | 192 | /* |
218 | * Media is considered to be present if TUR succeeds or fails with | 193 | * Media is considered to be present if TUR succeeds or fails with |
219 | * sense data indicating something other than media-not-present | 194 | * sense data indicating something other than media-not-present |
@@ -784,7 +759,7 @@ static void get_capabilities(struct scsi_cd *cd) | |||
784 | } | 759 | } |
785 | 760 | ||
786 | /* eat unit attentions */ | 761 | /* eat unit attentions */ |
787 | sr_test_unit_ready(cd->device, &sshdr); | 762 | scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr); |
788 | 763 | ||
789 | /* ask for mode page 0x2a */ | 764 | /* ask for mode page 0x2a */ |
790 | rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, | 765 | rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, |
diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h index 1e144dfdbd4b..81fbc0b78a52 100644 --- a/drivers/scsi/sr.h +++ b/drivers/scsi/sr.h | |||
@@ -61,7 +61,6 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed); | |||
61 | int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *); | 61 | int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *); |
62 | 62 | ||
63 | int sr_is_xa(Scsi_CD *); | 63 | int sr_is_xa(Scsi_CD *); |
64 | int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr); | ||
65 | 64 | ||
66 | /* sr_vendor.c */ | 65 | /* sr_vendor.c */ |
67 | void sr_vendor_init(Scsi_CD *); | 66 | void sr_vendor_init(Scsi_CD *); |
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c index 3cd8ffbad577..8be30554119b 100644 --- a/drivers/scsi/sr_ioctl.c +++ b/drivers/scsi/sr_ioctl.c | |||
@@ -307,7 +307,7 @@ int sr_drive_status(struct cdrom_device_info *cdi, int slot) | |||
307 | /* we have no changer support */ | 307 | /* we have no changer support */ |
308 | return -EINVAL; | 308 | return -EINVAL; |
309 | } | 309 | } |
310 | if (0 == sr_test_unit_ready(cd->device, &sshdr)) | 310 | if (!scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr)) |
311 | return CDS_DISC_OK; | 311 | return CDS_DISC_OK; |
312 | 312 | ||
313 | /* SK/ASC/ASCQ of 2/4/1 means "unit is becoming ready" */ | 313 | /* SK/ASC/ASCQ of 2/4/1 means "unit is becoming ready" */ |