Skip to content

Commit 4dcef69

Browse files
igawkawasaki
authored andcommitted
common/nvme: move nvmf_wait_for_state to common code
In preperation to add another tests which needs the nvmf_wait_for_state function, move it to the common code base. Signed-off-by: Daniel Wagner <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 2328940 commit 4dcef69

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

common/nvme

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,33 @@ _nvmf_wait_for_ns() {
573573
return 0
574574
}
575575

576+
_nvmf_wait_for_state() {
577+
local def_state_timeout=5
578+
local subsys_name="$1"
579+
local state="$2"
580+
local timeout="${3:-$def_state_timeout}"
581+
local nvmedev
582+
local state_file
583+
local start_time
584+
local end_time
585+
586+
nvmedev=$(_find_nvme_dev "${subsys_name}")
587+
state_file="/sys/class/nvme-fabrics/ctl/${nvmedev}/state"
588+
589+
start_time=$(date +%s)
590+
while ! grep -q "${state}" "${state_file}"; do
591+
sleep 1
592+
end_time=$(date +%s)
593+
if (( end_time - start_time > timeout )); then
594+
echo "expected state \"${state}\" not " \
595+
"reached within ${timeout} seconds"
596+
return 1
597+
fi
598+
done
599+
600+
return 0
601+
}
602+
576603
_create_nvmet_ns() {
577604
local subsysnqn="${def_subsysnqn}"
578605
local nsid="${def_nsid}"

tests/nvme/048

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,6 @@ set_conditions() {
1919
_set_nvme_trtype "$@"
2020
}
2121

22-
nvmf_wait_for_state() {
23-
local def_state_timeout=5
24-
local subsys_name="$1"
25-
local state="$2"
26-
local timeout="${3:-$def_state_timeout}"
27-
local nvmedev
28-
local state_file
29-
local start_time
30-
local end_time
31-
32-
nvmedev=$(_find_nvme_dev "${subsys_name}")
33-
state_file="/sys/class/nvme-fabrics/ctl/${nvmedev}/state"
34-
35-
start_time=$(date +%s)
36-
while ! grep -q "${state}" "${state_file}"; do
37-
sleep 1
38-
end_time=$(date +%s)
39-
if (( end_time - start_time > timeout )); then
40-
echo "expected state \"${state}\" not " \
41-
"reached within ${timeout} seconds"
42-
return 1
43-
fi
44-
done
45-
46-
return 0
47-
}
48-
4922
nvmf_check_queue_count() {
5023
local subsys_name="$1"
5124
local queue_count="$2"
@@ -87,7 +60,7 @@ set_qid_max() {
8760

8861
set_nvmet_attr_qid_max "${subsys_name}" "${qid_max}"
8962
nvmf_check_queue_count "${subsys_name}" "${qid_max}" || return 1
90-
nvmf_wait_for_state "${subsys_name}" "live" || return 1
63+
_nvmf_wait_for_state "${subsys_name}" "live" || return 1
9164

9265
return 0
9366
}
@@ -106,7 +79,7 @@ test() {
10679
_nvme_connect_subsys --keep-alive-tmo 1 \
10780
--reconnect-delay 2
10881

109-
if ! nvmf_wait_for_state "${def_subsysnqn}" "live" ; then
82+
if ! _nvmf_wait_for_state "${def_subsysnqn}" "live" ; then
11083
echo FAIL
11184
else
11285
set_qid_max "${def_subsysnqn}" 1 || echo FAIL

0 commit comments

Comments
 (0)