[PATCH blktests 11/15] common/nvme, nvme/003: add --no_port option to _nvme_connect_subsys

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


Commit "nvme: pass in port parameter to _nvme_connect_subsys()"
introduced the --port argument to _nvme_connect_subsys(). If the option
is not specified, _nvme_connect_subsys() automatically finds the port
for the specified subsysnqn. However, this does not work for the test
case nvme/003, since the test case connects to the subsys for discovery,
then, the port of the created subsysnqn is not to be used. This causes
the failure of the test case.

To avoid the failure, introduce --no_port option. When this is option is
specified, _nvme_connect_subsys() skips the port finding step.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
 common/nvme    | 33 ++++++++++++++++++++++++---------
 tests/nvme/003 |  3 ++-
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/common/nvme b/common/nvme
index 95a05de..758e248 100644
--- a/common/nvme
+++ b/common/nvme
@@ -275,7 +275,9 @@ _nvme_connect_subsys() {
 	local ctrl_loss_tmo=""
 	local no_wait=false
 	local port
+	local no_port=false
 	local i
+	local -a ARGS
 
 	while [[ $# -gt 0 ]]; do
 		case $1 in
@@ -283,6 +285,10 @@ _nvme_connect_subsys() {
 				port="$2"
 				shift 2
 				;;
+			--no_port)
+				no_port=true
+				shift
+				;;
 			--subsysnqn)
 				subsysnqn="$2"
 				shift 2
@@ -338,7 +344,9 @@ _nvme_connect_subsys() {
 		esac
 	done
 
-	if [[ -z "${port}" ]]; then
+	if [[ $no_port == true ]]; then
+		port=none
+	elif [[ -z "${port}" && $no_port == false ]]; then
 		local ports
 
 		_get_nvmet_ports "${subsysnqn}" ports
@@ -689,17 +697,24 @@ _get_nvmet_port_params() {
 	local port="$1"
 	local -a args=()
 	local cfs_path="${NVMET_CFS}/ports/${port}"
-	local trtype
-	local traddr
-	local trsvcid
+	local trtype="${nvme_trtype}"
+	local traddr="${def_traddr}"
+	local trsvcid="${def_trsvcid}"
+
+	if [[ $port != none ]]; then
+		[[ -d "${cfs_path}" ]] || exit 1
+		trtype=$(cat "${cfs_path}/addr_trtype")
+		traddr=$(cat "${cfs_path}/addr_traddr")
+		args+=(--traddr "${traddr}")
+		if [[ "${trtype}" == "tcp" ]] || [[ "${trtype}" == "rdma" ]]; then
+			trsvcid=$(cat "${cfs_path}/addr_trsvcid")
+		fi
+	elif [[ "${trtype}" != "loop" ]]; then
+		args+=(--traddr "${traddr}")
+	fi
 
-	[[ -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")")
diff --git a/tests/nvme/003 b/tests/nvme/003
index 36c0753..67c7df6 100755
--- a/tests/nvme/003
+++ b/tests/nvme/003
@@ -28,7 +28,8 @@ test() {
 
 	_nvmet_target_setup
 
-	_nvme_connect_subsys --subsysnqn "nqn.2014-08.org.nvmexpress.discovery"
+	_nvme_connect_subsys --no_port \
+			     --subsysnqn "nqn.2014-08.org.nvmexpress.discovery"
 
 	# This is ugly but checking for the absence of error messages is ...
 	sleep 10
-- 
2.45.2




More information about the Linux-nvme mailing list