* [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result
@ 2020-07-01 13:58 Ming Lei
2020-07-08 12:27 ` Ming Lei
2020-07-08 22:05 ` Jens Axboe
0 siblings, 2 replies; 7+ messages in thread
From: Ming Lei @ 2020-07-01 13:58 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Ming Lei, Christoph Hellwig
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.
Fixes: fc17b6534eb8 ("blk-mq: switch ->queue_rq return value to blk_status_t")
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
V2:
- change 'if else' to switch as suggested by Christoph
block/blk-mq.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 65e0846fd065..cc85775fc372 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1407,30 +1407,28 @@ 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) {
- 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);
--
2.25.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result
2020-07-01 13:58 [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result Ming Lei
@ 2020-07-08 12:27 ` Ming Lei
2020-07-08 12:53 ` Johannes Thumshirn
2020-07-08 14:05 ` John Garry
2020-07-08 22:05 ` Jens Axboe
1 sibling, 2 replies; 7+ messages in thread
From: Ming Lei @ 2020-07-08 12:27 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Christoph Hellwig
On Wed, Jul 01, 2020 at 09:58:57PM +0800, Ming Lei wrote:
> 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.
>
> Fixes: fc17b6534eb8 ("blk-mq: switch ->queue_rq return value to blk_status_t")
> Cc: Christoph Hellwig <hch@infradead.org>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> V2:
> - change 'if else' to switch as suggested by Christoph
>
> block/blk-mq.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 65e0846fd065..cc85775fc372 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -1407,30 +1407,28 @@ 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) {
> - 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);
>
> --
> 2.25.2
>
Hello,
Ping...
--
Ming
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result
2020-07-08 12:27 ` Ming Lei
@ 2020-07-08 12:53 ` Johannes Thumshirn
2020-07-08 14:05 ` John Garry
1 sibling, 0 replies; 7+ messages in thread
From: Johannes Thumshirn @ 2020-07-08 12:53 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block@vger.kernel.org, hch@infradead.org
Looks good to me,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result
2020-07-08 12:27 ` Ming Lei
2020-07-08 12:53 ` Johannes Thumshirn
@ 2020-07-08 14:05 ` John Garry
2020-07-08 14:23 ` Johannes Thumshirn
2020-07-08 22:03 ` Ming Lei
1 sibling, 2 replies; 7+ messages in thread
From: John Garry @ 2020-07-08 14:05 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block, Christoph Hellwig
On 08/07/2020 13:27, Ming Lei wrote:
> k;
> - } 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
question not on this patch specifically: is this supposed to be
"driver", and not "drive"? "driver" is mentioned earlier in the function
> * accept.
> */
> blk_mq_handle_zone_resource(rq, &zone_list);
> - if (list_empty(list))
> - break;
> - continue;
> - }
> -
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result
2020-07-08 14:05 ` John Garry
@ 2020-07-08 14:23 ` Johannes Thumshirn
2020-07-08 22:03 ` Ming Lei
1 sibling, 0 replies; 7+ messages in thread
From: Johannes Thumshirn @ 2020-07-08 14:23 UTC (permalink / raw)
To: John Garry, Ming Lei, Jens Axboe
Cc: linux-block@vger.kernel.org, hch@infradead.org
On 08/07/2020 16:06, John Garry wrote:
> On 08/07/2020 13:27, Ming Lei wrote:
>> k;
>> - } 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
>
> question not on this patch specifically: is this supposed to be
> "driver", and not "drive"? "driver" is mentioned earlier in the function
No it's drive, the sole purpose of BLK_STS_ZONE_RESOURCE is the apply some back
pressure for IO submitters to a SMR disk and the zone-append emulation it uses.
See drivers/scsi/sd_zbc.c for details.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result
2020-07-08 14:05 ` John Garry
2020-07-08 14:23 ` Johannes Thumshirn
@ 2020-07-08 22:03 ` Ming Lei
1 sibling, 0 replies; 7+ messages in thread
From: Ming Lei @ 2020-07-08 22:03 UTC (permalink / raw)
To: John Garry; +Cc: Jens Axboe, linux-block, Christoph Hellwig
On Wed, Jul 08, 2020 at 03:05:03PM +0100, John Garry wrote:
> On 08/07/2020 13:27, Ming Lei wrote:
> > k;
> > - } 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
>
> question not on this patch specifically: is this supposed to be "driver",
> and not "drive"? "driver" is mentioned earlier in the function
Hi John,
Please focus on change added by this patch instead of existed context code.
If you have question on existed code, start a new thread for the discussion.
Thanks,
Ming
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result
2020-07-01 13:58 [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result Ming Lei
2020-07-08 12:27 ` Ming Lei
@ 2020-07-08 22:05 ` Jens Axboe
1 sibling, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2020-07-08 22:05 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-block, Christoph Hellwig
On 7/1/20 7:58 AM, Ming Lei wrote:
> 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.
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-07-08 22:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-01 13:58 [PATCH V2] blk-mq: streamline handling of q->mq_ops->queue_rq result Ming Lei
2020-07-08 12:27 ` Ming Lei
2020-07-08 12:53 ` Johannes Thumshirn
2020-07-08 14:05 ` John Garry
2020-07-08 14:23 ` Johannes Thumshirn
2020-07-08 22:03 ` Ming Lei
2020-07-08 22:05 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).