diff mbox series

[3/4] block: remove a pointless queue enter pair in blk_mq_alloc_request_hctx

Message ID 20200513110419.2362556-4-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/4] block: move the call to blk_queue_enter_live out of blk_mq_get_request | expand

Commit Message

Christoph Hellwig May 13, 2020, 11:04 a.m. UTC
No need for two queue references.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-mq.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

Comments

Johannes Thumshirn May 13, 2020, 12:02 p.m. UTC | #1
On 13/05/2020 13:04, Christoph Hellwig wrote:
>  	rq = blk_mq_get_request(q, NULL, &alloc_data);
> -	blk_queue_exit(q);
> -
> -	if (!rq) {
> -		blk_queue_exit(q);
> -		return ERR_PTR(-EWOULDBLOCK);
> -	}
> +	if (!rq)
> +		goto out_queue_exit;
>  
>  	return rq;
> +out_queue_exit:
> +	blk_queue_exit(q);
> +	return ERR_PTR(ret);

I know success handling is discouraged in the kernel, but I think 

	rq = blk_mq_get_request(q, NULL, &alloc_data);
	if (rq)
		return rq;

out_queue_exit:
	blk_queue_exit(q);
	return ERR_PTR(ret);

looks nicer, doesn't it?
Christoph Hellwig May 13, 2020, 12:23 p.m. UTC | #2
On Wed, May 13, 2020 at 12:02:10PM +0000, Johannes Thumshirn wrote:
> I know success handling is discouraged in the kernel, but I think 
> 
> 	rq = blk_mq_get_request(q, NULL, &alloc_data);
> 	if (rq)
> 		return rq;
> 
> out_queue_exit:
> 	blk_queue_exit(q);
> 	return ERR_PTR(ret);
> 
> looks nicer, doesn't it?	

Not at all.  A flow of most common case stays in line, everything else
jumps out really helps with reading.
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index a3491c1397501..81b7af7be70b5 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -445,24 +445,22 @@  struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	 * Check if the hardware context is actually mapped to anything.
 	 * If not tell the caller that it should skip this queue.
 	 */
+	ret = -EXDEV;
 	alloc_data.hctx = q->queue_hw_ctx[hctx_idx];
-	if (!blk_mq_hw_queue_mapped(alloc_data.hctx)) {
-		blk_queue_exit(q);
-		return ERR_PTR(-EXDEV);
-	}
+	if (!blk_mq_hw_queue_mapped(alloc_data.hctx))
+		goto out_queue_exit;
 	cpu = cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask);
 	alloc_data.ctx = __blk_mq_get_ctx(q, cpu);
 
-	blk_queue_enter_live(q);
+	ret = -EWOULDBLOCK;
 	rq = blk_mq_get_request(q, NULL, &alloc_data);
-	blk_queue_exit(q);
-
-	if (!rq) {
-		blk_queue_exit(q);
-		return ERR_PTR(-EWOULDBLOCK);
-	}
+	if (!rq)
+		goto out_queue_exit;
 
 	return rq;
+out_queue_exit:
+	blk_queue_exit(q);
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);