Skip to contentSkip to conversation

block: return errors from blk_execute_rq()

PATCH In review Keith Busch 4 participants 11 messages Apr 16, 2021 – Apr 19, 2021

Subsystems (2)
lore
Share & tools
lore

Keith Busch

author maintainer
#0 lore raw

PATCH 1/2 block: return errors from blk_execute_rq()

The synchronous blk_execute_rq() had not provided a way for its callers to know if its request was successful or not. Return the errno from the completion status.

---
 block/blk-exec.c       | 6 ++++--
 include/linux/blkdev.h | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
block/blk-exec.c +4 -2
index beae70a0e5e5..3877a2677dd4 100644
@@ -21,7 +21,7 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error)
 {
 	struct completion *waiting = rq->end_io_data;
 
-	rq->end_io_data = NULL;
+	rq->end_io_data = ERR_PTR(blk_status_to_errno(error));
 
 	/*
 	 * complete last, if this is a stack request the process (and thus
@@ -72,8 +72,9 @@ EXPORT_SYMBOL_GPL(blk_execute_rq_nowait);
  * Description:
  *    Insert a fully prepared request at the back of the I/O scheduler queue
  *    for execution and wait for completion.
+ * Return: The errno value of the blk_status_t provided to blk_mq_end_request().
  */
-void blk_execute_rq(struct gendisk *bd_disk, struct request *rq, int at_head)
+int blk_execute_rq(struct gendisk *bd_disk, struct request *rq, int at_head)
 {
 	DECLARE_COMPLETION_ONSTACK(wait);
 	unsigned long hang_check;
@@ -87,5 +88,6 @@ void blk_execute_rq(struct gendisk *bd_disk, struct request *rq, int at_head)
 		while (!wait_for_completion_io_timeout(&wait, hang_check * (HZ/2)));
 	else
 		wait_for_completion_io(&wait);
+	return PTR_ERR_OR_ZERO(rq->end_io_data);
 }
 EXPORT_SYMBOL(blk_execute_rq);
include/linux/blkdev.h +1 -1
index b91ba6207365..15e4ffac33af 100644
@@ -938,7 +938,7 @@ extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, uns
 extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
 			       struct rq_map_data *, const struct iov_iter *,
 			       gfp_t);
-extern void blk_execute_rq(struct gendisk *, struct request *, int);
+extern int blk_execute_rq(struct gendisk *, struct request *, int);
 extern void blk_execute_rq_nowait(struct gendisk *,
 				  struct request *, int, rq_end_io_fn *);
 
Signature · 1 line
2.25.4
author maintainer
#1 lore raw

PATCH 2/2 nvme: use return value from blk_execute_rq()

We don't have an nvme status to report if the driver's .queue_rq() returns an error without dispatching the requested nvme command. Use the return value from blk_execute_rq() so the caller may know their command was not successful.

---
 drivers/nvme/host/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +2 -2
index 85538c38aae9..b57157106cac 100644
@@ -1000,12 +1000,12 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 	if (poll)
 		nvme_execute_rq_polled(req->q, NULL, req, at_head);
 	else
-		blk_execute_rq(NULL, req, at_head);
+		ret = blk_execute_rq(NULL, req, at_head);
 	if (result)
 		*result = nvme_req(req)->result;
 	if (nvme_req(req)->flags & NVME_REQ_CANCELLED)
 		ret = -EINTR;
-	else
+	else if (nvme_req(req)->status)
 		ret = nvme_req(req)->status;
  out:
 	blk_mq_free_request(req);
Signature · 1 line
2.25.4
#2 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

Quoted 2 lines
        if (poll)
                nvme_execute_rq_polled(req->q, NULL, req, at_head);

You may need to audit other completion handlers for blk_execute_rq_nowait(). How to get error ret from polled rq?

Quoted 10 lines

else

drivers/nvme/host/core.c +2 -2
-               blk_execute_rq(NULL, req, at_head);
+               ret = blk_execute_rq(NULL, req, at_head);
        if (result)
                *result = nvme_req(req)->result;
        if (nvme_req(req)->flags & NVME_REQ_CANCELLED)
                ret = -EINTR;
-       else
+       else if (nvme_req(req)->status)
                ret = nvme_req(req)->status;
Signature · 2 lines
Regards,
Yuanyuan Zhong
author maintainer
#3 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

Quoted 3 lines · Yuanyuan Zhong
Quoted 2 lines
        if (poll)
                nvme_execute_rq_polled(req->q, NULL, req, at_head);

You may need to audit other completion handlers for blk_execute_rq_nowait().

Why? Those callers already provide their own callback that directly get the error.

Quoted 1 line

How to get error ret from polled rq?

Please see nvme_end_sync_rq() for that driver's polled handler callback. It already has the error.

Reviewed-by on v1 2/2
#9 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

In reply to Keith Busch
Quoted 7 lines · Keith Busch

We don't have an nvme status to report if the driver's .queue_rq() returns an error without dispatching the requested nvme command. Use the return value from blk_execute_rq() so the caller may know their command was not successful.

