Skip to content

Commit b58da2d

Browse files
Tatsuya SasakiChristoph Hellwig
authored andcommitted
nvme: update keep alive interval when kato is modified
Currently the connection between host and NVMe-oF target gets disconnected by keep-alive timeout when a user connects to a target with a relatively large kato value and then sets the smaller kato with a set features command (e.g. connects with 60 seconds kato value and then sets 10 seconds kato value). The cause is that keep alive command interval on the host, which is defined as unsigned int kato in nvme_ctrl structure, does not follow the kato value changes. This patch updates the keep alive interval in the following steps when the kato is modified by a set features command: stops the keep alive work queue, then sets the kato as new timer value and re-start the queue. Signed-off-by: Tatsuya Sasaki <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 1ba2e50 commit b58da2d

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ static struct class *nvme_ns_chr_class;
116116
static void nvme_put_subsystem(struct nvme_subsystem *subsys);
117117
static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
118118
unsigned nsid);
119+
static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
120+
struct nvme_command *cmd);
119121

120122
/*
121123
* Prepare a queue for teardown.
@@ -1152,7 +1154,8 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
11521154
return effects;
11531155
}
11541156

1155-
static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
1157+
static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects,
1158+
struct nvme_command *cmd, int status)
11561159
{
11571160
if (effects & NVME_CMD_EFFECTS_CSE_MASK) {
11581161
nvme_unfreeze(ctrl);
@@ -1167,6 +1170,26 @@ static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
11671170
nvme_queue_scan(ctrl);
11681171
flush_work(&ctrl->scan_work);
11691172
}
1173+
1174+
switch (cmd->common.opcode) {
1175+
case nvme_admin_set_features:
1176+
switch (le32_to_cpu(cmd->common.cdw10) & 0xFF) {
1177+
case NVME_FEAT_KATO:
1178+
/*
1179+
* Keep alive commands interval on the host should be
1180+
* updated when KATO is modified by Set Features
1181+
* commands.
1182+
*/
1183+
if (!status)
1184+
nvme_update_keep_alive(ctrl, cmd);
1185+
break;
1186+
default:
1187+
break;
1188+
}
1189+
break;
1190+
default:
1191+
break;
1192+
}
11701193
}
11711194

11721195
int nvme_execute_passthru_rq(struct request *rq)
@@ -1181,7 +1204,7 @@ int nvme_execute_passthru_rq(struct request *rq)
11811204
effects = nvme_passthru_start(ctrl, ns, cmd->common.opcode);
11821205
ret = nvme_execute_rq(disk, rq, false);
11831206
if (effects) /* nothing to be done for zero cmd effects */
1184-
nvme_passthru_end(ctrl, effects);
1207+
nvme_passthru_end(ctrl, effects, cmd, ret);
11851208

11861209
return ret;
11871210
}
@@ -1269,6 +1292,21 @@ void nvme_stop_keep_alive(struct nvme_ctrl *ctrl)
12691292
}
12701293
EXPORT_SYMBOL_GPL(nvme_stop_keep_alive);
12711294

1295+
static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
1296+
struct nvme_command *cmd)
1297+
{
1298+
unsigned int new_kato =
1299+
DIV_ROUND_UP(le32_to_cpu(cmd->common.cdw11), 1000);
1300+
1301+
dev_info(ctrl->device,
1302+
"keep alive interval updated from %u ms to %u ms\n",
1303+
ctrl->kato * 1000 / 2, new_kato * 1000 / 2);
1304+
1305+
nvme_stop_keep_alive(ctrl);
1306+
ctrl->kato = new_kato;
1307+
nvme_start_keep_alive(ctrl);
1308+
}
1309+
12721310
/*
12731311
* In NVMe 1.0 the CNS field was just a binary controller or namespace
12741312
* flag, thus sending any new CNS opcodes has a big chance of not working.

0 commit comments

Comments
 (0)