Skip to contentSkip to conversation

blk-mq: streamline handling of q->mq_ops->queue_rq result

PATCH Applied Ming Lei 4 participants 7 messages Jul 1, 2020 – Jul 8, 2020 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH v2 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.

Fixes fc17b6534eb8 ("blk-mq: switch ->queue_rq return value to blk_status_t")
Cc Christoph Hellwig <[email protected]>

---
V2:
- change 'if else' to switch as suggested by Christoph

 block/blk-mq.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
block/blk-mq.c +11 -13
index 65e0846fd065..cc85775fc372 100644
@@ -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);
 
Signature · 1 line
2.25.2
author
#1 lore raw
Quoted 72 lines · Ming Lei

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 <[email protected]>

---
V2:
- change 'if else' to switch as suggested by Christoph

 block/blk-mq.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
block/blk-mq.c +11 -13
index 65e0846fd065..cc85775fc372 100644
@@ -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);
 
Signature · 1 line
2.25.2

Hello,

Ping...

Signature · 1 line
Ming
#3 lore raw
In reply to Ming Lei

block/blk-mq.c bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list, · line 1421

Quoted 10 lines · Ming Lei

k;

block/blk-mq.c +5 -1
-		} 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

Quoted 8 lines

* accept.
*/
blk_mq_handle_zone_resource(rq, &zone_list);

block/blk-mq.c +0 -5
-			if (list_empty(list))
-				break;
-			continue;
-		}
-
#4 lore raw
Quoted 14 lines · John Garry

block/blk-mq.c bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list, · line 1421

Quoted 10 lines · Ming Lei

k;

block/blk-mq.c +5 -1
-		} 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.

author
#5 lore raw
In reply to John Garry
Quoted 14 lines · John Garry

block/blk-mq.c bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list, · line 1421

Quoted 10 lines · Ming Lei

k;

block/blk-mq.c +5 -1
-		} 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

maintainer Applied
#6 lore raw
In reply to Ming Lei
Quoted 6 lines · Ming Lei

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);'

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.

Applied, thanks.

Signature · 1 line
Jens Axboe