blk-mq: streamline handling of q->mq_ops->queue_rq result
PATCH 1/1 blk-mq: streamline handling of q->mq_ops->queue_rq result
Current handling of q->mq_ops->queue_rq result is a bit ugly:
- two branches which needs to 'continue' have to check if the dispatch local list is empty, otherwise one bad request may
be retrieved via 'rq = list_first_entry(list, struct request, queuelist);'
- the branch of 'if (unlikely(ret != BLK_STS_OK))' isn't easy to follow, since it is actually one error branch.
Streamline this handling, so the code becomes more readable, meantime potential kernel oops can be avoided in case that the last request in local dispatch list is failed.
--- block/blk-mq.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
block/blk-mq.c +5 -10
@@ -1407,7 +1407,10 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,if (nr_budgets) nr_budgets--; ret = q->mq_ops->queue_rq (hctx, &bd); -if (ret ==BLK_STS_RESOURCE || ret ==BLK_STS_DEV_RESOURCE ) { +if (likely (ret ==BLK_STS_OK )) { + queued++; + }else if (ret ==BLK_STS_RESOURCE || + ret ==BLK_STS_DEV_RESOURCE ) {blk_mq_handle_dev_resource (rq, list);break ; }else if (ret ==BLK_STS_ZONE_RESOURCE ) {
@@ -1417,18 +1420,10 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,* accept. */ blk_mq_handle_zone_resource (rq, &zone_list); -if (list_empty (list)) -break ; -continue ; - } - -if (unlikely (ret !=BLK_STS_OK )) { + }else { errors++;blk_mq_end_request (rq,BLK_STS_IOERR ); -continue ; } - - queued++; }while (!list_empty (list));if (!list_empty (&zone_list))
Signature · 1 line
2.25.2
Quoted 6 lines · Ming Lei
Current handling of
q->mq_ops->queue_rqresult is a bit ugly:- two branches which needs to 'continue' have to check if the dispatch local list is empty, otherwise one bad request may
be retrieved via 'rq =list_first_entry(list, struct request, queuelist);'
Quoted 6 lines
- the branch of 'if (
unlikely(ret != BLK_STS_OK))' isn't easy to follow, since it is actually one error branch.Streamline this handling, so the code becomes more readable, meantime potential kernel oops can be avoided in case that the last request in local dispatch list is failed.
I don't really find that much easier to read. If we want to clean this up for rea we should use a proper switch statement. Something like this:
block/blk-mq.c +11 -13
@@ -1275,30 +1275,28 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, } ret = q->mq_ops->queue_rq (hctx, &bd); -if (ret ==BLK_STS_RESOURCE || ret ==BLK_STS_DEV_RESOURCE ) { -blk_mq_handle_dev_resource (rq, list); +switch (ret) { +case BLK_STS_OK : + queued++;break ; - }else if (ret ==BLK_STS_ZONE_RESOURCE ) { +case BLK_STS_RESOURCE : +case BLK_STS_DEV_RESOURCE : +blk_mq_handle_dev_resource (rq, list); + goto out; +case BLK_STS_ZONE_RESOURCE :/* * Move the request to zone_list and keep going through * the dispatch list to find more requests the drive can * accept. */ blk_mq_handle_zone_resource (rq, &zone_list); -if (list_empty (list)) -break ; -continue ; - } - -if (unlikely (ret !=BLK_STS_OK )) { +break ; +default : errors++;blk_mq_end_request (rq,BLK_STS_IOERR ); -continue ; } - - queued++; }while (!list_empty (list)); - +out:if (!list_empty (&zone_list))list_splice_tail_init (&zone_list, list);
Quoted 55 lines · Christoph Hellwig
Quoted 6 lines · Ming Lei
Current handling of
q->mq_ops->queue_rqresult is a bit ugly:- two branches which needs to 'continue' have to check if the dispatch local list is empty, otherwise one bad request may
be retrieved via 'rq =list_first_entry(list, struct request, queuelist);'Quoted 6 lines
- the branch of 'if (
unlikely(ret != BLK_STS_OK))' isn't easy to follow, since it is actually one error branch.Streamline this handling, so the code becomes more readable, meantime potential kernel oops can be avoided in case that the last request in local dispatch list is failed.
I don't really find that much easier to read. If we want to clean this up for rea we should use a proper switch statement. Something like this:
block/blk-mq.c +10
-9@@ -1275,30 +1275,28 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, } ret = q->mq_ops->queue_rq (hctx, &bd); -if (ret ==BLK_STS_RESOURCE || ret ==BLK_STS_DEV_RESOURCE ) { -blk_mq_handle_dev_resource (rq, list); +switch (ret) { +case BLK_STS_OK : + queued++;break ; - }else if (ret ==BLK_STS_ZONE_RESOURCE ) { +case BLK_STS_RESOURCE : +case BLK_STS_DEV_RESOURCE : +blk_mq_handle_dev_resource (rq, list); + goto out; +case BLK_STS_ZONE_RESOURCE :/* * Move the request to zone_list and keep going through * the dispatch list to find more requests the drive can * accept. */ blk_mq_handle_zone_resource (rq, &zone_list); -if (list_empty (list)) -break ; -continue ; - } - -if (unlikely (ret !=BLK_STS_OK )) { +break ; +default : errors++;blk_mq_end_request (rq,BLK_STS_IOERR );
block/blk-mq.c bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, · line 1302
Quoted 10 lines
block/blk-mq.c +1
-4-continue ; } - - queued++; }while (!list_empty (list)); - +out:if (!list_empty (&zone_list))list_splice_tail_init (&zone_list, list);
Agreed, also the presence of a switch (ret) makes it more than obvious that ret has more than one case.
Quoted 53 lines · Christoph Hellwig
Quoted 6 lines · Ming Lei
Current handling of
q->mq_ops->queue_rqresult is a bit ugly:- two branches which needs to 'continue' have to check if the dispatch local list is empty, otherwise one bad request may
be retrieved via 'rq =list_first_entry(list, struct request, queuelist);'Quoted 6 lines
- the branch of 'if (
unlikely(ret != BLK_STS_OK))' isn't easy to follow, since it is actually one error branch.Streamline this handling, so the code becomes more readable, meantime potential kernel oops can be avoided in case that the last request in local dispatch list is failed.
I don't really find that much easier to read. If we want to clean this up for rea we should use a proper switch statement. Something like this:
block/blk-mq.c +10
-9@@ -1275,30 +1275,28 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, } ret = q->mq_ops->queue_rq (hctx, &bd); -if (ret ==BLK_STS_RESOURCE || ret ==BLK_STS_DEV_RESOURCE ) { -blk_mq_handle_dev_resource (rq, list); +switch (ret) { +case BLK_STS_OK : + queued++;break ; - }else if (ret ==BLK_STS_ZONE_RESOURCE ) { +case BLK_STS_RESOURCE : +case BLK_STS_DEV_RESOURCE : +blk_mq_handle_dev_resource (rq, list); + goto out; +case BLK_STS_ZONE_RESOURCE :/* * Move the request to zone_list and keep going through * the dispatch list to find more requests the drive can * accept. */ blk_mq_handle_zone_resource (rq, &zone_list); -if (list_empty (list)) -break ; -continue ; - } - -if (unlikely (ret !=BLK_STS_OK )) { +break ; +default : errors++;
block/blk-mq.c bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, · line 1301
Quoted 10 lines
block/blk-mq.c +1
-4blk_mq_end_request (rq,BLK_STS_IOERR ); -continue ; } - - queued++; }while (!list_empty (list)); - +out:if (!list_empty (&zone_list))list_splice_tail_init (&zone_list, list);
I am fine to switch back to 'switch'. I doesn't take 'switch' because you changed 'switch' to 'if else' before.
Thanks,
Ming