block: add and use init disk helper
Subsystems (9)
cover block: add and use init disk helper
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(-)
Signature · 1 line
2.29.0
RFC PATCH 1/18 block: add and use init disk helper
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.
--- block/genhd.c | 13 +++++++++++++ drivers/block/null_blk/main.c | 12 ++++-------- include/linux/blkdev.h | 5 +++++ 3 files changed, 22 insertions(+), 8 deletions(-)
block/genhd.c +13 -0
@@ -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);
drivers/block/null_blk/main.c +4 -8
@@ -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) {
include/linux/blkdev.h +5 -0
@@ -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);
Signature · 1 line
2.29.0
block/genhd.c void inc_diskseq(struct gendisk *disk) · line 1483
Quoted 10 lines · Chaitanya Kulkarni
block/genhd.c +10
-0+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.
Quoted 17 lines · Christoph Hellwig
block/genhd.c void inc_diskseq(struct gendisk *disk) · line 1483
Quoted 10 lines · Chaitanya Kulkarni
block/genhd.c +10
-0+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.
Quoted 3 lines
It might make sense to pass the fops (and maybe
private_data) toblk_mq_alloc_disk/blk_alloc_disk, but even then I'm not quite sure it is worth the churn.
Okay I'll drop this, and see if I can get something meaningful with fops and private data.
-ck
RFC PATCH 2/18 nfblock: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- arch/m68k/emu/nfblock.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
arch/m68k/emu/nfblock.c +2 -6
@@ -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)
Signature · 1 line
2.29.0
RFC PATCH 3/18 amiflop: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/amiflop.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/block/amiflop.c +2 -6
@@ -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);
Signature · 1 line
2.29.0
RFC PATCH 4/18 brd: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/ataflop.c | 8 ++------ drivers/block/brd.c | 9 ++------- 2 files changed, 4 insertions(+), 13 deletions(-)
drivers/block/ataflop.c +2 -6
@@ -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 ;
drivers/block/brd.c +2 -7
@@ -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
Signature · 1 line
2.29.0
RFC PATCH 5/18 drbd: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/drbd/drbd_main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/block/drbd/drbd_main.c +1 -5
@@ -2706,13 +2706,9 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigset_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);
Signature · 1 line
2.29.0
Christoph Böhmwalder
maintainerRe: [RFC PATCH 05/18] drbd: use init disk helper
Am 05.10.22 um 07:00 schrieb Chaitanya Kulkarni:
Quoted 20 lines
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 <[email protected]>--- drivers/block/drbd/drbd_main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/block/drbd/drbd_main.c +0
-1@@ -2706,13 +2706,9 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigset_disk_ro (disk, true); - disk->major =DRBD_MAJOR ;
drivers/block/drbd/drbd_main.c enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig · line 2714
Quoted 10 lines
drivers/block/drbd/drbd_main.c +1
-4- 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?
Signature · 3 lines
Christoph Böhmwalder LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
Re: [RFC PATCH 05/18] drbd: use init disk helper
Quoted 18 lines
Quoted 18 lines
drivers/block/drbd/drbd_main.c +1
-5@@ -2706,13 +2706,9 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigset_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);
Quoted 7 lines
drivers/block/drbd/drbd_main.c enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig · line 2714
Quoted 2 lines
drivers/block/drbd/drbd_main.c +0
-0blk_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
RFC PATCH 6/18 floppy: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/floppy.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/block/floppy.c +2 -6
@@ -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;
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 7/18 loop: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/loop.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/block/loop.c +2 -5
@@ -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)
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 8/18 n64cart: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/n64cart.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/n64cart.c +1 -3
@@ -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 );
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 9/18 nbd: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/nbd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/block/nbd.c +2 -5
@@ -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;
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 10/18 pcd: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/paride/pcd.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/block/paride/pcd.c +1 -4
@@ -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 ;
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 11/18 pd: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/paride/pd.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/block/paride/pd.c +2 -6
@@ -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;
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 12/18 pf: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/paride/pf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/block/paride/pf.c +1 -5
@@ -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 );
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 13/18 pktcdvd: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/pktcdvd.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/block/pktcdvd.c +1 -5
@@ -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);
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 14/18 rnbd-clt: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/rnbd/rnbd-clt.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/block/rnbd/rnbd-clt.c +3 -6
@@ -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);
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 15/18 swim: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/swim.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/block/swim.c +2 -5
@@ -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;
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [RFC PATCH 15/18] swim: use init disk helper
Quoted 24 lines · 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 <[email protected]>--- drivers/block/swim.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/block/swim.c +0
-3@@ -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);
drivers/block/swim.c static int swim_floppy_init(struct swim_priv *swd) · line 846
Quoted 10 lines
drivers/block/swim.c +2
-2- 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.
RFC PATCH 16/18 swim3: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/swim3.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/block/swim3.c +2 -6
@@ -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;
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 17/18 z2ram: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/block/z2ram.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/block/z2ram.c +1 -4
@@ -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
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
RFC PATCH 18/18 ubi: use init disk helper
In reply to Chaitanya KulkarniAdd 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.
--- drivers/mtd/ubi/block.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mtd/ubi/block.c +1 -5
@@ -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;
Signature · 6 lines
2.29.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/