From 8cacb0118fca88f36cbd530dda409a6abd7fcc17 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Dec 2021 19:45:17 +0800 Subject: [PATCH] nvme: export fast_io_fail_tmo to sysfs mainline inclusion from mainline-v5.13-rc1 commit 09fbed636382867733c1713c9fe2fa2926dac537 category: bugfix bugzilla: NA CVE: NA Link: https://gitee.com/openeuler/kernel/issues/I4JFPM?from=project-issue ------------------------------------------------- Commit 8c4dfea97f15 ("nvme-fabrics: reject I/O to offline device") introduced fast_io_fail_tmo but didn't export the value to sysfs. The value can be set during the 'nvme connect'. Export the timeout value to user space via sysfs to allow runtime configuration. Cc: Victor Gladkov Signed-off-by: Daniel Wagner Reviewed-by: Ewan D. Milne Reviewed-by: Sagi Grimberg Reviewed-by: Himanshu Madhani Signed-off-by: Christoph Hellwig conflicts: drivers/nvme/host/core.c [adjust context] Signed-off-by: jiangtao Reviewed-by: chengjike Reviewed-by: Ao Sun Reviewed-by: Zhenwei Yang Reviewed-by: Hou Tao Signed-off-by: Yang Yingliang --- drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index c9ca375a5ddb..d51285539385 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3101,6 +3101,36 @@ static ssize_t nvme_sysfs_show_address(struct device *dev, } static DEVICE_ATTR(address, S_IRUGO, nvme_sysfs_show_address, NULL); +static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + + if (ctrl->opts->fast_io_fail_tmo == -1) + return sysfs_emit(buf, "off\n"); + return sysfs_emit(buf, "%d\n", ctrl->opts->fast_io_fail_tmo); +} + +static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + struct nvmf_ctrl_options *opts = ctrl->opts; + int fast_io_fail_tmo, err; + + err = kstrtoint(buf, 10, &fast_io_fail_tmo); + if (err) + return -EINVAL; + + if (fast_io_fail_tmo < 0) + opts->fast_io_fail_tmo = -1; + else + opts->fast_io_fail_tmo = fast_io_fail_tmo; + return count; +} +static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR, + nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store); + static struct attribute *nvme_dev_attrs[] = { &dev_attr_reset_controller.attr, &dev_attr_rescan_controller.attr, @@ -3113,6 +3143,7 @@ static struct attribute *nvme_dev_attrs[] = { &dev_attr_subsysnqn.attr, &dev_attr_address.attr, &dev_attr_state.attr, + &dev_attr_fast_io_fail_tmo.attr, NULL }; -- GitLab