nvme/host: perform delayed retries upon non-fatal error received during nvme namespace validation
cover nvme/host: perform delayed retries upon non-fatal error received during nvme namespace validation
This patch series aims to provide delayed retries for nvme namespace validation when a non-fatal error occurs instead of ignoring it. An arbitrary amount of retries are performed over an arbitrary interval.
Patch 1:
The nvme_ns_info struct is moved into the nvme header file. Patch 2:
The implementation of the delayed retires performed on nvme ns validation.
Revision: 1
---
Alex Tran (2):
nvme/host: move nvme_ns_info into nvme header file nvme/host: add delayed retries upon non-fatal error during ns validation
drivers/nvme/host/core.c | 58 ++++++++++++++++++++++++++++++++---------------- drivers/nvme/host/nvme.h | 24 ++++++++++++++++++++ 2 files changed, 63 insertions(+), 19 deletions(-)
---
base-commit: fa084c35afa13ab07a860ef0936cd987f9aa0460
change-id: 20251221-nvme_ns_validation-d4abe2b89b96
Best regards,
Signature · 1 line
Alex Tran <[email protected]>
PATCH 1/2 nvme/host: move nvme_ns_info into nvme header file
The nvme_ns_info struct is moved into the nvme header file. This is done because it is used as a field in the nvme_ns struct to store the pending info being used in the following patch.
--- drivers/nvme/host/core.c | 15 --------------- drivers/nvme/host/nvme.h | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-)
drivers/nvme/host/core.c +0 -15
@@ -33,21 +33,6 @@#define NVME_MINORS (1U << MINORBITS) -struct nvme_ns_info { -struct nvme_ns_ids ids; -u32 nsid; -__le32 anagrpid; -u8 pi_offset; -u16 endgid; -u64 runs; -bool is_shared; -bool is_readonly; -bool is_ready; -bool is_removed; -bool is_rotational; -bool no_vwc; -}; -unsigned int admin_timeout =60 ;module_param (admin_timeout, uint,0644 );MODULE_PARM_DESC (admin_timeout,"timeout in seconds for admin commands" );
drivers/nvme/host/nvme.h +15 -0
@@ -525,6 +525,21 @@ enum nvme_ns_features { NVME_NS_DEAC = 1 << 2, /* DEAC bit in Write Zeroes supported */ }; +struct nvme_ns_info { +struct nvme_ns_ids ids; +u32 nsid; +__le32 anagrpid; +u8 pi_offset; +u16 endgid; +u64 runs; +bool is_shared; +bool is_readonly; +bool is_ready; +bool is_removed; +bool is_rotational; +bool no_vwc; +}; +struct nvme_ns {struct list_head list;
Signature · 1 line
2.51.0
PATCH 2/2 nvme/host: add delayed retries upon non-fatal error during ns validation
In reply to Alex TranIf 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 retires 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.
--- drivers/nvme/host/core.c | 43 +++++++++++++++++++++++++++++++++++++++---- drivers/nvme/host/nvme.h | 9 +++++++++ 2 files changed, 48 insertions(+), 4 deletions(-)
drivers/nvme/host/core.c +39 -4
@@ -139,6 +139,7 @@ static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, struct nvme_command *cmd);static int nvme_get_log_lsi (struct nvme_ctrl *ctrl,u32 nsid,u8 log_page,u8 lsp,u8 csi,void *log,size_t size,u64 offset,u16 lsi); +static void nvme_validate_ns_work (struct work_struct *work);void nvme_queue_scan (struct nvme_ctrl *ctrl) {
@@ -4118,6 +4119,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) ns->ctrl = ctrl;kref_init (&ns->kref); +INIT_DELAYED_WORK (&ns->validate_work, nvme_validate_ns_work); +if (nvme_init_ns_head (ns, info)) goto out_cleanup_disk;
@@ -4215,6 +4218,8 @@ static void nvme_ns_remove(struct nvme_ns *ns) {bool last_path = false; +cancel_delayed_work_sync (&ns->validate_work); +if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags))return ;
@@ -4285,12 +4290,42 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info) 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, otherwise delayed retries are performed. */ -if (ret >0 && (ret &NVME_STATUS_DNR )) +if (ret >0 && (ret &NVME_STATUS_DNR )) {nvme_ns_remove (ns); + }else if (ret >0 ) { +if (ns->validate_retries <NVME_NS_VALIDATION_MAX_RETRIES ) { + ns->validate_retries++; + +if (!nvme_get_ns (ns)) +return ; + +dev_warn ( + ns->ctrl->device, +"validation failed for nsid %d, retry %d/%d in %ds\n" , + ns->head->ns_id, ns->validate_retries, +NVME_NS_VALIDATION_MAX_RETRIES , +NVME_NS_VALIDATION_RETRY_INTERVAL ); +memcpy (&ns->pending_info, info,sizeof (*info)); +schedule_delayed_work ( + &ns->validate_work, +NVME_NS_VALIDATION_RETRY_INTERVAL *HZ ); + }else { +dev_err (ns->ctrl->device, +"validation failed for nsid %d after %d retries\n" , + ns->head->ns_id, +NVME_NS_VALIDATION_MAX_RETRIES ); + } + } +} + +static void nvme_validate_ns_work (struct work_struct *work) +{ + struct nvme_ns *ns = container_of(to_delayed_work(work), struct nvme_ns, + validate_work); +nvme_validate_ns (ns, &ns->pending_info); +nvme_put_ns (ns); }static void nvme_scan_ns (struct nvme_ctrl *ctrl,unsigned nsid)
drivers/nvme/host/nvme.h +9 -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 3 seconds for namespace validation +*/ +#define NVME_NS_VALIDATION_MAX_RETRIES 3 +#define NVME_NS_VALIDATION_RETRY_INTERVAL 3 +extern struct workqueue_struct *nvme_wq;extern struct workqueue_struct *nvme_reset_wq;extern struct workqueue_struct *nvme_delete_wq;
@@ -565,6 +571,9 @@ struct nvme_ns {struct device cdev_device;struct nvme_fault_inject fault_inject; +struct delayed_work validate_work; +struct nvme_ns_info pending_info; +unsigned int validate_retries; };/* NVMe ns supports metadata actions by the controller (generate/strip) */
Signature · 1 line
2.51.0
Sagi Grimberg
maintainerRe: [PATCH 2/2] nvme/host: add delayed retries upon non-fatal error during ns validation
Quoted 64 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 retires 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.
Signed-off-by Alex Tran <[email protected]>--- drivers/nvme/host/core.c | 43 +++++++++++++++++++++++++++++++++++++++---- drivers/nvme/host/nvme.h | 9 +++++++++ 2 files changed, 48 insertions(+), 4 deletions(-)drivers/nvme/host/core.c +14
-4@@ -139,6 +139,7 @@ static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, struct nvme_command *cmd);static int nvme_get_log_lsi (struct nvme_ctrl *ctrl,u32 nsid,u8 log_page,u8 lsp,u8 csi,void *log,size_t size,u64 offset,u16 lsi); +static void nvme_validate_ns_work (struct work_struct *work);void nvme_queue_scan (struct nvme_ctrl *ctrl) {@@ -4118,6 +4119,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) ns->ctrl = ctrl;kref_init (&ns->kref); +INIT_DELAYED_WORK (&ns->validate_work, nvme_validate_ns_work); +if (nvme_init_ns_head (ns, info)) goto out_cleanup_disk;@@ -4215,6 +4218,8 @@ static void nvme_ns_remove(struct nvme_ns *ns) {bool last_path = false; +cancel_delayed_work_sync (&ns->validate_work); +if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags))return ;@@ -4285,12 +4290,42 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info) 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, otherwise delayed retries are performed. */ -if (ret >0 && (ret &NVME_STATUS_DNR )) +if (ret >0 && (ret &NVME_STATUS_DNR )) {nvme_ns_remove (ns); + }else if (ret >0 ) { +if (ns->validate_retries <NVME_NS_VALIDATION_MAX_RETRIES ) { + ns->validate_retries++; + +if (!nvme_get_ns (ns)) +return ; +
drivers/nvme/host/core.c static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info) · line 4313
Quoted 10 lines
drivers/nvme/host/core.c +10
-0+dev_warn ( + ns->ctrl->device, +"validation failed for nsid %d, retry %d/%d in %ds\n" , + ns->head->ns_id, ns->validate_retries, +NVME_NS_VALIDATION_MAX_RETRIES , +NVME_NS_VALIDATION_RETRY_INTERVAL ); +memcpy (&ns->pending_info, info,sizeof (*info)); +schedule_delayed_work ( + &ns->validate_work, +NVME_NS_VALIDATION_RETRY_INTERVAL *HZ );
Given that ns scanning is already async, wouldn't it be simpler to simply retry locally in a loop?
Re: [PATCH 2/2] nvme/host: add delayed retries upon non-fatal error during ns validation
Quoted 3 lines
Given that ns scanning is already async, wouldn't it be simpler to simply retry locally
in a loop?
It would be much simpler to perform this locally in a retry loop. Thanks for the feedback! I'll follow up with a rework in v2.
Signature · 2 lines
Yours, Alex Tran