]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - block/blk-mq.c
blk-mq: Make blk_mq_get_request() error path less confusing
[mirror_ubuntu-bionic-kernel.git] / block / blk-mq.c
index 9eea67ce82d90e2f77649a1bc46975e96f038358..13cdccef543ceed95e1af6901a65540deee8e2e1 100644 (file)
@@ -337,12 +337,14 @@ static struct request *blk_mq_get_request(struct request_queue *q,
        struct elevator_queue *e = q->elevator;
        struct request *rq;
        unsigned int tag;
-       struct blk_mq_ctx *local_ctx = NULL;
+       bool put_ctx_on_error = false;
 
        blk_queue_enter_live(q);
        data->q = q;
-       if (likely(!data->ctx))
-               data->ctx = local_ctx = blk_mq_get_ctx(q);
+       if (likely(!data->ctx)) {
+               data->ctx = blk_mq_get_ctx(q);
+               put_ctx_on_error = true;
+       }
        if (likely(!data->hctx))
                data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
        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);
        if (tag == BLK_MQ_TAG_FAIL) {
-               if (local_ctx) {
-                       blk_mq_put_ctx(local_ctx);
+               if (put_ctx_on_error) {
+                       blk_mq_put_ctx(data->ctx);
                        data->ctx = NULL;
                }
                blk_queue_exit(q);