blk-mq: Make blk_mq_get_request() error path less confusing
blk_mq_get_tag() can modify data->ctx. This means that in the
error path of blk_mq_get_request() data->ctx should be passed to
blk_mq_put_ctx() instead of local_ctx. Note: since blk_mq_put_ctx()
ignores its argument, this patch does not change any functionality.
References: commit 1ad43c0078
("blk-mq: don't leak preempt counter/q_usage_counter when allocating rq failed")
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
c2e82a2348
commit
21e768b442
|
@ -337,12 +337,14 @@ static struct request *blk_mq_get_request(struct request_queue *q,
|
||||||
struct elevator_queue *e = q->elevator;
|
struct elevator_queue *e = q->elevator;
|
||||||
struct request *rq;
|
struct request *rq;
|
||||||
unsigned int tag;
|
unsigned int tag;
|
||||||
struct blk_mq_ctx *local_ctx = NULL;
|
bool put_ctx_on_error = false;
|
||||||
|
|
||||||
blk_queue_enter_live(q);
|
blk_queue_enter_live(q);
|
||||||
data->q = q;
|
data->q = q;
|
||||||
if (likely(!data->ctx))
|
if (likely(!data->ctx)) {
|
||||||
data->ctx = local_ctx = blk_mq_get_ctx(q);
|
data->ctx = blk_mq_get_ctx(q);
|
||||||
|
put_ctx_on_error = true;
|
||||||
|
}
|
||||||
if (likely(!data->hctx))
|
if (likely(!data->hctx))
|
||||||
data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
|
data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
|
||||||
if (op & REQ_NOWAIT)
|
if (op & REQ_NOWAIT)
|
||||||
|
@ -361,8 +363,8 @@ static struct request *blk_mq_get_request(struct request_queue *q,
|
||||||
|
|
||||||
tag = blk_mq_get_tag(data);
|
tag = blk_mq_get_tag(data);
|
||||||
if (tag == BLK_MQ_TAG_FAIL) {
|
if (tag == BLK_MQ_TAG_FAIL) {
|
||||||
if (local_ctx) {
|
if (put_ctx_on_error) {
|
||||||
blk_mq_put_ctx(local_ctx);
|
blk_mq_put_ctx(data->ctx);
|
||||||
data->ctx = NULL;
|
data->ctx = NULL;
|
||||||
}
|
}
|
||||||
blk_queue_exit(q);
|
blk_queue_exit(q);
|
||||||
|
|
Loading…
Reference in New Issue