nvme: retry commands if DNR bit is not set
Subsystems (2)
Hannes Reinecke
maintainerPATCH 1/1 nvme: retry commands if DNR bit is not set
Add a 'retries' argument to __nvme_submit_sync_cmd() to instruct the function to retry the command if the DNR bit is not set in the command result, and modify the authentication code to allow for retries.
--- drivers/nvme/host/auth.c | 2 +- drivers/nvme/host/core.c | 29 ++++++++++++++++++++++++----- drivers/nvme/host/fabrics.c | 10 +++++----- drivers/nvme/host/nvme.h | 6 +++++- 4 files changed, 35 insertions(+), 12 deletions(-)
drivers/nvme/host/auth.c +1 -1
@@ -69,7 +69,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, ret =__nvme_submit_sync_cmd (q, &cmd,NULL , data, data_len, qid ==0 ?NVME_QID_ANY : qid, -0 , flags); +0 , flags, nvme_max_retries);if (ret >0 )dev_warn (ctrl->device,"qid %d auth_send failed with status %d\n" , qid, ret);
drivers/nvme/host/core.c +24 -5
@@ -54,7 +54,7 @@ static unsigned char shutdown_timeout = 5;module_param (shutdown_timeout, byte,0644 );MODULE_PARM_DESC (shutdown_timeout,"timeout in seconds for controller shutdown" ); -static u8 nvme_max_retries =5 ; +u8 nvme_max_retries =5 ;module_param_named (max_retries, nvme_max_retries, byte,0644 );MODULE_PARM_DESC (max_retries,"max number of retries a command may have" );
@@ -1016,7 +1016,7 @@ static int nvme_execute_rq(struct request *rq, bool at_head)*/ int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,union nvme_result *result,void *buffer,unsigned bufflen, -int qid,int at_head,blk_mq_req_flags_t flags) +int qid,int at_head,blk_mq_req_flags_t flags,int retries) {struct request *req;int ret;
@@ -1030,6 +1030,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,if (IS_ERR (req))return PTR_ERR (req);nvme_init_request (req, cmd); +nvme_req (req)->retries = retries;if (buffer && bufflen) { ret =blk_rq_map_kern (q, req, buffer, bufflen,GFP_KERNEL );
@@ -1037,8 +1038,18 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, goto out; } +retry: req->rq_flags |=RQF_QUIET ; ret =nvme_execute_rq (req, at_head); +if (ret >0 ) { +struct nvme_ctrl *ctrl =nvme_req (req)->ctrl; + +if (ctrl->kas) + ctrl->comp_seen = true; + +if (retries-- &&nvme_decide_disposition (req) !=COMPLETE ) + goto retry; + }if (result && ret >=0 ) *result =nvme_req (req)->result; out:
@@ -1051,10 +1062,18 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, void *buffer, unsigned bufflen) {return __nvme_submit_sync_cmd (q, cmd,NULL , buffer, bufflen, -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 ,0 ,0 ); }EXPORT_SYMBOL_GPL (nvme_submit_sync_cmd); +int nvme_submit_sync_cmd_retry (struct request_queue *q, +struct nvme_command *cmd,void *buffer,unsigned bufflen) +{ +return __nvme_submit_sync_cmd (q, cmd,NULL , buffer, bufflen, +NVME_QID_ANY ,0 ,0 , nvme_max_retries); +} +EXPORT_SYMBOL_GPL (nvme_submit_sync_cmd_retry); +static u32 nvme_known_admin_effects (u8 opcode) {switch (opcode) {
@@ -1500,7 +1519,7 @@ static int nvme_features(struct nvme_ctrl *dev, u8 op, unsigned int fid, c.features.dword11 =cpu_to_le32 (dword11); ret =__nvme_submit_sync_cmd (dev->admin_q, &c, &res, - buffer, buflen,NVME_QID_ANY ,0 ,0 ); + buffer, buflen,NVME_QID_ANY ,0 ,0 ,0 );if (ret >=0 && result) *result =le32_to_cpu (res.u32);return ret;
@@ -2195,7 +2214,7 @@ int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len, cmd.common.cdw11 =cpu_to_le32 (len);return __nvme_submit_sync_cmd (ctrl->admin_q, &cmd,NULL , buffer, len, - NVME_QID_ANY, 1, 0); + NVME_QID_ANY, 1, 0, 0); }EXPORT_SYMBOL_GPL (nvme_sec_submit);#endif /* CONFIG_BLK_SED_OPAL */
drivers/nvme/host/fabrics.c +5 -5
@@ -153,7 +153,7 @@ int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val) cmd.prop_get.offset =cpu_to_le32 (off); ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd, &res,NULL ,0 , -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 ,0 ,0 );if (ret >=0 ) *val =le64_to_cpu (res.u64);
@@ -199,7 +199,7 @@ int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val) cmd.prop_get.offset =cpu_to_le32 (off); ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd, &res,NULL ,0 , -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 ,0 ,0 );if (ret >=0 ) *val =le64_to_cpu (res.u64);
@@ -244,7 +244,7 @@ int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val) cmd.prop_set.value =cpu_to_le64 (val); ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd,NULL ,NULL ,0 , -NVME_QID_ANY ,0 ,0 ); +NVME_QID_ANY ,0 ,0 ,0 );if (unlikely (ret)) dev_err(ctrl->device, "Property Set error: %d, offset %#x\n",
@@ -401,7 +401,7 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) ret =__nvme_submit_sync_cmd (ctrl->fabrics_q, &cmd, &res, data,sizeof (*data),NVME_QID_ANY ,1 , -BLK_MQ_REQ_RESERVED |BLK_MQ_REQ_NOWAIT ); +BLK_MQ_REQ_RESERVED |BLK_MQ_REQ_NOWAIT ,0 );if (ret) {nvmf_log_connect_error (ctrl, ret,le32_to_cpu (res.u32), &cmd, data);
@@ -480,7 +480,7 @@ int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid) ret =__nvme_submit_sync_cmd (ctrl->connect_q, &cmd, &res, data,sizeof (*data), qid,1 , -BLK_MQ_REQ_RESERVED |BLK_MQ_REQ_NOWAIT ); +BLK_MQ_REQ_RESERVED |BLK_MQ_REQ_NOWAIT ,0 );if (ret) {nvmf_log_connect_error (ctrl, ret,le32_to_cpu (res.u32), &cmd, data);
drivers/nvme/host/nvme.h +5 -1
@@ -47,6 +47,8 @@ extern struct workqueue_struct *nvme_wq;extern struct workqueue_struct *nvme_reset_wq;extern struct workqueue_struct *nvme_delete_wq; +extern u8 nvme_max_retries; +/* * List of workarounds for devices that required behavior not specified in * the standard.
@@ -811,10 +813,12 @@ static inline bool nvme_is_unique_nsid(struct nvme_ctrl *ctrl,int nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,void *buf,unsigned bufflen); +int nvme_submit_sync_cmd_retry (struct request_queue *q, +struct nvme_command *cmd,void *buf,unsigned bufflen);int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,union nvme_result *result,void *buffer,unsigned bufflen,int qid,int at_head, -blk_mq_req_flags_t flags); +blk_mq_req_flags_t flags,int retries);int nvme_set_features (struct nvme_ctrl *dev,unsigned int fid,unsigned int dword11,void *buffer,size_t buflen,u32 *result);
Signature · 1 line
2.35.3
Quoted 64 lines · Hannes Reinecke
Add a 'retries' argument to
__nvme_submit_sync_cmd()to instruct the function to retry the command if the DNR bit is not set in the command result, and modify the authentication code to allow for retries.Signed-off-by Hannes Reinecke <[email protected]>--- drivers/nvme/host/auth.c | 2 +- drivers/nvme/host/core.c | 29 ++++++++++++++++++++++++----- drivers/nvme/host/fabrics.c | 10 +++++----- drivers/nvme/host/nvme.h | 6 +++++- 4 files changed, 35 insertions(+), 12 deletions(-)drivers/nvme/host/auth.c +1
-1@@ -69,7 +69,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, ret =__nvme_submit_sync_cmd (q, &cmd,NULL , data, data_len, qid ==0 ?NVME_QID_ANY : qid, -0 , flags); +0 , flags, nvme_max_retries);if (ret >0 )dev_warn (ctrl->device,"qid %d auth_send failed with status %d\n" , qid, ret);drivers/nvme/host/core.c +5
-2@@ -54,7 +54,7 @@ static unsigned char shutdown_timeout = 5;module_param (shutdown_timeout, byte,0644 );MODULE_PARM_DESC (shutdown_timeout,"timeout in seconds for controller shutdown" ); -static u8 nvme_max_retries =5 ; +u8 nvme_max_retries =5 ;module_param_named (max_retries, nvme_max_retries, byte,0644 );MODULE_PARM_DESC (max_retries,"max number of retries a command may have" );@@ -1016,7 +1016,7 @@ static int nvme_execute_rq(struct request *rq, bool at_head)*/ int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,union nvme_result *result,void *buffer,unsigned bufflen, -int qid,int at_head,blk_mq_req_flags_t flags) +int qid,int at_head,blk_mq_req_flags_t flags,int retries) {struct request *req;int ret;@@ -1030,6 +1030,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,if (IS_ERR (req))return PTR_ERR (req);nvme_init_request (req, cmd); +nvme_req (req)->retries = retries;if (buffer && bufflen) { ret =blk_rq_map_kern (q, req, buffer, bufflen,GFP_KERNEL );@@ -1037,8 +1038,18 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, goto out; } +retry: req->rq_flags |=RQF_QUIET ; ret =nvme_execute_rq (req, at_head); +if (ret >0 ) {
drivers/nvme/host/core.c int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, · line 1054
Quoted 10 lines
drivers/nvme/host/core.c +8
-0+struct nvme_ctrl *ctrl =nvme_req (req)->ctrl; + +if (ctrl->kas) + ctrl->comp_seen = true; + +if (retries-- &&nvme_decide_disposition (req) !=COMPLETE ) + goto retry; + }if (result && ret >=0 ) *result =nvme_req (req)->result;
Reusing the existing retry mechanism may be better.
We can do like this:
Do not set REQ_FAILFAST_DRIVER in nvme_init_request If need retry.
if (noretry) req->cmd_flags |= REQ_FAILFAST_DRIVER;
Hannes Reinecke
maintainerQuoted 73 lines · Chao Leng
Quoted 70 lines · Hannes Reinecke
Add a 'retries' argument to
__nvme_submit_sync_cmd()to instruct the function to retry the command if the DNR bit is not set in the command result, and modify the authentication code to allow for retries.Signed-off-by Hannes Reinecke <[email protected]>---
drivers/nvme/host/auth.c | 2 +- drivers/nvme/host/core.c | 29 ++++++++++++++++++++++++-----drivers/nvme/host/fabrics.c| 10 +++++----- drivers/nvme/host/nvme.h | 6 +++++-4 files changed, 35 insertions(+), 12 deletions(-)drivers/nvme/host/auth.c +1
-1@@ -69,7 +69,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl,int qid, ret = __nvme_submit_sync_cmd(q, &cmd, NULL, data, data_len, qid == 0 ? NVME_QID_ANY : qid, - 0, flags); + 0, flags, nvme_max_retries); if (ret > 0) dev_warn(ctrl->device, "qid %d auth_send failed with status %d\n", qid, ret);drivers/nvme/host/core.c +2
-2@@ -54,7 +54,7 @@ static unsigned char shutdown_timeout = 5; module_param(shutdown_timeout, byte, 0644); MODULE_PARM_DESC(shutdown_timeout, "timeout in seconds for controller shutdown"); -static u8 nvme_max_retries =5 ; +u8 nvme_max_retries =5 ; module_param_named(max_retries, nvme_max_retries, byte, 0644); MODULE_PARM_DESC(max_retries, "max number of retries a command may have");@@ -1016,7 +1016,7 @@ static int nvme_execute_rq(struct request *rq,bool at_head) */ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, union nvme_result *result, void *buffer, unsigned bufflen, - int qid, int at_head, blk_mq_req_flags_t flags) + int qid, int at_head, blk_mq_req_flags_t flags, int retries) { struct request *req;int ret;
drivers/nvme/host/core.c +10
-0@@ -1030,6 +1030,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, if (IS_ERR(req)) return PTR_ERR(req); nvme_init_request(req, cmd); + nvme_req(req)->retries = retries; if (buffer && bufflen) { ret = blk_rq_map_kern(q, req, buffer, bufflen, GFP_KERNEL);@@ -1037,8 +1038,18 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, goto out; } +retry: req->rq_flags |= RQF_QUIET; ret = nvme_execute_rq(req, at_head); + if (ret > 0) { + struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; + + if (ctrl->kas) + ctrl->comp_seen = true; + + if (retries-- && nvme_decide_disposition(req) != COMPLETE) + goto retry;
Quoted 9 lines
drivers/nvme/host/core.c int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, · line 1054
Quoted 3 lines
drivers/nvme/host/core.c +1
-0+ } if (result && ret >= 0) *result = nvme_req(req)->result;Reusing the existing retry mechanism may be better.
We can do like this:
Do not setREQ_FAILFAST_DRIVERinnvme_init_requestIf need retry.
if (noretry)
req->cmd_flags|=REQ_FAILFAST_DRIVER;
But then we still would need to set the retries; however, it's a good suggestion. Will be reworking the patch.
Cheers,
Hannes
Signature · 4 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