[RFC PATCH 1/6] block: add and use tagset init helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add and use a helper to initialize the common fields of the tag_set.
The newly added helper blk_mq_init_alloc_tag_set() replaces existing
call to blk_mq_alloc_tag_set() and takes following arguments to
initialize tag_set before calling blk_mq_alloc_tag_set() :-

* blk_mq_ops
* number of h/w queues
* queue depth
* driver data

The number of arguments to the new API are similar to the existing API
blk_mq_alloc_sq_tag_set() used in block layer to eliminate the common
code to initialize and allocate tag_set.

This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of tag set in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@xxxxxxxxxx>
---
 block/blk-mq.c                | 12 ++++++++++++
 drivers/block/null_blk/main.c |  7 ++-----
 include/linux/blk-mq.h        |  4 +++-
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 8070b6c10e8d..0060c6b37b69 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4429,6 +4429,18 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
 }
 EXPORT_SYMBOL(blk_mq_alloc_tag_set);
 
+int blk_mq_init_alloc_tag_set(struct blk_mq_tag_set *set,
+		const struct blk_mq_ops *ops, unsigned int nr_hw_queues,
+		unsigned int queue_depth, void *driver_data)
+{
+	set->ops = ops;
+	set->nr_hw_queues = nr_hw_queues;
+	set->queue_depth = queue_depth;
+	set->driver_data = driver_data;
+	return blk_mq_alloc_tag_set(set);
+}
+EXPORT_SYMBOL_GPL(blk_mq_init_alloc_tag_set);
+
 /* allocate and initialize a tagset for a simple single-queue device */
 int blk_mq_alloc_sq_tag_set(struct blk_mq_tag_set *set,
 		const struct blk_mq_ops *ops, unsigned int queue_depth,
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 1f154f92f4c2..3b32d5231eab 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1926,12 +1926,8 @@ static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set *set)
 			flags |= BLK_MQ_F_BLOCKING;
 	}
 
-	set->ops = &null_mq_ops;
 	set->cmd_size	= sizeof(struct nullb_cmd);
 	set->flags = flags;
-	set->driver_data = nullb;
-	set->nr_hw_queues = hw_queues;
-	set->queue_depth = queue_depth;
 	set->numa_node = numa_node;
 	if (poll_queues) {
 		set->nr_hw_queues += poll_queues;
@@ -1940,7 +1936,8 @@ static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set *set)
 		set->nr_maps = 1;
 	}
 
-	return blk_mq_alloc_tag_set(set);
+	return blk_mq_init_alloc_tag_set(set, &null_mq_ops, hw_queues,
+					 queue_depth, nullb);
 }
 
 static int null_validate_conf(struct nullb_device *dev)
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index ba18e9bdb799..b34d55fe79e0 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -707,7 +707,9 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *);
 int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 		struct request_queue *q);
 void blk_mq_destroy_queue(struct request_queue *);
-
+int blk_mq_init_alloc_tag_set(struct blk_mq_tag_set *set,
+		const struct blk_mq_ops *ops, unsigned int nr_hw_queues,
+		unsigned int queue_depth, void *driver_data);
 int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set);
 int blk_mq_alloc_sq_tag_set(struct blk_mq_tag_set *set,
 		const struct blk_mq_ops *ops, unsigned int queue_depth,
-- 
2.29.0




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux