Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ide: unexport DISK_EVENT_MEDIA_CHANGE for ide-gd and ide-cd

check_events() implementations in both ide-gd and ide-cd are
inadequate for in-kernel event polling. Both generate media change
events continuously when certain conditions are met causing infinite
event loop between the driver and userland event handler.

As disk event now supports suppression of unlisted events, simply
de-listing DISK_EVENT_MEDIA_CHANGE from disk->events resolves the
problem. Internal handling around media revalidation will behave the
same while userland will fall back to userland event polling after
detecting the device doesn't support disk events.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Jens Axboe <jaxboe@fusionio.com>
Acked-by: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>

authored by

Tejun Heo and committed by
Jens Axboe
7eec77a1 7c88a168

+12 -2
-1
drivers/ide/ide-cd.c
··· 1782 1782 ide_cd_read_toc(drive, &sense); 1783 1783 g->fops = &idecd_ops; 1784 1784 g->flags |= GENHD_FL_REMOVABLE; 1785 - g->events = DISK_EVENT_MEDIA_CHANGE; 1786 1785 add_disk(g); 1787 1786 return 0; 1788 1787
+6
drivers/ide/ide-cd_ioctl.c
··· 79 79 return CDS_DRIVE_NOT_READY; 80 80 } 81 81 82 + /* 83 + * ide-cd always generates media changed event if media is missing, which 84 + * makes it impossible to use for proper event reporting, so disk->events 85 + * is cleared to 0 and the following function is used only to trigger 86 + * revalidation and never propagated to userland. 87 + */ 82 88 unsigned int ide_cdrom_check_events_real(struct cdrom_device_info *cdi, 83 89 unsigned int clearing, int slot_nr) 84 90 {
+6 -1
drivers/ide/ide-gd.c
··· 298 298 return 0; 299 299 } 300 300 301 + /* 302 + * The following is used to force revalidation on the first open on 303 + * removeable devices, and never gets reported to userland as 304 + * genhd->events is 0. This is intended as removeable ide disk 305 + * can't really detect MEDIA_CHANGE events. 306 + */ 301 307 ret = drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED; 302 308 drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED; 303 309 ··· 419 413 if (drive->dev_flags & IDE_DFLAG_REMOVABLE) 420 414 g->flags = GENHD_FL_REMOVABLE; 421 415 g->fops = &ide_gd_ops; 422 - g->events = DISK_EVENT_MEDIA_CHANGE; 423 416 add_disk(g); 424 417 return 0; 425 418