From: jsmart2021@gmail.com (James Smart)
Subject: [PATCH v2 4/7] nvme_fc: add dev_loss_tmo to controller
Date: Tue, 26 Sep 2017 21:50:43 -0700 [thread overview]
Message-ID: <20170927045046.22238-5-jsmart2021@gmail.com> (raw)
In-Reply-To: <20170927045046.22238-1-jsmart2021@gmail.com>
This patch adds a dev_loss_tmo value to the controller. The value
is initialized from the remoteport.
The patch also adds a lldd-callable routine,
nvme_fc_set_remoteport_devloss() to change the value on the remoteport
and apply the new value to the controllers on the remote port.
The dev_loss_tmo value set on the controller will ultimately be the
maximum window allowed for reconnection, whether it was started due
to controller reset, transport error, or loss of connectivity to the
target.
The dev_loss_tmo value set on the controller will be the smaller of
the controller's (max_connects * reconnect_delay) window set at creation
and the remoteport's dev_loss_tmo value. After selecting the smallest
value, if the controller's reconnect window is superceeded by the
remoteport's dev_loss_tmo value, the reconnect values will be
adjusted for the new dev_loss_tmo value.
Signed-off-by: James Smart <james.smart at broadcom.com>
---
drivers/nvme/host/fc.c | 93 ++++++++++++++++++++++++++++++++++++++++++
include/linux/nvme-fc-driver.h | 2 +
2 files changed, 95 insertions(+)
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index db6484bfe02b..63fb35bb6f1f 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -163,6 +163,7 @@ struct nvme_fc_ctrl {
struct work_struct delete_work;
struct delayed_work connect_work;
+ u32 dev_loss_tmo;
struct kref ref;
u32 flags;
@@ -2740,6 +2741,96 @@ static const struct blk_mq_ops nvme_fc_admin_mq_ops = {
};
+static void
+nvme_fc_set_ctrl_devloss(struct nvme_fc_ctrl *ctrl,
+ struct nvmf_ctrl_options *opts)
+{
+ u32 dev_loss_tmo;
+
+ /*
+ * dev_loss_tmo will be the max amount of time after an association
+ * failure that will be allowed for a new association to be
+ * established. It doesn't matter why the original association
+ * failed (FC connectivity loss, transport error, admin-request).
+ * The new association must be established before dev_loss_tmo
+ * expires or the controller will be torn down.
+ *
+ * If the connect parameters are less than the FC port dev_loss_tmo
+ * parameter, scale dev_loss_tmo to the connect parameters.
+ *
+ * If the connect parameters are larger than the FC port
+ * dev_loss_tmo parameter, adjust the connect parameters so that
+ * there is at least 1 attempt at a reconnect attempt before failing.
+ * Note: reconnects will be attempted only if there is FC connectivity.
+ */
+
+ if (opts->max_reconnects < 1)
+ opts->max_reconnects = 1;
+ dev_loss_tmo = opts->reconnect_delay * opts->max_reconnects;
+
+ ctrl->dev_loss_tmo =
+ min_t(u32, ctrl->rport->remoteport.dev_loss_tmo, dev_loss_tmo);
+ if (ctrl->dev_loss_tmo < ctrl->rport->remoteport.dev_loss_tmo)
+ dev_info(ctrl->ctrl.device,
+ "NVME-FC{%d}: scaling dev_loss_tmo to reconnect "
+ "window (%d)\n",
+ ctrl->cnum, ctrl->dev_loss_tmo);
+
+ /* resync dev_loss_tmo with the reconnect window */
+ if (ctrl->dev_loss_tmo < opts->reconnect_delay * opts->max_reconnects) {
+ if (!ctrl->dev_loss_tmo)
+ opts->max_reconnects = 0;
+ else {
+ opts->reconnect_delay =
+ min_t(u32, opts->reconnect_delay,
+ ctrl->dev_loss_tmo -
+ NVME_FC_EXPECTED_RECONNECT_TM);
+ opts->max_reconnects = DIV_ROUND_UP(ctrl->dev_loss_tmo,
+ opts->reconnect_delay);
+ dev_info(ctrl->ctrl.device,
+ "NVME-FC{%d}: dev_loss_tmo %d: scaling "
+ "reconnect delay %d max reconnects %d\n",
+ ctrl->cnum, ctrl->dev_loss_tmo,
+ opts->reconnect_delay, opts->max_reconnects);
+ }
+ }
+}
+
+int
+nvme_fc_set_remoteport_devloss(struct nvme_fc_remote_port *portptr,
+ u32 dev_loss_tmo)
+{
+ struct nvme_fc_rport *rport = remoteport_to_rport(portptr);
+ struct nvme_fc_ctrl *ctrl;
+ unsigned long flags;
+
+ /*
+ * Allow dev_loss_tmo set to 0. This will allow
+ * nvme_fc_unregister_remoteport() to immediately delete
+ * controllers without waiting a dev_loss_tmo timeout.
+ */
+ if (dev_loss_tmo && dev_loss_tmo < NVME_FC_MIN_DEV_LOSS_TMO)
+ return -ERANGE;
+
+ spin_lock_irqsave(&rport->lock, flags);
+
+ if (portptr->port_state != FC_OBJSTATE_ONLINE) {
+ spin_unlock_irqrestore(&rport->lock, flags);
+ return -EINVAL;
+ }
+
+ rport->remoteport.dev_loss_tmo = dev_loss_tmo;
+
+ list_for_each_entry(ctrl, &rport->ctrl_list, ctrl_list)
+ /* Apply values for use in next reconnect cycle */
+ nvme_fc_set_ctrl_devloss(ctrl, ctrl->ctrl.opts);
+
+ spin_unlock_irqrestore(&rport->lock, flags);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(nvme_fc_set_remoteport_devloss);
+
static struct nvme_ctrl *
nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
struct nvme_fc_lport *lport, struct nvme_fc_rport *rport)
@@ -2837,6 +2928,8 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
list_add_tail(&ctrl->ctrl_list, &rport->ctrl_list);
spin_unlock_irqrestore(&rport->lock, flags);
+ nvme_fc_set_ctrl_devloss(ctrl, opts);
+
ret = nvme_fc_create_association(ctrl);
if (ret) {
ctrl->ctrl.opts = NULL;
diff --git a/include/linux/nvme-fc-driver.h b/include/linux/nvme-fc-driver.h
index 6e457e4f9543..a2344456266c 100644
--- a/include/linux/nvme-fc-driver.h
+++ b/include/linux/nvme-fc-driver.h
@@ -452,6 +452,8 @@ int nvme_fc_register_remoteport(struct nvme_fc_local_port *localport,
int nvme_fc_unregister_remoteport(struct nvme_fc_remote_port *remoteport);
+int nvme_fc_set_remoteport_devloss(struct nvme_fc_remote_port *remoteport,
+ u32 dev_loss_tmo);
/*
* *************** LLDD FC-NVME Target/Subsystem API ***************
--
2.13.1
next prev parent reply other threads:[~2017-09-27 4:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 4:50 [PATCH v2 0/7] nvme_fc: add dev_loss_tmo support James Smart
2017-09-27 4:50 ` [PATCH v2 1/7] nvme core: allow controller RESETTING to RECONNECTING transition James Smart
2017-10-04 8:28 ` Christoph Hellwig
2017-10-11 10:02 ` Sagi Grimberg
2017-09-27 4:50 ` [PATCH v2 2/7] nvme_fc: change ctlr state assignments during reset/reconnect James Smart
2017-10-05 7:57 ` Christoph Hellwig
2017-10-07 15:53 ` James Smart
2017-10-11 10:07 ` Sagi Grimberg
2017-10-11 14:29 ` James Smart
2017-09-27 4:50 ` [PATCH v2 3/7] nvme_fc: add a dev_loss_tmo field to the remoteport James Smart
2017-10-11 10:11 ` Sagi Grimberg
2017-10-11 14:35 ` James Smart
2017-09-27 4:50 ` James Smart [this message]
2017-10-05 8:00 ` [PATCH v2 4/7] nvme_fc: add dev_loss_tmo to controller Christoph Hellwig
2017-10-07 16:08 ` James Smart
2017-10-11 10:17 ` Sagi Grimberg
2017-10-11 15:10 ` James Smart
2017-10-11 10:14 ` Sagi Grimberg
2017-09-27 4:50 ` [PATCH v2 5/7] nvme_fc: check connectivity before initiating reconnects James Smart
2017-10-05 8:01 ` Christoph Hellwig
2017-09-27 4:50 ` [PATCH v2 6/7] nvme_fc: move remote port get/put/free location James Smart
2017-10-05 8:03 ` Christoph Hellwig
2017-10-11 10:18 ` Sagi Grimberg
2017-09-27 4:50 ` [PATCH v2 7/7] nvme_fc: add dev_loss_tmo timeout and remoteport resume support James Smart
2017-10-11 10:29 ` Sagi Grimberg
2017-10-11 14:52 ` James Smart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170927045046.22238-5-jsmart2021@gmail.com \
--to=jsmart2021@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).