From: Daniel Wagner <dwagner@suse.de>
To: linux-block@vger.kernel.org
Cc: linux-nvme@lists.infradead.org,
Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
Sagi Grimberg <sagi@grimberg.me>, Hannes Reinecke <hare@suse.de>,
James Smart <jsmart2021@gmail.com>,
Daniel Wagner <dwagner@suse.de>
Subject: [PATCH blktests v5 3/4] nvme/rc: Add helper to wait for nvme ctrl state
Date: Wed, 5 Apr 2023 17:46:29 +0200 [thread overview]
Message-ID: <20230405154630.16298-4-dwagner@suse.de> (raw)
In-Reply-To: <20230405154630.16298-1-dwagner@suse.de>
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(+)
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
next prev parent reply other threads:[~2023-04-05 15:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 15:46 [PATCH blktests v5 0/4] test queue count changes on reconnect Daniel Wagner
2023-04-05 15:46 ` [PATCH blktests v5 1/4] nvme/rc: Add setter for attr_qid_max Daniel Wagner
2023-04-05 18:39 ` Chaitanya Kulkarni
2023-04-06 6:12 ` Daniel Wagner
2023-04-06 7:05 ` Chaitanya Kulkarni
2023-04-06 7:32 ` Daniel Wagner
2023-04-05 15:46 ` [PATCH blktests v5 2/4] nvme/rc: Add nvmet attribute feature detection function Daniel Wagner
2023-04-05 15:46 ` Daniel Wagner [this message]
2023-04-05 18:43 ` [PATCH blktests v5 3/4] nvme/rc: Add helper to wait for nvme ctrl state Chaitanya Kulkarni
2023-04-05 15:46 ` [PATCH blktests v5 4/4] nvme/048: test queue count changes on reconnect Daniel Wagner
2023-04-05 18:44 ` Chaitanya Kulkarni
2023-04-05 18:57 ` Chaitanya Kulkarni
2023-04-06 6:17 ` Daniel Wagner
2023-04-06 7:04 ` Chaitanya Kulkarni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230405154630.16298-4-dwagner@suse.de \
--to=dwagner@suse.de \
--cc=hare@suse.de \
--cc=jsmart2021@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox