[PATCH blktests v2 08/13] nvme: simplify _get_nvmet_ports()

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


From: Hannes Reinecke <hare at suse.de>

Rework the loop to iterate over ports, and check for the correct
subsysnqn afterwards. With that we can drop 'sed' calls and simplify
the loop.

Signed-off-by: Hannes Reinecke <hare at suse.de.>
Reviewed-by: Daniel Wagner <dwagner at suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
 common/nvme | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/common/nvme b/common/nvme
index 5d2e38e..758df33 100644
--- a/common/nvme
+++ b/common/nvme
@@ -672,15 +672,14 @@ _remove_nvmet_subsystem_from_port() {
 }
 
 _get_nvmet_ports() {
-	local nvmet_subsystem="$1"
+	local nvmet_subsysnqn="${1:-$def_subsysnqn}"
 	local -n nvmet_ports="$2"
 	local cfs_path="${NVMET_CFS}/ports"
-	local sarg
 
-	sarg="s;^${cfs_path}/\([0-9]\+\)/subsystems/${nvmet_subsystem}$;\1;p"
-
-	for path in "${cfs_path}/"*"/subsystems/${nvmet_subsystem}"; do
-		nvmet_ports+=("$(echo "${path}" | sed -n -s "${sarg}")")
+	for port in "${cfs_path}/"*; do
+		if [[ -e "${port}/subsystems/${nvmet_subsysnqn}" ]]; then
+			nvmet_ports+=("${port##*/}")
+		fi
 	done
 }
 
-- 
2.45.2




More information about the Linux-nvme mailing list