[PATCH blktests 1/2] nvme/052: move nvmf_wait_for_ns() to common/nvme

Nilay Shroff
2024-11-29T08:02:58Z

In a preparation for the use of nvmf_wait_for_ns function from
other nvme test script, move nvmf_wait_for_ns from nvme/052 to
common/nvme file so that we can reuse the nvmf_wait_for_ns from
multiple test scripts.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
common/nvme | 26 ++++++++++++++++++++++++++
tests/nvme/052 | 30 ++----------------------------
2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/common/nvme b/common/nvme
index fd472fe..6b8a57a 100644
--- a/common/nvme
+++ b/common/nvme
@@ -483,6 +483,32 @@ _remove_nvmet_port() {
rmdir "${NVMET_CFS}/ports/${port}"
}

+# Wait for the namespace with specified uuid to fulfill the specified condtion,
+# "created" or "removed".
+_nvmf_wait_for_ns() {
+ local ns
+ local timeout="5"
+ local uuid="$1"
+ local condition="$2"
+
+ ns=$(_find_nvme_ns "${uuid}" 2>> "$FULL")
+
+ start_time=$(date +%s)
+ while [[ -z "$ns" && "$condition" == created ]] ||
+ [[ -n "$ns" && "$condition" == removed ]]; do
+ sleep .1
+ end_time=$(date +%s)
+ if (( end_time - start_time > timeout )); then
+ echo "namespace with uuid \"${uuid}\" not " \
+ "${condition} within ${timeout} seconds"
+ return 1
+ fi
+ ns=$(_find_nvme_ns "${uuid}" 2>> "$FULL")
+ done
+
+ return 0
+}
+
_create_nvmet_ns() {
local subsysnqn="${def_subsysnqn}"
local nsid="${def_nsid}"
diff --git a/tests/nvme/052 b/tests/nvme/052
index 8443c90..22d8a9e 100755
--- a/tests/nvme/052
+++ b/tests/nvme/052
@@ -20,32 +20,6 @@ set_conditions() {
_set_nvme_trtype "$@"
}

-# Wait for the namespace with specified uuid to fulfill the specified condtion,
-# "created" or "removed".
-nvmf_wait_for_ns() {
- local ns
- local timeout="5"
- local uuid="$1"
- local condition="$2"
-
- ns=$(_find_nvme_ns "${uuid}" 2>> "$FULL")
-
- start_time=$(date +%s)
- while [[ -z "$ns" && "$condition" == created ]] ||
- [[ -n "$ns" && "$condition" == removed ]]; do
- sleep .1
- end_time=$(date +%s)
- if (( end_time - start_time > timeout )); then
- echo "namespace with uuid \"${uuid}\" not " \
- "${condition} within ${timeout} seconds"
- return 1
- fi
- ns=$(_find_nvme_ns "${uuid}" 2>> "$FULL")
- done
-
- return 0
-}
-
test() {
echo "Running ${TEST_NAME}"

@@ -65,7 +39,7 @@ test() {
uuid=$(_create_nvmet_ns --blkdev "$filepath" --nsid "${nsid}")

# wait until async request is processed and ns is created
- if ! nvmf_wait_for_ns "${uuid}" created; then
+ if ! _nvmf_wait_for_ns "${uuid}" created; then
echo "FAIL"
rm "$filepath"
break
@@ -74,7 +48,7 @@ test() {
_remove_nvmet_ns "${def_subsysnqn}" "${nsid}"

# wait until async request is processed and ns is removed
- if ! nvmf_wait_for_ns "${uuid}" removed; then
+ if ! _nvmf_wait_for_ns "${uuid}" removed; then
echo "FAIL"
rm "$filepath"
break
--
2.45.2