The function waits until it sees a given state (or timeouts). Unfortunately, we can't use /sys/class/nvme/nvme%d because this symlink will be removed if the controller is going through resetting state. Thus use the real nvme%d directly. Signed-off-by: Daniel Wagner <dwagner@xxxxxxx> --- tests/nvme/rc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/nvme/rc b/tests/nvme/rc index e720a35113aa..ae4a69fe8438 100644 --- a/tests/nvme/rc +++ b/tests/nvme/rc @@ -16,6 +16,7 @@ def_local_wwnn="0x10001100aa000002" def_local_wwpn="0x20001100aa000002" def_hostnqn="$(cat /etc/nvme/hostnqn 2> /dev/null)" def_hostid="$(cat /etc/nvme/hostid 2> /dev/null)" +def_state_timeout=20 nvme_trtype=${nvme_trtype:-"loop"} _nvme_requires() { @@ -198,6 +199,28 @@ _nvme_fcloop_del_tport() { echo "wwnn=${wwnn},wwpn=${wwpn}" > ${loopctl}/del_target_port 2> /dev/null } +_nvmf_wait_for_state() { + local subsys_name="$1" + local state="$2" + local timeout="${3:-$def_state_timeout}" + + local nvmedev=$(_find_nvme_dev "${subsys_name}") + local state_file="/sys/class/nvme-fabrics/ctl/${nvmedev}/state" + + local start_time=$(date +%s) + local end_time + + while ! grep -q "${state}" "${state_file}"; do + sleep 1 + end_time=$(date +%s) + if (( end_time - start_time > timeout )); then + echo "expected state \"${state}\" not " \ + "reached within ${timeout} seconds" + break + fi + done +} + _cleanup_fcloop() { local local_wwnn="${1:-$def_local_wwnn}" local local_wwpn="${2:-$def_local_wwpn}" -- 2.40.0