linux-m68k.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 00/18] block: add and use init disk helper
@ 2022-10-05  5:00 Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 01/18] " Chaitanya Kulkarni
                   ` (17 more replies)
  0 siblings, 18 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Hi,

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

-ck

Chaitanya Kulkarni (18):
  block: add and use init disk helper
  nfblock: use init disk helper
  amiflop: use init disk helper
  brd: use init disk helper
  drbd: use init disk helper
  floppy: use init disk helper
  loop: use init disk helper
  n64cart: use init disk helper
  nbd: use init disk helper
  pcd: use init disk helper
  pd: use init disk helper
  pf: use init disk helper
  pktcdvd: use init disk helper
  rnbd-clt: use init disk helper
  swim: use init disk helper
  swim3: use init disk helper
  z2ram: use init disk helper
  ubi: use init disk helper

 arch/m68k/emu/nfblock.c        |  8 ++------
 block/genhd.c                  | 13 +++++++++++++
 drivers/block/amiflop.c        |  8 ++------
 drivers/block/ataflop.c        |  8 ++------
 drivers/block/brd.c            |  9 ++-------
 drivers/block/drbd/drbd_main.c |  6 +-----
 drivers/block/floppy.c         |  8 ++------
 drivers/block/loop.c           |  7 ++-----
 drivers/block/n64cart.c        |  4 +---
 drivers/block/nbd.c            |  7 ++-----
 drivers/block/null_blk/main.c  | 12 ++++--------
 drivers/block/paride/pcd.c     |  5 +----
 drivers/block/paride/pd.c      |  8 ++------
 drivers/block/paride/pf.c      |  6 +-----
 drivers/block/pktcdvd.c        |  6 +-----
 drivers/block/rnbd/rnbd-clt.c  |  9 +++------
 drivers/block/swim.c           |  7 ++-----
 drivers/block/swim3.c          |  8 ++------
 drivers/block/z2ram.c          |  5 +----
 drivers/mtd/ubi/block.c        |  6 +-----
 include/linux/blkdev.h         |  5 +++++
 21 files changed, 52 insertions(+), 103 deletions(-)

-- 
2.29.0


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [RFC PATCH 01/18] block: add and use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-10  7:59   ` Christoph Hellwig
  2022-10-05  5:00 ` [RFC PATCH 02/18] nfblock: " Chaitanya Kulkarni
                   ` (16 subsequent siblings)
  17 siblings, 1 reply; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 block/genhd.c                 | 13 +++++++++++++
 drivers/block/null_blk/main.c | 12 ++++--------
 include/linux/blkdev.h        |  5 +++++
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 514395361d7c..701309a7388e 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1470,3 +1470,16 @@ void inc_diskseq(struct gendisk *disk)
 {
 	disk->diskseq = atomic64_inc_return(&diskseq);
 }
+
+void init_disk(struct gendisk *disk, int major, int first_minor,
+		int minors, sector_t sectors, void *private_data,
+		const struct block_device_operations *fops)
+{
+	disk->major = major;
+	disk->first_minor = first_minor;
+	disk->minors = minors;
+	set_capacity(disk, sectors);
+	disk->private_data = private_data;
+	disk->fops = fops;
+}
+EXPORT_SYMBOL_GPL(init_disk);
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 1f154f92f4c2..d31085c94fd3 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1871,18 +1871,14 @@ static int init_driver_queues(struct nullb *nullb)
 static int null_gendisk_register(struct nullb *nullb)
 {
 	sector_t size = ((sector_t)nullb->dev->size * SZ_1M) >> SECTOR_SHIFT;
+	const struct block_device_operations *fops;
 	struct gendisk *disk = nullb->disk;
 
-	set_capacity(disk, size);
-
-	disk->major		= null_major;
-	disk->first_minor	= nullb->index;
-	disk->minors		= 1;
 	if (queue_is_mq(nullb->q))
-		disk->fops		= &null_rq_ops;
+		fops		= &null_rq_ops;
 	else
-		disk->fops		= &null_bio_ops;
-	disk->private_data	= nullb;
+		fops		= &null_bio_ops;
+	init_disk(disk, null_major, nullb->index, 1, size, nullb, fops);
 	strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
 
 	if (nullb->dev->zoned) {
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 49373d002631..cb9db857f890 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -757,6 +757,11 @@ static inline int __must_check add_disk(struct gendisk *disk)
 {
 	return device_add_disk(NULL, disk, NULL);
 }
+
+void init_disk(struct gendisk *disk, int major, int first_minor,
+		int minors, sector_t sectors, void *private_data,
+		const struct block_device_operations *fops);
+
 void del_gendisk(struct gendisk *gp);
 void invalidate_disk(struct gendisk *disk);
 void set_disk_ro(struct gendisk *disk, bool read_only);
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 02/18] nfblock: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 01/18] " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 03/18] amiflop: " Chaitanya Kulkarni
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 arch/m68k/emu/nfblock.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/m68k/emu/nfblock.c b/arch/m68k/emu/nfblock.c
index a708fbd5a844..81d3d3edace6 100644
--- a/arch/m68k/emu/nfblock.c
+++ b/arch/m68k/emu/nfblock.c
@@ -121,13 +121,9 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
 	if (!dev->disk)
 		goto free_dev;
 
