Skip to content

Commit

Permalink
blk-mq: Fix queue usage on failed request allocation
Browse files Browse the repository at this point in the history
blk_mq_get_request() does not release the callers queue usage counter
when allocation fails. The caller still needs to account for its own
queue usage when it is unable to allocate a request.

Fixes: 1ad43c0 ("blk-mq: don't leak preempt counter/q_usage_counter when allocating rq failed")

Reported-by: Max Gurtovoy <[email protected]>
Reviewed-by: Ming Lei <[email protected]>
Reviewed-by: Sagi Grimberg <[email protected]>
Tested-by: Max Gurtovoy <[email protected]>
Signed-off-by: Keith Busch <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Keith Busch authored and axboe committed Aug 15, 2017
1 parent ef95484 commit 3280d66
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
return ERR_PTR(ret);

rq = blk_mq_get_request(q, NULL, op, &alloc_data);
blk_queue_exit(q);

if (!rq)
return ERR_PTR(-EWOULDBLOCK);

blk_mq_put_ctx(alloc_data.ctx);
blk_queue_exit(q);

rq->__data_len = 0;
rq->__sector = (sector_t) -1;
Expand Down Expand Up @@ -411,12 +411,11 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
alloc_data.ctx = __blk_mq_get_ctx(q, cpu);

rq = blk_mq_get_request(q, NULL, op, &alloc_data);
blk_queue_exit(q);

if (!rq)
return ERR_PTR(-EWOULDBLOCK);

blk_queue_exit(q);

return rq;
}
EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);
Expand Down

0 comments on commit 3280d66

Please sign in to comment.