2022-10-05 05:08:02

by Chaitanya Kulkarni

[permalink] [raw]
Subject: [RFC PATCH 14/18] rnbd-clt: 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.

Signed-off-by: Chaitanya Kulkarni <[email protected]>
---
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