-	dev->disk->major = major_num;
-	dev->disk->first_minor = dev_id * 16;
-	dev->disk->minors = 16;
-	dev->disk->fops = &nfhd_ops;
-	dev->disk->private_data = dev;
+	init_disk(dev->disk, major_num, dev_id * 16, 16,
+			(sector_t)blocks * (bsize / 512), dev, &nfhd_ops);
 	sprintf(dev->disk->disk_name, "nfhd%u", dev_id);
-	set_capacity(dev->disk, (sector_t)blocks * (bsize / 512));
 	blk_queue_logical_block_size(dev->disk->queue, bsize);
 	err = add_disk(dev->disk);
 	if (err)
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 03/18] amiflop: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 01/18] " Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 02/18] nfblock: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 04/18] brd: " Chaitanya Kulkarni
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/amiflop.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 4c8b2ba579ee..40f220fd61a7 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -1786,18 +1786,14 @@ static int fd_alloc_disk(int drive, int system)
 	if (IS_ERR(disk))
 		return PTR_ERR(disk);
 
-	disk->major = FLOPPY_MAJOR;
-	disk->first_minor = drive + system;
-	disk->minors = 1;
-	disk->fops = &floppy_fops;
 	disk->flags |= GENHD_FL_NO_PART;
 	disk->events = DISK_EVENT_MEDIA_CHANGE;
 	if (system)
 		sprintf(disk->disk_name, "fd%d_msdos", drive);
 	else
 		sprintf(disk->disk_name, "fd%d", drive);
-	disk->private_data = &unit[drive];
-	set_capacity(disk, 880 * 2);
+	init_disk(disk, FLOPPY_MAJOR, drive + system, 1, 880 * 2, &unit[drive],
+			&floppy_fops);
 
 	unit[drive].gendisk[system] = disk;
 	err = add_disk(disk);
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 04/18] brd: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (2 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 03/18] amiflop: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 05/18] drbd: " Chaitanya Kulkarni
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/ataflop.c | 8 ++------
 drivers/block/brd.c     | 9 ++-------
 2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 9deb4df6bdb8..cd70f7b329c4 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1997,15 +1997,11 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
 	if (IS_ERR(disk))
 		return PTR_ERR(disk);
 
-	disk->major = FLOPPY_MAJOR;
-	disk->first_minor = drive + (type << 2);
-	disk->minors = 1;
 	sprintf(disk->disk_name, "fd%d", drive);
-	disk->fops = &floppy_fops;
 	disk->flags |= GENHD_FL_NO_PART;
 	disk->events = DISK_EVENT_MEDIA_CHANGE;
-	disk->private_data = &unit[drive];
-	set_capacity(disk, MAX_DISK_SIZE * 2);
+	init_disk(disk, FLOPPY_MAJOR, drive + (type << 2), 1,
+			MAX_DISK_SIZE * 2, &unit[drive], &floppy_fops);
 
 	unit[drive].disk[type] = disk;
 	return 0;
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 20acc4a1fd6d..f60fda36a813 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -392,14 +392,9 @@ static int brd_alloc(int i)
 	if (!disk)
 		goto out_free_dev;
 
-	disk->major		= RAMDISK_MAJOR;
-	disk->first_minor	= i * max_part;
-	disk->minors		= max_part;
-	disk->fops		= &brd_fops;
-	disk->private_data	= brd;
 	strscpy(disk->disk_name, buf, DISK_NAME_LEN);
