From: Ming Lei <tom.leiming@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, linux-kernel@vger.kernel.org
Cc: Ming Lei <tom.leiming@gmail.com>
Subject: [PATCH v1 2/3] blk-mq: avoid code duplication
Date: Tue, 27 May 2014 23:35:13 +0800 [thread overview]
Message-ID: <1401204914-3340-3-git-send-email-tom.leiming@gmail.com> (raw)
In-Reply-To: <1401204914-3340-1-git-send-email-tom.leiming@gmail.com>
blk_mq_exit_hw_queues() and blk_mq_free_hw_queues()
are introduced to avoid code duplication.
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
block/blk-mq.c | 61 ++++++++++++++++++++++++++++++++++----------------------
1 file changed, 37 insertions(+), 24 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index dad22a9..0785175 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1523,11 +1523,43 @@ static int blk_mq_hctx_notify(void *data, unsigned long action,
return NOTIFY_OK;
}
+static void blk_mq_exit_hw_queues(struct request_queue *q,
+ struct blk_mq_tag_set *set, int nr_queue)
+{
+ struct blk_mq_hw_ctx *hctx;
+ unsigned int i;
+
+ queue_for_each_hw_ctx(q, hctx, i) {
+ if (i == nr_queue)
+ break;
+
+ if (set->ops->exit_hctx)
+ set->ops->exit_hctx(hctx, i);
+
+ blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);
+ kfree(hctx->ctxs);
+ blk_mq_free_bitmap(&hctx->ctx_map);
+ }
+
+}
+
+static void blk_mq_free_hw_queues(struct request_queue *q,
+ struct blk_mq_tag_set *set)
+{
+ struct blk_mq_hw_ctx *hctx;
+ unsigned int i;
+
+ queue_for_each_hw_ctx(q, hctx, i) {
+ free_cpumask_var(hctx->cpumask);
+ set->ops->free_hctx(hctx, i);
+ }
+}
+
static int blk_mq_init_hw_queues(struct request_queue *q,
struct blk_mq_tag_set *set)
{
struct blk_mq_hw_ctx *hctx;
- unsigned int i, j;
+ unsigned int i;
/*
* Initialize hardware queues
@@ -1579,17 +1611,7 @@ static int blk_mq_init_hw_queues(struct request_queue *q,
/*
* Init failed
*/
- queue_for_each_hw_ctx(q, hctx, j) {
- if (i == j)
- break;
-
- if (set->ops->exit_hctx)
- set->ops->exit_hctx(hctx, j);
-
- blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);
- kfree(hctx->ctxs);
- blk_mq_free_bitmap(&hctx->ctx_map);
- }
+ blk_mq_exit_hw_queues(q, set, i);
return 1;
}
@@ -1838,21 +1860,12 @@ EXPORT_SYMBOL(blk_mq_init_queue);
void blk_mq_free_queue(struct request_queue *q)
{
- struct blk_mq_hw_ctx *hctx;
- int i;
+ struct blk_mq_tag_set *set = q->tag_set;
blk_mq_del_queue_tag_set(q);
- queue_for_each_hw_ctx(q, hctx, i) {
- blk_mq_tag_idle(hctx);
- kfree(hctx->ctxs);
- blk_mq_free_bitmap(&hctx->ctx_map);
- blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);
- if (q->mq_ops->exit_hctx)
- q->mq_ops->exit_hctx(hctx, i);
- free_cpumask_var(hctx->cpumask);
- q->mq_ops->free_hctx(hctx, i);
- }
+ blk_mq_exit_hw_queues(q, set, set->nr_hw_queues);
+ blk_mq_free_hw_queues(q, set);
free_percpu(q->queue_ctx);
kfree(q->queue_hw_ctx);
--
1.7.9.5
next prev parent reply other threads:[~2014-05-27 15:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-27 15:35 [PATCH v1 0/3] blk-mq: misc changes Ming Lei
2014-05-27 15:35 ` [PATCH v1 1/3] blk-mq: fix leak of hctx->ctx_map Ming Lei
2014-05-27 15:35 ` Ming Lei [this message]
2014-05-27 15:35 ` [PATCH v1 3/3] block: only allocate/free mq_usage_counter in blk-mq Ming Lei
2014-05-27 15:41 ` [PATCH v1 0/3] blk-mq: misc changes Jens Axboe
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=1401204914-3340-3-git-send-email-tom.leiming@gmail.com \
--to=tom.leiming@gmail.com \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox