Skip to content

Commit

Permalink
nvme/052: move nvmf_wait_for_ns() to common/nvme
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Chaitanya Kulkarni <[email protected]>
Signed-off-by: Nilay Shroff <[email protected]>
Reviewed-by: Daniel Wagner <[email protected]>
[Shin'ichiro: fixed indent]
Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
shroffni authored and kawasaki committed Dec 9, 2024
1 parent dadbcb0 commit 19f74d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
26 changes: 26 additions & 0 deletions common/nvme
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
30 changes: 2 additions & 28 deletions tests/nvme/052
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 19f74d3

Please sign in to comment.