Re: [PATCH v2] nvme: update keep alive interval when kato is modified
From: Sagi Grimberg <sagi@grimberg.me>
Date: 2021-08-24 20:41:51
Also in:
linux-nvme
On 8/23/21 10:44 PM, sasaki tatsuya wrote:
quoted hunk ↗ jump to hunk
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 <redacted> --- Changes since v1: - Add nvme_update_keep_alive to update keep alive timer in core routine. - Add nvme_user_cmd_post to call nvme_update_keep_alive in ioctl.c drivers/nvme/host/core.c | 12 ++++++++++++ drivers/nvme/host/ioctl.c | 19 +++++++++++++++++++ drivers/nvme/host/nvme.h | 1 + 3 files changed, 32 insertions(+)diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index dfd9dec0c1f6..76f0ee431b11 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c@@ -1263,6 +1263,18 @@ static void nvme_start_keep_alive(struct nvme_ctrl *ctrl) nvme_queue_keep_alive_work(ctrl); } +void nvme_update_keep_alive(struct nvme_ctrl *ctrl, unsigned int new_kato) +{ + dev_info(ctrl->device, + "keep alive commands interval on the host is updated from %u ms to %u ms\n", + ctrl->kato * 1000 / 2, new_kato * 1000 / 2); + + nvme_stop_keep_alive(ctrl); + ctrl->kato = new_kato; + nvme_start_keep_alive(ctrl); +} +EXPORT_SYMBOL_GPL(nvme_update_keep_alive); + void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) { if (unlikely(ctrl->kato == 0))diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 305ddd415e45..79006bfb5537 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c@@ -187,6 +187,22 @@ static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl, return true; } +static void nvme_user_cmd_post(struct nvme_passthru_cmd *cmd, + struct nvme_ctrl *ctrl) +{ + /* + * Keep alive commands interval on the host should be updated + * when KATO is modified by Set Features commands. + */ + if (cmd->opcode == nvme_admin_set_features && + (cmd->cdw10 & 0xFF) == NVME_FEAT_KATO) { + /* ms -> s */
no need for this comment.
+ unsigned int new_kato = DIV_ROUND_UP(cmd->cdw11, 1000); + + nvme_update_keep_alive(ctrl, new_kato);
I think you can now inline nvme_update_keep_alive here, no need to keep it in a function.