[PATCH 14/18] nvme-fc: Use CCR to recover controller that hits an error
Hannes Reinecke
hare at suse.de
Mon Sep 21 01:07:10 PDT 2026
On 9/18/26 8:14 PM, Mohamed Khalfella wrote:
> An alive nvme controller that hits an error now will move to FENCING
> state instead of RESETTING state. ctrl->fencing_work attempts CCR to
> terminate inflight IOs. Regardless of the success or failure of CCR
> operation the controller is transitioned to RESETTING state to continue
> error recovery process.
>
> Signed-off-by: Mohamed Khalfella <mkhalfella at purestorage.com>
> ---
> drivers/nvme/host/fc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
>
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 5a530aa37641..42671cca439f 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -166,6 +166,7 @@ struct nvme_fc_ctrl {
> struct blk_mq_tag_set admin_tag_set;
> struct blk_mq_tag_set tag_set;
>
> + struct work_struct fencing_work;
> struct work_struct ioerr_work;
> struct delayed_work connect_work;
>
> @@ -990,6 +991,7 @@ static void nvme_fc_ctrl_put(struct nvme_fc_ctrl *);
> static int nvme_fc_ctrl_get(struct nvme_fc_ctrl *);
>
> static void nvme_fc_error_recovery(struct nvme_fc_ctrl *ctrl);
> +static void nvme_fc_delete_association(struct nvme_fc_ctrl *ctrl);
>
> static void
> __nvme_fc_finish_ls_req(struct nvmefc_ls_req_op *lsop)
> @@ -1870,6 +1872,30 @@ __nvme_fc_fcpop_chk_teardowns(struct nvme_fc_ctrl *ctrl,
> }
> }
>
> +static void nvme_fc_fencing_work(struct work_struct *work)
> +{
> + struct nvme_fc_ctrl *fc_ctrl =
> + container_of(work, struct nvme_fc_ctrl, fencing_work);
> + struct nvme_ctrl *ctrl = &fc_ctrl->ctrl;
> + unsigned long rem;
> +
> + /*
> + * Tear the association down now so the LLDD can finish unregistering
> + * the remoteport/localport while the fencing this controller.
> + */
> + nvme_stop_keep_alive(ctrl);
> + cancel_work_sync(&ctrl->async_event_work);
> + nvme_fc_delete_association(fc_ctrl);
> +
> + rem = nvme_fence_ctrl(ctrl);
> + if (rem)
> + dev_info(ctrl->device, "CCR failed, starting error recovery\n");
> +
> + nvme_change_ctrl_state(ctrl, NVME_CTRL_FENCED);
> + if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
> + queue_work(nvme_reset_wq, &fc_ctrl->ioerr_work);
> +}
> +
> static void
> nvme_fc_ctrl_ioerr_work(struct work_struct *work)
> {
> @@ -1950,6 +1976,14 @@ nvme_fc_start_ioerr_recovery(struct nvme_fc_ctrl *ctrl, char *errmsg)
> return;
> }
>
> + if (nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_FENCING)) {
> + dev_warn(ctrl->ctrl.device,
> + "NVME-FC{%d}: starting controller fencing %s\n",
> + ctrl->cnum, errmsg);
> + queue_work(nvme_wq, &ctrl->fencing_work);
> + return;
> + }
> +
> if (nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RESETTING)) {
> dev_warn(ctrl->ctrl.device, "NVME-FC{%d}: starting error recovery %s\n",
> ctrl->cnum, errmsg);
> @@ -2463,6 +2497,12 @@ nvme_fc_ctrl_get(struct nvme_fc_ctrl *ctrl)
> return kref_get_unless_zero(&ctrl->ref);
> }
>
> +static void
> +nvme_fc_stop_ctrl(struct nvme_ctrl *nctrl)
> +{
> + flush_work(&to_fc_ctrl(nctrl)->fencing_work);
> +}
> +
> /*
> * All accesses from nvme core layer done - can now free the
> * controller. Called after last nvme_put_ctrl() call
> @@ -3428,6 +3468,7 @@ static const struct nvme_ctrl_ops nvme_fc_ctrl_ops = {
> .submit_async_event = nvme_fc_submit_async_event,
> .delete_ctrl = nvme_fc_delete_ctrl,
> .get_address = nvmf_get_address,
> + .stop_ctrl = nvme_fc_stop_ctrl,
> .get_virt_boundary = nvmf_get_virt_boundary,
> };
>
> @@ -3547,6 +3588,7 @@ nvme_fc_alloc_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
>
> INIT_WORK(&ctrl->ctrl.reset_work, nvme_fc_reset_ctrl_work);
> INIT_DELAYED_WORK(&ctrl->connect_work, nvme_fc_connect_ctrl_work);
> + INIT_WORK(&ctrl->fencing_work, nvme_fc_fencing_work);
> INIT_WORK(&ctrl->ioerr_work, nvme_fc_ctrl_ioerr_work);
> spin_lock_init(&ctrl->lock);
>
I would merge it with the previous patch as both are required to get FC
error handling working properly.
Otherwise:
Reviewed-by: Hannes Reinecke <hare at kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare at suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
More information about the Linux-nvme
mailing list