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

Shin'ichiro Kawasaki shinichiro.kawasaki at wdc.com
Tue Oct 29 23:51:46 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]
Reviewed-by: Daniel Wagner <dwagner at suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
 common/nvme | 46 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/common/nvme b/common/nvme
index fa64ad4..6513205 100644
--- a/common/nvme
+++ b/common/nvme
@@ -274,10 +274,16 @@ _nvme_connect_subsys() {
 	local reconnect_delay=""
 	local ctrl_loss_tmo=""
 	local no_wait=false
+	local port
 	local i
+	local -a ARGS
 
 	while [[ $# -gt 0 ]]; do
 		case $1 in
+			--port)
+				port="$2"
+				shift 2
+				;;
 			--subsysnqn)
 				subsysnqn="$2"
 				shift 2
@@ -333,20 +339,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
+	_get_nvmet_port_params "${port}" ARGS
+	ARGS+=(--nqn "${subsysnqn}")
 	ARGS+=(--hostnqn="${hostnqn}")
 	ARGS+=(--hostid="${hostid}")
 	if [[ -n "${hostkey}" ]]; then
@@ -682,6 +686,28 @@ _get_nvmet_ports() {
 	done
 }
 
+_get_nvmet_port_params() {
+	local port="$1"
+	local -n args="$2"
+	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
+}
+
 _find_nvme_dev() {
 	local subsys=$1
 	local subsysnqn
-- 
2.45.2




More information about the Linux-nvme mailing list