All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <kch@nvidia.com>
To: <linux-block@vger.kernel.org>
Cc: <axboe@kernel.dk>, <kch@nvidia.com>, <hch@lst.de>,
	<damien.lemoal@opensource.wdc.com>, <johannes.thumshirn@wdc.com>,
	<bvanassche@acm.org>, <ming.lei@redhat.com>,
	<shinichiro.kawasaki@wdc.com>, <vincent.fu@samsung.com>
Subject: [RFC PATCH 1/6] block: add and use tagset init helper
Date: Mon, 10 Oct 2022 10:00:21 -0700	[thread overview]
Message-ID: <20221010170026.49808-2-kch@nvidia.com> (raw)
In-Reply-To: <20221010170026.49808-1-kch@nvidia.com>

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@nvidia.com>
---
 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


  reply	other threads:[~2022-10-10 17:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 17:00 [RFC PATCH 0/6] block: add and use tagset init helper Chaitanya Kulkarni
2022-10-10 17:00 ` Chaitanya Kulkarni [this message]
2022-10-10 17:00 ` [RFC PATCH 2/6] nbd: use init alloc tagset helper Chaitanya Kulkarni
2022-10-10 17:00 ` [RFC PATCH 3/6] virtio-blk: " Chaitanya Kulkarni
2022-10-10 17:00 ` [RFC PATCH 4/6] nvme-apple: " Chaitanya Kulkarni
2022-10-11 11:53   ` kernel test robot
2022-10-11 13:07     ` Chaitanya Kulkarni
2022-10-11 13:07       ` Chaitanya Kulkarni
2022-10-10 17:00 ` [RFC PATCH 5/6] nvme-core: " Chaitanya Kulkarni
2022-10-10 17:00 ` [RFC PATCH 6/6] nvme-pci: " Chaitanya Kulkarni
2022-10-10 17:40 ` [RFC PATCH 0/6] block: add and use tagset init helper Chaitanya Kulkarni
2022-10-11  6:06 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010170026.49808-2-kch@nvidia.com \
    --to=kch@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=hch@lst.de \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=shinichiro.kawasaki@wdc.com \
    --cc=vincent.fu@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.