Fixup return value for nvme_submit_sync_cmd()
Subsystems (2)
v4 cover Fixup return value for nvme_submit_sync_cmd()
Hi all,
here are some small patches for fixing up the return value of nvme_submit_sync_cmd().
As Keith correctly noted, nvme_submit_sync_cmd() should be returning an error if the command could not be performed; however, currently only pci does that.
So we need to fix up nvme_cancel_request() to return an -EINTR on any pending sync commands during reset.
And modify nvme-fc to return the same nvme status after timing out or cancelling requests.
As usual, comments and reviews are welcome.
Changes to v3:
- Dropped patch to change the status code for aborted commands
- Dropped patch to set -ETIMEDOUT on timed out commands
- Include reviews from Chao Leng
Changes to v2:
- Include reviews from Sagi
- Simplify error logic from nvme_validate_ns()
Changes to v1:
- Include reviews from Daniel
- Include changes for nvme-fc to return the same status as the other transports
Hannes Reinecke (4):
nvme: simplify error logic in nvme_validate_ns()
nvme: add NVME_REQ_CANCELLED flag in nvme_cancel_request()
nvme-fc: set NVME_REQ_CANCELLED in nvme_fc_terminate_exchange()
nvme-fc: return NVME_SC_HOST_ABORTED_CMD when a command has been
aborted
drivers/nvme/host/core.c | 9 +++++---- drivers/nvme/host/fc.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-)
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 4/4 nvme-fc: return NVME_SC_HOST_ABORTED_CMD when a command has been aborted
When a command has been aborted we should return NVME_SC_HOST_ABORTED_CMD to be consistent with the other transports.
--- drivers/nvme/host/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/fc.c +1 -1
@@ -1956,7 +1956,7 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req) sizeof(op->rsp_iu), DMA_FROM_DEVICE);if (opstate ==FCPOP_STATE_ABORTED ) - status =cpu_to_le16 (NVME_SC_HOST_PATH_ERROR <<1 ); + status =cpu_to_le16 (NVME_SC_HOST_ABORTED_CMD <<1 );else if (freq->status) { status =cpu_to_le16 (NVME_SC_HOST_PATH_ERROR <<1 ); dev_info(ctrl->ctrl.device,
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 2/4 nvme: add NVME_REQ_CANCELLED flag in nvme_cancel_request()
In reply to Hannes ReineckeNVME_REQ_CANCELLED is translated into -EINTR in nvme_submit_sync_cmd(), so we should be setting this flags during nvme_cancel_request() to ensure that the callers to nvme_submit_sync_cmd() will get the correct error code when the controller is reset.
--- drivers/nvme/host/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/core.c +1 -0
@@ -380,6 +380,7 @@ bool nvme_cancel_request(struct request *req, void *data, bool reserved)return true;nvme_req (req)->status =NVME_SC_HOST_ABORTED_CMD ; +nvme_req (req)->flags |=NVME_REQ_CANCELLED ;blk_mq_complete_request (req);return true; }
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 3/4 nvme-fc: set NVME_REQ_CANCELLED in nvme_fc_terminate_exchange()
In reply to Hannes Reineckenvme_fc_terminate_exchange() is being called when exchanges are being deleted, and as such we should be setting the NVME_REQ_CANCELLED flag to have identical behaviour on all transports.
--- drivers/nvme/host/fc.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/fc.c +1 -0
@@ -2443,6 +2443,7 @@ nvme_fc_terminate_exchange(struct request *req, void *data, bool reserved)struct nvme_fc_ctrl *ctrl =to_fc_ctrl (nctrl);struct nvme_fc_fcp_op *op =blk_mq_rq_to_pdu (req); + op->nreq.flags |=NVME_REQ_CANCELLED ;__nvme_fc_abort_op (ctrl, op);return true; }
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 1/4 nvme: simplify error logic in nvme_validate_ns()
In reply to Hannes ReineckeWe only should remove namespaces when we get fatal error back from the device or when the namespace IDs have changed.
So instead of painfully masking out error numbers which might indicate that the error should be ignored we could use an NVME status code to indicated when the namespace should be removed.
That simplifies the final logic and makes it less error-prone.
--- drivers/nvme/host/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/nvme/host/core.c +4 -4
@@ -1439,7 +1439,7 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, goto out_free_id; } - error = -ENODEV ; + error =NVME_SC_INVALID_NS |NVME_SC_DNR ;if ((*id)->ncap ==0 )/* namespace not allocated or attached */ goto out_free_id;
@@ -4036,7 +4036,7 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)static void nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) {struct nvme_id_ns *id; -int ret = -ENODEV ; +int ret =NVME_SC_INVALID_NS |NVME_SC_DNR ;if (test_bit (NVME_NS_DEAD , &ns->flags)) goto out;
@@ -4045,7 +4045,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)if (ret) goto out; - ret = -ENODEV ; + ret =NVME_SC_INVALID_NS |NVME_SC_DNR ;if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ns->ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id);
@@ -4063,7 +4063,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)* * TODO: we should probably schedule a delayed retry here. */ -if (ret && ret != -ENOMEM && !(ret >0 && !(ret &NVME_SC_DNR ))) +if (ret >0 && (ret &NVME_SC_DNR ))nvme_ns_remove (ns); }
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/4] nvme: simplify error logic in nvme_validate_ns()
Hi Hannes,
Quoted 10 lines · Hannes Reinecke
drivers/nvme/host/core.c +1
-1@@ -4045,7 +4045,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)if (ret) goto out; - ret = -ENODEV ; + ret =NVME_SC_INVALID_NS |NVME_SC_DNR ;if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ns->ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id);
drivers/nvme/host/core.c static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids) · line 4067
Quoted 6 lines
drivers/nvme/host/core.c +1
-1@@ -4063,7 +4063,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)* * TODO: we should probably schedule a delayed retry here. */ -if (ret && ret != -ENOMEM && !(ret >0 && !(ret &NVME_SC_DNR ))) +if (ret >0 && (ret &NVME_SC_DNR ))nvme_ns_remove (ns);
I think Chao's comment still holds, nvme_update_ns_info() can return -EINVAL, -IEO or -ENODEV. Don't we have to remove the NS in these cases?
Thanks,
Daniel
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 12 lines · Hannes Reinecke
Hi all,
here are some small patches for fixing up the return value of
nvme_submit_sync_cmd().
As Keith correctly noted,nvme_submit_sync_cmd()should be returning an error if the command could not be performed; however, currently only pci does that.
So we need to fix upnvme_cancel_request()to return an-EINTRon any pending sync commands during reset.
And modify nvme-fc to return the same nvme status after timing out or cancelling requests.
Quoted 5 lines
As usual, comments and reviews are welcome.
Changes to v3:
- Dropped patch to change the status code for aborted commands
- Dropped patch to set-ETIMEDOUTon timed out commands
->timeout() also need to consider, maybe can add the flag:NVME_REQ_CANCELLED like nvme_cancel_request.
Quoted 18 lines
- Include reviews from Chao Leng
Changes to v2:
- Include reviews from Sagi
- Simplify error logic fromnvme_validate_ns()Changes to v1:
- Include reviews from Daniel
- Include changes for nvme-fc to return the same status as the other transportsHannes Reinecke (4):
nvme: simplify error logic innvme_validate_ns()
nvme: addNVME_REQ_CANCELLEDflag innvme_cancel_request()
nvme-fc: setNVME_REQ_CANCELLEDinnvme_fc_terminate_exchange()
nvme-fc: returnNVME_SC_HOST_ABORTED_CMDwhen a command has been
aborted
Quoted 4 lines
drivers/nvme/host/core.c | 9 +++++---- drivers/nvme/host/fc.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-)
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/4] nvme: simplify error logic in nvme_validate_ns()
In reply to Daniel WagnerQuoted 7 lines · Daniel Wagner
Hi Hannes,
Quoted 4 lines · Hannes Reinecke
drivers/nvme/host/core.c +0
-0@@ -4045,7 +4045,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)if (ret) goto out;
Quoted 17 lines
drivers/nvme/host/core.c static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids) · line 4067
Quoted 12 lines
drivers/nvme/host/core.c +2
-2- ret = -ENODEV ; + ret =NVME_SC_INVALID_NS |NVME_SC_DNR ;if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ns->ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id);@@ -4063,7 +4063,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)* * TODO: we should probably schedule a delayed retry here. */ -if (ret && ret != -ENOMEM && !(ret >0 && !(ret &NVME_SC_DNR ))) +if (ret >0 && (ret &NVME_SC_DNR ))nvme_ns_remove (ns);I think Chao's comment still holds,
nvme_update_ns_info()can return-EINVAL, -IEO or-ENODEV. Don't we have to remove the NS in these cases?
I thought I had fixed up all instances where we can return -ENODEV; and all others are indeed transport or transient error which should not result in a namespace removal.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Daniel Wagner
Reviewed-byRe: [PATCH 1/4] nvme: simplify error logic in nvme_validate_ns()
Quoted 3 lines · Hannes Reinecke
I thought I had fixed up all instances where we can return
-ENODEV; and all others are indeed transport or transient error which should not result in a namespace removal.
I think I was digging through the wrong tree. There is indeed no ENODEV in nvme/nvme-5.12. Sorry about the noise.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 4/4] nvme-fc: return NVME_SC_HOST_ABORTED_CMD when a command has been aborted
In reply to Hannes ReineckeQuoted 15 lines · Hannes Reinecke
When a command has been aborted we should return
NVME_SC_HOST_ABORTED_CMDto be consistent with the other transports.Cc James Smart <[email protected]>Signed-off-by Hannes Reinecke <[email protected]>Reviewed-by Daniel Wagner <[email protected]>--- drivers/nvme/host/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvme/host/fc.c +0
-0
drivers/nvme/host/fc.c nvme_fc_fcpio_done(struct nvmefc_fcp_req *req) · line 1962
Quoted 8 lines
drivers/nvme/host/fc.c +1
-1@@ -1956,7 +1956,7 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req) sizeof(op->rsp_iu), DMA_FROM_DEVICE);if (opstate ==FCPOP_STATE_ABORTED ) - status =cpu_to_le16 (NVME_SC_HOST_PATH_ERROR <<1 ); + status =cpu_to_le16 (NVME_SC_HOST_ABORTED_CMD <<1 );else if (freq->status) { status =cpu_to_le16 (NVME_SC_HOST_PATH_ERROR <<1 ); dev_info(ctrl->ctrl.device,
Is there a difference between an I/O aborted by a NVME ABORT cmd vs a transport-cancelled io ? This line is more the transport-cancelled io.
-- james
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 4/4] nvme-fc: return NVME_SC_HOST_ABORTED_CMD when a command has been aborted
Quoted 11 lines · James Smart
Quoted 10 lines · Hannes Reinecke
When a command has been aborted we should return
NVME_SC_HOST_ABORTED_CMDto be consistent with the other transports.Cc James Smart <[email protected]>Signed-off-by Hannes Reinecke <[email protected]>Reviewed-by Daniel Wagner <[email protected]>---
drivers/nvme/host/fc.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
drivers/nvme/host/fc.c nvme_fc_fcpio_done(struct nvmefc_fcp_req *req) · line 1961
Quoted 12 lines
drivers/nvme/host/fc.c +1
-1@@ -1956,7 +1956,7 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req) sizeof(op->rsp_iu), DMA_FROM_DEVICE); if (opstate == FCPOP_STATE_ABORTED) - status = cpu_to_le16(NVME_SC_HOST_PATH_ERROR << 1); + status = cpu_to_le16(NVME_SC_HOST_ABORTED_CMD << 1); else if (freq->status) { status = cpu_to_le16(NVME_SC_HOST_PATH_ERROR << 1); dev_info(ctrl->ctrl.device,Is there a difference between an I/O aborted by a NVME ABORT cmd vs a transport-cancelled io ? This line is more the transport-cancelled io.
Well, as we have several distinct error codes for that:
0x07 (Command abort requested) is for commands terminated by NVME Abort 0x08 (Command aborted due to SQ deletion) is for commands terminated due to an explicit 'Delete I/O submission queue' command0x370 (Host pathing error) is for any random host pathing error 0x371 (Command aborted by host) is for commands being aborted 'as a result of a host action'
arguably both (0x370 and 0x371) can be used when failing I/O on path loss, but all other transports are using 0x371 here, so FC really should be using the same convention to have consistent error handling.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/4] nvme: simplify error logic in nvme_validate_ns()
In reply to Hannes ReineckeQuoted 45 lines · Hannes Reinecke
We only should remove namespaces when we get fatal error back from the device or when the namespace IDs have changed.
So instead of painfully masking out error numbers which might indicate that the error should be ignored we could use an NVME status code to indicated when the namespace should be removed.
That simplifies the final logic and makes it less error-prone.Signed-off-by Hannes Reinecke <[email protected]>Reviewed-by Keith Busch <[email protected]>--- drivers/nvme/host/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/nvme/host/core.c +3
-3@@ -1439,7 +1439,7 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, goto out_free_id; } - error = -ENODEV ; + error =NVME_SC_INVALID_NS |NVME_SC_DNR ;if ((*id)->ncap ==0 )/* namespace not allocated or attached */ goto out_free_id;@@ -4036,7 +4036,7 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)static void nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) {struct nvme_id_ns *id; -int ret = -ENODEV ; +int ret =NVME_SC_INVALID_NS |NVME_SC_DNR ;if (test_bit (NVME_NS_DEAD , &ns->flags)) goto out;@@ -4045,7 +4045,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)if (ret) goto out; - ret = -ENODEV ; + ret =NVME_SC_INVALID_NS |NVME_SC_DNR ;if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ns->ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id);
drivers/nvme/host/core.c static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids) · line 4068
Quoted 7 lines
drivers/nvme/host/core.c +1
-1@@ -4063,7 +4063,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)* * TODO: we should probably schedule a delayed retry here. */ -if (ret && ret != -ENOMEM && !(ret >0 && !(ret &NVME_SC_DNR ))) +if (ret >0 && (ret &NVME_SC_DNR ))nvme_ns_remove (ns); }
This looks ok to me,
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 2/4] nvme: add NVME_REQ_CANCELLED flag in nvme_cancel_request()
In reply to Hannes Reinecke_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 3/4] nvme-fc: set NVME_REQ_CANCELLED in nvme_fc_terminate_exchange()
In reply to Hannes Reinecke_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 4/4] nvme-fc: return NVME_SC_HOST_ABORTED_CMD when a command has been aborted
In reply to Hannes Reinecke_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 3/4] nvme-fc: set NVME_REQ_CANCELLED in nvme_fc_terminate_exchange()
In reply to Hannes ReineckeQuoted 9 lines · Hannes Reinecke
nvme_fc_terminate_exchange()is being called when exchanges are being deleted, and as such we should be setting theNVME_REQ_CANCELLEDflag to have identical behaviour on all transports.Cc James Smart <[email protected]>Signed-off-by Hannes Reinecke <[email protected]>Reviewed-by Daniel Wagner <[email protected]>Reviewed-by Keith Busch <[email protected]>---
Looks good.
-- james
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 4/4] nvme-fc: return NVME_SC_HOST_ABORTED_CMD when a command has been aborted
In reply to Hannes ReineckeQuoted 8 lines · Hannes Reinecke
When a command has been aborted we should return
NVME_SC_HOST_ABORTED_CMDto be consistent with the other transports.Cc James Smart <[email protected]>Signed-off-by Hannes Reinecke <[email protected]>Reviewed-by Daniel Wagner <[email protected]>--- drivers/nvme/host/fc.c | 2 +-
Looks good.
-- james
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks,
applied to nvme-5.12.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme