2022-11-01 16:11:31

by Jinlong Chen

[permalink] [raw]
Subject: [PATCH 0/4] some random cleanups for blk-mq.c

Patch 1 updates the outdated comment of blk_mq_quiesce_queue_nowait().
Patch 2 improves the error handling blk_mq_alloc_rq_map(). Patch 3 and 4
improve readability of request alloc routines.

Jinlong Chen (4):
blk-mq: update comment for blk_mq_quiesce_queue_nowait()
blk-mq: improve error handling in blk_mq_alloc_rq_map()
blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()
blk-mq: improve readability of blk_mq_alloc_request()

block/blk-mq.c | 105 ++++++++++++++++++++++++++++---------------------
1 file changed, 61 insertions(+), 44 deletions(-)

--
2.31.1



2022-11-01 16:21:52

by Jinlong Chen

[permalink] [raw]
Subject: [PATCH 3/4] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()

if-else is more readable than goto here.

Signed-off-by: Jinlong Chen <[email protected]>
---
block/blk-mq.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 408a929be90e..87a6348a0d0a 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -547,25 +547,26 @@ static struct request *blk_mq_alloc_cached_request(struct request_queue *q,

if (!plug)
return NULL;
+
if (rq_list_empty(plug->cached_rq)) {
if (plug->nr_ios == 1)
return NULL;
rq = blk_mq_rq_cache_fill(q, plug, opf, flags);
- if (rq)
- goto got_it;
- return NULL;
- }
- rq = rq_list_peek(&plug->cached_rq);
- if (!rq || rq->q != q)
- return NULL;
+ if (!rq)
+ return NULL;
+ } else {
+ rq = rq_list_peek(&plug->cached_rq);
+ if (!rq || rq->q != q)
+ return NULL;

- if (blk_mq_get_hctx_type(opf) != rq->mq_hctx->type)
- return NULL;
- if (op_is_flush(rq->cmd_flags) != op_is_flush(opf))
- return NULL;
+ if (blk_mq_get_hctx_type(opf) != rq->mq_hctx->type)
+ return NULL;
+ if (op_is_flush(rq->cmd_flags) != op_is_flush(opf))
+ return NULL;
+
+ plug->cached_rq = rq_list_next(rq);
+ }

- plug->cached_rq = rq_list_next(rq);
-got_it:
rq->cmd_flags = opf;
INIT_LIST_HEAD(&rq->queuelist);
return rq;
--
2.31.1


2022-11-01 17:55:13

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 3/4] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()

On Tue, Nov 01, 2022 at 11:11:36PM +0800, Jinlong Chen wrote:
> if-else is more readable than goto here.

Looks good:

Reviewed-by: Christoph Hellwig <[email protected]>