Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
block: add the events* attributes to disk_attrs
Browse files Browse the repository at this point in the history
Add the events attributes to the disk_attrs array, which ensures they are
added by the driver core when the device is created rather than adding
them after the device has been added, which is racy versus uevents and
requires more boilerplate code.

Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jun 24, 2021
1 parent d5870ed commit 2bc8cda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
3 changes: 3 additions & 0 deletions block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,8 @@ void disk_alloc_events(struct gendisk *disk);
void disk_add_events(struct gendisk *disk);
void disk_del_events(struct gendisk *disk);
void disk_release_events(struct gendisk *disk);
extern struct device_attribute dev_attr_events;
extern struct device_attribute dev_attr_events_async;
extern struct device_attribute dev_attr_events_poll_msecs;

#endif /* BLK_INTERNAL_H */
23 changes: 4 additions & 19 deletions block/disk-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,10 @@ static ssize_t disk_events_poll_msecs_store(struct device *dev,
return count;
}

static const DEVICE_ATTR(events, 0444, disk_events_show, NULL);
static const DEVICE_ATTR(events_async, 0444, disk_events_async_show, NULL);
static const DEVICE_ATTR(events_poll_msecs, 0644,
disk_events_poll_msecs_show,
disk_events_poll_msecs_store);

static const struct attribute *disk_events_attrs[] = {
&dev_attr_events.attr,
&dev_attr_events_async.attr,
&dev_attr_events_poll_msecs.attr,
NULL,
};
DEVICE_ATTR(events, 0444, disk_events_show, NULL);
DEVICE_ATTR(events_async, 0444, disk_events_async_show, NULL);
DEVICE_ATTR(events_poll_msecs, 0644, disk_events_poll_msecs_show,
disk_events_poll_msecs_store);

/*
* The default polling interval can be specified by the kernel
Expand Down Expand Up @@ -444,11 +436,6 @@ void disk_alloc_events(struct gendisk *disk)

void disk_add_events(struct gendisk *disk)
{
/* FIXME: error handling */
if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0)
pr_warn("%s: failed to create sysfs files for events\n",
disk->disk_name);

if (!disk->ev)
return;

Expand All @@ -472,8 +459,6 @@ void disk_del_events(struct gendisk *disk)
list_del_init(&disk->ev->node);
mutex_unlock(&disk_events_mutex);
}

sysfs_remove_files(&disk_to_dev(disk)->kobj, disk_events_attrs);
}

void disk_release_events(struct gendisk *disk)
Expand Down
3 changes: 3 additions & 0 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,9 @@ static struct attribute *disk_attrs[] = {
&dev_attr_stat.attr,
&dev_attr_inflight.attr,
&dev_attr_badblocks.attr,
&dev_attr_events.attr,
&dev_attr_events_async.attr,
&dev_attr_events_poll_msecs.attr,
#ifdef CONFIG_FAIL_MAKE_REQUEST
&dev_attr_fail.attr,
#endif
Expand Down

0 comments on commit 2bc8cda

Please sign in to comment.