[SCSI] sd: implement sd_check_events()
Replace sd_media_change() with sd_check_events(). * Move media removed logic into set_media_not_present() and media_not_present() and set sdev->changed iff an existing media is removed or the device indicates UNIT_ATTENTION. * Make sd_check_events() sets sdev->changed if previously missing media becomes present. * Event is reported only if sdev->changed is set. This makes media presence event reported if scsi_disk->media_present actually changed or the device indicated UNIT_ATTENTION. For backward compatibility, SDEV_EVT_MEDIA_CHANGE is generated each time sd_check_events() detects media change event. [jejb: fix boot failure] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Jens Axboe <jaxboe@fusionio.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
This commit is contained in:
parent
52cfd503ad
commit
2bae0093ca
|
@ -990,30 +990,51 @@ out:
|
||||||
|
|
||||||
static void set_media_not_present(struct scsi_disk *sdkp)
|
static void set_media_not_present(struct scsi_disk *sdkp)
|
||||||
{
|
{
|
||||||
|
if (sdkp->media_present)
|
||||||
|
sdkp->device->changed = 1;
|
||||||
|
|
||||||
|
if (sdkp->device->removable) {
|
||||||
sdkp->media_present = 0;
|
sdkp->media_present = 0;
|
||||||
sdkp->capacity = 0;
|
sdkp->capacity = 0;
|
||||||
sdkp->device->changed = 1;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int media_not_present(struct scsi_disk *sdkp,
|
||||||
|
struct scsi_sense_hdr *sshdr)
|
||||||
|
{
|
||||||
|
if (!scsi_sense_valid(sshdr))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* not invoked for commands that could return deferred errors */
|
||||||
|
switch (sshdr->sense_key) {
|
||||||
|
case UNIT_ATTENTION:
|
||||||
|
case NOT_READY:
|
||||||
|
/* medium not present */
|
||||||
|
if (sshdr->asc == 0x3A) {
|
||||||
|
set_media_not_present(sdkp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sd_media_changed - check if our medium changed
|
* sd_check_events - check media events
|
||||||
* @disk: kernel device descriptor
|
* @disk: kernel device descriptor
|
||||||
|
* @clearing: disk events currently being cleared
|
||||||
*
|
*
|
||||||
* Returns 0 if not applicable or no change; 1 if change
|
* Returns mask of DISK_EVENT_*.
|
||||||
*
|
*
|
||||||
* Note: this function is invoked from the block subsystem.
|
* Note: this function is invoked from the block subsystem.
|
||||||
**/
|
**/
|
||||||
static int sd_media_changed(struct gendisk *disk)
|
static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
|
||||||
{
|
{
|
||||||
struct scsi_disk *sdkp = scsi_disk(disk);
|
struct scsi_disk *sdkp = scsi_disk(disk);
|
||||||
struct scsi_device *sdp = sdkp->device;
|
struct scsi_device *sdp = sdkp->device;
|
||||||
struct scsi_sense_hdr *sshdr = NULL;
|
struct scsi_sense_hdr *sshdr = NULL;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_media_changed\n"));
|
SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_check_events\n"));
|
||||||
|
|
||||||
if (!sdp->removable)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the device is offline, don't send any commands - just pretend as
|
* If the device is offline, don't send any commands - just pretend as
|
||||||
|
@ -1043,40 +1064,37 @@ static int sd_media_changed(struct gendisk *disk)
|
||||||
sshdr);
|
sshdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval) {
|
/* failed to execute TUR, assume media not present */
|
||||||
|
if (host_byte(retval)) {
|
||||||
set_media_not_present(sdkp);
|
set_media_not_present(sdkp);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (media_not_present(sdkp, sshdr))
|
||||||
|
goto out;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For removable scsi disk we have to recognise the presence
|
* For removable scsi disk we have to recognise the presence
|
||||||
* of a disk in the drive. This is kept in the struct scsi_disk
|
* of a disk in the drive.
|
||||||
* struct and tested at open ! Daniel Roche (dan@lectra.fr)
|
|
||||||
*/
|
*/
|
||||||
|
if (!sdkp->media_present)
|
||||||
|
sdp->changed = 1;
|
||||||
sdkp->media_present = 1;
|
sdkp->media_present = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
/*
|
/*
|
||||||
* Report a media change under the following conditions:
|
* sdp->changed is set under the following conditions:
|
||||||
*
|
*
|
||||||
* Medium is present now and wasn't present before.
|
* Medium present state has changed in either direction.
|
||||||
* Medium wasn't present before and is present now.
|
* Device has indicated UNIT_ATTENTION.
|
||||||
* Medium was present at all times, but it changed while
|
|
||||||
* we weren't looking (sdp->changed is set).
|
|
||||||
*
|
*
|
||||||
* If there was no medium before and there is no medium now then
|
* Report SDEV_EVT_MEDIA_CHANGE too for backward compatibility.
|
||||||
* don't report a change, even if a medium was inserted and removed
|
|
||||||
* while we weren't looking.
|
|
||||||
*/
|
*/
|
||||||
retval = (sdkp->media_present != sdkp->previous_state ||
|
if (sdp->changed)
|
||||||
(sdkp->media_present && sdp->changed));
|
|
||||||
if (retval)
|
|
||||||
sdev_evt_send_simple(sdp, SDEV_EVT_MEDIA_CHANGE, GFP_KERNEL);
|
sdev_evt_send_simple(sdp, SDEV_EVT_MEDIA_CHANGE, GFP_KERNEL);
|
||||||
sdkp->previous_state = sdkp->media_present;
|
|
||||||
|
|
||||||
/* sdp->changed indicates medium was changed or is not present */
|
|
||||||
sdp->changed = !sdkp->media_present;
|
|
||||||
kfree(sshdr);
|
kfree(sshdr);
|
||||||
|
|
||||||
|
retval = sdp->changed ? DISK_EVENT_MEDIA_CHANGE : 0;
|
||||||
|
sdp->changed = 0;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1169,7 +1187,7 @@ static const struct block_device_operations sd_fops = {
|
||||||
#ifdef CONFIG_COMPAT
|
#ifdef CONFIG_COMPAT
|
||||||
.compat_ioctl = sd_compat_ioctl,
|
.compat_ioctl = sd_compat_ioctl,
|
||||||
#endif
|
#endif
|
||||||
.media_changed = sd_media_changed,
|
.check_events = sd_check_events,
|
||||||
.revalidate_disk = sd_revalidate_disk,
|
.revalidate_disk = sd_revalidate_disk,
|
||||||
.unlock_native_capacity = sd_unlock_native_capacity,
|
.unlock_native_capacity = sd_unlock_native_capacity,
|
||||||
};
|
};
|
||||||
|
@ -1312,23 +1330,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)
|
||||||
return good_bytes;
|
return good_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int media_not_present(struct scsi_disk *sdkp,
|
|
||||||
struct scsi_sense_hdr *sshdr)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!scsi_sense_valid(sshdr))
|
|
||||||
return 0;
|
|
||||||
/* not invoked for commands that could return deferred errors */
|
|
||||||
if (sshdr->sense_key != NOT_READY &&
|
|
||||||
sshdr->sense_key != UNIT_ATTENTION)
|
|
||||||
return 0;
|
|
||||||
if (sshdr->asc != 0x3A) /* medium not present */
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
set_media_not_present(sdkp);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* spinup disk - called only in sd_revalidate_disk()
|
* spinup disk - called only in sd_revalidate_disk()
|
||||||
*/
|
*/
|
||||||
|
@ -1503,7 +1504,7 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
|
||||||
*/
|
*/
|
||||||
if (sdp->removable &&
|
if (sdp->removable &&
|
||||||
sense_valid && sshdr->sense_key == NOT_READY)
|
sense_valid && sshdr->sense_key == NOT_READY)
|
||||||
sdp->changed = 1;
|
set_media_not_present(sdkp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We used to set media_present to 0 here to indicate no media
|
* We used to set media_present to 0 here to indicate no media
|
||||||
|
@ -2389,8 +2390,10 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
|
||||||
|
|
||||||
gd->driverfs_dev = &sdp->sdev_gendev;
|
gd->driverfs_dev = &sdp->sdev_gendev;
|
||||||
gd->flags = GENHD_FL_EXT_DEVT;
|
gd->flags = GENHD_FL_EXT_DEVT;
|
||||||
if (sdp->removable)
|
if (sdp->removable) {
|
||||||
gd->flags |= GENHD_FL_REMOVABLE;
|
gd->flags |= GENHD_FL_REMOVABLE;
|
||||||
|
gd->events |= DISK_EVENT_MEDIA_CHANGE;
|
||||||
|
}
|
||||||
|
|
||||||
add_disk(gd);
|
add_disk(gd);
|
||||||
sd_dif_config_host(sdkp);
|
sd_dif_config_host(sdkp);
|
||||||
|
@ -2472,7 +2475,6 @@ static int sd_probe(struct device *dev)
|
||||||
sdkp->disk = gd;
|
sdkp->disk = gd;
|
||||||
sdkp->index = index;
|
sdkp->index = index;
|
||||||
atomic_set(&sdkp->openers, 0);
|
atomic_set(&sdkp->openers, 0);
|
||||||
sdkp->previous_state = 1;
|
|
||||||
|
|
||||||
if (!sdp->request_queue->rq_timeout) {
|
if (!sdp->request_queue->rq_timeout) {
|
||||||
if (sdp->type != TYPE_MOD)
|
if (sdp->type != TYPE_MOD)
|
||||||
|
|
|
@ -55,7 +55,6 @@ struct scsi_disk {
|
||||||
u8 media_present;
|
u8 media_present;
|
||||||
u8 write_prot;
|
u8 write_prot;
|
||||||
u8 protection_type;/* Data Integrity Field */
|
u8 protection_type;/* Data Integrity Field */
|
||||||
unsigned previous_state : 1;
|
|
||||||
unsigned ATO : 1; /* state of disk ATO bit */
|
unsigned ATO : 1; /* state of disk ATO bit */
|
||||||
unsigned WCE : 1; /* state of disk WCE bit */
|
unsigned WCE : 1; /* state of disk WCE bit */
|
||||||
unsigned RCD : 1; /* state of disk RCD bit, unused */
|
unsigned RCD : 1; /* state of disk RCD bit, unused */
|
||||||
|
|
Loading…
Reference in New Issue