[PATCH v2] nvme: add optional ipv6 test flavor

Sagi Grimberg sagi at grimberg.me
Mon Jun 27 04:32:00 PDT 2022


Allow Setting nvme_adrfam=[ipv4|ipv6] and running tests on either
address family. Ignored for non IP transports.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
Changes from v1:
- fix shellcheck
- prefer double brackets
- fix 80-char long line

 common/multipath-over-rdma | 10 ++++++++++
 tests/nvme/rc              | 32 +++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/common/multipath-over-rdma b/common/multipath-over-rdma
index f9d7b9a236ce..661eabd56548 100644
--- a/common/multipath-over-rdma
+++ b/common/multipath-over-rdma
@@ -74,6 +74,16 @@ get_ipv6_addr() {
 		sed -n 's/.*[[:blank:]]inet6[[:blank:]]*\([^[:blank:]/]*\).*/\1/p'
 }
 
+# grab only the link local address
+get_ipv6_ll_addr() {
+	if [[ ! -e "/sys/class/net/$1" ]]; then
+		echo "get_ipv6_addr(): $1 is not a network interface" 1>&2
+	fi
+	ll_addr=$(ip -6 -o addr show dev "$1" | grep "scope link" |
+		sed -n 's/.*[[:blank:]]inet6[[:blank:]]*\([^[:blank:]/]*\).*/\1/p')
+	echo "$ll_addr%$1"
+}
+
 # Whether or not $1 is a number.
 is_number() {
 	[ "$1" -eq "0$1" ] 2>/dev/null
diff --git a/tests/nvme/rc b/tests/nvme/rc
index 998b18164306..4bebbc762cbb 100644
--- a/tests/nvme/rc
+++ b/tests/nvme/rc
@@ -38,6 +38,25 @@ _nvme_requires() {
 		SKIP_REASON="unsupported nvme_trtype=${nvme_trtype}"
 		return 1
 	esac
+
+	if [[ -n ${nvme_adrfam} ]]; then
+		case ${nvme_adrfam} in
+		ipv6)
+			def_traddr="::1"
+			def_adrfam="ipv6"
+			;;
+		ipv4)
+			;; # was already set
+		*)
+			# ignore for non ip transports
+			if [[ "${nvme_trtype}" == "tcp" ||
+			      "${nvme_trtype}" == "rdma" ]]; then
+				SKIP_REASON="unsupported nvme_adrfam=${nvme_adrfam}"
+				return 1
+			fi
+		esac
+	fi
+
 	return 0
 }
 
@@ -148,9 +167,16 @@ _setup_nvmet() {
 		start_soft_rdma
 		for i in $(rdma_network_interfaces)
 		do
-			ipv4_addr=$(get_ipv4_addr "$i")
-			if [ -n "${ipv4_addr}" ]; then
-				def_traddr=${ipv4_addr}
+			if [[ "${nvme_adrfam}" == "ipv6" ]]; then
+				ipv6_addr=$(get_ipv6_ll_addr "$i")
+				if [[ -n "${ipv6_addr}" ]]; then
+					def_traddr=${ipv6_addr}
+				fi
+			else
+				ipv4_addr=$(get_ipv4_addr "$i")
+				if [[ -n "${ipv4_addr}" ]]; then
+					def_traddr=${ipv4_addr}
+				fi
 			fi
 		done
 	fi
-- 
2.34.1




More information about the Linux-nvme mailing list