[PATCH blktests 12/15] nvme: remove "local -n" from _get_nvmet_ports()

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


The -n option of the bash local variable declaration means that the
variable is used as nameref. However, this nameref feature was
introduced to bash at its version 4.3. On the other hand, blktests
requires bash version 4.2. To not rely on the bash version 4.3, replace
the nameref feature with the "read -ra" command to parse arguments.

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

diff --git a/common/nvme b/common/nvme
index 758e248..dce3943 100644
--- a/common/nvme
+++ b/common/nvme
@@ -349,7 +349,7 @@ _nvme_connect_subsys() {
 	elif [[ -z "${port}" && $no_port == false ]]; then
 		local ports
 
-		_get_nvmet_ports "${subsysnqn}" ports
+		read -ra ports < <(_get_nvmet_ports "${subsysnqn}")
 		port="${ports[0]##*/}"
 		if [[ -z "${port}" ]]; then
 			echo "WARNING: no port found"
@@ -683,7 +683,7 @@ _remove_nvmet_subsystem_from_port() {
 
 _get_nvmet_ports() {
 	local nvmet_subsysnqn="${1:-$def_subsysnqn}"
-	local -n nvmet_ports="$2"
+	local -a nvmet_ports=()
 	local cfs_path="${NVMET_CFS}/ports"
 
 	for port in "${cfs_path}/"*; do
@@ -691,6 +691,10 @@ _get_nvmet_ports() {
 			nvmet_ports+=("${port##*/}")
 		fi
 	done
+
+	if (( ${#nvmet_ports[@]} )); then
+		echo "${nvmet_ports[@]}"
+	fi
 }
 
 _get_nvmet_port_params() {
@@ -784,7 +788,7 @@ _nvmet_target_cleanup() {
 		esac
 	done
 
-	_get_nvmet_ports "${subsysnqn}" ports
+	read -ra ports < <(_get_nvmet_ports "${subsysnqn}")
 
 	for port in "${ports[@]}"; do
 		_remove_nvmet_subsystem_from_port "${port}" "${subsysnqn}"
diff --git a/tests/nvme/rc b/tests/nvme/rc
index 64a31e0..167e085 100644
--- a/tests/nvme/rc
+++ b/tests/nvme/rc
@@ -452,7 +452,7 @@ _nvmet_passthru_target_cleanup() {
 		esac
 	done
 
-	_get_nvmet_ports "${subsysnqn}" ports
+	read -ra ports < <(_get_nvmet_ports "${subsysnqn}")
 
 	for port in "${ports[@]}"; do
 		_remove_nvmet_subsystem_from_port "${port}" "${subsysnqn}"
-- 
2.45.2




More information about the Linux-nvme mailing list