]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
nvme/{033,034,035,036,37}: drop port handle between passthru target setup and cleanup
authorDaniel Wagner <dwagner@suse.de>
Wed, 30 Aug 2023 09:20:18 +0000 (11:20 +0200)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Thu, 31 Aug 2023 02:03:59 +0000 (11:03 +0900)
The passthru nvmet setup and cleanup helpers are using the port as
handle to track resources.

Instead returning the port from the setup call, we figure out in the
cleanup code which resources have been allocated. This avoids passing
around awkward handles.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
tests/nvme/033
tests/nvme/034
tests/nvme/035
tests/nvme/036
tests/nvme/037
tests/nvme/rc

index d924883460c26157074d8900e50a3fbe76a51541..6cc4f57e6d601f816f8009e9ac07012086001714 100755 (executable)
@@ -50,16 +50,15 @@ test_device() {
        _setup_nvmet
 
        local nsdev
-       local port
 
-       port=$(_nvmet_passthru_target_setup "${def_subsysnqn}")
+       _nvmet_passthru_target_setup "${def_subsysnqn}"
 
        nsdev=$(_nvmet_passthru_target_connect "${nvme_trtype}" "${def_subsysnqn}")
 
        compare_dev_info "${nsdev}"
 
        _nvme_disconnect_subsys "${def_subsysnqn}"
-       _nvmet_passthru_target_cleanup "${port}" "${def_subsysnqn}"
+       _nvmet_passthru_target_cleanup "${def_subsysnqn}"
 
        echo "Test complete"
 }
index e79eef5e756dad9221e5d35caec40f598e6f1daf..3bd1c3ad2f6144286a89125700cc20385e1895c0 100755 (executable)
@@ -21,15 +21,14 @@ test_device() {
 
        local ctrldev
        local nsdev
-       local port
 
-       port=$(_nvmet_passthru_target_setup "${def_subsysnqn}")
+       _nvmet_passthru_target_setup "${def_subsysnqn}"
        nsdev=$(_nvmet_passthru_target_connect "${nvme_trtype}" "${def_subsysnqn}")
 
        _run_fio_verify_io --size="${nvme_img_size}" --filename="${nsdev}"
 
        _nvme_disconnect_subsys "${def_subsysnqn}"
-       _nvmet_passthru_target_cleanup "${port}" "${def_subsysnqn}"
+       _nvmet_passthru_target_cleanup "${def_subsysnqn}"
 
        echo "Test complete"
 }
index f0dfc92ceeea0910227989455b42d9767427e2d1..712fe1dbcfb83c22373a81708d977c669a394f9a 100755 (executable)
@@ -27,15 +27,14 @@ test_device() {
 
        local ctrldev
        local nsdev
-       local port
 
-       port=$(_nvmet_passthru_target_setup "${def_subsysnqn}")
+       _nvmet_passthru_target_setup "${def_subsysnqn}"
        nsdev=$(_nvmet_passthru_target_connect "${nvme_trtype}" "${def_subsysnqn}")
 
        _xfs_run_fio_verify_io "${nsdev}" "${nvme_img_size}"
 
        _nvme_disconnect_subsys "${def_subsysnqn}"
-       _nvmet_passthru_target_cleanup "${port}" "${def_subsysnqn}"
+       _nvmet_passthru_target_cleanup "${def_subsysnqn}"
 
        echo "Test complete"
 }
index 61b9e2309da73258e2bb2c5aeb3f5cc50d7b5b05..89ccd256a67cb5b4ea1cfb159376154c80f3963c 100755 (executable)
@@ -19,9 +19,8 @@ test_device() {
        _setup_nvmet
 
        local ctrldev
-       local port
 
-       port=$(_nvmet_passthru_target_setup "${def_subsysnqn}")
+       _nvmet_passthru_target_setup "${def_subsysnqn}"
        nsdev=$(_nvmet_passthru_target_connect "${nvme_trtype}" "${def_subsysnqn}")
 
        ctrldev=$(_find_nvme_dev "${def_subsysnqn}")
@@ -31,7 +30,7 @@ test_device() {
        fi
 
        _nvme_disconnect_subsys "${def_subsysnqn}"
-       _nvmet_passthru_target_cleanup "${port}" "${def_subsysnqn}"
+       _nvmet_passthru_target_cleanup "${def_subsysnqn}"
 
        echo "Test complete"
 }
index 5a78444b7e78f8c796995cb2ec48d75bf3a9f6cc..a2815b3ff2d7273dfd89383445c8c249e2fa56a0 100755 (executable)
@@ -20,15 +20,14 @@ test_device() {
        local subsys="blktests-subsystem-"
        local iterations=10
        local ctrldev
-       local port
 
        for ((i = 0; i < iterations; i++)); do
-               port=$(_nvmet_passthru_target_setup "${subsys}${i}")
+               _nvmet_passthru_target_setup "${subsys}${i}"
                nsdev=$(_nvmet_passthru_target_connect "${nvme_trtype}" \
                                "${subsys}${i}")
 
                _nvme_disconnect_subsys "${subsys}${i}" >>"${FULL}" 2>&1
-               _nvmet_passthru_target_cleanup "${port}" "${subsys}${i}"
+               _nvmet_passthru_target_cleanup "${subsys}${i}"
        done
 
        echo "Test complete"
index 10a0d6d27f026e44dad73f7dd5e61e6b4f386b6f..fdffc07da34ad3db8a4f6b33c417f8c75a953be2 100644 (file)
@@ -745,6 +745,19 @@ _remove_nvmet_subsystem_from_port() {
        rm "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
 }
 
+_get_nvmet_ports() {
+       local nvmet_subsystem="$1"
+       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}")")
+       done
+}
+
 _set_nvmet_hostkey() {
        local nvmet_hostnqn="$1"
        local nvmet_hostkey="$2"
@@ -807,13 +820,12 @@ _find_nvme_passthru_loop_dev() {
 
 _nvmet_passthru_target_setup() {
        local subsys_name=$1
+       local port
 
        _create_nvmet_passthru "${subsys_name}"
        port="$(_create_nvmet_port "${nvme_trtype}")"
        _add_nvmet_subsys_to_port "${port}" "${subsys_name}"
        _create_nvmet_host "${subsys_name}" "${def_hostnqn}"
-
-       echo "$port"
 }
 
 _nvmet_passthru_target_connect() {
@@ -832,11 +844,17 @@ _nvmet_passthru_target_connect() {
 }
 
 _nvmet_passthru_target_cleanup() {
-       local port=$1
-       local subsys_name=$2
+       local subsys_name=$1
+       local ports
+       local port
+
+       _get_nvmet_ports "${subsys_name}" ports
+
+       for port in "${ports[@]}"; do
+               _remove_nvmet_subsystem_from_port "${port}" "${subsys_name}"
+               _remove_nvmet_port "${port}"
+       done
 
-       _remove_nvmet_subsystem_from_port "${port}" "${subsys_name}"
-       _remove_nvmet_port "${port}"
        _remove_nvmet_passhtru "${subsys_name}"
        _remove_nvmet_host "${def_hostnqn}"
 }