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

block: don't propagate unlisted DISK_EVENTs to userland

DISK_EVENT_MEDIA_CHANGE is used for both userland visible event and
internal event for revalidation of removeable devices. Some legacy
drivers don't implement proper event detection and continuously
generate events under certain circumstances. For example, ide-cd
generates media changed continuously if there's no media in the drive,
which can lead to infinite loop of events jumping back and forth
between the driver and userland event handler.

This patch updates disk event infrastructure such that it never
propagates events not listed in disk->events to userland. Those
events are processed the same for internal purposes but uevent
generation is suppressed.

This also ensures that userland only gets events which are advertised
in the @events sysfs node lowering risk of confusion.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>

authored by

Tejun Heo and committed by
Jens Axboe
7c88a168 3aa72873

+6 -2
+6 -2
block/genhd.c
··· 1588 1588 1589 1589 spin_unlock_irq(&ev->lock); 1590 1590 1591 - /* tell userland about new events */ 1591 + /* 1592 + * Tell userland about new events. Only the events listed in 1593 + * @disk->events are reported. Unlisted events are processed the 1594 + * same internally but never get reported to userland. 1595 + */ 1592 1596 for (i = 0; i < ARRAY_SIZE(disk_uevents); i++) 1593 - if (events & (1 << i)) 1597 + if (events & disk->events & (1 << i)) 1594 1598 envp[nr_events++] = disk_uevents[i]; 1595 1599 1596 1600 if (nr_events)