nvme/host: add delayed retries upon non-fatal error during ns validation
PATCH v3 1/1 nvme/host: add delayed retries upon non-fatal error during ns validation
If a non-fatal error is received during nvme namespace validation, it should not be ignored and the namespace should not be removed immediately. Rather, delayed retries should be performed on the namespace validation process.
This handles non-fatal issues more robustly, by retrying a few times before giving up and removing the namespace. The number of retries is set to 3 and the interval between retries is set to 3 seconds.
The retries are handled locally. Upon success then end. Upon fatal error then remove the namespace before ending. Upon non-fatal error, retry until the max retry amount is hit before ending and removing the ns.
---
Changes in v3:
- Simplify retry loop to i < NVME_NS_VALIDATION_MAX_RETRIES
- Use dev_dbg print
- Remove ns when still receiving non-fatal error after max retries
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Simplify retry logic with local loop instead of delayed work.
--- drivers/nvme/host/core.c | 31 +++++++++++++++++++++++-------- drivers/nvme/host/nvme.h | 6 ++++++ 2 files changed, 29 insertions(+), 8 deletions(-)
drivers/nvme/host/core.c +23 -8
@@ -4289,23 +4289,38 @@ 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_info *info) {int ret =NVME_SC_INVALID_NS |NVME_STATUS_DNR ; +unsigned int i;if (!nvme_ns_ids_equal (&ns->head->ids, &info->ids)) { -dev_err (ns->ctrl->device, -"identifiers changed for nsid %d\n" , ns->head->ns_id); +dev_err (ns->ctrl->device,"identifiers changed for nsid %d\n" , + ns->head->ns_id); goto out; } - ret =nvme_update_ns_info (ns, info); +for (i =0 ; i <NVME_NS_VALIDATION_MAX_RETRIES ; i++) { + ret =nvme_update_ns_info (ns, info); +if (ret ==0 ) +return ; + +if (ret >0 && (ret &NVME_STATUS_DNR )) + goto out; + +dev_dbg (ns->ctrl->device, +"validation failed for nsid %d, retry %d/%d in %dms\n" , + ns->head->ns_id, i +1 ,NVME_NS_VALIDATION_MAX_RETRIES , +NVME_NS_VALIDATION_RETRY_INTERVAL ); +msleep (NVME_NS_VALIDATION_RETRY_INTERVAL ); + } + +dev_err (ns->ctrl->device, +"validation failed for nsid %d after %d retries\n" , + ns->head->ns_id,NVME_NS_VALIDATION_MAX_RETRIES ); out:/* * Only remove the namespace if we got a fatal error back from the -* device, otherwise ignore the error and just move on. -* -* TODO: we should probably schedule a delayed retry here. +* device or if a non-fatal error still appears after max retries. */ -if (ret >0 && (ret &NVME_STATUS_DNR )) -nvme_ns_remove (ns); +nvme_ns_remove (ns); }static void nvme_scan_ns (struct nvme_ctrl *ctrl,unsigned nsid)
drivers/nvme/host/nvme.h +6 -0
@@ -46,6 +46,12 @@ extern unsigned int admin_timeout;#define NVME_CTRL_PAGE_SHIFT 12#define NVME_CTRL_PAGE_SIZE (1 << NVME_CTRL_PAGE_SHIFT) +/* +* Default to 3 retries in intervals of 3000ms for namespace validation +*/ +#define NVME_NS_VALIDATION_MAX_RETRIES 3 +#define NVME_NS_VALIDATION_RETRY_INTERVAL 3000 +extern struct workqueue_struct *nvme_wq;extern struct workqueue_struct *nvme_reset_wq;extern struct workqueue_struct *nvme_delete_wq;
---
base-commit: fa084c35afa13ab07a860ef0936cd987f9aa0460
change-id: 20251225-nvme_ns_validation-310a07aa8b2b
Best regards,
Signature · 1 line
Alex Tran <[email protected]>
Christoph Hellwig
maintainerQuoted 5 lines · Alex Tran
If a non-fatal error is received during nvme namespace validation, it should not be ignored and the namespace should not be removed immediately. Rather, delayed retries should be performed on the namespace validation process.
Quoted 7 lines
This handles non-fatal issues more robustly, by retrying a few times before giving up and removing the namespace. The number of retries is set to 3 and the interval between retries is set to 3 seconds.
The retries are handled locally. Upon success then end. Upon fatal error then remove the namespace before ending. Upon non-fatal error, retry until the max retry amount is hit before ending and removing the ns.
What non-fatal errors do you see?