Skip to content

Commit

Permalink
Merge branch 'for-2.6.38/event-handling' into for-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Axboe committed Dec 16, 2010
2 parents c4ffa14 + c8d2e93 commit 8ae47c1
Show file tree
Hide file tree
Showing 15 changed files with 779 additions and 270 deletions.
544 changes: 516 additions & 28 deletions block/genhd.c

Large diffs are not rendered by default.

55 changes: 52 additions & 3 deletions drivers/cdrom/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,10 @@ static int cdrom_select_disc(struct cdrom_device_info *cdi, int slot)
if (!CDROM_CAN(CDC_SELECT_DISC))
return -EDRIVE_CANT_DO_THIS;

(void) cdi->ops->media_changed(cdi, slot);
if (cdi->ops->check_events)
cdi->ops->check_events(cdi, 0, slot);
else
cdi->ops->media_changed(cdi, slot);

if (slot == CDSL_NONE) {
/* set media changed bits, on both queues */
Expand Down Expand Up @@ -1392,6 +1395,41 @@ static int cdrom_select_disc(struct cdrom_device_info *cdi, int slot)
return slot;
}

/*
* As cdrom implements an extra ioctl consumer for media changed
* event, it needs to buffer ->check_events() output, such that event
* is not lost for both the usual VFS and ioctl paths.
* cdi->{vfs|ioctl}_events are used to buffer pending events for each
* path.
*
* XXX: Locking is non-existent. cdi->ops->check_events() can be
* called in parallel and buffering fields are accessed without any
* exclusion. The original media_changed code had the same problem.
* It might be better to simply deprecate CDROM_MEDIA_CHANGED ioctl
* and remove this cruft altogether. It doesn't have much usefulness
* at this point.
*/
static void cdrom_update_events(struct cdrom_device_info *cdi,
unsigned int clearing)
{
unsigned int events;

events = cdi->ops->check_events(cdi, clearing, CDSL_CURRENT);
cdi->vfs_events |= events;
cdi->ioctl_events |= events;
}

unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
unsigned int clearing)
{
unsigned int events;

cdrom_update_events(cdi, clearing);
events = cdi->vfs_events;
cdi->vfs_events = 0;
return events;
}

/* We want to make media_changed accessible to the user through an
* ioctl. The main problem now is that we must double-buffer the
* low-level implementation, to assure that the VFS and the user both
Expand All @@ -1403,15 +1441,26 @@ int media_changed(struct cdrom_device_info *cdi, int queue)
{
unsigned int mask = (1 << (queue & 1));
int ret = !!(cdi->mc_flags & mask);
bool changed;

if (!CDROM_CAN(CDC_MEDIA_CHANGED))
return ret;
return ret;

/* changed since last call? */
if (cdi->ops->media_changed(cdi, CDSL_CURRENT)) {
if (cdi->ops->check_events) {
BUG_ON(!queue); /* shouldn't be called from VFS path */
cdrom_update_events(cdi, DISK_EVENT_MEDIA_CHANGE);
changed = cdi->ioctl_events & DISK_EVENT_MEDIA_CHANGE;
cdi->ioctl_events = 0;
} else
changed = cdi->ops->media_changed(cdi, CDSL_CURRENT);

if (changed) {
cdi->mc_flags = 0x3; /* set bit on both queues */
ret |= 1;
cdi->media_written = 0;
}

cdi->mc_flags &= ~mask; /* clear bit */
return ret;
}
Expand Down
13 changes: 1 addition & 12 deletions drivers/scsi/scsi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,8 +1984,7 @@ EXPORT_SYMBOL(scsi_mode_sense);
* in.
*
* Returns zero if unsuccessful or an error if TUR failed. For
* removable media, a return of NOT_READY or UNIT_ATTENTION is
* translated to success, with the ->changed flag updated.
* removable media, UNIT_ATTENTION sets ->changed flag.
**/
int
scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries,
Expand All @@ -2012,16 +2011,6 @@ scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries,
} while (scsi_sense_valid(sshdr) &&
sshdr->sense_key == UNIT_ATTENTION && --retries);

if (!sshdr)
/* could not allocate sense buffer, so can't process it */
return result;

