diff mbox series

[2/2] blk-mq: provide a helper to check if a queue is busy

Message ID 20181108160609.27568-4-axboe@kernel.dk (mailing list archive)
State New, archived
Headers show
Series Add queue_is_busy helper | expand

Commit Message

Jens Axboe Nov. 8, 2018, 4:06 p.m. UTC
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(+)

Comments

Bart Van Assche Nov. 8, 2018, 4:30 p.m. UTC | #1
On Thu, 2018-11-08 at 09:06 -0700, Jens Axboe wrote:
> +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;

I think the "(bool *)" cast can be left out. Anyway:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Jens Axboe Nov. 8, 2018, 4:32 p.m. UTC | #2
On 11/8/18 9:30 AM, Bart Van Assche wrote:
> On Thu, 2018-11-08 at 09:06 -0700, Jens Axboe wrote:
>> +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;
> 
> I think the "(bool *)" cast can be left out. Anyway:

It can, I'll drop it.

> Reviewed-by: Bart Van Assche <bvanassche@acm.org>

Thanks
diff mbox series

Patch

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),