-	set_capacity(disk, rd_size * 2);
-	
+	init_disk(disk, RAMDISK_MAJOR, i * max_part, max_part, rd_size * 2,
+			brd, &brd_fops);
 	/*
 	 * This is so fdisk will align partitions on 4k, because of
 	 * direct_access API needing 4k alignment, returning a PFN
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 05/18] drbd: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (3 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 04/18] brd: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05 10:09   ` Christoph Böhmwalder
  2022-10-05  5:00 ` [RFC PATCH 06/18] floppy: " Chaitanya Kulkarni
                   ` (12 subsequent siblings)
  17 siblings, 1 reply; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/drbd/drbd_main.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index f3e4db16fd07..58fae122de16 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -2706,13 +2706,9 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
 
 	set_disk_ro(disk, true);
 
-	disk->major = DRBD_MAJOR;
-	disk->first_minor = minor;
-	disk->minors = 1;
-	disk->fops = &drbd_ops;
 	disk->flags |= GENHD_FL_NO_PART;
 	sprintf(disk->disk_name, "drbd%d", minor);
-	disk->private_data = device;
+	init_disk(disk, DRBD_MAJOR, minor, 1, 0, device, &drbd_ops);
 
 	blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
 	blk_queue_write_cache(disk->queue, true, true);
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 06/18] floppy: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (4 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 05/18] drbd: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 07/18] loop: " Chaitanya Kulkarni
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/floppy.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index ccad3d7b3ddd..7304fd87c038 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4516,18 +4516,14 @@ static int floppy_alloc_disk(unsigned int drive, unsigned int type)
 		return PTR_ERR(disk);
 
 	blk_queue_max_hw_sectors(disk->queue, 64);
-	disk->major = FLOPPY_MAJOR;
-	disk->first_minor = TOMINOR(drive) | (type << 2);
-	disk->minors = 1;
-	disk->fops = &floppy_fops;
 	disk->flags |= GENHD_FL_NO_PART;
 	disk->events = DISK_EVENT_MEDIA_CHANGE;
+	init_disk(disk, FLOPPY_MAJOR, TOMINOR(drive) | (type << 2), 1, 0,
+			(void *)(long)drive, &floppy_fops);
 	if (type)
 		sprintf(disk->disk_name, "fd%d_type%d", drive, type);
 	else
 		sprintf(disk->disk_name, "fd%d", drive);
-	/* to be cleaned up... */
-	disk->private_data = (void *)(long)drive;
 	disk->flags |= GENHD_FL_REMOVABLE;
 
 	disks[drive][type] = disk;
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 07/18] loop: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (5 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 06/18] floppy: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 08/18] n64cart: " Chaitanya Kulkarni
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/loop.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index ad92192c7d61..82cdb57ecd18 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2023,15 +2023,12 @@ static int loop_add(int i)
 	spin_lock_init(&lo->lo_work_lock);
 	INIT_WORK(&lo->rootcg_work, loop_rootcg_workfn);
 	INIT_LIST_HEAD(&lo->rootcg_cmd_list);
-	disk->major		= LOOP_MAJOR;
-	disk->first_minor	= i << part_shift;
-	disk->minors		= 1 << part_shift;
-	disk->fops		= &lo_fops;
-	disk->private_data	= lo;
 	disk->queue		= lo->lo_queue;
 	disk->events		= DISK_EVENT_MEDIA_CHANGE;
 	disk->event_flags	= DISK_EVENT_FLAG_UEVENT;
 	sprintf(disk->disk_name, "loop%d", i);
+	init_disk(disk, LOOP_MAJOR, i << part_shift, 1 << part_shift, 0, lo,
+			&lo_fops);
 	/* Make this loop device reachable from pathname. */
 	err = add_disk(disk);
 	if (err)
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 08/18] n64cart: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (6 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 07/18] loop: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 09/18] nbd: " Chaitanya Kulkarni
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/n64cart.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/block/n64cart.c b/drivers/block/n64cart.c
index d914156db2d8..28b32fbe6586 100644
--- a/drivers/block/n64cart.c
+++ b/drivers/block/n64cart.c
@@ -135,14 +135,12 @@ static int __init n64cart_probe(struct platform_device *pdev)
 	if (!disk)
 		goto out;
 
-	disk->first_minor = 0;
 	disk->flags = GENHD_FL_NO_PART;
 	disk->fops = &n64cart_fops;
