All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: linux-block@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 2/2] blk-mq: provide a helper to check if a queue is busy
Date: Thu,  8 Nov 2018 09:06:09 -0700	[thread overview]
Message-ID: <20181108160609.27568-4-axboe@kernel.dk> (raw)
In-Reply-To: <20181108160609.27568-1-axboe@kernel.dk>

Returns true if the queue currently has requests pending,
false if not.

DM can use this to replace the atomic_inc/dec they do per device
to see if a device is busy.

Reviewed-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 block/blk-mq.c         | 26 ++++++++++++++++++++++++++
 include/linux/blk-mq.h |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 4a622c832b31..65243c40ac7c 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -790,6 +790,32 @@ struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag)
 }
 EXPORT_SYMBOL(blk_mq_tag_to_rq);
 
+static bool blk_mq_check_busy(struct blk_mq_hw_ctx *hctx, struct request *rq,
+			      void *priv, bool reserved)
+{
+	/*
+	 * If we find a request, we know the queue is busy. Return false
+	 * to stop the iteration.
+	 */
+	if (rq->q == hctx->queue) {
+		bool *busy = (bool *) priv;
+
+		*busy = true;
+		return false;
+	}
+
+	return false;
+}
+
+bool blk_mq_queue_busy(struct request_queue *q)
+{
+	bool busy = false;
+
+	blk_mq_queue_tag_busy_iter(q, blk_mq_check_busy, &busy);
+	return busy;
+}
+EXPORT_SYMBOL_GPL(blk_mq_queue_busy);
+
 static void blk_mq_rq_timed_out(struct request *req, bool reserved)
 {
 	req->rq_flags |= RQF_TIMED_OUT;
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index ff497dfcbbf9..929e8abc5535 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -250,6 +250,8 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule);
 void blk_mq_free_request(struct request *rq);
 bool blk_mq_can_queue(struct blk_mq_hw_ctx *);
 
+bool blk_mq_queue_busy(struct request_queue *q);
+
 enum {
 	/* return when out of requests */
 	BLK_MQ_REQ_NOWAIT	= (__force blk_mq_req_flags_t)(1 << 0),
-- 
2.17.1

  parent reply	other threads:[~2018-11-08 16:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08 16:06 [PATCHSET v2 0/2] Add queue_is_busy helper Jens Axboe
2018-11-08 16:06 ` [PATCH] blk-mq: provide a helper to check if a queue is busy Jens Axboe
2018-11-08 16:06 ` [PATCH 1/2] blk-mq-tag: change busy_iter_fn to return whether to continue or not Jens Axboe
2018-11-08 16:28   ` Bart Van Assche
2018-11-08 16:31     ` Jens Axboe
2018-11-08 17:35       ` Bart Van Assche
2018-11-08 17:47         ` Jens Axboe
2018-11-08 17:50           ` Jens Axboe
2018-11-08 18:04             ` Bart Van Assche
2018-11-08 16:06 ` Jens Axboe [this message]
2018-11-08 16:30   ` [PATCH 2/2] blk-mq: provide a helper to check if a queue is busy Bart Van Assche
2018-11-08 16:32     ` Jens Axboe
2018-11-09  1:53 ` [PATCHSET v2 0/2] Add queue_is_busy helper jianchao.wang
2018-11-09  2:08   ` jianchao.wang
  -- strict thread matches above, loose matches on Subject: below --
2018-11-08 15:42 [PATCHSET " Jens Axboe
2018-11-08 15:42 ` [PATCH 2/2] blk-mq: provide a helper to check if a queue is busy Jens Axboe
2018-11-08 15:49   ` Mike Snitzer
2018-11-08 15:54   ` Laurence Oberman
2018-11-08 15:58     ` 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=20181108160609.27568-4-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=linux-block@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 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.