From: Victor Gladkov victor.gladkov@kioxia.com
mainline inclusion from mainline-v5.11-rc1 commit 8c4dfea97f15b80097b3f882ca428fb2751ec30c category: bugfix bugzilla: NA CVE: NA Link: https://gitee.com/openeuler/kernel/issues/I4JFPM?from=project-issue
-------------------------------------------------
Commands get stuck while Host NVMe-oF controller is in reconnect state. The controller enters into reconnect state when it loses connection with the target. It tries to reconnect every 10 seconds (default) until a successful reconnect or until the reconnect time-out is reached. The default reconnect time out is 10 minutes.
Applications are expecting commands to complete with success or error within a certain timeout (30 seconds by default). The NVMe host is enforcing that timeout while it is connected, but during reconnect the timeout is not enforced and commands may get stuck for a long period or even forever.
To fix this long delay due to the default timeout, introduce new "fast_io_fail_tmo" session parameter. The timeout is measured in seconds from the controller reconnect and any command beyond that timeout is rejected. The new parameter value may be passed during 'connect'. The default value of -1 means no timeout (similar to current behavior).
Signed-off-by: Victor Gladkov victor.gladkov@kioxia.com Signed-off-by: Chaitanya Kulkarni chaitanya.kulkarni@wdc.com Reviewed-by: Hannes Reinecke hare@suse.de Reviewed-by: Sagi Grimberg sagi@grimberg.me Reviewed-by: Chao Leng lengchao@huawei.com Signed-off-by: Christoph Hellwig hch@lst.de
conflicts:: drivers/nvme/host/core.c [adjust context]
Signed-off-by: jiangtao jiangtao62@huawei.com Reviewed-by: chengjike chengjike.cheng@huawei.com Reviewed-by: Ao Sun sunao.sun@huawei.com Reviewed-by: Zhenwei Yang yangzhenwei@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/nvme/host/core.c | 51 +++++++++++++++++++++++++++++++++-- drivers/nvme/host/fabrics.c | 28 ++++++++++++++++--- drivers/nvme/host/fabrics.h | 5 ++++ drivers/nvme/host/multipath.c | 2 ++ drivers/nvme/host/nvme.h | 3 +++ 5 files changed, 83 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index b45ae13aa5fe6..c9ca375a5ddb9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -130,6 +130,37 @@ static void nvme_queue_scan(struct nvme_ctrl *ctrl) queue_work(nvme_wq, &ctrl->scan_work); }
+static void nvme_failfast_work(struct work_struct *work) +{ + struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), + struct nvme_ctrl, failfast_work); + + if (ctrl->state != NVME_CTRL_CONNECTING) + return; + + set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); + dev_info(ctrl->device, "failfast expired\n"); + nvme_kick_requeue_lists(ctrl); +} + +static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) +{ + if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) + return; + + schedule_delayed_work(&ctrl->failfast_work, + ctrl->opts->fast_io_fail_tmo * HZ); +} + +static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) +{ + if (!ctrl->opts) + return; + + cancel_delayed_work_sync(&ctrl->failfast_work); + clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); +} + int nvme_reset_ctrl(struct nvme_ctrl *ctrl) { if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) @@ -385,8 +416,21 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, ctrl->state = new_state;
spin_unlock_irqrestore(&ctrl->lock, flags); - if (changed && ctrl->state == NVME_CTRL_LIVE) - nvme_kick_requeue_lists(ctrl); + if (changed) { + switch (ctrl->state) { + case NVME_CTRL_LIVE: + if (old_state == NVME_CTRL_CONNECTING) + nvme_stop_failfast_work(ctrl); + nvme_kick_requeue_lists(ctrl); + break; + case NVME_CTRL_CONNECTING: + if (old_state == NVME_CTRL_RESETTING) + nvme_start_failfast_work(ctrl); + break; + default: + break; + } + } return changed; } EXPORT_SYMBOL_GPL(nvme_change_ctrl_state); @@ -3712,6 +3756,7 @@ void nvme_stop_ctrl(struct nvme_ctrl *ctrl) { nvme_mpath_stop(ctrl); nvme_stop_keep_alive(ctrl); + nvme_stop_failfast_work(ctrl); flush_work(&ctrl->async_event_work); cancel_work_sync(&ctrl->fw_act_work); if (ctrl->ops->stop_ctrl) @@ -3776,6 +3821,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, int ret;
ctrl->state = NVME_CTRL_NEW; + clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); spin_lock_init(&ctrl->lock); mutex_init(&ctrl->scan_lock); INIT_LIST_HEAD(&ctrl->namespaces); @@ -3791,6 +3837,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; + INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work);
BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) > PAGE_SIZE); diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index 738794af3f389..650b3bd89968f 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -550,6 +550,7 @@ blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl, { if (ctrl->state != NVME_CTRL_DELETING && ctrl->state != NVME_CTRL_DEAD && + !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH)) return BLK_STS_RESOURCE;
@@ -607,6 +608,7 @@ static const match_table_t opt_tokens = { { NVMF_OPT_HOST_TRADDR, "host_traddr=%s" }, { NVMF_OPT_HOST_ID, "hostid=%s" }, { NVMF_OPT_DUP_CONNECT, "duplicate_connect" }, + { NVMF_OPT_FAIL_FAST_TMO, "fast_io_fail_tmo=%d" }, { NVMF_OPT_ERR, NULL } };
@@ -626,6 +628,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, opts->reconnect_delay = NVMF_DEF_RECONNECT_DELAY; opts->kato = NVME_DEFAULT_KATO; opts->duplicate_connect = false; + opts->fast_io_fail_tmo = NVMF_DEF_FAIL_FAST_TMO;
options = o = kstrdup(buf, GFP_KERNEL); if (!options) @@ -750,6 +753,17 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, pr_warn("ctrl_loss_tmo < 0 will reconnect forever\n"); ctrl_loss_tmo = token; break; + case NVMF_OPT_FAIL_FAST_TMO: + if (match_int(args, &token)) { + ret = -EINVAL; + goto out; + } + + if (token >= 0) + pr_warn("I/O will fail on after %d sec reconnect\n", + token); + opts->fast_io_fail_tmo = token; + break; case NVMF_OPT_HOSTNQN: if (opts->host) { pr_err("hostnqn already user-assigned: %s\n", @@ -830,11 +844,17 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, opts->nr_io_queues = 0; opts->duplicate_connect = true; } - if (ctrl_loss_tmo < 0) + + if (ctrl_loss_tmo < 0) { opts->max_reconnects = -1; - else + } else { opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, opts->reconnect_delay); + if (ctrl_loss_tmo < opts->fast_io_fail_tmo) + pr_warn("failfast tmo (%d) > ctrl_loss_tmo (%d)\n", + opts->fast_io_fail_tmo, + ctrl_loss_tmo); + }
if (!opts->host) { kref_get(&nvmf_default_host->ref); @@ -903,8 +923,8 @@ EXPORT_SYMBOL_GPL(nvmf_free_options); #define NVMF_REQUIRED_OPTS (NVMF_OPT_TRANSPORT | NVMF_OPT_NQN) #define NVMF_ALLOWED_OPTS (NVMF_OPT_QUEUE_SIZE | NVMF_OPT_NR_IO_QUEUES | \ NVMF_OPT_KATO | NVMF_OPT_HOSTNQN | \ - NVMF_OPT_HOST_ID | NVMF_OPT_DUP_CONNECT) - + NVMF_OPT_HOST_ID | NVMF_OPT_DUP_CONNECT |\ + NVMF_OPT_FAIL_FAST_TMO) static struct nvme_ctrl * nvmf_create_ctrl(struct device *dev, const char *buf, size_t count) { diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h index 188ebbeec32ce..645ed75f22980 100644 --- a/drivers/nvme/host/fabrics.h +++ b/drivers/nvme/host/fabrics.h @@ -24,6 +24,8 @@ /* default to 600 seconds of reconnect attempts before giving up */ #define NVMF_DEF_CTRL_LOSS_TMO 600 #define NVMF_DEF_RECONNECT_FOREVER -1 +/* default is -1: the fail fast mechanism is disabled */ +#define NVMF_DEF_FAIL_FAST_TMO -1
/* * Define a host as seen by the target. We allocate one at boot, but also @@ -59,6 +61,7 @@ enum { NVMF_OPT_CTRL_LOSS_TMO = 1 << 11, NVMF_OPT_HOST_ID = 1 << 12, NVMF_OPT_DUP_CONNECT = 1 << 13, + NVMF_OPT_FAIL_FAST_TMO = 1 << 20, };
/** @@ -86,6 +89,7 @@ enum { * @max_reconnects: maximum number of allowed reconnect attempts before removing * the controller, (-1) means reconnect forever, zero means remove * immediately; + * @fast_io_fail_tmo: Fast I/O fail timeout in seconds */ struct nvmf_ctrl_options { unsigned mask; @@ -102,6 +106,7 @@ struct nvmf_ctrl_options { unsigned int kato; struct nvmf_host *host; int max_reconnects; + int fast_io_fail_tmo; };
/* diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index f4616df1f7f15..9201946568630 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -198,6 +198,8 @@ static bool nvme_available_path(struct nvme_ns_head *head) struct nvme_ns *ns;
list_for_each_entry_rcu(ns, &head->list, siblings) { + if (test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ns->ctrl->flags)) + continue; switch (ns->ctrl->state) { case NVME_CTRL_LIVE: case NVME_CTRL_RESETTING: diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 85f814a91ce9c..cd66364eb5429 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -211,6 +211,7 @@ struct nvme_ctrl { struct work_struct scan_work; struct work_struct async_event_work; struct delayed_work ka_work; + struct delayed_work failfast_work; struct nvme_command ka_cmd; struct work_struct fw_act_work; unsigned long events; @@ -245,6 +246,8 @@ struct nvme_ctrl { u16 icdoff; u16 maxcmd; int nr_reconnects; + unsigned long flags; +#define NVME_CTRL_FAILFAST_EXPIRED 0 struct nvmf_ctrl_options *opts;
struct page *discard_page;
From: Daniel Wagner dwagner@suse.de
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 Victor.Gladkov@kioxia.com Signed-off-by: Daniel Wagner dwagner@suse.de Reviewed-by: Ewan D. Milne emilne@redhat.com Reviewed-by: Sagi Grimberg sagi@grimberg.me Reviewed-by: Himanshu Madhani himanshu.madhaani@oracle.com Signed-off-by: Christoph Hellwig hch@lst.de
conflicts: drivers/nvme/host/core.c [adjust context]
Signed-off-by: jiangtao jiangtao62@huawei.com Reviewed-by: chengjike chengjike.cheng@huawei.com Reviewed-by: Ao Sun sunao.sun@huawei.com Reviewed-by: Zhenwei Yang yangzhenwei@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- 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 c9ca375a5ddb9..d512855393851 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 };
From: Gopal Tiwari gtiwari@redhat.com
mainline inclusion from mainline-v5.13-rc1 commit d6609084b0b81abc74dc9db0281cdd0e074df5d4 category: bugfix bugzilla: NA CVE: NA Link: https://gitee.com/openeuler/kernel/issues/I4JFPM?from=project-issue
-------------------------------------------------
Adding entry for dev_attr_fast_io_fail_tmo to avoid the kernel crash while reading and writing the fast_io_fail_tmo.
Fixes: 09fbed636382 (nvme: export fast_io_fail_tmo to sysfs) Signed-off-by: Gopal Tiwari gtiwari@redhat.com Reviewed-by: Keith Busch kbusch@kernel.org Signed-off-by: Christoph Hellwig hch@lst.de Signed-off-by: jiangtao jiangtao62@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/nvme/host/core.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d512855393851..36558dfe6f654 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3157,6 +3157,8 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj, return 0; if (a == &dev_attr_address.attr && !ctrl->ops->get_address) return 0; + if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts) + return 0;
return a->mode; }
From: jiangtao jiangtao62@huawei.com
driver inclusion category: bugfix bugzilla: NA CVE: NA Link: https://gitee.com/openeuler/kernel/issues/I4JFPM?from=project-issue
-------------------------------------------------
Kabi is broken by adding new member variables to "nvme_ctrl" and "nvmf_ctrl_options" structure in "reject I/O to offline device" patch. So kabi was repaired by constructing a new structure.
Signed-off-by: jiangtao jiangtao62@huawei.com Reviewed-by: chengjike chengjike.cheng@huawei.com Reviewed-by: Ao Sun sunao.sun@huawei.com Reviewed-by: Zhenwei Yang yangzhenwei@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/nvme/host/core.c | 37 ++++++++++++++++++++++------------- drivers/nvme/host/fabrics.c | 20 +++++++++++-------- drivers/nvme/host/fabrics.h | 9 ++++++++- drivers/nvme/host/fc.c | 5 ++++- drivers/nvme/host/multipath.c | 3 ++- drivers/nvme/host/nvme.h | 14 ++++++++++--- drivers/nvme/host/pci.c | 5 ++++- drivers/nvme/host/rdma.c | 5 ++++- drivers/nvme/target/loop.c | 5 ++++- 9 files changed, 72 insertions(+), 31 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 36558dfe6f654..feba1a34c15ed 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -132,24 +132,31 @@ static void nvme_queue_scan(struct nvme_ctrl *ctrl)
static void nvme_failfast_work(struct work_struct *work) { - struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), - struct nvme_ctrl, failfast_work); + struct nvme_ctrl_plus *ctrl_plus = container_of(to_delayed_work(work), + struct nvme_ctrl_plus, failfast_work); + struct nvme_ctrl *ctrl = &ctrl_plus->ctrl;
if (ctrl->state != NVME_CTRL_CONNECTING) return;
- set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); + set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl_plus->flags); dev_info(ctrl->device, "failfast expired\n"); nvme_kick_requeue_lists(ctrl); }
static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) { - if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) + struct nvmf_ctrl_options_plus *ops_plus = NULL; + + if (!ctrl->opts) + return; + + ops_plus = nvmf_opt_to_plus(ctrl->opts); + if (ops_plus->fast_io_fail_tmo == -1) return;
- schedule_delayed_work(&ctrl->failfast_work, - ctrl->opts->fast_io_fail_tmo * HZ); + schedule_delayed_work(&nvme_ctrl_to_plus(ctrl)->failfast_work, + ops_plus->fast_io_fail_tmo * HZ); }
static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) @@ -157,8 +164,8 @@ static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) if (!ctrl->opts) return;
- cancel_delayed_work_sync(&ctrl->failfast_work); - clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); + cancel_delayed_work_sync(&nvme_ctrl_to_plus(ctrl)->failfast_work); + clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &nvme_ctrl_to_plus(ctrl)->flags); }
int nvme_reset_ctrl(struct nvme_ctrl *ctrl) @@ -3105,10 +3112,11 @@ 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); + int value = nvmf_opt_to_plus(ctrl->opts)->fast_io_fail_tmo;
- if (ctrl->opts->fast_io_fail_tmo == -1) + if (value == -1) return sysfs_emit(buf, "off\n"); - return sysfs_emit(buf, "%d\n", ctrl->opts->fast_io_fail_tmo); + return sysfs_emit(buf, "%d\n", value); }
static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, @@ -3123,9 +3131,9 @@ static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev, return -EINVAL;
if (fast_io_fail_tmo < 0) - opts->fast_io_fail_tmo = -1; + nvmf_opt_to_plus(opts)->fast_io_fail_tmo = -1; else - opts->fast_io_fail_tmo = fast_io_fail_tmo; + nvmf_opt_to_plus(opts)->fast_io_fail_tmo = fast_io_fail_tmo; return count; } static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR, @@ -3854,7 +3862,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, int ret;
ctrl->state = NVME_CTRL_NEW; - clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); + clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &nvme_ctrl_to_plus(ctrl)->flags); spin_lock_init(&ctrl->lock); mutex_init(&ctrl->scan_lock); INIT_LIST_HEAD(&ctrl->namespaces); @@ -3870,7 +3878,8 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; - INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); + INIT_DELAYED_WORK(&nvme_ctrl_to_plus(ctrl)->failfast_work, + nvme_failfast_work);
BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) > PAGE_SIZE); diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index 650b3bd89968f..a1f6648b63c40 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -550,7 +550,8 @@ blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl, { if (ctrl->state != NVME_CTRL_DELETING && ctrl->state != NVME_CTRL_DEAD && - !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && + !test_bit(NVME_CTRL_FAILFAST_EXPIRED, + &nvme_ctrl_to_plus(ctrl)->flags) && !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH)) return BLK_STS_RESOURCE;
@@ -628,7 +629,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, opts->reconnect_delay = NVMF_DEF_RECONNECT_DELAY; opts->kato = NVME_DEFAULT_KATO; opts->duplicate_connect = false; - opts->fast_io_fail_tmo = NVMF_DEF_FAIL_FAST_TMO; + nvmf_opt_to_plus(opts)->fast_io_fail_tmo = NVMF_DEF_FAIL_FAST_TMO;
options = o = kstrdup(buf, GFP_KERNEL); if (!options) @@ -762,7 +763,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, if (token >= 0) pr_warn("I/O will fail on after %d sec reconnect\n", token); - opts->fast_io_fail_tmo = token; + nvmf_opt_to_plus(opts)->fast_io_fail_tmo = token; break; case NVMF_OPT_HOSTNQN: if (opts->host) { @@ -850,9 +851,9 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, } else { opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, opts->reconnect_delay); - if (ctrl_loss_tmo < opts->fast_io_fail_tmo) + if (ctrl_loss_tmo < nvmf_opt_to_plus(opts)->fast_io_fail_tmo) pr_warn("failfast tmo (%d) > ctrl_loss_tmo (%d)\n", - opts->fast_io_fail_tmo, + nvmf_opt_to_plus(opts)->fast_io_fail_tmo, ctrl_loss_tmo); }
@@ -916,7 +917,7 @@ void nvmf_free_options(struct nvmf_ctrl_options *opts) kfree(opts->trsvcid); kfree(opts->subsysnqn); kfree(opts->host_traddr); - kfree(opts); + kfree(nvmf_opt_to_plus(opts)); } EXPORT_SYMBOL_GPL(nvmf_free_options);
@@ -925,18 +926,21 @@ EXPORT_SYMBOL_GPL(nvmf_free_options); NVMF_OPT_KATO | NVMF_OPT_HOSTNQN | \ NVMF_OPT_HOST_ID | NVMF_OPT_DUP_CONNECT |\ NVMF_OPT_FAIL_FAST_TMO) + static struct nvme_ctrl * nvmf_create_ctrl(struct device *dev, const char *buf, size_t count) { + struct nvmf_ctrl_options_plus *opts_plus; struct nvmf_ctrl_options *opts; struct nvmf_transport_ops *ops; struct nvme_ctrl *ctrl; int ret;
- opts = kzalloc(sizeof(*opts), GFP_KERNEL); - if (!opts) + opts_plus = kzalloc(sizeof(*opts_plus), GFP_KERNEL); + if (!opts_plus) return ERR_PTR(-ENOMEM);
+ opts = &opts_plus->ops; ret = nvmf_parse_options(opts, buf); if (ret) goto out_free_opts; diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h index 645ed75f22980..b7a47b8687573 100644 --- a/drivers/nvme/host/fabrics.h +++ b/drivers/nvme/host/fabrics.h @@ -106,9 +106,16 @@ struct nvmf_ctrl_options { unsigned int kato; struct nvmf_host *host; int max_reconnects; - int fast_io_fail_tmo; };
+struct nvmf_ctrl_options_plus { + struct nvmf_ctrl_options ops; + int fast_io_fail_tmo; +}; + +#define nvmf_opt_to_plus(ps) \ + container_of(ps, struct nvmf_ctrl_options_plus, ops) + /* * struct nvmf_transport_ops - used to register a specific * fabric implementation of NVMe fabrics. diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index cb4331d9720e3..8cc714c4c35cf 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -162,7 +162,10 @@ struct nvme_fc_ctrl {
struct nvme_fc_fcp_op aen_ops[NVME_NR_AEN_COMMANDS];
- struct nvme_ctrl ctrl; + union { + struct nvme_ctrl ctrl; + struct nvme_ctrl_plus ctrl_plus; + }; };
static inline struct nvme_fc_ctrl * diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 9201946568630..267395704a3b7 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -198,7 +198,8 @@ static bool nvme_available_path(struct nvme_ns_head *head) struct nvme_ns *ns;
list_for_each_entry_rcu(ns, &head->list, siblings) { - if (test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ns->ctrl->flags)) + if (test_bit(NVME_CTRL_FAILFAST_EXPIRED, + &nvme_ctrl_to_plus(ns->ctrl)->flags)) continue; switch (ns->ctrl->state) { case NVME_CTRL_LIVE: diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index cd66364eb5429..afe212063af25 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -211,7 +211,6 @@ struct nvme_ctrl { struct work_struct scan_work; struct work_struct async_event_work; struct delayed_work ka_work; - struct delayed_work failfast_work; struct nvme_command ka_cmd; struct work_struct fw_act_work; unsigned long events; @@ -246,14 +245,23 @@ struct nvme_ctrl { u16 icdoff; u16 maxcmd; int nr_reconnects; - unsigned long flags; -#define NVME_CTRL_FAILFAST_EXPIRED 0 struct nvmf_ctrl_options *opts;
struct page *discard_page; unsigned long discard_page_busy; };
+#define NVME_CTRL_FAILFAST_EXPIRED 0 +struct nvme_ctrl_plus { + struct nvme_ctrl ctrl; + unsigned long flags; + struct delayed_work failfast_work; +}; + +#define nvme_ctrl_to_plus(t) \ + container_of(t, struct nvme_ctrl_plus, ctrl) + + struct nvme_subsystem { int instance; struct device dev; diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 8d3508b2f9381..4357b870bd82b 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -105,7 +105,10 @@ struct nvme_dev { u64 cmb_size; u32 cmbsz; u32 cmbloc; - struct nvme_ctrl ctrl; + union { + struct nvme_ctrl ctrl; + struct nvme_ctrl_plus ctrl_plus; + }; struct completion ioq_wait;
mempool_t *iod_mempool; diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index c16f899bd6b3a..d86a50f09646e 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -118,7 +118,10 @@ struct nvme_rdma_ctrl { struct sockaddr_storage addr; struct sockaddr_storage src_addr;
- struct nvme_ctrl ctrl; + union { + struct nvme_ctrl ctrl; + struct nvme_ctrl_plus ctrl_plus; + }; bool use_inline_data; };
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index ffe7fa814d8c8..1eee21310deee 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -42,7 +42,10 @@ struct nvme_loop_ctrl { struct list_head list; struct blk_mq_tag_set tag_set; struct nvme_loop_iod async_event_iod; - struct nvme_ctrl ctrl; + union { + struct nvme_ctrl ctrl; + struct nvme_ctrl_plus ctrl_plus; + };
struct nvmet_ctrl *target_ctrl; struct nvmet_port *port;