-	disk->private_data = &pdev->dev;
 	strcpy(disk->disk_name, "n64cart");
 
-	set_capacity(disk, size >> SECTOR_SHIFT);
 	set_disk_ro(disk, 1);
+	init_disk(disk, 0, 0, 0, size >> 9, &pdev->dev, &n64cart_fops);
 
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
 	blk_queue_physical_block_size(disk->queue, 4096);
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 09/18] nbd: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (7 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 08/18] n64cart: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 10/18] pcd: " Chaitanya Kulkarni
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/nbd.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 2a2a1d996a57..b4f2d7e1be89 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1816,12 +1816,9 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
 	 */
 	refcount_set(&nbd->refs, 0);
 	INIT_LIST_HEAD(&nbd->list);
-	disk->major = NBD_MAJOR;
-	disk->first_minor = index << part_shift;
-	disk->minors = 1 << part_shift;
-	disk->fops = &nbd_fops;
-	disk->private_data = nbd;
 	sprintf(disk->disk_name, "nbd%d", index);
+	init_disk(disk, NBD_MAJOR, index << part_shift, 1 << part_shift, 0,
+			nbd, &nbd_fops);
 	err = add_disk(disk);
 	if (err)
 		goto out_free_work;
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 10/18] pcd: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (8 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 09/18] nbd: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 11/18] pd: " Chaitanya Kulkarni
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/paride/pcd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index a5ab40784119..4474fd28a6de 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -923,15 +923,12 @@ static int pcd_init_unit(struct pcd_unit *cd, bool autoprobe, int port,
 	cd->info.speed = 0;
 	cd->info.capacity = 1;
 	cd->info.mask = 0;
-	disk->major = major;
-	disk->first_minor = unit;
-	disk->minors = 1;
 	strcpy(disk->disk_name, cd->name);	/* umm... */
-	disk->fops = &pcd_bdops;
 	disk->flags |= GENHD_FL_NO_PART;
 	disk->events = DISK_EVENT_MEDIA_CHANGE;
 	disk->event_flags = DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE;
 
+	init_disk(disk, major, unit, 1, 0, NULL, &pcd_bdops);
 	if (!pi_init(cd->pi, autoprobe, port, mode, unit, protocol, delay,
 			pcd_buffer, PI_PCD, verbose, cd->name)) {
 		ret = -ENODEV;
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 11/18] pd: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (9 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 10/18] pcd: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 12/18] pf: " Chaitanya Kulkarni
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/paride/pd.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index f8a75bc90f70..9457ad0cc25f 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -919,12 +919,7 @@ static int pd_probe_drive(struct pd_unit *disk, int autoprobe, int port,
 	disk->gd = p;
 
 	strcpy(p->disk_name, disk->name);
-	p->fops = &pd_fops;
-	p->major = major;
-	p->first_minor = (disk - pd) << PD_BITS;
-	p->minors = 1 << PD_BITS;
 	p->events = DISK_EVENT_MEDIA_CHANGE;
-	p->private_data = disk;
 	blk_queue_max_hw_sectors(p->queue, cluster);
 	blk_queue_bounce_limit(p->queue, BLK_BOUNCE_HIGH);
 
@@ -939,7 +934,8 @@ static int pd_probe_drive(struct pd_unit *disk, int autoprobe, int port,
 	}
 	if (ret)
 		goto put_disk;
-	set_capacity(disk->gd, disk->capacity);
+	init_disk(disk, major, (disk - pd) << PD_BITS, 1 << PD_BITS,
+			disk->capacity, disk, *pd_fops);
 	ret = add_disk(disk->gd);
 	if (ret)
 		goto cleanup_disk;
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 12/18] pf: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (10 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 11/18] pd: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 13/18] pktcdvd: " Chaitanya Kulkarni
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/paride/pf.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index eec1b9fde245..2950642402a8 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -937,15 +937,11 @@ static int __init pf_init_unit(struct pf_unit *pf, bool autoprobe, int port,
 		ret = PTR_ERR(disk);
 		goto out_free_tag_set;
 	}
-	disk->major = major;
-	disk->first_minor = pf - units;
-	disk->minors = 1;
 	strcpy(disk->disk_name, pf->name);
-	disk->fops = &pf_fops;
 	disk->flags |= GENHD_FL_NO_PART;
 	disk->events = DISK_EVENT_MEDIA_CHANGE;
-	disk->private_data = pf;
 
