Skip to contentSkip to conversation

nvme: consider also host_iface when checking ip options

PATCH Applied Daniel Wagner 3 participants 4 messages Jul 29, 2022 – Sep 5, 2022 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 nvme: consider also host_iface when checking ip options

It's perfectly fine to use the same traddr and trsvcid more than once as long we use different host interface. This is used in setups where the host has more than one interface but the target exposes only one traddr/trsvcid combination.

Use the same acceptance rules for host_iface as we have for host_traddr.

---

tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 -f enp1s0 tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 -f enp1s0 Failed to write to /dev/nvme-fabrics: Operation already in progress no controller found: failed to write to nvme-fabrics device tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 -f enp7s0 tw:~ # nvme list-subsys
nvme-subsys0 - NQN=nvmet-test
\

 +- nvme0 tcp traddr=192.168.19.54,trsvcid=4420,host_iface=enp1s0 live optimized
 +- nvme1 tcp traddr=192.168.19.54,trsvcid=4420 live optimized
 +- nvme2 tcp traddr=192.168.19.54,trsvcid=4420,host_iface=enp7s0 live optimized

changes:
v3: same check rules as for local address
v2: added NVMF_OPT_HOST_TRADDR checks but to strict
v1: initial version

 drivers/nvme/host/fabrics.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/nvme/host/fabrics.c +18 -5
index 5207a2348257..2d948bcc31e0 100644
@@ -965,13 +965,17 @@ bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
 		return false;
 
 	/*
-	 * Checking the local address is rough. In most cases, none is specified
-	 * and the host port is selected by the stack.
+	 * Checking the local address or host interfaces is rough.
+	 *
+	 * In most cases, none is specified and the host port or
+	 * host interface is selected by the stack.
 	 *
 	 * Assume no match if:
-	 * -  local address is specified and address is not the same
-	 * -  local address is not specified but remote is, or vice versa
-	 *    (admin using specific host_traddr when it matters).
+	 * -  local address or host interface is specified and address
+	 *    or host interface is not the same
+	 * -  local address or host interface is not specified but
+	 *    remote is, or vice versa (admin using specific
+	 *    host_traddr/host_iface when it matters).
 	 */
 	if ((opts->mask & NVMF_OPT_HOST_TRADDR) &&
 	    (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) {
@@ -982,6 +986,15 @@ bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
 		return false;
 	}
 
+	if ((opts->mask & NVMF_OPT_HOST_IFACE) &&
+	    (ctrl->opts->mask & NVMF_OPT_HOST_IFACE)) {
+		if (strcmp(opts->host_iface, ctrl->opts->host_iface))
+			return false;
+	} else if ((opts->mask & NVMF_OPT_HOST_IFACE) ||
+		   (ctrl->opts->mask & NVMF_OPT_HOST_IFACE)) {
+		return false;
+	}
+
 	return true;
 }
 EXPORT_SYMBOL_GPL(nvmf_ip_options_match);
Signature · 1 line
2.37.1
Reviewed-by on v3 1/1
#1 lore raw

Looks good to me.

Quoted 76 lines · Daniel Wagner

It's perfectly fine to use the same traddr and trsvcid more than once as long we use different host interface. This is used in setups where the host has more than one interface but the target exposes only one traddr/trsvcid combination.

Use the same acceptance rules for host_iface as we have for host_traddr.

---

tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 -f enp1s0 tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 -f enp1s0 Failed to write to /dev/nvme-fabrics: Operation already in progress no controller found: failed to write to nvme-fabrics device tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 tw:~ # nvme connect -t tcp -n nvmet-test -a 192.168.19.54 -s 4420 -f enp7s0 tw:~ # nvme list-subsys
nvme-subsys0 - NQN=nvmet-test
\

  +- nvme0 tcp traddr=192.168.19.54,trsvcid=4420,host_iface=enp1s0 live optimized
  +- nvme1 tcp traddr=192.168.19.54,trsvcid=4420 live optimized
  +- nvme2 tcp traddr=192.168.19.54,trsvcid=4420,host_iface=enp7s0 live optimized

changes:
v3: same check rules as for local address
v2: added NVMF_OPT_HOST_TRADDR checks but to strict
v1: initial version

  drivers/nvme/host/fabrics.c | 23 ++++++++++++++++++-----
  1 file changed, 18 insertions(+), 5 deletions(-)
drivers/nvme/host/fabrics.c +18 -5
index 5207a2348257..2d948bcc31e0 100644
@@ -965,13 +965,17 @@ bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
  		return false;
 
  	/*
-	 * Checking the local address is rough. In most cases, none is specified
-	 * and the host port is selected by the stack.
+	 * Checking the local address or host interfaces is rough.
+	 *
+	 * In most cases, none is specified and the host port or
+	 * host interface is selected by the stack.
  	 *
  	 * Assume no match if:
-	 * -  local address is specified and address is not the same
-	 * -  local address is not specified but remote is, or vice versa
-	 *    (admin using specific host_traddr when it matters).
+	 * -  local address or host interface is specified and address
+	 *    or host interface is not the same
+	 * -  local address or host interface is not specified but
+	 *    remote is, or vice versa (admin using specific
+	 *    host_traddr/host_iface when it matters).
  	 */
  	if ((opts->mask & NVMF_OPT_HOST_TRADDR) &&
  	    (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) {
@@ -982,6 +986,15 @@ bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
  		return false;
  	}
 
+	if ((opts->mask & NVMF_OPT_HOST_IFACE) &&
+	    (ctrl->opts->mask & NVMF_OPT_HOST_IFACE)) {
+		if (strcmp(opts->host_iface, ctrl->opts->host_iface))
+			return false;
+	} else if ((opts->mask & NVMF_OPT_HOST_IFACE) ||
+		   (ctrl->opts->mask & NVMF_OPT_HOST_IFACE)) {
+		return false;
+	}
+
  	return true;
  }
  EXPORT_SYMBOL_GPL(nvmf_ip_options_match);