Skip to content

Commit f13409b

Browse files
igawkeithbusch
authored andcommitted
nvme-fc: rely on state transitions to handle connectivity loss
It's not possible to call nvme_state_ctrl_state with holding a spin lock, because nvme_state_ctrl_state calls cancel_delayed_work_sync when fastfail is enabled. Instead syncing the ASSOC_FLAG and state transitions using a lock, it's possible to only rely on the state machine transitions. That means nvme_fc_ctrl_connectivity_loss should unconditionally call nvme_reset_ctrl which avoids the read race on the ctrl state variable. Actually, it's not necessary to test in which state the ctrl is, the reset work will only scheduled when the state machine is in LIVE state. In nvme_fc_create_association, the LIVE state can only be entered if it was previously CONNECTING. If this is not possible then the reset handler got triggered. Thus just error out here. Fixes: ee59e38 ("nvme-fc: do not ignore connectivity loss during connecting") Closes: https://lore.kernel.org/all/denqwui6sl5erqmz2gvrwueyxakl5txzbbiu3fgebryzrfxunm@iwxuthct377m/ Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com> Tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Daniel Wagner <wagi@kernel.org> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 3f22421 commit f13409b

File tree

1 file changed

+6
-61
lines changed
  • drivers/nvme/host

1 file changed

+6
-61
lines changed

drivers/nvme/host/fc.c

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -781,61 +781,12 @@ nvme_fc_abort_lsops(struct nvme_fc_rport *rport)
781781
static void
782782
nvme_fc_ctrl_connectivity_loss(struct nvme_fc_ctrl *ctrl)
783783
{
784-
enum nvme_ctrl_state state;
785-
unsigned long flags;
786-
787784
dev_info(ctrl->ctrl.device,
788785
"NVME-FC{%d}: controller connectivity lost. Awaiting "
789786
"Reconnect", ctrl->cnum);
790787

791-
spin_lock_irqsave(&ctrl->lock, flags);
792788
set_bit(ASSOC_FAILED, &ctrl->flags);
793-
state = nvme_ctrl_state(&ctrl->ctrl);
794-
spin_unlock_irqrestore(&ctrl->lock, flags);
795-
796-
switch (state) {
797-
case NVME_CTRL_NEW:
798-
case NVME_CTRL_LIVE:
799-
/*
800-
* Schedule a controller reset. The reset will terminate the
801-
* association and schedule the reconnect timer. Reconnects
802-
* will be attempted until either the ctlr_loss_tmo
803-
* (max_retries * connect_delay) expires or the remoteport's
804-
* dev_loss_tmo expires.
805-
*/
806-
if (nvme_reset_ctrl(&ctrl->ctrl)) {
807-
dev_warn(ctrl->ctrl.device,
808-
"NVME-FC{%d}: Couldn't schedule reset.\n",
809-
ctrl->cnum);
810-
nvme_delete_ctrl(&ctrl->ctrl);
811-
}
812-
break;
813-
814-
case NVME_CTRL_CONNECTING:
815-
/*
816-
* The association has already been terminated and the
817-
* controller is attempting reconnects. No need to do anything
818-
* futher. Reconnects will be attempted until either the
819-
* ctlr_loss_tmo (max_retries * connect_delay) expires or the
820-
* remoteport's dev_loss_tmo expires.
821-
*/
822-
break;
823-
824-
case NVME_CTRL_RESETTING:
825-
/*
826-
* Controller is already in the process of terminating the
827-
* association. No need to do anything further. The reconnect
828-
* step will kick in naturally after the association is
829-
* terminated.
830-
*/
831-
break;
832-
833-
case NVME_CTRL_DELETING:
834-
case NVME_CTRL_DELETING_NOIO:
835-
default:
836-
/* no action to take - let it delete */
837-
break;
838-
}
789+
nvme_reset_ctrl(&ctrl->ctrl);
839790
}
840791

841792
/**
@@ -3071,7 +3022,6 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
30713022
struct nvmefc_ls_rcv_op *disls = NULL;
30723023
unsigned long flags;
30733024
int ret;
3074-
bool changed;
30753025

30763026
++ctrl->ctrl.nr_reconnects;
30773027

@@ -3177,23 +3127,18 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
31773127
else
31783128
ret = nvme_fc_recreate_io_queues(ctrl);
31793129
}
3130+
if (!ret && test_bit(ASSOC_FAILED, &ctrl->flags))
3131+
ret = -EIO;
31803132
if (ret)
31813133
goto out_term_aen_ops;
31823134

3183-
spin_lock_irqsave(&ctrl->lock, flags);
3184-
if (!test_bit(ASSOC_FAILED, &ctrl->flags))
3185-
changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
3186-
else
3135+
if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE)) {
31873136
ret = -EIO;
3188-
spin_unlock_irqrestore(&ctrl->lock, flags);
3189-
3190-
if (ret)
31913137
goto out_term_aen_ops;
3138+
}
31923139

31933140
ctrl->ctrl.nr_reconnects = 0;
3194-
3195-
if (changed)
3196-
nvme_start_ctrl(&ctrl->ctrl);
3141+
nvme_start_ctrl(&ctrl->ctrl);
31973142

31983143
return 0; /* Success */
31993144

0 commit comments

Comments
 (0)