diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 13:45:01 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 13:45:01 -0500 |
commit | 275220f0fcff1adf28a717076e00f575edf05fda (patch) | |
tree | d249bccc80c64443dab211639050c4fb14332648 /drivers/scsi | |
parent | fe3c560b8a22cb28e54fe8950abef38e88d75831 (diff) | |
parent | 81c5e2ae33c4b19e53966b427e33646bf6811830 (diff) |
Merge branch 'for-2.6.38/core' of git://git.kernel.dk/linux-2.6-block
* 'for-2.6.38/core' of git://git.kernel.dk/linux-2.6-block: (43 commits)
block: ensure that completion error gets properly traced
blktrace: add missing probe argument to block_bio_complete
block cfq: don't use atomic_t for cfq_group
block cfq: don't use atomic_t for cfq_queue
block: trace event block fix unassigned field
block: add internal hd part table references
block: fix accounting bug on cross partition merges
kref: add kref_test_and_get
bio-integrity: mark kintegrityd_wq highpri and CPU intensive
block: make kblockd_workqueue smarter
Revert "sd: implement sd_check_events()"
block: Clean up exit_io_context() source code.
Fix compile warnings due to missing removal of a 'ret' variable
fs/block: type signature of major_to_index(int) to major_to_index(unsigned)
block: convert !IS_ERR(p) && p to !IS_ERR_NOR_NULL(p)
cfq-iosched: don't check cfqg in choose_service_tree()
fs/splice: Pull buf->ops->confirm() from splice_from_pipe actors
cdrom: export cdrom_check_events()
sd: implement sd_check_events()
sr: implement sr_check_events()
...
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 13 | ||||
-rw-r--r-- | drivers/scsi/sd.c | 10 | ||||
-rw-r--r-- | drivers/scsi/sr.c | 174 | ||||
-rw-r--r-- | drivers/scsi/sr.h | 3 | ||||
-rw-r--r-- | drivers/scsi/sr_ioctl.c | 2 |
5 files changed, 103 insertions, 99 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 501f67bef719..9045c52abd25 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -1977,8 +1977,7 @@ EXPORT_SYMBOL(scsi_mode_sense); | |||
1977 | * in. | 1977 | * in. |
1978 | * | 1978 | * |
1979 | * Returns zero if unsuccessful or an error if TUR failed. For | 1979 | * Returns zero if unsuccessful or an error if TUR failed. For |
1980 | * removable media, a return of NOT_READY or UNIT_ATTENTION is | 1980 | * removable media, UNIT_ATTENTION sets ->changed flag. |
1981 | * translated to success, with the ->changed flag updated. | ||
1982 | **/ | 1981 | **/ |
1983 | int | 1982 | int |
1984 | scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, | 1983 | scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, |
@@ -2005,16 +2004,6 @@ scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, | |||
2005 | } while (scsi_sense_valid(sshdr) && | 2004 | } while (scsi_sense_valid(sshdr) && |
2006 | sshdr->sense_key == UNIT_ATTENTION && --retries); | 2005 | sshdr->sense_key == UNIT_ATTENTION && --retries); |
2007 | 2006 | ||
2008 | if (!sshdr) | ||
2009 | /* could not allocate sense buffer, so can't process it */ | ||
2010 | return result; | ||
2011 | |||
2012 | if (sdev->removable && scsi_sense_valid(sshdr) && | ||
2013 | (sshdr->sense_key == UNIT_ATTENTION || | ||
2014 | sshdr->sense_key == NOT_READY)) { | ||
2015 | sdev->changed = 1; | ||
2016 | result = 0; | ||
2017 | } | ||
2018 | if (!sshdr_external) | 2007 | if (!sshdr_external) |
2019 | kfree(sshdr); | 2008 | kfree(sshdr); |
2020 | return result; | 2009 | return result; |
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 365024b0c407..b65e65aa07eb 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -1043,15 +1043,7 @@ static int sd_media_changed(struct gendisk *disk) | |||
1043 | sshdr); | 1043 | sshdr); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | /* | 1046 | if (retval) { |
1047 | * Unable to test, unit probably not ready. This usually | ||
1048 | * means there is no disc in the drive. Mark as changed, | ||
1049 | * and we will figure it out later once the drive is | ||
1050 | * available again. | ||
1051 | */ | ||
1052 | if (retval || (scsi_sense_valid(sshdr) && | ||
1053 | /* 0x3a is medium not present */ | ||
1054 | sshdr->asc == 0x3a)) { | ||
1055 | set_media_not_present(sdkp); | 1047 | set_media_not_present(sdkp); |
1056 | goto out; | 1048 | goto out; |
1057 | } | 1049 | } |
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index d7b383c96d5d..be6baf8ad704 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c | |||
@@ -104,14 +104,15 @@ static void sr_release(struct cdrom_device_info *); | |||
104 | static void get_sectorsize(struct scsi_cd *); | 104 | static void get_sectorsize(struct scsi_cd *); |
105 | static void get_capabilities(struct scsi_cd *); | 105 | static void get_capabilities(struct scsi_cd *); |
106 | 106 | ||
107 | static int sr_media_change(struct cdrom_device_info *, int); | 107 | static unsigned int sr_check_events(struct cdrom_device_info *cdi, |
108 | unsigned int clearing, int slot); | ||
108 | static int sr_packet(struct cdrom_device_info *, struct packet_command *); | 109 | static int sr_packet(struct cdrom_device_info *, struct packet_command *); |
109 | 110 | ||
110 | static struct cdrom_device_ops sr_dops = { | 111 | static struct cdrom_device_ops sr_dops = { |
111 | .open = sr_open, | 112 | .open = sr_open, |
112 | .release = sr_release, | 113 | .release = sr_release, |
113 | .drive_status = sr_drive_status, | 114 | .drive_status = sr_drive_status, |
114 | .media_changed = sr_media_change, | 115 | .check_events = sr_check_events, |
115 | .tray_move = sr_tray_move, | 116 | .tray_move = sr_tray_move, |
116 | .lock_door = sr_lock_door, | 117 | .lock_door = sr_lock_door, |
117 | .select_speed = sr_select_speed, | 118 | .select_speed = sr_select_speed, |
@@ -165,90 +166,96 @@ static void scsi_cd_put(struct scsi_cd *cd) | |||
165 | mutex_unlock(&sr_ref_mutex); | 166 | mutex_unlock(&sr_ref_mutex); |
166 | } | 167 | } |
167 | 168 | ||
168 | /* identical to scsi_test_unit_ready except that it doesn't | 169 | static unsigned int sr_get_events(struct scsi_device *sdev) |
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 | { | 170 | { |
172 | int retries = MAX_RETRIES; | 171 | u8 buf[8]; |
173 | int the_result; | 172 | u8 cmd[] = { GET_EVENT_STATUS_NOTIFICATION, |
174 | u8 cmd[] = {TEST_UNIT_READY, 0, 0, 0, 0, 0 }; | 173 | 1, /* polled */ |
174 | 0, 0, /* reserved */ | ||
175 | 1 << 4, /* notification class: media */ | ||
176 | 0, 0, /* reserved */ | ||
177 | 0, sizeof(buf), /* allocation length */ | ||
178 | 0, /* control */ | ||
179 | }; | ||
180 | struct event_header *eh = (void *)buf; | ||
181 | struct media_event_desc *med = (void *)(buf + 4); | ||
182 | struct scsi_sense_hdr sshdr; | ||
183 | int result; | ||
175 | 184 | ||
176 | /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION | 185 | result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, sizeof(buf), |
177 | * conditions are gone, or a timeout happens | 186 | &sshdr, SR_TIMEOUT, MAX_RETRIES, NULL); |
178 | */ | 187 | if (scsi_sense_valid(&sshdr) && sshdr.sense_key == UNIT_ATTENTION) |
179 | do { | 188 | return DISK_EVENT_MEDIA_CHANGE; |
180 | the_result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, | 189 | |
181 | 0, sshdr, SR_TIMEOUT, | 190 | if (result || be16_to_cpu(eh->data_len) < sizeof(*med)) |
182 | retries--, NULL); | 191 | return 0; |
183 | if (scsi_sense_valid(sshdr) && | 192 | |
184 | sshdr->sense_key == UNIT_ATTENTION) | 193 | if (eh->nea || eh->notification_class != 0x4) |
185 | sdev->changed = 1; | 194 | return 0; |
186 | 195 | ||
187 | } while (retries > 0 && | 196 | if (med->media_event_code == 1) |
188 | (!scsi_status_is_good(the_result) || | 197 | return DISK_EVENT_EJECT_REQUEST; |
189 | (scsi_sense_valid(sshdr) && | 198 | else if (med->media_event_code == 2) |
190 | sshdr->sense_key == UNIT_ATTENTION))); | 199 | return DISK_EVENT_MEDIA_CHANGE; |
191 | return the_result; | 200 | return 0; |
192 | } | 201 | } |
193 | 202 | ||
194 | /* | 203 | /* |
195 | * This function checks to see if the media has been changed in the | 204 | * This function checks to see if the media has been changed or eject |
196 | * CDROM drive. It is possible that we have already sensed a change, | 205 | * button has been pressed. It is possible that we have already |
197 | * or the drive may have sensed one and not yet reported it. We must | 206 | * sensed a change, or the drive may have sensed one and not yet |
198 | * be ready for either case. This function always reports the current | 207 | * reported it. The past events are accumulated in sdev->changed and |
199 | * value of the changed bit. If flag is 0, then the changed bit is reset. | 208 | * returned together with the current state. |
200 | * This function could be done as an ioctl, but we would need to have | ||
201 | * an inode for that to work, and we do not always have one. | ||
202 | */ | 209 | */ |
203 | 210 | static unsigned int sr_check_events(struct cdrom_device_info *cdi, | |
204 | static int sr_media_change(struct cdrom_device_info *cdi, int slot) | 211 | unsigned int clearing, int slot) |
205 | { | 212 | { |
206 | struct scsi_cd *cd = cdi->handle; | 213 | struct scsi_cd *cd = cdi->handle; |
207 | int retval; | 214 | bool last_present; |
208 | struct scsi_sense_hdr *sshdr; | 215 | struct scsi_sense_hdr sshdr; |
216 | unsigned int events; | ||
217 | int ret; | ||
209 | 218 | ||
210 | if (CDSL_CURRENT != slot) { | 219 | /* no changer support */ |
211 | /* no changer support */ | 220 | if (CDSL_CURRENT != slot) |
212 | return -EINVAL; | 221 | return 0; |
213 | } | ||
214 | 222 | ||
215 | sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL); | 223 | events = sr_get_events(cd->device); |
216 | retval = sr_test_unit_ready(cd->device, sshdr); | 224 | /* |
217 | if (retval || (scsi_sense_valid(sshdr) && | 225 | * GET_EVENT_STATUS_NOTIFICATION is enough unless MEDIA_CHANGE |
218 | /* 0x3a is medium not present */ | 226 | * is being cleared. Note that there are devices which hang |
219 | sshdr->asc == 0x3a)) { | 227 | * if asked to execute TUR repeatedly. |
220 | /* Media not present or unable to test, unit probably not | 228 | */ |
221 | * ready. This usually means there is no disc in the drive. | 229 | if (!(clearing & DISK_EVENT_MEDIA_CHANGE)) |
222 | * Mark as changed, and we will figure it out later once | 230 | goto skip_tur; |
223 | * the drive is available again. | 231 | |
224 | */ | 232 | /* let's see whether the media is there with TUR */ |
225 | cd->device->changed = 1; | 233 | last_present = cd->media_present; |
226 | /* This will force a flush, if called from check_disk_change */ | 234 | ret = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr); |
227 | retval = 1; | 235 | |
228 | goto out; | 236 | /* |
229 | }; | 237 | * Media is considered to be present if TUR succeeds or fails with |
238 | * sense data indicating something other than media-not-present | ||
239 | * (ASC 0x3a). | ||
240 | */ | ||
241 | cd->media_present = scsi_status_is_good(ret) || | ||
242 | (scsi_sense_valid(&sshdr) && sshdr.asc != 0x3a); | ||
230 | 243 | ||
231 | retval = cd->device->changed; | 244 | if (last_present != cd->media_present) |
232 | cd->device->changed = 0; | 245 | events |= DISK_EVENT_MEDIA_CHANGE; |
233 | /* If the disk changed, the capacity will now be different, | 246 | skip_tur: |
234 | * so we force a re-read of this information */ | 247 | if (cd->device->changed) { |
235 | if (retval) { | 248 | events |= DISK_EVENT_MEDIA_CHANGE; |
236 | /* check multisession offset etc */ | 249 | cd->device->changed = 0; |
237 | sr_cd_check(cdi); | ||
238 | get_sectorsize(cd); | ||
239 | } | 250 | } |
240 | 251 | ||
241 | out: | 252 | /* for backward compatibility */ |
242 | /* Notify userspace, that media has changed. */ | 253 | if (events & DISK_EVENT_MEDIA_CHANGE) |
243 | if (retval != cd->previous_state) | ||
244 | sdev_evt_send_simple(cd->device, SDEV_EVT_MEDIA_CHANGE, | 254 | sdev_evt_send_simple(cd->device, SDEV_EVT_MEDIA_CHANGE, |
245 | GFP_KERNEL); | 255 | GFP_KERNEL); |
246 | cd->previous_state = retval; | 256 | return events; |
247 | kfree(sshdr); | ||
248 | |||
249 | return retval; | ||
250 | } | 257 | } |
251 | 258 | ||
252 | /* | 259 | /* |
253 | * sr_done is the interrupt routine for the device driver. | 260 | * sr_done is the interrupt routine for the device driver. |
254 | * | 261 | * |
@@ -533,10 +540,25 @@ out: | |||
533 | return ret; | 540 | return ret; |
534 | } | 541 | } |
535 | 542 | ||
536 | static int sr_block_media_changed(struct gendisk *disk) | 543 | static unsigned int sr_block_check_events(struct gendisk *disk, |
544 | unsigned int clearing) | ||
537 | { | 545 | { |
538 | struct scsi_cd *cd = scsi_cd(disk); | 546 | struct scsi_cd *cd = scsi_cd(disk); |
539 | return cdrom_media_changed(&cd->cdi); | 547 | return cdrom_check_events(&cd->cdi, clearing); |
548 | } | ||
549 | |||
550 | static int sr_block_revalidate_disk(struct gendisk *disk) | ||
551 | { | ||
552 | struct scsi_cd *cd = scsi_cd(disk); | ||
553 | struct scsi_sense_hdr sshdr; | ||
554 | |||
555 | /* if the unit is not ready, nothing more to do */ | ||
556 | if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr)) | ||
557 | return 0; | ||
558 | |||
559 | sr_cd_check(&cd->cdi); | ||
560 | get_sectorsize(cd); | ||
561 | return 0; | ||
540 | } | 562 | } |
541 | 563 | ||
542 | static const struct block_device_operations sr_bdops = | 564 | static const struct block_device_operations sr_bdops = |
@@ -545,7 +567,8 @@ static const struct block_device_operations sr_bdops = | |||
545 | .open = sr_block_open, | 567 | .open = sr_block_open, |
546 | .release = sr_block_release, | 568 | .release = sr_block_release, |
547 | .ioctl = sr_block_ioctl, | 569 | .ioctl = sr_block_ioctl, |
548 | .media_changed = sr_block_media_changed, | 570 | .check_events = sr_block_check_events, |
571 | .revalidate_disk = sr_block_revalidate_disk, | ||
549 | /* | 572 | /* |
550 | * No compat_ioctl for now because sr_block_ioctl never | 573 | * No compat_ioctl for now because sr_block_ioctl never |
551 | * seems to pass arbitary ioctls down to host drivers. | 574 | * seems to pass arbitary ioctls down to host drivers. |
@@ -618,6 +641,7 @@ static int sr_probe(struct device *dev) | |||
618 | sprintf(disk->disk_name, "sr%d", minor); | 641 | sprintf(disk->disk_name, "sr%d", minor); |
619 | disk->fops = &sr_bdops; | 642 | disk->fops = &sr_bdops; |
620 | disk->flags = GENHD_FL_CD; | 643 | disk->flags = GENHD_FL_CD; |
644 | disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST; | ||
621 | 645 | ||
622 | blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT); | 646 | blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT); |
623 | 647 | ||
@@ -627,7 +651,7 @@ static int sr_probe(struct device *dev) | |||
627 | cd->disk = disk; | 651 | cd->disk = disk; |
628 | cd->capacity = 0x1fffff; | 652 | cd->capacity = 0x1fffff; |
629 | cd->device->changed = 1; /* force recheck CD type */ | 653 | cd->device->changed = 1; /* force recheck CD type */ |
630 | cd->previous_state = 1; | 654 | cd->media_present = 1; |
631 | cd->use = 1; | 655 | cd->use = 1; |
632 | cd->readcd_known = 0; | 656 | cd->readcd_known = 0; |
633 | cd->readcd_cdda = 0; | 657 | cd->readcd_cdda = 0; |
@@ -780,7 +804,7 @@ static void get_capabilities(struct scsi_cd *cd) | |||
780 | } | 804 | } |
781 | 805 | ||
782 | /* eat unit attentions */ | 806 | /* eat unit attentions */ |
783 | sr_test_unit_ready(cd->device, &sshdr); | 807 | scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr); |
784 | 808 | ||
785 | /* ask for mode page 0x2a */ | 809 | /* ask for mode page 0x2a */ |
786 | rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, | 810 | rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, |
diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h index 1e144dfdbd4b..e036f1dc83c8 100644 --- a/drivers/scsi/sr.h +++ b/drivers/scsi/sr.h | |||
@@ -40,7 +40,7 @@ typedef struct scsi_cd { | |||
40 | unsigned xa_flag:1; /* CD has XA sectors ? */ | 40 | unsigned xa_flag:1; /* CD has XA sectors ? */ |
41 | unsigned readcd_known:1; /* drive supports READ_CD (0xbe) */ | 41 | unsigned readcd_known:1; /* drive supports READ_CD (0xbe) */ |
42 | unsigned readcd_cdda:1; /* reading audio data using READ_CD */ | 42 | unsigned readcd_cdda:1; /* reading audio data using READ_CD */ |
43 | unsigned previous_state:1; /* media has changed */ | 43 | unsigned media_present:1; /* media is present */ |
44 | struct cdrom_device_info cdi; | 44 | struct cdrom_device_info cdi; |
45 | /* We hold gendisk and scsi_device references on probe and use | 45 | /* We hold gendisk and scsi_device references on probe and use |
46 | * the refs on this kref to decide when to release them */ | 46 | * the refs on this kref to decide when to release them */ |
@@ -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" */ |