[PATCH blktests v2 13/13] nvme, md/001: support only long options for _create_nvmet_subsystem()

Shin'ichiro Kawasaki shinichiro.kawasaki at wdc.com
Tue Oct 29 23:51:49 PDT 2024


From: Hannes Reinecke <hare at suse.de>

Most callers use the default settings anyway, so simplify them
by using long options for _create_nvmet_subsystem().

Signed-off-by: Hannes Reinecke <hare at suse.de>
[Shin'ichiro: rebased on the commit e3fe06e and resolved conflicts]
Reviewed-by: Daniel Wagner <dwagner at suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
 common/nvme    | 19 +++++++++++--------
 tests/md/001   |  4 +---
 tests/nvme/016 |  3 +--
 tests/nvme/017 |  4 +---
 tests/nvme/rc  | 19 ++++++++++++++-----
 5 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/common/nvme b/common/nvme
index bc5019a..cbfdd2d 100644
--- a/common/nvme
+++ b/common/nvme
@@ -573,17 +573,17 @@ _create_nvmet_ns() {
 }
 
 _create_nvmet_subsystem() {
-	local nvmet_subsystem=""
-	local blkdev=""
-	local uuid="00000000-0000-0000-0000-000000000000"
-	local resv_enable=""
-	local cfs_path=""
+	local subsystem="${def_subsysnqn}"
+	local blkdev
+	local uuid="${def_subsys_uuid}"
+	local resv_enable
+	local cfs_path
 	local -a ARGS
 
 	while [[ $# -gt 0 ]]; do
 		case $1 in
 			--subsysnqn)
-				nvmet_subsystem="$2"
+				subsystem="$2"
 				shift 2
 				;;
 			--blkdev)
@@ -605,10 +605,13 @@ _create_nvmet_subsystem() {
 		esac
 	done
 
-	cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+	cfs_path="${NVMET_CFS}/subsystems/${subsystem}"
 	mkdir -p "${cfs_path}"
 	echo 0 > "${cfs_path}/attr_allow_any_host"
-	ARGS+=(--subsysnqn "${nvmet_subsystem}")
+	if [[ -z "${blkdev}" ]]; then
+		return 0
+	fi
+	ARGS+=(--subsysnqn "${subsystem}")
 	ARGS+=(--blkdev "${blkdev}")
 	if [[ -n "$uuid" ]]; then
 		ARGS+=(--uuid "${uuid}")
diff --git a/tests/md/001 b/tests/md/001
index 5d0752f..f1d92c8 100755
--- a/tests/md/001
+++ b/tests/md/001
@@ -52,9 +52,7 @@ setup_nvme_over_tcp() {
 	local port
 	port="$(_create_nvmet_port)"
 
-	_create_nvmet_subsystem --subsysnqn "${def_subsysnqn}" \
-				--blkdev "/dev/mapper/ram0_big_optio" \
-				--uuid "${def_subsys_uuid}"
+	_create_nvmet_subsystem --blkdev "/dev/mapper/ram0_big_optio"
 	_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
 
 	_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
diff --git a/tests/nvme/016 b/tests/nvme/016
index 56f1477..8e4fc8b 100755
--- a/tests/nvme/016
+++ b/tests/nvme/016
@@ -29,8 +29,7 @@ test() {
 	loop_dev="$(losetup -f)"
 	local genctr=1
 
-	_create_nvmet_subsystem --subsysnqn "${def_subsysnqn}" \
-				--blkdev "${loop_dev}"
+	_create_nvmet_subsystem --blkdev "${loop_dev}"
 
 	for ((i = 2; i <= iterations; i++)); do
 		_create_nvmet_ns --nsid "${i}" \
diff --git a/tests/nvme/017 b/tests/nvme/017
index edd70ca..adebea1 100755
--- a/tests/nvme/017
+++ b/tests/nvme/017
@@ -29,9 +29,7 @@ test() {
 
 	local genctr=1
 
-	_create_nvmet_subsystem --subsysnqn "${def_subsysnqn}" \
-				--blkdev "$(_nvme_def_file_path)" \
-				--uuid "${def_subsys_uuid}"
+	_create_nvmet_subsystem --blkdev "$(_nvme_def_file_path)"
 
 	for ((i = 2; i <= iterations; i++)); do
 		_create_nvmet_ns --nsid "${i}" \
diff --git a/tests/nvme/rc b/tests/nvme/rc
index 64a31e0..f03851c 100644
--- a/tests/nvme/rc
+++ b/tests/nvme/rc
@@ -323,9 +323,10 @@ _nvmet_target_setup() {
 	local ctrlkey=""
 	local hostkey=""
 	local subsysnqn="${def_subsysnqn}"
-	local subsys_uuid="${def_subsys_uuid}"
+	local subsys_uuid
 	local port
 	local resv_enable=""
+	local -a ARGS
 
 	while [[ $# -gt 0 ]]; do
 		case $1 in
@@ -367,10 +368,18 @@ _nvmet_target_setup() {
 		blkdev="$(_nvme_def_file_path)"
 	fi
 
-	_create_nvmet_subsystem --subsysnqn "${subsysnqn}" \
-				--blkdev "${blkdev}" \
-				--uuid "${subsys_uuid}" \
-				${resv_enable}
+	ARGS=(--subsysnqn "${subsysnqn}")
+	if [[ -n "${blkdev}" ]]; then
+		ARGS+=(--blkdev "${blkdev}")
+	fi
+	if [[ -n "${subsys_uuid}" ]]; then
+		ARGS+=(--uuid "${subsys_uuid}")
+	fi
+	if [[ -n "${resv_enable}" ]]; then
+		ARGS+=("${resv_enable}")
+	fi
+	_create_nvmet_subsystem "${ARGS[@]}"
+
 	port="$(_create_nvmet_port)"
 	_add_nvmet_subsys_to_port "${port}" "${subsysnqn}"
 	_create_nvmet_host "${subsysnqn}" "${def_hostnqn}" \
-- 
2.45.2




More information about the Linux-nvme mailing list