Looks good.

#4 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

In reply to Keith Busch
Quoted 5 lines · Keith Busch
Quoted 3 lines · Yuanyuan Zhong
Quoted 2 lines
        if (poll)
                nvme_execute_rq_polled(req->q, NULL, req, at_head);

You may need to audit other completion handlers for blk_execute_rq_nowait().

Quoted 7 lines

Why? Those callers already provide their own callback that directly get the error.

Quoted 1 line

How to get error ret from polled rq?

Please see nvme_end_sync_rq() for that driver's polled handler callback. It already has the error.

But it never looks at it..

author maintainer
#5 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Keith Busch
Quoted 3 lines · Yuanyuan Zhong
Quoted 2 lines
        if (poll)
                nvme_execute_rq_polled(req->q, NULL, req, at_head);

You may need to audit other completion handlers for blk_execute_rq_nowait().

Why? Those callers already provide their own callback that directly get the error.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

How to get error ret from polled rq?

Please see nvme_end_sync_rq() for that driver's polled handler callback. It already has the error.

But it never looks at it..

The question was how to get ret. I didn't mean to imply the example was actually using it. :)

#6 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

Quoted 10 lines · Keith Busch
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Keith Busch
Quoted 3 lines · Yuanyuan Zhong
Quoted 2 lines
        if (poll)
                nvme_execute_rq_polled(req->q, NULL, req, at_head);

You may need to audit other completion handlers for blk_execute_rq_nowait().

Why? Those callers already provide their own callback that directly get the error.

See below clarification. I was wondering whether the way you were going to propose for nvme_end_sync_rq() would establish new convention for other blk_execute_rq_nowait() completion handlers implementation.

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

How to get error ret from polled rq?

Please see nvme_end_sync_rq() for that driver's polled handler callback. It already has the error.

But it never looks at it..

The question was how to get ret. I didn't mean to imply the example was actually using it. :)

The question was how to let nvme_end_sync_rq() propagate the blk_status_t error to the ret for __nvme_submit_sync_cmd(). That's part of the problem
here: __nvme_submit_sync_cmd() may return success for a command that failed submission.

Signature · 2 lines
Regards,
Yuanyuan Zhong
author maintainer
#7 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

Quoted 7 lines · Yuanyuan Zhong
Quoted 6 lines · Keith Busch
Quoted 4 lines · Christoph Hellwig
Quoted 3 lines · Keith Busch
Quoted 2 lines · Yuanyuan Zhong
Quoted 2 lines
        if (poll)
                nvme_execute_rq_polled(req->q, NULL, req, at_head);
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

You may need to audit other completion handlers for blk_execute_rq_nowait().

Why? Those callers already provide their own callback that directly get the error.

See below clarification. I was wondering whether the way you were going to propose for nvme_end_sync_rq() would establish new convention for other blk_execute_rq_nowait() completion handlers implementation.

I'm not sure it can be turned into a common pattern. The callbacks are implementation specific.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

How to get error ret from polled rq?

Please see nvme_end_sync_rq() for that driver's polled handler callback. It already has the error.

But it never looks at it..

Quoted 7 lines
Quoted 2 lines

The question was how to get ret. I didn't mean to imply the example was actually using it. :)

The question was how to let nvme_end_sync_rq() propagate the blk_status_t error to the ret for __nvme_submit_sync_cmd(). That's part of the problem
here: __nvme_submit_sync_cmd() may return success for a command that failed submission.

---

drivers/nvme/host/core.c +2 -0
index b57157106cac..a0fb9ad132af 100644
@@ -949,6 +949,9 @@ static void nvme_end_sync_rq(struct request *rq, blk_status_t error)
 	struct completion *waiting = rq->end_io_data;
 
 	rq->end_io_data = NULL;
+	if (error && !nvme_req(rq)->status)
+		nvme_req(rq)->status = blk_status_to_errno(error);
 	complete(waiting);
 }
 

--

#8 lore raw

Re: [PATCH 2/2] nvme: use return value from blk_execute_rq()

drivers/nvme/host/core.c static void nvme_end_sync_rq(struct request *rq, blk_status_t error) · line 952

Quoted 11 lines · Keith Busch
drivers/nvme/host/core.c +1 -0
index b57157106cac..a0fb9ad132af 100644
@@ -949,6 +949,9 @@ static void nvme_end_sync_rq(struct request *rq, blk_status_t error)
        struct completion *waiting = rq->end_io_data;
 
        rq->end_io_data = NULL;
+       if (error && !nvme_req(rq)->status)

Is setting nvme_req(rq)->status for each error return in ->queue_rq() going to gradually roll out, and eventually skipping the fallback here?

drivers/nvme/host/core.c static void nvme_end_sync_rq(struct request *rq, blk_status_t error) · line 953

Quoted 1 line
drivers/nvme/host/core.c +1 -0
+               nvme_req(rq)->status = blk_status_to_errno(error);

Casting int negative errno to u16 will get 0xfff., meaning NVME_SC_DNR is set. Is that always right?

--
Regards,
Yuanyuan Zhong