[PATCH] nvme-fabrics: Use shutdown timeout on disconnect

Martin Belanger nitram_67 at hotmail.com
Thu Sep 30 07:56:34 PDT 2021


From: Martin Belanger <martin.belanger at dell.com>

Before disconnecting from a controller the driver may send commands
such as setting the NVME_CC_SHN_NORMAL bit.

However, if the controller cannot be reached (e.g. network down),
these commands will block for 1 minute, which is the default timeout
for a write opration. We should not be waiting for this long when
we're actually trying to disconnect.

The driver already specifies a shorter 5-second timeout to be used
during shutdowns (ctrl->shutdown_timeout).

This patch checks the state of the controller before performing a
write command, and if the state is NVME_CTRL_DELETING,
NVME_CTRL_DELETING_NOIO, or NVME_CTRL_DEAD, the shorter timeout
ctrl->shutdown_timeout is used instead of the default.

Signed-off-by: Martin Belanger <martin.belanger at dell.com>
---
 drivers/nvme/host/fabrics.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 668c6bb7a567..fa1ef8b5fd02 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -237,6 +237,19 @@ int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val)
 {
 	struct nvme_command cmd = { };
 	int ret;
+	unsigned int timeout = 0;
+
+	/* Use shutdown timeout when the controller is being deleted */
+	switch (ctrl->state) {
+	case NVME_CTRL_DELETING:
+	case NVME_CTRL_DELETING_NOIO:
+	case NVME_CTRL_DEAD:
+		timeout = jiffies + (ctrl->shutdown_timeout * HZ);
+		break;
+	default:
+		timeout = 0;
+		break;
+	}
 
 	cmd.prop_set.opcode = nvme_fabrics_command;
 	cmd.prop_set.fctype = nvme_fabrics_type_property_set;
@@ -244,8 +257,8 @@ int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val)
 	cmd.prop_set.offset = cpu_to_le32(off);
 	cmd.prop_set.value = cpu_to_le64(val);
 
-	ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, NULL, NULL, 0, 0,
-			NVME_QID_ANY, 0, 0);
+	ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, NULL, NULL, 0,
+				     timeout, NVME_QID_ANY, 0, 0);
 	if (unlikely(ret))
 		dev_err(ctrl->device,
 			"Property Set error: %d, offset %#x\n",
-- 
2.31.1




More information about the Linux-nvme mailing list