Commit ae879912 authored by Jens Axboe's avatar Jens Axboe

blk-mq: provide a helper to check if a queue is busy

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: default avatarMike Snitzer <snitzer@redhat.com>
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7baa8572
...@@ -790,6 +790,32 @@ struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag) ...@@ -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); 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 = priv;
*busy = true;
return false;
}
return true;
}
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) static void blk_mq_rq_timed_out(struct request *req, bool reserved)
{ {
req->rq_flags |= RQF_TIMED_OUT; req->rq_flags |= RQF_TIMED_OUT;
......
...@@ -250,6 +250,8 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule); ...@@ -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); void blk_mq_free_request(struct request *rq);
bool blk_mq_can_queue(struct blk_mq_hw_ctx *); bool blk_mq_can_queue(struct blk_mq_hw_ctx *);
bool blk_mq_queue_busy(struct request_queue *q);
enum { enum {
/* return when out of requests */ /* return when out of requests */
BLK_MQ_REQ_NOWAIT = (__force blk_mq_req_flags_t)(1 << 0), BLK_MQ_REQ_NOWAIT = (__force blk_mq_req_flags_t)(1 << 0),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment