diff mbox series

[blktests,v5,3/4] nvme/rc: Add helper to wait for nvme ctrl state

Message ID 20230405154630.16298-4-dwagner@suse.de (mailing list archive)
State New, archived
Headers show
Series test queue count changes on reconnect | expand

Commit Message

Daniel Wagner April 5, 2023, 3:46 p.m. UTC
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@suse.de>
---
 tests/nvme/rc | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Chaitanya Kulkarni April 5, 2023, 6:43 p.m. UTC | #1
On 4/5/23 08:46, Daniel Wagner wrote:
> 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@suse.de>
> ---
>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
diff mbox series

Patch

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}"