diff mbox series

[v3,3/6] block: refactor sysfs code

Message ID 20210623105858.6978-4-mcroce@linux.microsoft.com (mailing list archive)
State New, archived
Headers show
Series block: add a sequence number to disks | expand

Commit Message

Matteo Croce June 23, 2021, 10:58 a.m. UTC
From: Matteo Croce <mcroce@microsoft.com>

Move the sysfs register code from a function named disk_add_events() to
a new function named disk_add_sysfs(). Also, rename the attribute list
with a more generic name than disk_events_attrs.

This is a prerequisite patch to export diskseq in sysfs later.

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 block/genhd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig June 23, 2021, 11:52 a.m. UTC | #1
> -static void disk_add_events(struct gendisk *disk)
> +static void disk_add_sysfs(struct gendisk *disk)
>  {
>  	/* FIXME: error handling */
> -	if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0)
> +	if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_sysfs_attrs) < 0)
>  		pr_warn("%s: failed to create sysfs files for events\n",
>  			disk->disk_name);
> +}

Actually, what we need here is a way how we can setup the ->groups
field of the device to include all attribute groups instead of having
to call sysfs_create_files at all.
Matteo Croce June 23, 2021, 7:03 p.m. UTC | #2
On Wed, Jun 23, 2021 at 1:53 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> > -static void disk_add_events(struct gendisk *disk)
> > +static void disk_add_sysfs(struct gendisk *disk)
> >  {
> >       /* FIXME: error handling */
> > -     if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0)
> > +     if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_sysfs_attrs) < 0)
> >               pr_warn("%s: failed to create sysfs files for events\n",
> >                       disk->disk_name);
> > +}
>
> Actually, what we need here is a way how we can setup the ->groups
> field of the device to include all attribute groups instead of having
> to call sysfs_create_files at all.

I don't get this one. You mean in general or in this series?
Christoph Hellwig June 24, 2021, 6:12 a.m. UTC | #3
On Wed, Jun 23, 2021 at 09:03:40PM +0200, Matteo Croce wrote:
> On Wed, Jun 23, 2021 at 1:53 PM Christoph Hellwig <hch@infradead.org> wrote:
> >
> > > -static void disk_add_events(struct gendisk *disk)
> > > +static void disk_add_sysfs(struct gendisk *disk)
> > >  {
> > >       /* FIXME: error handling */
> > > -     if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0)
> > > +     if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_sysfs_attrs) < 0)
> > >               pr_warn("%s: failed to create sysfs files for events\n",
> > >                       disk->disk_name);
> > > +}
> >
> > Actually, what we need here is a way how we can setup the ->groups
> > field of the device to include all attribute groups instead of having
> > to call sysfs_create_files at all.
> 
> I don't get this one. You mean in general or in this series?

In general before we make more use of the block device provided attrs.
diff mbox series

Patch

diff --git a/block/genhd.c b/block/genhd.c
index c96b667136ee..610dd86fd4b6 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -39,6 +39,7 @@  static void disk_alloc_events(struct gendisk *disk);
 static void disk_add_events(struct gendisk *disk);
 static void disk_del_events(struct gendisk *disk);
 static void disk_release_events(struct gendisk *disk);
+static void disk_add_sysfs(struct gendisk *disk);
 
 void set_capacity(struct gendisk *disk, sector_t sectors)
 {
@@ -560,6 +561,7 @@  static void __device_add_disk(struct device *parent, struct gendisk *disk,
 	 */
 	WARN_ON_ONCE(!blk_get_queue(disk->queue));
 
+	disk_add_sysfs(disk);
 	disk_add_events(disk);
 	blk_integrity_add(disk);
 }
@@ -1754,7 +1756,7 @@  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[] = {
+static const struct attribute *disk_sysfs_attrs[] = {
 	&dev_attr_events.attr,
 	&dev_attr_events_async.attr,
 	&dev_attr_events_poll_msecs.attr,
@@ -1825,13 +1827,16 @@  static void disk_alloc_events(struct gendisk *disk)
 	disk->ev = ev;
 }
 
-static void disk_add_events(struct gendisk *disk)
+static void disk_add_sysfs(struct gendisk *disk)
 {
 	/* FIXME: error handling */
-	if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0)
+	if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_sysfs_attrs) < 0)
 		pr_warn("%s: failed to create sysfs files for events\n",
 			disk->disk_name);
+}
 
+static void disk_add_events(struct gendisk *disk)
+{
 	if (!disk->ev)
 		return;
 
@@ -1856,7 +1861,7 @@  static void disk_del_events(struct gendisk *disk)
 		mutex_unlock(&disk_events_mutex);
 	}
 
-	sysfs_remove_files(&disk_to_dev(disk)->kobj, disk_events_attrs);
+	sysfs_remove_files(&disk_to_dev(disk)->kobj, disk_sysfs_attrs);
 }
 
 static void disk_release_events(struct gendisk *disk)