if (sdev->removable && scsi_sense_valid(sshdr) &&
(sshdr->sense_key == UNIT_ATTENTION ||
sshdr->sense_key == NOT_READY)) {
sdev->changed = 1;
result = 0;
}
if (!sshdr_external)
kfree(sshdr);
return result;
Expand Down
95 changes: 47 additions & 48 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,30 +991,50 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,

static void set_media_not_present(struct scsi_disk *sdkp)
{
if (sdkp->media_present)
sdkp->device->changed = 1;
sdkp->media_present = 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:
sdkp->device->changed = 1;
/* fall through */
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
* @disk: kernel device descriptor
* sd_check_events - check media events
* @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.
**/
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_device *sdp = sdkp->device;
struct scsi_sense_hdr *sshdr = NULL;
int retval;

SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_media_changed\n"));

if (!sdp->removable)
return 0;
SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_check_events\n"));

/*
* If the device is offline, don't send any commands - just pretend as
Expand All @@ -1024,7 +1044,6 @@ static int sd_media_changed(struct gendisk *disk)
*/
if (!scsi_device_online(sdp)) {
set_media_not_present(sdkp);
retval = 1;
goto out;
}

Expand All @@ -1045,34 +1064,30 @@ static int sd_media_changed(struct gendisk *disk)
sshdr);
}

/*
* 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.
*/
if (retval || (scsi_sense_valid(sshdr) &&
/* 0x3a is medium not present */
sshdr->asc == 0x3a)) {
/* failed to execute TUR, assume media not present */
if (host_byte(retval)) {
set_media_not_present(sdkp);
retval = 1;
goto out;
}

if (media_not_present(sdkp, sshdr))
goto out;

/*
* For removable scsi disk we have to recognise the presence
* of a disk in the drive. This is kept in the struct scsi_disk
* struct and tested at open ! Daniel Roche (dan@lectra.fr)
* of a disk in the drive.
*/
if (!sdkp->media_present)
sdp->changed = 1;
sdkp->media_present = 1;

retval = sdp->changed;
sdp->changed = 0;
out:
if (retval != sdkp->previous_state)
/* for backward compatibility */
if (sdp->changed)
sdev_evt_send_simple(sdp, SDEV_EVT_MEDIA_CHANGE, GFP_KERNEL);
sdkp->previous_state = retval;
kfree(sshdr);

retval = sdp->changed ? DISK_EVENT_MEDIA_CHANGE : 0;
sdp->changed = 0;
return retval;
}

Expand Down Expand Up @@ -1165,7 +1180,7 @@ static const struct block_device_operations sd_fops = {
#ifdef CONFIG_COMPAT
.compat_ioctl = sd_compat_ioctl,
#endif
.media_changed = sd_media_changed,
.check_events = sd_check_events,
.revalidate_disk = sd_revalidate_disk,
.unlock_native_capacity = sd_unlock_native_capacity,
};
Expand Down Expand Up @@ -1301,23 +1316,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)
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()
*/
Expand Down Expand Up @@ -1492,7 +1490,7 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
*/
if (sdp->removable &&
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
Expand Down Expand Up @@ -2347,8 +2345,10 @@ static void sd_probe_async(void *data, async_cookie_t cookie)

gd->driverfs_dev = &sdp->sdev_gendev;
gd->flags = GENHD_FL_EXT_DEVT;
if (sdp->removable)
if (sdp->removable) {
gd->flags |= GENHD_FL_REMOVABLE;
gd->events |= DISK_EVENT_MEDIA_CHANGE;
}

add_disk(gd);
sd_dif_config_host(sdkp);
Expand Down Expand Up @@ -2430,7 +2430,6 @@ static int sd_probe(struct device *dev)
sdkp->disk = gd;
sdkp->index = index;
atomic_set(&sdkp->openers, 0);
sdkp->previous_state = 1;

if (!sdp->request_queue->rq_timeout) {
if (sdp->type != TYPE_MOD)
Expand Down
1 change: 0 additions & 1 deletion drivers/scsi/sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ struct scsi_disk {
u8 media_present;
u8 write_prot;
u8 protection_type;/* Data Integrity Field */
unsigned previous_state : 1;
unsigned ATO : 1; /* state of disk ATO bit */
unsigned WCE : 1; /* state of disk WCE bit */
unsigned RCD : 1; /* state of disk RCD bit, unused */
Expand Down
Loading

0 comments on commit 8ae47c1

Please sign in to comment.