disk events cleanup
Hi all,
this series first moves the disk events code into its own file, as it clearly is pretty distinct from the main genhd.c code (Tejun, feel free to add a Copyright statement as there was none), and then switch the registeration of the disk event attributes away from sysfs_create_files in favor of just adding them to the main disk class.
PATCH 1/2 block: move the disk events code to a separate file
Move the code for handling disk events from genhd.c into a new file as it isn't very related to the rest of the file while at the same time requiring lots of forward declarations.
--- block/Makefile | 3 +- block/blk.h | 5 + block/disk-events.c | 484 +++++++++++++++++++++++++++++++++++++++++++ block/genhd.c | 492 -------------------------------------------- 4 files changed, 491 insertions(+), 493 deletions(-) create mode 100644 block/disk-events.c
block/Makefile +2 -1
@@ -8,7 +8,8 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-sysfs.o \ blk-exec.o blk-merge.o blk-timeout.o \ blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \ blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \ - genhd.o ioprio.o badblocks.o partitions/ blk-rq-qos.o + genhd.o ioprio.o badblocks.o partitions/ blk-rq-qos.o \ + disk-events.o obj-$(CONFIG_BOUNCE) += bounce.o obj-$(CONFIG_BLK_SCSI_REQUEST) += scsi_ioctl.o
block/blk.h +5 -0
@@ -360,4 +360,9 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio,struct request_queue *blk_alloc_queue (int node_id); +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); +#endif /* BLK_INTERNAL_H */
block/disk-events.c new file +484 -0
484 lines not on this page · raw message
block/genhd.c +0 -492
501 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH 1/2] block: move the disk events code to a separate file
Quoted 4 lines · Christoph Hellwig
Move the code for handling disk events from
genhd.cinto a new file as it isn't very related to the rest of the file while at the same time requiring lots of forward declarations.
Quoted 9 lines
Signed-off-by Christoph Hellwig <[email protected]>--- block/Makefile | 3 +- block/blk.h | 5 + block/disk-events.c | 484 +++++++++++++++++++++++++++++++++++++++++++ block/genhd.c | 492 -------------------------------------------- 4 files changed, 491 insertions(+), 493 deletions(-) create mode 100644 block/disk-events.c
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
PATCH 2/2 block: add the events* attributes to disk_attrs
In reply to Christoph HellwigAdd 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.
--- block/blk.h | 3 +++ block/disk-events.c | 23 ++++------------------- block/genhd.c | 3 +++ 3 files changed, 10 insertions(+), 19 deletions(-)
block/blk.h +3 -0
@@ -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 */
block/disk-events.c +4 -19
@@ -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
@@ -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 ;
@@ -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)
block/genhd.c +3 -0
@@ -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
Signature · 1 line
2.30.2
Re: [PATCH 2/2] block: add the events* attributes to disk_attrs
Quoted 5 lines · Christoph Hellwig
Add the events attributes to the
disk_attrsarray, 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.
Quoted 7 lines
Signed-off-by Christoph Hellwig <[email protected]>--- block/blk.h | 3 +++ block/disk-events.c | 23 ++++------------------- block/genhd.c | 3 +++ 3 files changed, 10 insertions(+), 19 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
Quoted 7 lines · Christoph Hellwig
Hi all,
this series first moves the disk events code into its own file, as it clearly is pretty distinct from the main
genhd.ccode (Tejun, feel free to add a Copyright statement as there was none), and then switch the registeration of the disk event attributes away fromsysfs_create_filesin favor of just adding them to the main disk class.
Applied, thanks.
Signature · 1 line
Jens Axboe