[PATCH blktests 10/15] nvme: pass in port parameter to _nvme_connect_subsys()

Shin'ichiro Kawasaki shinichiro.kawasaki at wdc.com
Wed Oct 23 18:00:20 PDT 2024


From: Hannes Reinecke <hare at suse.de>

A subsystem might have more than one port, and that port might be
configured differently from the default settings. So rather than
to rely on the default settings we should extract the parameters
from the passed in ports on that subsystem and issue 'nvme connect'
with the extracted parameters.

Signed-off-by: Hannes Reinecke <hare at suse.de>
[Shin'ichiro: fixed conflicts for fc transport]
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
 common/nvme | 47 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/common/nvme b/common/nvme
index fa64ad4..95a05de 100644
--- a/common/nvme
+++ b/common/nvme
@@ -274,10 +274,15 @@ _nvme_connect_subsys() {
 	local reconnect_delay=""
 	local ctrl_loss_tmo=""
 	local no_wait=false
+	local port
 	local i
 
 	while [[ $# -gt 0 ]]; do
 		case $1 in
+			--port)
+				port="$2"
+				shift 2
+				;;
 			--subsysnqn)
 				subsysnqn="$2"
 				shift 2
@@ -333,20 +338,18 @@ _nvme_connect_subsys() {
 		esac
 	done
 
-	ARGS=(--transport "${nvme_trtype}" --nqn "${subsysnqn}")
-	if [[ "${nvme_trtype}" == "fc" ]] ; then
+	if [[ -z "${port}" ]]; then
 		local ports
+
 		_get_nvmet_ports "${subsysnqn}" ports
-		if ((${#ports[@]} != 1)); then
-			echo only one port is supported at this moment...
-			exit 1
+		port="${ports[0]##*/}"
+		if [[ -z "${port}" ]]; then
+			echo "WARNING: no port found"
+			return 1
 		fi
-		local port=${ports[0]}
-		ARGS+=(--traddr "$(_fc_traddr "$port")")
-		ARGS+=(--host-traddr "$(_fc_host_traddr "$port")")
-	elif [[ "${nvme_trtype}" != "loop" ]]; then
-		ARGS+=(--traddr "${def_traddr}" --trsvcid "${def_trsvcid}")
 	fi
+	read -ra ARGS < <(_get_nvmet_port_params "${port}")
+	ARGS+=(--nqn "${subsysnqn}")
 	ARGS+=(--hostnqn="${hostnqn}")
 	ARGS+=(--hostid="${hostid}")
 	if [[ -n "${hostkey}" ]]; then
@@ -682,6 +685,30 @@ _get_nvmet_ports() {
 	done
 }
 
+_get_nvmet_port_params() {
+	local port="$1"
+	local -a args=()
+	local cfs_path="${NVMET_CFS}/ports/${port}"
+	local trtype
+	local traddr
+	local trsvcid
+
+	[[ -d "${cfs_path}" ]] || exit 1
+	trtype=$(cat "${cfs_path}/addr_trtype")
+	args+=(--transport "${trtype}")
+	traddr=$(cat "${cfs_path}/addr_traddr")
+	args+=(--traddr "${traddr}")
+	if [[ "${trtype}" == "tcp" ]] || [[ "${trtype}" == "rdma" ]]; then
+		trsvcid=$(cat "${cfs_path}/addr_trsvcid")
+		args+=(--trsvcid "${trsvcid}")
+	elif [[ "${trtype}" == "fc" ]]; then
+		args+=(--traddr "$(_fc_traddr "$port")")
+		args+=(--host-traddr "$(_fc_host_traddr "$port")")
+	fi
+
+	echo "${args[@]}"
+}
+
 _find_nvme_dev() {
 	local subsys=$1
 	local subsysnqn
-- 
2.45.2




More information about the Linux-nvme mailing list