+	init_disk(disk, major, pf - units, 1, 0, pf, &pf_ops);
 	blk_queue_max_segments(disk->queue, cluster);
 	blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
 
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 13/18] pktcdvd: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (11 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 12/18] pf: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 14/18] rnbd-clt: " Chaitanya Kulkarni
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/pktcdvd.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 4cea3b08087e..db8f4ca5c09c 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2698,13 +2698,9 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
 	if (!disk)
 		goto out_mem;
 	pd->disk = disk;
-	disk->major = pktdev_major;
-	disk->first_minor = idx;
-	disk->minors = 1;
-	disk->fops = &pktcdvd_ops;
 	disk->flags = GENHD_FL_REMOVABLE | GENHD_FL_NO_PART;
 	strcpy(disk->disk_name, pd->name);
-	disk->private_data = pd;
+	init_disk(disk, pktdev_major, idx, 1, 0, pd, &pktcdvd_ops);
 
 	pd->pkt_dev = MKDEV(pktdev_major, idx);
 	ret = pkt_new_dev(pd, dev);
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 14/18] rnbd-clt: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (12 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 13/18] pktcdvd: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 15/18] swim: " Chaitanya Kulkarni
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/rnbd/rnbd-clt.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
index 78334da74d8b..4f29364a6f4d 100644
--- a/drivers/block/rnbd/rnbd-clt.c
+++ b/drivers/block/rnbd/rnbd-clt.c
@@ -1369,12 +1369,7 @@ static int rnbd_clt_setup_gen_disk(struct rnbd_clt_dev *dev,
 {
 	int err;
 
-	dev->gd->major		= rnbd_client_major;
-	dev->gd->first_minor	= idx << RNBD_PART_BITS;
-	dev->gd->minors		= 1 << RNBD_PART_BITS;
-	dev->gd->fops		= &rnbd_client_ops;
 	dev->gd->queue		= dev->queue;
-	dev->gd->private_data	= dev;
 	snprintf(dev->gd->disk_name, sizeof(dev->gd->disk_name), "rnbd%d",
 		 idx);
 	pr_debug("disk_name=%s, capacity=%llu\n",
@@ -1382,7 +1377,9 @@ static int rnbd_clt_setup_gen_disk(struct rnbd_clt_dev *dev,
 		 le64_to_cpu(rsp->nsectors) *
 		 (le16_to_cpu(rsp->logical_block_size) / SECTOR_SIZE));
 
-	set_capacity(dev->gd, le64_to_cpu(rsp->nsectors));
+	init_disk(dev->gd, rnbd_client_major, idx << RNBD_PART_BITS,
+			1 << RNBD_PART_BITS, le64_to_cpu(rsp->nsectors), dev,
+			&rnbd_client_ops);
 
 	if (dev->access_mode == RNBD_ACCESS_RO)
 		set_disk_ro(dev->gd, true);
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 15/18] swim: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (13 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 14/18] rnbd-clt: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  6:54   ` Finn Thain
  2022-10-05  5:00 ` [RFC PATCH 16/18] swim3: " Chaitanya Kulkarni
                   ` (2 subsequent siblings)
  17 siblings, 1 reply; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/swim.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 42b4b6828690..7fa4b2766367 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -835,15 +835,12 @@ static int swim_floppy_init(struct swim_priv *swd)
 
 	for (drive = 0; drive < swd->floppy_count; drive++) {
 		swd->unit[drive].disk->flags = GENHD_FL_REMOVABLE;
-		swd->unit[drive].disk->major = FLOPPY_MAJOR;
-		swd->unit[drive].disk->first_minor = drive;
-		swd->unit[drive].disk->minors = 1;
 		sprintf(swd->unit[drive].disk->disk_name, "fd%d", drive);
-		swd->unit[drive].disk->fops = &floppy_fops;
 		swd->unit[drive].disk->flags |= GENHD_FL_NO_PART;
 		swd->unit[drive].disk->events = DISK_EVENT_MEDIA_CHANGE;
 		swd->unit[drive].disk->private_data = &swd->unit[drive];
-		set_capacity(swd->unit[drive].disk, 2880);
+		init_disk(swd->unit[drive].disk, FLOPPY_MAJOR, drive, 1, 2880,
+				&swd->unit[drive], &floopy_dops);
 		err = add_disk(swd->unit[drive].disk);
 		if (err)
 			goto exit_put_disks;
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 16/18] swim3: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (14 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 15/18] swim: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 17/18] z2ram: " Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 18/18] ubi: " Chaitanya Kulkarni
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/swim3.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index da811a7da03f..3c1b92b464d1 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -1221,15 +1221,11 @@ static int swim3_attach(struct macio_dev *mdev,
 	if (rc)
 		goto out_cleanup_disk;
 
-	disk->major = FLOPPY_MAJOR;
-	disk->first_minor = floppy_count;
-	disk->minors = 1;
-	disk->fops = &floppy_fops;
-	disk->private_data = fs;
 	disk->events = DISK_EVENT_MEDIA_CHANGE;
 	disk->flags |= GENHD_FL_REMOVABLE | GENHD_FL_NO_PART;
 	sprintf(disk->disk_name, "fd%d", floppy_count);
-	set_capacity(disk, 2880);
+	init_disk(swd->unit[drive].disk, FLOPPY_MAJOR, floppy_count, 1, 2880,
+			&fs, &floopy_dops);
 	rc = add_disk(disk);
 	if (rc)
 		goto out_cleanup_disk;
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 17/18] z2ram: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (15 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 16/18] swim3: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  2022-10-05  5:00 ` [RFC PATCH 18/18] ubi: " Chaitanya Kulkarni
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/z2ram.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index c1e85f356e4d..74432fbfe42c 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -324,11 +324,8 @@ static int z2ram_register_disk(int minor)
 	if (IS_ERR(disk))
 		return PTR_ERR(disk);
 
-	disk->major = Z2RAM_MAJOR;
-	disk->first_minor = minor;
-	disk->minors = 1;
 	disk->flags |= GENHD_FL_NO_PART;
-	disk->fops = &z2_fops;
+	init_disk(disk, Z2RAM_MAJOR, minor, 1, 0, NULL, &z2_fops);
 	if (minor)
 		sprintf(disk->disk_name, "z2ram%d", minor);
 	else
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [RFC PATCH 18/18] ubi: use init disk helper
  2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
                   ` (16 preceding siblings ...)
  2022-10-05  5:00 ` [RFC PATCH 17/18] z2ram: " Chaitanya Kulkarni
@ 2022-10-05  5:00 ` Chaitanya Kulkarni
  17 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05  5:00 UTC (permalink / raw)
  To: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd, linux-mtd
  Cc: axboe, philipp.reisner, lars.ellenberg, christoph.boehmwalder,
	efremov, josef, tim, haris.iqbal, jinpu.wang, richard,
	miquel.raynal, vigneshr, kch, mcgrof, hare, damien.lemoal,
	johannes.thumshirn, bvanassche, ming.lei, vincent.fu,
	shinichiro.kawasaki

Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/mtd/ubi/block.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 4cf67a2a0d04..07c085a5fd52 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -420,9 +420,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
 		goto out_free_tags;
 	}
 
-	gd->fops = &ubiblock_ops;
-	gd->major = ubiblock_major;
-	gd->minors = 1;
+	init_disk(gd, ubiblock_major, 1, 0, disk_capacity, dev, &ubiblock_ops);
 	gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL);
 	if (gd->first_minor < 0) {
 		dev_err(disk_to_dev(gd),
@@ -431,9 +429,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
 		goto out_cleanup_disk;
 	}
 	gd->flags |= GENHD_FL_NO_PART;
-	gd->private_data = dev;
 	sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
-	set_capacity(gd, disk_capacity);
 	dev->gd = gd;
 
 	dev->rq = gd->queue;
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [RFC PATCH 15/18] swim: use init disk helper
  2022-10-05  5:00 ` [RFC PATCH 15/18] swim: " Chaitanya Kulkarni
@ 2022-10-05  6:54   ` Finn Thain
  0 siblings, 0 replies; 23+ messages in thread
From: Finn Thain @ 2022-10-05  6:54 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: geert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd,
	linux-mtd, axboe, philipp.reisner, lars.ellenberg,
	christoph.boehmwalder, efremov, josef, tim, haris.iqbal,
	jinpu.wang, richard, miquel.raynal, vigneshr, mcgrof, hare,
	damien.lemoal, johannes.thumshirn, bvanassche, ming.lei,
	vincent.fu, shinichiro.kawasaki

On Tue, 4 Oct 2022, Chaitanya Kulkarni wrote:

> Add and use the helper to initialize the common fields of struct gendisk
> such as major, first_minor, minors, disk_name, private_data, and ops.
> This initialization is spread all over the block drivers. This avoids
> code repetation of inialization code of gendisk in current block drivers
> and any future ones.
> 
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
> ---
>  drivers/block/swim.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/block/swim.c b/drivers/block/swim.c
> index 42b4b6828690..7fa4b2766367 100644
> --- a/drivers/block/swim.c
> +++ b/drivers/block/swim.c
> @@ -835,15 +835,12 @@ static int swim_floppy_init(struct swim_priv *swd)
>  
>  	for (drive = 0; drive < swd->floppy_count; drive++) {
>  		swd->unit[drive].disk->flags = GENHD_FL_REMOVABLE;
> -		swd->unit[drive].disk->major = FLOPPY_MAJOR;
> -		swd->unit[drive].disk->first_minor = drive;
> -		swd->unit[drive].disk->minors = 1;
>  		sprintf(swd->unit[drive].disk->disk_name, "fd%d", drive);
> -		swd->unit[drive].disk->fops = &floppy_fops;
>  		swd->unit[drive].disk->flags |= GENHD_FL_NO_PART;
>  		swd->unit[drive].disk->events = DISK_EVENT_MEDIA_CHANGE;
>  		swd->unit[drive].disk->private_data = &swd->unit[drive];
> -		set_capacity(swd->unit[drive].disk, 2880);
> +		init_disk(swd->unit[drive].disk, FLOPPY_MAJOR, drive, 1, 2880,
> +				&swd->unit[drive], &floopy_dops);
>  		err = add_disk(swd->unit[drive].disk);
>  		if (err)
>  			goto exit_put_disks;
> 

You typo'd the ops struct. By inspection, I'd say your patches 11/18 and 
16/18 will not compile either.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [RFC PATCH 05/18] drbd: use init disk helper
  2022-10-05  5:00 ` [RFC PATCH 05/18] drbd: " Chaitanya Kulkarni
@ 2022-10-05 10:09   ` Christoph Böhmwalder
  2022-10-05 17:24     ` Chaitanya Kulkarni
  0 siblings, 1 reply; 23+ messages in thread
From: Christoph Böhmwalder @ 2022-10-05 10:09 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: ogeert, linux-block, linux-m68k, drbd-dev, nbd, linux-mtd,
	linux-kernel, axboe, philipp.reisner, lars.ellenberg, efremov,
	josef, tim, haris.iqbal, jinpu.wang, richard, miquel.raynal,
	vigneshr, mcgrof, hare, damien.lemoal, johannes.thumshirn,
	bvanassche, ming.lei, vincent.fu, shinichiro.kawasaki

Am 05.10.22 um 07:00 schrieb Chaitanya Kulkarni:
> Add and use the helper to initialize the common fields of struct gendisk
> such as major, first_minor, minors, disk_name, private_data, and ops.
> This initialization is spread all over the block drivers. This avoids
> code repetation of inialization code of gendisk in current block drivers
> and any future ones.
> 
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
> ---
>  drivers/block/drbd/drbd_main.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
> index f3e4db16fd07..58fae122de16 100644
> --- a/drivers/block/drbd/drbd_main.c
> +++ b/drivers/block/drbd/drbd_main.c
> @@ -2706,13 +2706,9 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
>  
>  	set_disk_ro(disk, true);
>  
> -	disk->major = DRBD_MAJOR;
> -	disk->first_minor = minor;
> -	disk->minors = 1;
> -	disk->fops = &drbd_ops;
>  	disk->flags |= GENHD_FL_NO_PART;
>  	sprintf(disk->disk_name, "drbd%d", minor);
> -	disk->private_data = device;
> +	init_disk(disk, DRBD_MAJOR, minor, 1, 0, device, &drbd_ops);
>  
>  	blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
>  	blk_queue_write_cache(disk->queue, true, true);

This now does a set_capacity(..., 0), which it did not do before.
I'm guessing this does not have any side effects as the capacity should
already be initialized to 0? Do you know this for sure?

-- 
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA —  Disaster Recovery — Software defined Storage

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [RFC PATCH 05/18] drbd: use init disk helper
  2022-10-05 10:09   ` Christoph Böhmwalder
@ 2022-10-05 17:24     ` Chaitanya Kulkarni
  0 siblings, 0 replies; 23+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-05 17:24 UTC (permalink / raw)
  To: Christoph Böhmwalder, Chaitanya Kulkarni
  Cc: ogeert, linux-block, linux-m68k, drbd-dev, nbd, linux-mtd,
	linux-kernel, axboe, philipp.reisner, lars.ellenberg, efremov,
	josef, tim, haris.iqbal, jinpu.wang, richard, miquel.raynal,
	vigneshr, mcgrof, hare, damien.lemoal, johannes.thumshirn,
	bvanassche, ming.lei, vincent.fu, shinichiro.kawasaki


>> diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
>> index f3e4db16fd07..58fae122de16 100644
>> --- a/drivers/block/drbd/drbd_main.c
>> +++ b/drivers/block/drbd/drbd_main.c
>> @@ -2706,13 +2706,9 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
>>   
>>   	set_disk_ro(disk, true);
>>   
>> -	disk->major = DRBD_MAJOR;
>> -	disk->first_minor = minor;
>> -	disk->minors = 1;
>> -	disk->fops = &drbd_ops;
>>   	disk->flags |= GENHD_FL_NO_PART;
>>   	sprintf(disk->disk_name, "drbd%d", minor);
>> -	disk->private_data = device;
>> +	init_disk(disk, DRBD_MAJOR, minor, 1, 0, device, &drbd_ops);
>>   
>>   	blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
>>   	blk_queue_write_cache(disk->queue, true, true);
> 
> This now does a set_capacity(..., 0), which it did not do before.
> I'm guessing this does not have any side effects as the capacity should
> already be initialized to 0? Do you know this for sure?
> 

I think I'll move  the call to set_capcity out of the caller,
Will resend the series shortly.

-ck


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [RFC PATCH 01/18] block: add and use init disk helper
  2022-10-05  5:00 ` [RFC PATCH 01/18] " Chaitanya Kulkarni
@ 2022-10-10  7:59   ` Christoph Hellwig
  0 siblings, 0 replies; 23+ messages in thread
From: Christoph Hellwig @ 2022-10-10  7:59 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: ogeert, linux-block, linux-m68k, linux-kernel, drbd-dev, nbd,
	linux-mtd, axboe, philipp.reisner, lars.ellenberg,
	christoph.boehmwalder, efremov, josef, tim, haris.iqbal,
	jinpu.wang, richard, miquel.raynal, vigneshr, mcgrof, hare,
	damien.lemoal, johannes.thumshirn, bvanassche, ming.lei,
	vincent.fu, shinichiro.kawasaki

On Tue, Oct 04, 2022 at 10:00:10PM -0700, Chaitanya Kulkarni wrote:
> +void init_disk(struct gendisk *disk, int major, int first_minor,
> +		int minors, sector_t sectors, void *private_data,
> +		const struct block_device_operations *fops)
> +{
> +	disk->major = major;
> +	disk->first_minor = first_minor;
> +	disk->minors = minors;
> +	set_capacity(disk, sectors);
> +	disk->private_data = private_data;
> +	disk->fops = fops;

I don't like this at all.  For one major/first_minor/minors are
optional and discouraged for new drivers.  Setting the capacity is
a different thing and is done by helpers also used for revalidation
in many drivers.

It might make sense to pass the fops (and maybe private_data) to
blk_mq_alloc_disk / blk_alloc_disk, but even then I'm not quite
sure it is worth the churn.

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2022-10-10  7:59 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-05  5:00 [RFC PATCH 00/18] block: add and use init disk helper Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 01/18] " Chaitanya Kulkarni
2022-10-10  7:59   ` Christoph Hellwig
2022-10-05  5:00 ` [RFC PATCH 02/18] nfblock: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 03/18] amiflop: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 04/18] brd: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 05/18] drbd: " Chaitanya Kulkarni
2022-10-05 10:09   ` Christoph Böhmwalder
2022-10-05 17:24     ` Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 06/18] floppy: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 07/18] loop: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 08/18] n64cart: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 09/18] nbd: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 10/18] pcd: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 11/18] pd: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 12/18] pf: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 13/18] pktcdvd: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 14/18] rnbd-clt: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 15/18] swim: " Chaitanya Kulkarni
2022-10-05  6:54   ` Finn Thain
2022-10-05  5:00 ` [RFC PATCH 16/18] swim3: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 17/18] z2ram: " Chaitanya Kulkarni
2022-10-05  5:00 ` [RFC PATCH 18/18] ubi: " Chaitanya Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).