History

block: disk_events: introduce event flags

Currently, an empty disk->events field tells the block layer not to forward media change events to user space. This was done in commit 7c88a168da80 ("block: don't propagate unlisted DISK_EVENTs to userland") in order to avoid events from "fringe" drivers to be forwarded to user space. By doing so, the block layer lost the information which events were supported by a particular block device, and most importantly, whether or not a given device supports media change events at all. Prepare for not interpreting the "events" field this way in the future any more. This is done by adding an additional field "event_flags" to struct gendisk, and two flag bits that can be set to have the device treated like one that had the "events" field set to a non-zero value before. This applies only to the sd and sr drivers, which are changed to set the new flags. The new flags are DISK_EVENT_FLAG_POLL to enforce polling of the device for synchronous events, and DISK_EVENT_FLAG_UEVENT to tell the blocklayer to generate udev events from kernel events. In order to add the event_flags field to struct gendisk, the events field is converted to an "unsigned short"; it doesn't need to hold values bigger than 2 anyway. This patch doesn't change behavior.

Martin Wilck committed 7 years ago

Commit c92e2f01 parent 673387a4 files · +20 −5Browse files

Unified · Split

4 files
  1. block/genhd.c +9 −4
  2. drivers/scsi/sd.c +1 −0
  3. drivers/scsi/sr.c +1 −0
  4. include/linux/genhd.h +9 −1
block/genhd.c+9−4
@@ -1632,7 +1632,7 @@ static unsigned long disk_events_poll_jiffies(struct gendisk *disk) · 1631 unmodified lines
16321632 */
16331633 if (ev->poll_msecs >= 0)
16341634 intv_msecs = ev->poll_msecs;
1635− else if (disk->events)
1635+ else if (disk->event_flags & DISK_EVENT_FLAG_POLL)
16361636 intv_msecs = disk_events_dfl_poll_msecs;
16371637
16381638 return msecs_to_jiffies(intv_msecs);
@@ -1842,11 +1842,13 @@ static void disk_check_events(struct disk_events *ev, · 203 unmodified lines
18421842
18431843 /*
18441844 * Tell userland about new events. Only the events listed in
1845− * @disk->events are reported. Unlisted events are processed the
1846− * same internally but never get reported to userland.
1845+ * @disk->events are reported, and only if DISK_EVENT_FLAG_UEVENT
1846+ * is set. Otherwise, events are processed internally but never
1847+ * get reported to userland.
18471848 */
18481849 for (i = 0; i < ARRAY_SIZE(disk_uevents); i++)
1849− if (events & disk->events & (1 << i))
1850+ if ((events & disk->events & (1 << i)) &&
1851+ (disk->event_flags & DISK_EVENT_FLAG_UEVENT))
18501852 envp[nr_events++] = disk_uevents[i];
18511853
18521854 if (nr_events)
@@ -1884,6 +1886,9 @@ static ssize_t disk_events_show(struct device *dev, · 31 unmodified lines
18841886 {
18851887 struct gendisk *disk = dev_to_disk(dev);
18861888
1889+ if (!(disk->event_flags & DISK_EVENT_FLAG_UEVENT))
1890+ return 0;
1891+
18871892 return __disk_events_show(disk->events, buf);
18881893 }
18891894
drivers/scsi/sd.c+1−0
@@ -3293,6 +3293,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie) · 3292 unmodified lines
32933293 if (sdp->removable) {
32943294 gd->flags |= GENHD_FL_REMOVABLE;
32953295 gd->events |= DISK_EVENT_MEDIA_CHANGE;
3296+ gd->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT;
32963297 }
32973298
32983299 blk_pm_runtime_init(sdp->request_queue, dev);
drivers/scsi/sr.c+1−0
@@ -716,6 +716,7 @@ static int sr_probe(struct device *dev) · 715 unmodified lines
716716 disk->fops = &sr_bdops;
717717 disk->flags = GENHD_FL_CD | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE;
718718 disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST;
719+ disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT;
719720
720721 blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT);
721722
include/linux/genhd.h+9−1
@@ -150,6 +150,13 @@ enum { · 149 unmodified lines
150150 DISK_EVENT_EJECT_REQUEST = 1 << 1, /* eject requested */
151151 };
152152
153+enum {
154+ /* Poll even if events_poll_msecs is unset */
155+ DISK_EVENT_FLAG_POLL = 1 << 0,
156+ /* Forward events to udev */
157+ DISK_EVENT_FLAG_UEVENT = 1 << 1,
158+};
159+
153160 struct disk_part_tbl {
154161 struct rcu_head rcu_head;
155162 int len;
@@ -184,7 +191,8 @@ struct gendisk { · 28 unmodified lines
184191 char disk_name[DISK_NAME_LEN]; /* name of major driver */
185192 char *(*devnode)(struct gendisk *gd, umode_t *mode);
186193
187− unsigned int events; /* supported events */
194+ unsigned short events; /* supported events */
195+ unsigned short event_flags; /* flags related to event processing */
188196
189197 /* Array of pointers to partitions indexed by partno.
190198 * Protected with matching bdev lock but stat and other

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t