block: Convert block drivers to ->check_events(), take#2
Subsystems (6)
PATCH 1/1 block: Convert block drivers to ->check_events(), take#2
Hello,
This is the second take of convert-block-drivers-to-check_events patchset. Other than addition of Acked-by's and rebasing on top of the current block:for-2.6.39/core (df457f845e), nothing really changed.
This patchset converts all in-kernel block drivers from ->media_changed() to ->check_events(). Most conversions are fairly mechanical. The only notable exceptions are,
* 0014-umem: media_changed was dummy. As ->check_events() can be omitted, just drop it.
* 0015-pktcdvd: inherits and forwards ->check_events() instead of ->media_changed() from the underlying device.
This patchset contains the following sixteen patches.
0001-block-Don-t-implicitly-trigger-event-check-on-disk_u.patch 0002-block-Don-t-check-events-on-close-unless-it-was-bloc.patch 0003-block-Don-t-check-events-while-open-is-in-progress.patch 0004-ide-Convert-to-bdops-check_events.patch 0005-floppy-ami-ata-flop-Convert-to-bdops-check_events.patch 0006-gdrom-viocd-Convert-to-bdops-check_events.patch 0007-paride-Convert-to-bdops-check_events.patch 0008-dac960-Convert-to-bdops-check_events.patch 0009-swim-3-Convert-to-bdops-check_events.patch 0010-ub-Convert-to-bdops-check_events.patch 0011-xsysace-Convert-to-bdops-check_events.patch 0012-i2o_block-Convert-to-bdops-check_events.patch 0013-s390-tape_block-Convert-to-bdops-check_events.patch 0014-umem-Drop-dummy-media_changed.patch 0015-pktcdvd-Convert-to-bdops-check_events.patch 0016-staging-Convert-to-bdops-check_events.patch
0001-0003 prepare for further conversions. Some of the conversions are not very well behaved in that they may generate spurious events and allow event polling between event clearing check and the actual clearing. These three patches modify the disk event check behavior such that such faults can be tolerated.
0004-0016 convert all block drivers. Conversions are mostly mechanical, all changes except for one of the staging driver are compile-tested and ide is verified to behave correctly after the conversion.
This patchset is available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git disk-event-convert
HEAD is 7904f29ceb3847e7bb8f3296b406c54b8856de56. As git.korg may take some time to sync, if you're seeing an old commit, please pull from master.korg.
ssh://master.kernel.org/pub/scm/linux/kernel/git/tj/misc.git disk-event-convert
diffstat follows.
block/genhd.c | 2 - drivers/block/DAC960.c | 8 +++-- drivers/block/amiflop.c | 9 +++--- drivers/block/ataflop.c | 14 +++++---- drivers/block/floppy.c | 10 ++++-- drivers/block/paride/pcd.c | 18 +++++++----- drivers/block/paride/pd.c | 7 ++-- drivers/block/paride/pf.c | 10 ++++-- drivers/block/pktcdvd.c | 13 ++++++-- drivers/block/swim.c | 8 +++-- drivers/block/swim3.c | 11 ++++--- drivers/block/ub.c | 10 ++++-- drivers/block/umem.c | 10 ------ drivers/block/xsysace.c | 9 +++--- drivers/cdrom/gdrom.c | 16 ++++++---- drivers/cdrom/viocd.c | 17 ++++++----- drivers/ide/ide-cd.c | 10 ++++-- drivers/ide/ide-cd.h | 3 +- drivers/ide/ide-cd_ioctl.c | 8 ++--- drivers/ide/ide-gd.c | 14 +++++---- drivers/message/i2o/i2o_block.c | 11 ++++--- drivers/s390/char/tape_block.c | 11 ++++--- drivers/staging/hv/blkvsc_drv.c | 11 ++++--- drivers/staging/westbridge/astoria/block/cyasblkdev_block.c | 11 ++++--- fs/block_dev.c | 11 ++++--- 25 files changed, 152 insertions(+), 110 deletions(-)
Thanks.
--
tejun
PATCH 4/16 ide: Convert to bdops->check_events()
Convert ->media_changed() to the new ->check_events() method. The conversion is mostly mechanical. The only notable change is that cdrom now doesn't generate any event if @slot_nr isn't CDSL_CURRENT. It used to return -EINVAL which would be treated as media changed. As media changer isn't supported anyway, this doesn't make any difference.
This makes ide emit the standard disk events and allows kernel event polling. Currently, only MEDIA_CHANGE event is implemented. Adding support for EJECT_REQUEST shouldn't be difficult; however, given that ide driver is already deprecated, it probably is best to leave it alone.
--- drivers/ide/ide-cd.c | 10 ++++++---- drivers/ide/ide-cd.h | 3 ++- drivers/ide/ide-cd_ioctl.c | 8 ++++---- drivers/ide/ide-gd.c | 14 ++++++++------ 4 files changed, 20 insertions(+), 15 deletions(-)
drivers/ide/ide-cd.c +6 -4
@@ -1177,7 +1177,7 @@ static struct cdrom_device_ops ide_cdrom_dops = { .open = ide_cdrom_open_real, .release = ide_cdrom_release_real, .drive_status = ide_cdrom_drive_status, - .media_changed = ide_cdrom_check_media_change_real, + .check_events = ide_cdrom_check_events_real, .tray_move = ide_cdrom_tray_move, .lock_door = ide_cdrom_lock_door, .select_speed = ide_cdrom_select_speed,
@@ -1702,10 +1702,11 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode, } -static int idecd_media_changed (struct gendisk *disk) +static unsigned int idecd_check_events (struct gendisk *disk, +unsigned int clearing) {struct cdrom_info *info =ide_drv_g (disk, cdrom_info); -return cdrom_media_changed (&info->devinfo); +return cdrom_check_events (&info->devinfo, clearing); }static int idecd_revalidate_disk (struct gendisk *disk)
@@ -1723,7 +1724,7 @@ static const struct block_device_operations idecd_ops = { .open = idecd_open, .release = idecd_release, .ioctl = idecd_ioctl, - .media_changed = idecd_media_changed, + .check_events = idecd_check_events, .revalidate_disk = idecd_revalidate_disk };
@@ -1790,6 +1791,7 @@ static int ide_cd_probe(ide_drive_t *drive)ide_cd_read_toc (drive, &sense); g->fops = &idecd_ops; g->flags |=GENHD_FL_REMOVABLE ; + g->events =DISK_EVENT_MEDIA_CHANGE ;add_disk (g);return 0 ;
drivers/ide/ide-cd.h +2 -1
@@ -111,7 +111,8 @@ int cdrom_check_status(ide_drive_t *, struct request_sense *);int ide_cdrom_open_real (struct cdrom_device_info *,int );void ide_cdrom_release_real (struct cdrom_device_info *);int ide_cdrom_drive_status (struct cdrom_device_info *,int ); -int ide_cdrom_check_media_change_real (struct cdrom_device_info *,int ); +unsigned int ide_cdrom_check_events_real (struct cdrom_device_info *, +unsigned int clearing,int slot_nr);int ide_cdrom_tray_move (struct cdrom_device_info *,int );int ide_cdrom_lock_door (struct cdrom_device_info *,int );int ide_cdrom_select_speed (struct cdrom_device_info *,int );
drivers/ide/ide-cd_ioctl.c +4 -4
@@ -79,8 +79,8 @@ int ide_cdrom_drive_status(struct cdrom_device_info *cdi, int slot_nr)return CDS_DRIVE_NOT_READY ; } -int ide_cdrom_check_media_change_real (struct cdrom_device_info *cdi, -int slot_nr) +unsigned int ide_cdrom_check_events_real (struct cdrom_device_info *cdi, +unsigned int clearing,int slot_nr) {ide_drive_t *drive = cdi->handle;int retval;
@@ -89,9 +89,9 @@ int ide_cdrom_check_media_change_real(struct cdrom_device_info *cdi, (void )cdrom_check_status (drive,NULL ); retval = (drive->dev_flags &IDE_DFLAG_MEDIA_CHANGED ) ?1 :0 ; drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED ; -return retval; +return retval ?DISK_EVENT_MEDIA_CHANGE :0 ; }else { -return -EINVAL ; +return 0 ; } }
drivers/ide/ide-gd.c +8 -6
@@ -285,11 +285,12 @@ static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)return 0 ; } -static int ide_gd_media_changed (struct gendisk *disk) +static unsigned int ide_gd_check_events (struct gendisk *disk, +unsigned int clearing) {struct ide_disk_obj *idkp =ide_drv_g (disk, ide_disk_obj);ide_drive_t *drive = idkp->drive; -int ret; +bool ret;/* do not scan partitions twice if this is a removable device */ if (drive->dev_flags &IDE_DFLAG_ATTACH ) {
@@ -297,10 +298,10 @@ static int ide_gd_media_changed(struct gendisk *disk)return 0 ; } - ret = !!(drive->dev_flags &IDE_DFLAG_MEDIA_CHANGED ); + ret = drive->dev_flags &IDE_DFLAG_MEDIA_CHANGED ; drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED ; -return ret; +return ret ?DISK_EVENT_MEDIA_CHANGE :0 ; }static void ide_gd_unlock_native_capacity (struct gendisk *disk)
@@ -318,7 +319,7 @@ static int ide_gd_revalidate_disk(struct gendisk *disk)struct ide_disk_obj *idkp =ide_drv_g (disk, ide_disk_obj);ide_drive_t *drive = idkp->drive; -if (ide_gd_media_changed (disk)) +if (ide_gd_check_events (disk,0 )) drive->disk_ops->get_capacity (drive);set_capacity (disk,ide_gd_capacity (drive));
@@ -340,7 +341,7 @@ static const struct block_device_operations ide_gd_ops = { .release = ide_gd_release, .ioctl = ide_gd_ioctl, .getgeo = ide_gd_getgeo, - .media_changed = ide_gd_media_changed, + .check_events = ide_gd_check_events, .unlock_native_capacity = ide_gd_unlock_native_capacity, .revalidate_disk = ide_gd_revalidate_disk };
@@ -412,6 +413,7 @@ static int ide_gd_probe(ide_drive_t *drive)if (drive->dev_flags &IDE_DFLAG_REMOVABLE ) g->flags =GENHD_FL_REMOVABLE ; g->fops = &ide_gd_ops; + g->events =DISK_EVENT_MEDIA_CHANGE ;add_disk (g);return 0 ;
Signature · 1 line
1.7.1
PATCH 6/16 gdrom,viocd: Convert to bdops->check_events()
In reply to Tejun HeoConvert gdrom and viocd from ->media_changed() to ->check_events().
It's unclear how the conditions are cleared and it's possible that it may generate spurious events when polled.
--- drivers/cdrom/gdrom.c | 16 ++++++++++------ drivers/cdrom/viocd.c | 17 ++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/cdrom/gdrom.c +10 -6
@@ -395,10 +395,12 @@ static int gdrom_drivestatus(struct cdrom_device_info *cd_info, int ignore)return CDS_NO_INFO ; } -static int gdrom_mediachanged (struct cdrom_device_info *cd_info,int ignore) +static unsigned int gdrom_check_events (struct cdrom_device_info *cd_info, +unsigned int clearing,int ignore) {/* check the sense key */ -return (__raw_readb (GDROM_ERROR_REG ) &0xF0 ) ==0x60 ; +return (__raw_readb (GDROM_ERROR_REG ) &0xF0 ) ==0x60 ? +DISK_EVENT_MEDIA_CHANGE :0 ; }/* reset the G1 bus */
@@ -483,7 +485,7 @@ static struct cdrom_device_ops gdrom_ops = { .open = gdrom_open, .release = gdrom_release, .drive_status = gdrom_drivestatus, - .media_changed = gdrom_mediachanged, + .check_events = gdrom_check_events, .get_last_session = gdrom_get_last_session, .reset = gdrom_hardreset, .audio_ioctl = gdrom_audio_ioctl,
@@ -509,9 +511,10 @@ static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode)return 0 ; } -static int gdrom_bdops_mediachanged (struct gendisk *disk) +static unsigned int gdrom_bdops_check_events (struct gendisk *disk, +unsigned int clearing) { -return cdrom_media_changed (gd.cd_info); +return cdrom_check_events (gd.cd_info, clearing); } static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode,
@@ -530,7 +533,7 @@ static const struct block_device_operations gdrom_bdops = { .owner = THIS_MODULE, .open = gdrom_bdops_open, .release = gdrom_bdops_release, - .media_changed = gdrom_bdops_mediachanged, + .check_events = gdrom_bdops_check_events, .ioctl = gdrom_bdops_ioctl, };
@@ -800,6 +803,7 @@ static int __devinit probe_gdrom(struct platform_device *devptr) goto probe_fail_cdrom_register; } gd.disk->fops = &gdrom_bdops; + gd.disk->events =DISK_EVENT_MEDIA_CHANGE ;/* latch on to the interrupt */ err =gdrom_set_interrupt_handlers ();if (err)
drivers/cdrom/viocd.c +10 -7
@@ -186,10 +186,11 @@ static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode,return ret; } -static int viocd_blk_media_changed (struct gendisk *disk) +static unsigned int viocd_blk_check_events (struct gendisk *disk, +unsigned int clearing) {struct disk_info *di = disk->private_data; -return cdrom_media_changed (&di->viocd_info); +return cdrom_check_events (&di->viocd_info, clearing); }static const struct block_device_operations viocd_fops = {
@@ -197,7 +198,7 @@ static const struct block_device_operations viocd_fops = { .open = viocd_blk_open, .release = viocd_blk_release, .ioctl = viocd_blk_ioctl, - .media_changed = viocd_blk_media_changed, + .check_events = viocd_blk_check_events, };static int viocd_open (struct cdrom_device_info *cdi,int purpose)
@@ -320,7 +321,8 @@ static void do_viocd_request(struct request_queue *q) } } -static int viocd_media_changed (struct cdrom_device_info *cdi,int disc_nr) +static unsigned int viocd_check_events (struct cdrom_device_info *cdi, +unsigned int clearing,int disc_nr) {struct viocd_waitevent we;HvLpEvent_Rc hvrc;
@@ -340,7 +342,7 @@ static int viocd_media_changed(struct cdrom_device_info *cdi, int disc_nr)if (hvrc !=0 ) {pr_warning ("bad rc on HvCallEvent_signalLpEventFast %d\n" , (int )hvrc); -return -EIO ; +return 0 ; }wait_for_completion (&we.com);
@@ -354,7 +356,7 @@ static int viocd_media_changed(struct cdrom_device_info *cdi, int disc_nr)return 0 ; } -return we.changed; +return we.changed ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int viocd_lock_door (struct cdrom_device_info *cdi,int locking)
@@ -550,7 +552,7 @@ static int viocd_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd,static struct cdrom_device_ops viocd_dops = { .open = viocd_open, .release = viocd_release, - .media_changed = viocd_media_changed, + .check_events = viocd_check_events, .lock_door = viocd_lock_door, .generic_packet = viocd_packet, .audio_ioctl = viocd_audio_ioctl,
@@ -624,6 +626,7 @@ static int viocd_probe(struct vio_dev *vdev, const struct vio_device_id *id) gendisk->queue = q; gendisk->fops = &viocd_fops; gendisk->flags =GENHD_FL_CD |GENHD_FL_REMOVABLE ; + gendisk->events =DISK_EVENT_MEDIA_CHANGE ;set_capacity (gendisk,0 ); gendisk->private_data = d; d->viocd_disk = gendisk;
Signature · 1 line
1.7.1
PATCH 7/16 paride: Convert to bdops->check_events()
In reply to Tejun HeoConvert paride drivers from ->media_changed() to ->check_events().
pcd and pd buffer and clear events after reporting; however, pf unconditionally reports MEDIA_CHANGE and will generate spurious events when polled.
--- drivers/block/paride/pcd.c | 18 +++++++++++------- drivers/block/paride/pd.c | 7 ++++--- drivers/block/paride/pf.c | 10 ++++++---- 3 files changed, 21 insertions(+), 14 deletions(-)
drivers/block/paride/pcd.c +11 -7
@@ -172,7 +172,8 @@ module_param_array(drive3, int, NULL, 0);static int pcd_open (struct cdrom_device_info *cdi,int purpose);static void pcd_release (struct cdrom_device_info *cdi);static int pcd_drive_status (struct cdrom_device_info *cdi,int slot_nr); -static int pcd_media_changed (struct cdrom_device_info *cdi,int slot_nr); +static unsigned int pcd_check_events (struct cdrom_device_info *cdi, +unsigned int clearing,int slot_nr);static int pcd_tray_move (struct cdrom_device_info *cdi,int position);static int pcd_lock_door (struct cdrom_device_info *cdi,int lock);static int pcd_drive_reset (struct cdrom_device_info *cdi);
@@ -257,10 +258,11 @@ static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,return ret; } -static int pcd_block_media_changed (struct gendisk *disk) +static unsigned int pcd_block_check_events (struct gendisk *disk, +unsigned int clearing) {struct pcd_unit *cd = disk->private_data; -return cdrom_media_changed (&cd->info); +return cdrom_check_events (&cd->info, clearing); }static const struct block_device_operations pcd_bdops = {
@@ -268,14 +270,14 @@ static const struct block_device_operations pcd_bdops = { .open = pcd_block_open, .release = pcd_block_release, .ioctl = pcd_block_ioctl, - .media_changed = pcd_block_media_changed, + .check_events = pcd_block_check_events, };static struct cdrom_device_ops pcd_dops = { .open = pcd_open, .release = pcd_release, .drive_status = pcd_drive_status, - .media_changed = pcd_media_changed, + .check_events = pcd_check_events, .tray_move = pcd_tray_move, .lock_door = pcd_lock_door, .get_mcn = pcd_get_mcn,
@@ -318,6 +320,7 @@ static void pcd_init_units(void) disk->first_minor = unit;strcpy (disk->disk_name, cd->name);/* umm... */ disk->fops = &pcd_bdops; + disk->events =DISK_EVENT_MEDIA_CHANGE ; } }
@@ -502,13 +505,14 @@ static int pcd_packet(struct cdrom_device_info *cdi, struct packet_command *cgc)#define DBMSG (msg) ((verbose>1)?(msg):NULL) -static int pcd_media_changed (struct cdrom_device_info *cdi,int slot_nr) +static unsigned int pcd_check_events (struct cdrom_device_info *cdi, +unsigned int clearing,int slot_nr) {struct pcd_unit *cd = cdi->handle;int res = cd->changed;if (res) cd->changed =0 ; -return res; +return res ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int pcd_lock_door (struct cdrom_device_info *cdi,int lock)
drivers/block/paride/pd.c +4 -3
@@ -794,7 +794,7 @@ static int pd_release(struct gendisk *p, fmode_t mode)return 0 ; } -static int pd_check_media (struct gendisk *p) +static unsigned int pd_check_events (struct gendisk *p,unsigned int clearing) {struct pd_unit *disk = p->private_data;int r;
@@ -803,7 +803,7 @@ static int pd_check_media(struct gendisk *p)pd_special_command (disk, pd_media_check); r = disk->changed; disk->changed =0 ; -return r; +return r ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int pd_revalidate (struct gendisk *p)
@@ -822,7 +822,7 @@ static const struct block_device_operations pd_fops = { .release = pd_release, .ioctl = pd_ioctl, .getgeo = pd_getgeo, - .media_changed = pd_check_media, + .check_events = pd_check_events, .revalidate_disk= pd_revalidate };
@@ -837,6 +837,7 @@ static void pd_probe_drive(struct pd_unit *disk) p->fops = &pd_fops; p->major = major; p->first_minor = (disk - pd) <<PD_BITS ; + p->events =DISK_EVENT_MEDIA_CHANGE ; disk->gd = p; p->private_data = disk; p->queue = pd_queue;
drivers/block/paride/pf.c +6 -4
@@ -243,7 +243,8 @@ static struct pf_unit units[PF_UNITS];static int pf_identify (struct pf_unit *pf);static void pf_lock (struct pf_unit *pf,int func);static void pf_eject (struct pf_unit *pf); -static int pf_check_media (struct gendisk *disk); +static unsigned int pf_check_events (struct gendisk *disk, +unsigned int clearing);static char pf_scratch[512 ];/* scratch block buffer */
@@ -270,7 +271,7 @@ static const struct block_device_operations pf_fops = { .release = pf_release, .ioctl = pf_ioctl, .getgeo = pf_getgeo, - .media_changed = pf_check_media, + .check_events = pf_check_events, };static void __init pf_init_units (void )
@@ -293,6 +294,7 @@ static void __init pf_init_units(void) disk->first_minor = unit;strcpy (disk->disk_name, pf->name); disk->fops = &pf_fops; + disk->events =DISK_EVENT_MEDIA_CHANGE ;if (!(*drives[unit])[D_PRT ]) pf_drive_count++; }
@@ -377,9 +379,9 @@ static int pf_release(struct gendisk *disk, fmode_t mode) } -static int pf_check_media (struct gendisk *disk) +static unsigned int pf_check_events (struct gendisk *disk,unsigned int clearing) { -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; }static inline int status_reg (struct pf_unit *pf)
Signature · 1 line
1.7.1
PATCH 8/16 dac960: Convert to bdops->check_events()
In reply to Tejun HeoConvert from ->media_changed() to ->check_events().
DAC960 media change notification seems to be one way (once set, never cleared) and will generate spurious events when polled once the condition triggers.
--- drivers/block/DAC960.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/block/DAC960.c +5 -3
@@ -140,13 +140,14 @@ static int DAC960_getgeo(struct block_device *bdev, struct hd_geometry *geo)return 0 ; } -static int DAC960_media_changed (struct gendisk *disk) +static unsigned int DAC960_check_events (struct gendisk *disk, +unsigned int clearing) {DAC960_Controller_T *p = disk->queue->queuedata;int drive_nr = (long )disk->private_data;if (!p->LogicalDriveInitiallyAccessible[drive_nr]) -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ;return 0 ; }
@@ -163,7 +164,7 @@ static const struct block_device_operations DAC960_BlockDeviceOperations = { .owner = THIS_MODULE, .open = DAC960_open, .getgeo = DAC960_getgeo, - .media_changed = DAC960_media_changed, + .check_events = DAC960_check_events, .revalidate_disk = DAC960_revalidate_disk, };
@@ -2546,6 +2547,7 @@ static bool DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller) disk->major = MajorNumber; disk->first_minor = n << DAC960_MaxPartitionsBits; disk->fops = &DAC960_BlockDeviceOperations; + disk->events =DISK_EVENT_MEDIA_CHANGE ; }/* Indicate the Block Device Registration completed successfully,
Signature · 1 line
1.7.1
PATCH 11/16 xsysace: Convert to bdops->check_events()
In reply to Tejun HeoConvert from ->media_changed() to ->check_events().
xsysace buffers media changed state and clears it on revalidation. It will behave correctly with kernel event polling.
--- drivers/block/xsysace.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
drivers/block/xsysace.c +5 -4
@@ -867,12 +867,12 @@ static void ace_request(struct request_queue * q) } } -static int ace_media_changed (struct gendisk *gd) +static unsigned int ace_check_events (struct gendisk *gd,unsigned int clearing) {struct ace_device *ace = gd->private_data; -dev_dbg (ace->dev,"ace_media_changed(): %i\n" , ace->media_change); +dev_dbg (ace->dev,"ace_check_events(): %i\n" , ace->media_change); -return ace->media_change; +return ace->media_change ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int ace_revalidate_disk (struct gendisk *gd)
@@ -953,7 +953,7 @@ static const struct block_device_operations ace_fops = { .owner = THIS_MODULE, .open = ace_open, .release = ace_release, - .media_changed = ace_media_changed, + .check_events = ace_check_events, .revalidate_disk = ace_revalidate_disk, .getgeo = ace_getgeo, };
@@ -1005,6 +1005,7 @@ static int __devinit ace_setup(struct ace_device *ace) ace->gd->major = ace_major; ace->gd->first_minor = ace->id *ACE_NUM_MINORS ; ace->gd->fops = &ace_fops; + ace->gd->events =DISK_EVENT_MEDIA_CHANGE ; ace->gd->queue = ace->queue; ace->gd->private_data = ace;snprintf (ace->gd->disk_name,32 ,"xs%c" , ace->id +'a' );
Signature · 1 line
1.7.1
PATCH 10/16 ub: Convert to bdops->check_events()
In reply to Tejun HeoConvert from ->media_changed() to ->check_events().
ub buffers media changed state and clears it on revalidation. It will behave correctly with kernel event polling.
--- drivers/block/ub.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/block/ub.c +6 -4
@@ -1788,7 +1788,8 @@ static int ub_bd_revalidate(struct gendisk *disk)* * The return code is bool! */ -static int ub_bd_media_changed (struct gendisk *disk) +static unsigned int ub_bd_check_events (struct gendisk *disk, +unsigned int clearing) {struct ub_lun *lun = disk->private_data;
@@ -1806,10 +1807,10 @@ static int ub_bd_media_changed(struct gendisk *disk)*/ if (ub_sync_tur (lun->udev, lun) !=0 ) { lun->changed =1 ; -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; } -return lun->changed; +return lun->changed ?DISK_EVENT_MEDIA_CHANGE :0 ; }static const struct block_device_operations ub_bd_fops = {
@@ -1817,7 +1818,7 @@ static const struct block_device_operations ub_bd_fops = { .open = ub_bd_unlocked_open, .release = ub_bd_release, .ioctl = ub_bd_ioctl, - .media_changed = ub_bd_media_changed, + .check_events = ub_bd_check_events, .revalidate_disk = ub_bd_revalidate, };
@@ -2333,6 +2334,7 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum) disk->major =UB_MAJOR ; disk->first_minor = lun->id *UB_PARTS_PER_LUN ; disk->fops = &ub_bd_fops; + disk->events =DISK_EVENT_MEDIA_CHANGE ; disk->private_data = lun; disk->driverfs_dev = &sc->intf->dev;
Signature · 1 line
1.7.1
PATCH 1/16 block: Don't implicitly trigger event check on disk_unblock_events()
In reply to Tejun HeoCurrently, disk_unblock_events() implicitly kick event check if the block count reaches zero. This behavior is not described in the comment and hinders with future changes. Make the unblocker explicitly check events by calling disk_check_events() as necessary.
This patch doesn't cause any behavior difference.
--- block/genhd.c | 2 +- fs/block_dev.c | 1 + 2 files changed, 2 insertions(+), 1 deletions(-)
block/genhd.c +1 -1
@@ -1494,7 +1494,7 @@ void disk_block_events(struct gendisk *disk)void disk_unblock_events (struct gendisk *disk) {if (disk->ev) -__disk_unblock_events (disk, true); +__disk_unblock_events (disk, false); }/**
fs/block_dev.c +1 -0
@@ -1446,6 +1446,7 @@ int blkdev_put(struct block_device *bdev, fmode_t mode)if (bdev_free) {if (bdev->bd_write_holder) {disk_unblock_events (bdev->bd_disk); +disk_check_events (bdev->bd_disk); bdev->bd_write_holder = false; }else disk_check_events (bdev->bd_disk);
Signature · 1 line
1.7.1
PATCH 3/16 block: Don't check events while open is in progress
In reply to Tejun HeoNot all block drivers clear events immediately after reporting. Some do so in ->revalidate_disk() or other steps during ->open(). There is a slim chance event poll may happen between the clearing event check from check_disk_change() and the actual clearing of the events which would result in spurious events.
Block event checks while block device open is in progress. There is no need to kick explicit event check afterwards as events are always checked during open.
--- fs/block_dev.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
fs/block_dev.c +4 -0
@@ -1087,6 +1087,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)if (!disk) goto out; +disk_block_events (disk);mutex_lock_nested (&bdev->bd_mutex, for_part);if (!bdev->bd_openers) { bdev->bd_disk = disk;
@@ -1112,6 +1113,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)put_disk (disk); bdev->bd_disk =NULL ;mutex_unlock (&bdev->bd_mutex); +disk_unblock_events (disk); goto restart; }if (ret)
@@ -1165,6 +1167,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)if (for_part) bdev->bd_part_count++;mutex_unlock (&bdev->bd_mutex); +disk_unblock_events (disk);return 0 ; out_clear:
@@ -1177,6 +1180,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) bdev->bd_contains =NULL ; out_unlock_bdev:mutex_unlock (&bdev->bd_mutex); +disk_unblock_events (disk); out:if (disk)module_put (disk->fops->owner);
Signature · 1 line
1.7.1
PATCH 2/16 block: Don't check events on close unless it was blocked
In reply to Tejun HeoThe block event mechanism currently always checks events when the device is being closed regardless of the open mode. The intention was to allow detection of EJECT_REQUEST when a device is closed whether disk event polling is enabled or not.
This is unnecessary as, for devices of interest, events are checked from either userland or kernel and in the former case ->check_events() is performed on open of each poll attempt anyway. Furthermore, this unconditional event check on close makes the code susceptible to event loop if the block driver doesn't clear reported events correctly - an event triggers userland to open and close the device which in turn causes another event, rinse and repeat.
Check events on close only if it was blocked by excl write open.
--- fs/block_dev.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
fs/block_dev.c +2 -4
@@ -1448,13 +1448,11 @@ int blkdev_put(struct block_device *bdev, fmode_t mode)disk_unblock_events (bdev->bd_disk);disk_check_events (bdev->bd_disk); bdev->bd_write_holder = false; - }else -disk_check_events (bdev->bd_disk); + } }mutex_unlock (&bdev->bd_mutex); - }else -disk_check_events (bdev->bd_disk); + }return __blkdev_put (bdev, mode,0 ); }
Signature · 1 line
1.7.1
PATCH 5/16 floppy,{ami|ata}flop: Convert to bdops->check_events()
In reply to Tejun HeoConvert the floppy drivers from ->media_changed() to ->check_events(). Both floppy and ataflop buffer media changed state bit and clear them on revalidation and will behave correctly with kernel event polling.
I can't tell how amiflop clears its event and it's possible that it may generate spurious events when polled.
--- drivers/block/amiflop.c | 9 +++++---- drivers/block/ataflop.c | 14 ++++++++------ drivers/block/floppy.c | 10 ++++++---- 3 files changed, 19 insertions(+), 14 deletions(-)
drivers/block/amiflop.c +5 -4
@@ -1658,12 +1658,12 @@ static int floppy_release(struct gendisk *disk, fmode_t mode) }/* -* floppy-change is never called from an interrupt, so we can relax a bit +* check_events is never called from an interrupt, so we can relax a bit * here, sleep etc. Note that floppy-on tries to set current_DOR to point * to the desired drive, but it will probably not survive the sleep if * several floppies are used at the same time: thus the loop. */ -static int amiga_floppy_change (struct gendisk *disk) +static unsigned amiga_check_events (struct gendisk *disk,unsigned int clearing) {struct amiga_floppy_struct *p = disk->private_data;int drive = p - unit;
@@ -1686,7 +1686,7 @@ static int amiga_floppy_change(struct gendisk *disk) p->dirty =0 ; writepending =0 ;/* if this was true before, too bad! */ writefromint =0 ; -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; }return 0 ; }
@@ -1697,7 +1697,7 @@ static const struct block_device_operations floppy_fops = { .release = floppy_release, .ioctl = fd_ioctl, .getgeo = fd_getgeo, - .media_changed = amiga_floppy_change, + .check_events = amiga_check_events, };static int __init fd_probe_drives (void )
@@ -1736,6 +1736,7 @@ static int __init fd_probe_drives(void) disk->major =FLOPPY_MAJOR ; disk->first_minor = drive; disk->fops = &floppy_fops; + disk->events =DISK_EVENT_MEDIA_CHANGE ;sprintf (disk->disk_name,"fd%d" , drive); disk->private_data = &unit[drive];set_capacity (disk,880 *2 );
drivers/block/ataflop.c +8 -6
@@ -1324,23 +1324,24 @@ static void finish_fdc_done( int dummy )* due to unrecognised disk changes. */ -static int check_floppy_change (struct gendisk *disk) +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing) {struct atari_floppy_struct *p = disk->private_data;unsigned int drive = p - unit;if (test_bit (drive, &fake_change)) {/* simulated change (e.g. after formatting) */ -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; }if (test_bit (drive, &changed_floppies)) {/* surely changed (the WP signal changed at least once) */ -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; }if (UD .wpstat) {/* WP is on -> could be changed: to be sure, buffers should be * invalidated... */ -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; }return 0 ;
@@ -1570,7 +1571,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode,* or the next access will revalidate - and clear UDT :-( */ -if (check_floppy_change (disk)) +if (floppy_check_events (disk,0 ))floppy_revalidate (disk);if (UD .flags &FTD_MSG )
@@ -1904,7 +1905,7 @@ static const struct block_device_operations floppy_fops = { .open = floppy_unlocked_open, .release = floppy_release, .ioctl = fd_ioctl, - .media_changed = check_floppy_change, + .check_events = floppy_check_events, .revalidate_disk= floppy_revalidate, };
@@ -1963,6 +1964,7 @@ static int __init atari_floppy_init (void) unit[i].disk->first_minor = i;sprintf (unit[i].disk->disk_name,"fd%d" , i); unit[i].disk->fops = &floppy_fops; + unit[i].disk->events =DISK_EVENT_MEDIA_CHANGE ; unit[i].disk->private_data = &unit[i]; unit[i].disk->queue =blk_init_queue (do_fd_request, &ataflop_lock);
drivers/block/floppy.c +6 -4
@@ -3770,13 +3770,14 @@ out2:/* * Check if the disk has been changed or if a change has been faked. */ -static int check_floppy_change (struct gendisk *disk) +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing) {int drive = (long )disk->private_data;if (test_bit (FD_DISK_CHANGED_BIT , &UDRS ->flags) ||test_bit (FD_VERIFY_BIT , &UDRS ->flags)) -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ;if (time_after (jiffies,UDRS ->last_checked +UDP ->checkfreq)) {lock_fdc (drive, false);
@@ -3788,7 +3789,7 @@ static int check_floppy_change(struct gendisk *disk)test_bit (FD_VERIFY_BIT , &UDRS ->flags) ||test_bit (drive, &fake_change) || drive_no_geom(drive)) - return 1; + return DISK_EVENT_MEDIA_CHANGE;return 0 ; }
@@ -3898,7 +3899,7 @@ static const struct block_device_operations floppy_fops = { .release = floppy_release, .ioctl = fd_ioctl, .getgeo = fd_getgeo, - .media_changed = check_floppy_change, + .check_events = floppy_check_events, .revalidate_disk = floppy_revalidate, };
@@ -4205,6 +4206,7 @@ static int __init floppy_init(void) disks[dr]->major =FLOPPY_MAJOR ; disks[dr]->first_minor =TOMINOR (dr); disks[dr]->fops = &floppy_fops; + disks[dr]->events =DISK_EVENT_MEDIA_CHANGE ;sprintf (disks[dr]->disk_name,"fd%d" , dr);init_timer (&motor_off_timer[dr]);
Signature · 1 line
1.7.1
PATCH 13/16 s390/tape_block: Convert to bdops->check_events()
In reply to Tejun HeoConvert from ->media_changed() to ->check_events().
s390/tape_block buffers media changed state and clears it on revalidation. It will behave correctly with kernel event polling.
--- drivers/s390/char/tape_block.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
drivers/s390/char/tape_block.c +6 -5
@@ -48,14 +48,14 @@static DEFINE_MUTEX (tape_block_mutex);static int tapeblock_open (struct block_device *,fmode_t );static int tapeblock_release (struct gendisk *,fmode_t ); -static int tapeblock_medium_changed (struct gendisk *); +static unsigned int tapeblock_check_events (struct gendisk *,unsigned int );static int tapeblock_revalidate_disk (struct gendisk *);static const struct block_device_operations tapeblock_fops = { .owner =THIS_MODULE , .open = tapeblock_open, .release = tapeblock_release, - .media_changed = tapeblock_medium_changed, + .check_events = tapeblock_check_events, .revalidate_disk = tapeblock_revalidate_disk, };
@@ -237,6 +237,7 @@ tapeblock_setup_device(struct tape_device * device) disk->major = tapeblock_major; disk->first_minor = device->first_minor; disk->fops = &tapeblock_fops; + disk->events =DISK_EVENT_MEDIA_CHANGE ; disk->private_data =tape_get_device (device); disk->queue = blkdat->request_queue;set_capacity (disk,0 );
@@ -340,8 +341,8 @@ tapeblock_revalidate_disk(struct gendisk *disk)return 0 ; } -static int -tapeblock_medium_changed (struct gendisk *disk) +static unsigned int +tapeblock_check_events (struct gendisk *disk,unsigned int clearing) {struct tape_device *device;
@@ -349,7 +350,7 @@ tapeblock_medium_changed(struct gendisk *disk)DBF_LH (6 ,"tapeblock_medium_changed(%p) = %d\n" , device, device->blk_data.medium_changed); -return device->blk_data.medium_changed; +return device->blk_data.medium_changed ?DISK_EVENT_MEDIA_CHANGE :0 ; }/*
Signature · 1 line
1.7.1
PATCH 9/16 swim[3]: Convert to bdops->check_events()
In reply to Tejun HeoConvert from ->media_changed() to ->check_events().
Both swim and swim3 buffer media changed state and clear it on revalidation. They will behave correctly with kernel event polling.
--- drivers/block/swim.c | 8 +++++--- drivers/block/swim3.c | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/block/swim.c +5 -3
@@ -741,11 +741,12 @@ static int floppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)return 0 ; } -static int floppy_check_change (struct gendisk *disk) +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing) {struct floppy_state *fs = disk->private_data; -return fs->ejected; +return fs->ejected ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int floppy_revalidate (struct gendisk *disk)
@@ -772,7 +773,7 @@ static const struct block_device_operations floppy_fops = { .release = floppy_release, .ioctl = floppy_ioctl, .getgeo = floppy_getgeo, - .media_changed = floppy_check_change, + .check_events = floppy_check_events, .revalidate_disk = floppy_revalidate, };
@@ -857,6 +858,7 @@ static int __devinit swim_floppy_init(struct swim_priv *swd) swd->unit[drive].disk->first_minor = drive;sprintf (swd->unit[drive].disk->disk_name,"fd%d" , drive); swd->unit[drive].disk->fops = &floppy_fops; + swd->unit[drive].disk->events =DISK_EVENT_MEDIA_CHANGE ; swd->unit[drive].disk->private_data = &swd->unit[drive]; swd->unit[drive].disk->queue = swd->queue;set_capacity (swd->unit[drive].disk,2880 );
drivers/block/swim3.c +7 -4
@@ -250,7 +250,8 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long param);static int floppy_open (struct block_device *bdev,fmode_t mode);static int floppy_release (struct gendisk *disk,fmode_t mode); -static int floppy_check_change (struct gendisk *disk); +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing);static int floppy_revalidate (struct gendisk *disk);static bool swim3_end_request (int err,unsigned int nr_bytes)
@@ -975,10 +976,11 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)return 0 ; } -static int floppy_check_change (struct gendisk *disk) +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing) {struct floppy_state *fs = disk->private_data; -return fs->ejected; +return fs->ejected ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int floppy_revalidate (struct gendisk *disk)
@@ -1025,7 +1027,7 @@ static const struct block_device_operations floppy_fops = { .open = floppy_unlocked_open, .release = floppy_release, .ioctl = floppy_ioctl, - .media_changed = floppy_check_change, + .check_events = floppy_check_events, .revalidate_disk= floppy_revalidate, };
@@ -1161,6 +1163,7 @@ static int __devinit swim3_attach(struct macio_dev *mdev, const struct of_device disk->major =FLOPPY_MAJOR ; disk->first_minor = i; disk->fops = &floppy_fops; + disk->events =DISK_EVENT_MEDIA_CHANGE ; disk->private_data = &floppy_states[i]; disk->queue = swim3_queue; disk->flags |=GENHD_FL_REMOVABLE ;
Signature · 1 line
1.7.1
PATCH 16/16 staging: Convert to bdops->check_events()
In reply to Tejun HeoConvert two staging drivers - blkvsc_drv and cyasblkdev_block - from ->media_changed() to ->check_events(). The former always indicated media changed while the latter always indicated media not changed. Not sure what the drivers are trying to achieve but keep the original behavior.
--- drivers/staging/hv/blkvsc_drv.c | 11 +++++++---- .../westbridge/astoria/block/cyasblkdev_block.c | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/staging/hv/blkvsc_drv.c +7 -4
@@ -131,7 +131,8 @@ static void blkvsc_shutdown(struct device *device);static int blkvsc_open (struct block_device *bdev,fmode_t mode);static int blkvsc_release (struct gendisk *disk,fmode_t mode); -static int blkvsc_media_changed (struct gendisk *gd); +static unsigned int blkvsc_check_events (struct gendisk *gd, +unsigned int clearing);static int blkvsc_revalidate_disk (struct gendisk *gd);static int blkvsc_getgeo (struct block_device *bd,struct hd_geometry *hg); static int blkvsc_ioctl(struct block_device *bd, fmode_t mode,
@@ -162,7 +163,7 @@ static const struct block_device_operations block_ops = { .owner = THIS_MODULE, .open = blkvsc_open, .release = blkvsc_release, - .media_changed = blkvsc_media_changed, + .check_events = blkvsc_check_events, .revalidate_disk = blkvsc_revalidate_disk, .getgeo = blkvsc_getgeo, .ioctl = blkvsc_ioctl,
@@ -367,6 +368,7 @@ static int blkvsc_probe(struct device *device)else blkdev->gd->first_minor =0 ; blkdev->gd->fops = &block_ops; + blkdev->gd->events =DISK_EVENT_MEDIA_CHANGE ; blkdev->gd->private_data = blkdev; blkdev->gd->driverfs_dev = &(blkdev->device_ctx->device);sprintf (blkdev->gd->disk_name,"hd%c" ,'a' + devnum);
@@ -1352,10 +1354,11 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)return 0 ; } -static int blkvsc_media_changed (struct gendisk *gd) +static unsigned int blkvsc_check_events (struct gendisk *gd, +unsigned int clearing) {DPRINT_DBG (BLKVSC_DRV ,"- enter\n" ); -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; }static int blkvsc_revalidate_disk (struct gendisk *gd)
drivers/staging/westbridge/astoria/block/cyasblkdev_block.c +7 -4
@@ -381,10 +381,10 @@ static int cyasblkdev_blk_ioctl(return -ENOTTY ; } -/* Media_changed block_device opp +/* check_events block_device opp * this one is called by kernel to confirm if the media really changed * as we indicated by issuing check_disk_change() call */ -int cyasblkdev_media_changed (struct gendisk *gd) +unsigned int cyasblkdev_check_events (struct gendisk *gd,unsigned int clearing) {struct cyasblkdev_blk_data *bd;
@@ -402,7 +402,7 @@ int cyasblkdev_media_changed(struct gendisk *gd)#endif } -/* return media change state "1" yes, 0 no */ +/* return media change state - DISK_EVENT_MEDIA_CHANGE yes, 0 no */ return 0 ; }
@@ -432,7 +432,7 @@ static struct block_device_operations cyasblkdev_bdops = { .ioctl = cyasblkdev_blk_ioctl,/* .getgeo = cyasblkdev_blk_getgeo, */ /* added to support media removal( real and simulated) media */ - .media_changed = cyasblkdev_media_changed, + .check_events = cyasblkdev_check_events,/* added to support media removal( real and simulated) media */ .revalidate_disk = cyasblkdev_revalidate_disk, .owner = THIS_MODULE,
@@ -1090,6 +1090,7 @@ static int cyasblkdev_add_disks(int bus_num, bd->user_disk_0->first_minor = devidx <<CYASBLKDEV_SHIFT ; bd->user_disk_0->minors =8 ; bd->user_disk_0->fops = &cyasblkdev_bdops; + bd->user_disk_0->events =DISK_EVENT_MEDIA_CHANGE ; bd->user_disk_0->private_data = bd; bd->user_disk_0->queue = bd->queue.queue; bd->dbgprn_flags =DBGPRN_RD_RQ ;
@@ -1190,6 +1191,7 @@ static int cyasblkdev_add_disks(int bus_num, bd->user_disk_1->first_minor = (devidx +1 ) <<CYASBLKDEV_SHIFT ; bd->user_disk_1->minors =8 ; bd->user_disk_1->fops = &cyasblkdev_bdops; + bd->user_disk_0->events =DISK_EVENT_MEDIA_CHANGE ; bd->user_disk_1->private_data = bd; bd->user_disk_1->queue = bd->queue.queue; bd->dbgprn_flags =DBGPRN_RD_RQ ;
@@ -1278,6 +1280,7 @@ static int cyasblkdev_add_disks(int bus_num, (devidx +2 ) <<CYASBLKDEV_SHIFT ; bd->system_disk->minors =8 ; bd->system_disk->fops = &cyasblkdev_bdops; + bd->system_disk->events =DISK_EVENT_MEDIA_CHANGE ; bd->system_disk->private_data = bd; bd->system_disk->queue = bd->queue.queue;/* don't search for vfat
Signature · 1 line
1.7.1
PATCH 14/16 umem: Drop dummy ->media_changed()
In reply to Tejun Heoumem doesn't implement media changed detection and there's no need to implement dummy callback anymore. Remove it.
--- drivers/block/umem.c | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-)
drivers/block/umem.c +0 -10
@@ -779,20 +779,10 @@ static int mm_getgeo(struct block_device *bdev, struct hd_geometry *geo)return 0 ; } -/* -* Future support for removable devices -*/ -static int mm_check_change (struct gendisk *disk) -{ -/* struct cardinfo *dev = disk->private_data; */ -return 0 ; -} -static const struct block_device_operations mm_fops = { .owner =THIS_MODULE , .getgeo = mm_getgeo, .revalidate_disk = mm_revalidate, - .media_changed = mm_check_change, }; static int __devinit mm_pci_probe(struct pci_dev *dev,
Signature · 1 line
1.7.1
PATCH 15/16 pktcdvd: Convert to bdops->check_events()
In reply to Tejun HeoConvert from ->media_changed() to ->check_events().
pktcdvd needs to forward all event related operations to the underlying device. Forward ->check_events() instead of ->media_changed() and inherit disk->[async_]events.
--- drivers/block/pktcdvd.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
drivers/block/pktcdvd.c +9 -4
@@ -2796,7 +2796,8 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,return ret; } -static int pkt_media_changed (struct gendisk *disk) +static unsigned int pkt_check_events (struct gendisk *disk, +unsigned int clearing) {struct pktcdvd_device *pd = disk->private_data;struct gendisk *attached_disk;
@@ -2806,9 +2807,9 @@ static int pkt_media_changed(struct gendisk *disk)if (!pd->bdev)return 0 ; attached_disk = pd->bdev->bd_disk; -if (!attached_disk) +if (!attached_disk || !attached_disk->fops->check_events)return 0 ; -return attached_disk->fops->media_changed (attached_disk); +return attached_disk->fops->check_events (attached_disk, clearing); }static const struct block_device_operations pktcdvd_ops = {
@@ -2816,7 +2817,7 @@ static const struct block_device_operations pktcdvd_ops = { .open = pkt_open, .release = pkt_close, .ioctl = pkt_ioctl, - .media_changed = pkt_media_changed, + .check_events = pkt_check_events, };static char *pktcdvd_devnode (struct gendisk *gd,mode_t *mode)
@@ -2889,6 +2890,10 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)if (ret) goto out_new_dev; +/* inherit events of the host device */ + disk->events = pd->bdev->bd_disk->events; + disk->async_events = pd->bdev->bd_disk->async_events; +add_disk (disk);pkt_sysfs_dev_new (pd);
Signature · 1 line
1.7.1
PATCH 12/16 i2o_block: Convert to bdops->check_events()
In reply to Tejun HeoConvert from ->media_changed() to ->check_events().
i2o_block buffers media changed state and clears it after reporting. It will behave correctly with kernel event polling.
--- drivers/message/i2o/i2o_block.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/message/i2o/i2o_block.c +7 -4
@@ -695,20 +695,22 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode, };/** -* i2o_block_media_changed - Have we seen a media change? +* i2o_block_check_events - Have we seen a media change? * @disk: gendisk which should be verified +* @clearing: events being cleared * * Verifies if the media has changed. * * Returns 1 if the media was changed or 0 otherwise. */ -static int i2o_block_media_changed (struct gendisk *disk) +static unsigned int i2o_block_check_events (struct gendisk *disk, +unsigned int clearing) {struct i2o_block_device *p = disk->private_data;if (p->media_change_flag) { p->media_change_flag =0 ; -return 1 ; +return DISK_EVENT_MEDIA_CHANGE ; }return 0 ; }
@@ -950,7 +952,7 @@ static const struct block_device_operations i2o_block_fops = { .ioctl = i2o_block_ioctl, .compat_ioctl = i2o_block_ioctl, .getgeo = i2o_block_getgeo, - .media_changed = i2o_block_media_changed + .check_events = i2o_block_check_events, };/**
@@ -1002,6 +1004,7 @@ static struct i2o_block_device *i2o_block_device_alloc(void) gd->major =I2O_MAJOR ; gd->queue = queue; gd->fops = &i2o_block_fops; + gd->events =DISK_EVENT_MEDIA_CHANGE ; gd->private_data = dev; dev->gd = gd;
Signature · 1 line
1.7.1
Jens Axboe
maintainerQuoted 6 lines · Tejun Heo
Hello,
This is the second take of convert-block-drivers-to-check_events patchset. Other than addition of Acked-by's and rebasing on top of the current block:for-2.6.39/core (
df457f845e), nothing really changed.
Thanks Tejun, applied.
Signature · 1 line
Jens Axboe
Quoted 9 lines · Jens Axboe
Quoted 6 lines · Tejun Heo
Hello,
This is the second take of convert-block-drivers-to-check_events patchset. Other than addition of Acked-by's and rebasing on top of the current block:for-2.6.39/core (
df457f845e), nothing really changed.Thanks Tejun, applied.
No worky:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000238 IP: [<ffffffff81216741>] disk_unblock_events+0x1/0x20 PGD 87573c067 PUD 877a29067 PMD 0 Oops: 0000 [#1] PREEMPT SMP last sysfs file: /sys/devices/virtual/net/lo/operstate CPU 3 Modules linked in: hid_apple usbhid uhci_hcd
input: Mitsumi Electric Apple Extended USB Keyboard as /devices/pci0000:00/0000:00:1d.2/usb8/8-1/8-1.1/8-1.1.3/8-1.1.3:1.0/input/input6 generic-usb 0003:05AC:020B.0005: input: USB HID v1.10 Keyboard [Mitsumi Electric Apple Extended USB Keyboard] on usb-0000:00:1d.2-1.1.3/input0
input: Mitsumi Electric Apple Extended USB Keyboard as /devices/pci0000:00/0000:00:1d.2/usb8/8-1/8-1.1/8-1.1.3/8-1.1.3:1.1/input/input7 generic-usb 0003:05AC:020B.0006: input: USB HID v1.10 Device [Mitsumi Electric Apple Extended USB Keyboard] on usb-0000:00:1d.2-1.1.3/input1
ehci_hcd igb usbcore ahci libahci nls_base
Pid: 4283, comm: swapon Not tainted 2.6.38-rc6+ #40 QCI QSSC-S4R/QSSC-S4R
RIP: 0010:[<ffffffff81216741>] [<ffffffff81216741>] disk_unblock_events+0x1/0x20 RSP: 0018:ffff880674183b78 EFLAGS: 00010202 RAX: 0000000000000000 RBX: ffff8808774c5040 RCX: ffff880477b20800 RDX: ffff8808774c5040 RSI: 000000000000001d RDI: 0000000000000000 RBP: ffff880674183bd8 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000001 R11: 0000000000000010 R12: 0000000000000000 R13: ffff8808774c5060 R14: 0000000000000000 R15: 000000000000001d FS: 00007f8e9f34b740(0000) GS:ffff88087fc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000238 CR3: 0000000875761000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process swapon (pid: 4283, threadinfo ffff880674182000, task ffff880676632090) Stack: ffff880674183bd8 ffffffff8112a388 ffff8808774c5040 00000001812230c7 ffff880674183bb8 0000000076536c48 ffff880674183bb8 ffff8808775aaa80 ffff880276536c00 ffff8808775aaaa0 0000000000000004 000000000000001d Call Trace: [<ffffffff8112a388>] ? __blkdev_get+0x168/0x3b0 [<ffffffff8112a444>] __blkdev_get+0x224/0x3b0 [<ffffffff8112a8e0>] ? blkdev_open+0x0/0x80 [<ffffffff8112a61f>] blkdev_get+0x4f/0x310 [<ffffffff8112988a>] ? bdget+0x10a/0x120 [<ffffffff8112a8e0>] ? blkdev_open+0x0/0x80 [<ffffffff8112a940>] blkdev_open+0x60/0x80 [<ffffffff810f6410>] __dentry_open+0x100/0x360 [<ffffffff81101f9e>] ? generic_permission+0x1e/0xb0 [<ffffffff810f6791>] nameidata_to_filp+0x71/0x80 [<ffffffff81104318>] finish_open+0xc8/0x1a0 [<ffffffff8110598d>] ? do_path_lookup+0x5d/0xe0 [<ffffffff81106a7d>] do_filp_open+0x27d/0x7d0 [<ffffffff81114e91>] ? mntput_no_expire+0x71/0x1a0 [<ffffffff81112292>] ? alloc_fd+0xf2/0x140 [<ffffffff810f6214>] do_sys_open+0x64/0x110 [<ffffffff810f62eb>] sys_open+0x1b/0x20 [<ffffffff81002d3b>] system_call_fastpath+0x16/0x1b Code: ff ff ff 48 8b 1b 48 8b 03 48 81 fb 80 8f 5e 81 0f 18 08 75 e5 48 c7 c7 60 8f 5e 81 e8 59 30 1f 00 31 c0 48 83 c4 08 5b c9 c3 55 <48> 83 bf 38 02 00 00 00 48 89 e5 74 07 31 f6 e8 2b fe ff ff c9
Signature · 1 line
Jens Axboe
block: Fix oops caused by __blkdev_get() calling disk_unblock_events() with invalid @disk
Commit 57c966b8b2 (block: Don't check events while open is in progress) made __blkdev_get() block events around open calls; however, it used invalid @disk pointer in the following cases.
* When ->open() returns -ERESTARTSYS, disk_unblock_events() is called after @disk is put. @disk may be invalid by the time unblock is called.
This is fixed by moving references after disk_unblock_events().
* When there are multiple openers, @disk is cleared to %NULL and later disk_unblock_disk() is called with %NULL @disk causing oops.
This is fixed by moving reference putting after open success is determined and not clearing @disk to %NULL. On success, @disk is valid because there is another opener holding reference to it. On failure, the references are put after disk_unblock_events() is called.
---
Ah, sorry about that. My test setup didn't include a device with multiple partitions on it so the more than one opener case never triggered.
Thanks.
fs/block_dev.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/block_dev.c +6 -7
@@ -1109,11 +1109,11 @@ static int __blkdev_get(struct block_dev*/ disk_put_part (bdev->bd_part); bdev->bd_part =NULL ; -module_put (disk->fops->owner); -put_disk (disk); bdev->bd_disk =NULL ;mutex_unlock (&bdev->bd_mutex);disk_unblock_events (disk); +module_put (disk->fops->owner); +put_disk (disk); goto restart; }if (ret)
@@ -1150,9 +1150,6 @@ static int __blkdev_get(struct block_devbd_set_size (bdev, (loff_t )bdev->bd_part->nr_sects <<9 ); } }else { -module_put (disk->fops->owner); -put_disk (disk); - disk =NULL ;if (bdev->bd_contains == bdev) {if (bdev->bd_disk->fops->open) { ret = bdev->bd_disk->fops->open (bdev, mode);
@@ -1162,6 +1159,9 @@ static int __blkdev_get(struct block_devif (bdev->bd_invalidated)rescan_partitions (bdev->bd_disk, bdev); } +/* only one opener holds refs to the module and disk */ +module_put (disk->fops->owner); +put_disk (disk); } bdev->bd_openers++;if (for_part)
@@ -1182,8 +1182,7 @@ static int __blkdev_get(struct block_devmutex_unlock (&bdev->bd_mutex);disk_unblock_events (disk); out: -if (disk) -module_put (disk->fops->owner); +module_put (disk->fops->owner);put_disk (disk);bdput (bdev);
Re: [PATCH 10/16] ub: Convert to bdops->check_events()
In reply to Tejun Heodrivers/block/ub.c static int ub_bd_revalidate(struct gendisk *disk) · line 1795
Quoted 12 lines · On Wed, 9 Mar 2011 10:13:30 +0100 Tejun Heo <[email protected]> wrote:
+++
b/drivers/block/ub.cdrivers/block/ub.c +3
-2@@ -1788,7 +1788,8 @@ static int ub_bd_revalidate(struct gendisk *disk)* * The return code is bool! */ -static int ub_bd_media_changed(struct gendisk *disk) +static unsigned int ub_bd_check_events(struct gendisk *disk, + unsigned int clearing) - return lun->changed; + return lun->changed ? DISK_EVENT_MEDIA_CHANGE : 0; }
Return code is not so bool anymore. The comment meant that usually "int" means "return 0 on success, -1 on failure, maybe some integer for a tricky condition" but not here. I'll have the comment fixed up, or if you want you do it.
-- Pete
Re: [PATCH 10/16] ub: Convert to bdops->check_events()
Quoted 12 lines · Pete Zaitcev
Quoted 8 lines · On Wed, 9 Mar 2011 10:13:30 +0100 Tejun Heo <[email protected]> wrote:
+++
b/drivers/block/ub.cdrivers/block/ub.c +2
-1@@ -1788,7 +1788,8 @@ static int ub_bd_revalidate(struct gendisk *disk)* * The return code is bool! */ -static int ub_bd_media_changed (struct gendisk *disk) +static unsigned int ub_bd_check_events (struct gendisk *disk, +unsigned int clearing)
Quoted 8 lines
drivers/block/ub.c static int ub_bd_media_changed(struct gendisk *disk) · line 1814
Quoted 3 lines
drivers/block/ub.c +1
-1-return lun->changed; +return lun->changed ?DISK_EVENT_MEDIA_CHANGE :0 ; }Return code is not so bool anymore. The comment meant that usually "int" means "return 0 on success, -1 on failure, maybe some integer for a tricky condition" but not here. I'll have the comment fixed up, or if you want you do it.
Ooh, right. Please go ahead and fix that up.
Thank you.
Signature · 1 line
tejun
Jens Axboe
AppliedRe: block: Fix oops caused by __blkdev_get() calling disk_unblock_events() with invalid @disk
In reply to Tejun HeoQuoted 10 lines · Tejun Heo
Commit
57c966b8b2(block: Don't check events while open is in progress) made__blkdev_get()block events around open calls; however, it used invalid @disk pointer in the following cases.* When ->open() returns
-ERESTARTSYS,disk_unblock_events()is called after @disk is put. @disk may be invalid by the time unblock is called.This is fixed by moving references after
disk_unblock_events().
Quoted 8 lines
* When there are multiple openers, @disk is cleared to %NULL and later
disk_unblock_disk()is called with %NULL @disk causing oops.This is fixed by moving reference putting after open success is determined and not clearing @disk to %NULL. On success, @disk is valid because there is another opener holding reference to it. On failure, the references are put after
disk_unblock_events()is called.
Thanks, applied. A bit unfortunate to have a 100% crasher in the tree, though. Will suck for bisects.
Signature · 1 line
Jens Axboe
Re: block: Fix oops caused by __blkdev_get() calling disk_unblock_events() with invalid @disk
Quoted 8 lines · Jens Axboe
Quoted 5 lines
This is fixed by moving reference putting after open success is determined and not clearing @disk to %NULL. On success, @disk is valid because there is another opener holding reference to it. On failure, the references are put after
disk_unblock_events()is called.Thanks, applied. A bit unfortunate to have a 100% crasher in the tree, though. Will suck for bisects.
Yeah, that does suck. I folded in the fix to the offending commit and regenerated the tree in case you want to rebase the tree.
ssh://master.kernel.org/pub/scm/linux/kernel/git/tj/misc.git disk-event-convert-fixed
Thank you.
Signature · 1 line
tejun
Re: block: Fix oops caused by __blkdev_get() calling disk_unblock_events() with invalid @disk
Quoted 7 lines · Tejun Heo
Quoted 6 lines · Jens Axboe
Quoted 5 lines
This is fixed by moving reference putting after open success is determined and not clearing @disk to %NULL. On success, @disk is valid because there is another opener holding reference to it. On failure, the references are put after
disk_unblock_events()is called.
Quoted 7 lines
Quoted 2 lines
Thanks, applied. A bit unfortunate to have a 100% crasher in the tree, though. Will suck for bisects.
Yeah, that does suck. I folded in the fix to the offending commit and regenerated the tree in case you want to rebase the tree.
ssh://master.kernel.org/pub/scm/linux/kernel/git/tj/misc.git disk-event-convert-fixed
Thanks, but it's pretty deep in at this point. I'll take a look at it.
Signature · 1 line
Jens Axboe
Re: [PATCH 04/16] ide: Convert to bdops->check_events()
In reply to Tejun HeoFrom: Tejun Heo <[email protected]>
Date: Wed, 9 Mar 2011 10:13:24 +0100
Quoted 7 lines
Convert ->media_changed() to the new ->check_events() method. The conversion is mostly mechanical. The only notable change is that cdrom now doesn't generate any event if @slot_nr isn't
CDSL_CURRENT. It used to return-EINVALwhich would be treated as media changed. As media changer isn't supported anyway, this doesn't make any difference.
Quoted 8 lines
This makes ide emit the standard disk events and allows kernel event polling. Currently, only
MEDIA_CHANGEevent is implemented. Adding support forEJECT_REQUESTshouldn't be difficult; however, given that ide driver is already deprecated, it probably is best to leave it alone.Signed-off-by Tejun Heo <[email protected]>Acked-by Jens Axboe <[email protected]>
Re: [PATCH 09/16] swim[3]: Convert to bdops->check_events()
In reply to Tejun HeoQuoted 4 lines · Tejun Heo
Convert from ->media_changed() to ->check_events().
Both swim and swim3 buffer media changed state and clear it on revalidation. They will behave correctly with kernel event polling.
No objection. I don't have HW to test at the moment but it looks obvious enough provided you compiled tested it :
I'll try to dig HW later.
Cheers,
Ben.
Quoted 91 lines
Signed-off-by Tejun Heo <[email protected]>Cc Jens Axboe <[email protected]>Cc Kay Sievers <[email protected]>Cc Laurent Vivier <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>--- drivers/block/swim.c | 8 +++++--- drivers/block/swim3.c | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-)drivers/block/swim.c +5
-3@@ -741,11 +741,12 @@ static int floppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)return 0 ; } -static int floppy_check_change (struct gendisk *disk) +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing) {struct floppy_state *fs = disk->private_data; -return fs->ejected; +return fs->ejected ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int floppy_revalidate (struct gendisk *disk)@@ -772,7 +773,7 @@ static const struct block_device_operations floppy_fops = { .release = floppy_release, .ioctl = floppy_ioctl, .getgeo = floppy_getgeo, - .media_changed = floppy_check_change, + .check_events = floppy_check_events, .revalidate_disk = floppy_revalidate, };@@ -857,6 +858,7 @@ static int __devinit swim_floppy_init(struct swim_priv *swd) swd->unit[drive].disk->first_minor = drive;sprintf (swd->unit[drive].disk->disk_name,"fd%d" , drive); swd->unit[drive].disk->fops = &floppy_fops; + swd->unit[drive].disk->events =DISK_EVENT_MEDIA_CHANGE ; swd->unit[drive].disk->private_data = &swd->unit[drive]; swd->unit[drive].disk->queue = swd->queue;set_capacity (swd->unit[drive].disk,2880 );drivers/block/swim3.c +7
-4@@ -250,7 +250,8 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long param);static int floppy_open (struct block_device *bdev,fmode_t mode);static int floppy_release (struct gendisk *disk,fmode_t mode); -static int floppy_check_change (struct gendisk *disk); +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing);static int floppy_revalidate (struct gendisk *disk);static bool swim3_end_request (int err,unsigned int nr_bytes)@@ -975,10 +976,11 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)return 0 ; } -static int floppy_check_change (struct gendisk *disk) +static unsigned int floppy_check_events (struct gendisk *disk, +unsigned int clearing) {struct floppy_state *fs = disk->private_data; -return fs->ejected; +return fs->ejected ?DISK_EVENT_MEDIA_CHANGE :0 ; }static int floppy_revalidate (struct gendisk *disk)@@ -1025,7 +1027,7 @@ static const struct block_device_operations floppy_fops = { .open = floppy_unlocked_open, .release = floppy_release, .ioctl = floppy_ioctl, - .media_changed = floppy_check_change, + .check_events = floppy_check_events, .revalidate_disk= floppy_revalidate, };@@ -1161,6 +1163,7 @@ static int __devinit swim3_attach(struct macio_dev *mdev, const struct of_device disk->major =FLOPPY_MAJOR ; disk->first_minor = i; disk->fops = &floppy_fops; + disk->events =DISK_EVENT_MEDIA_CHANGE ; disk->private_data = &floppy_states[i]; disk->queue = swim3_queue; disk->flags |=GENHD_FL_REMOVABLE ;