[PATCH blktests 6/7] test/nvme: add test for basic ANA support

Shin'ichiro Kawasaki
2024-11-29T13:26:31Z

From: Hannes Reinecke <hare@suse.de>

Add a test for basic ANA support by creating 4 paths, run a fio
process to generate load, and then switch port states to check
if I/O continues uninterrupted.

Signed-off-by: Hannes Reinecke <hare@suse.de>
[Shin'ichiro: renumbered the test case from 054 to 055]
[Shin'ichiro: fixed a fio option typo]
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
tests/nvme/055 | 97 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/055.out | 5 +++
2 files changed, 102 insertions(+)
create mode 100755 tests/nvme/055
create mode 100644 tests/nvme/055.out

diff --git a/tests/nvme/055 b/tests/nvme/055
new file mode 100755
index 0000000..525193c
--- /dev/null
+++ b/tests/nvme/055
@@ -0,0 +1,97 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Hannes Reinecke (SUSE) <hare@suse.de>
+#
+# Test nvme fabrics controller ANA failover during I/O
+
+. tests/nvme/rc
+
+DESCRIPTION="test nvme fabrics controller ANA failover during I/O"
+
+requires() {
+ _nvme_requires
+ _have_loop
+ _have_fio
+ _require_nvme_trtype_is_fabrics
+}
+
+set_conditions() {
+ _set_nvme_trtype "$@"
+}
+
+failback() {
+ local portno=0
+
+ for port in "$@"; do
+ if (( portno == 0 )); then
+ _setup_nvmet_port_ana "${port}" 1 "optimized"
+ elif (( portno == 1 )); then
+ _setup_nvmet_port_ana "${port}" 1 "non-optimized"
+ else
+ _setup_nvmet_port_ana "${port}" 1 "inaccessible"
+ fi
+ portno=$(( portno + 1 ))
+ done
+}
+
+failover() {
+ local portno=0
+
+ for port in "$@"; do
+ if (( portno == 2 )); then
+ _setup_nvmet_port_ana "${port}" 1 "optimized"
+ elif (( portno == 3 )); then
+ _setup_nvmet_port_ana "${port}" 1 "non-optimized"
+ else
+ _setup_nvmet_port_ana "${port}" 1 "inaccessible"
+ fi
+ portno=$(( portno + 1))
+ done
+}
+
+test() {
+ local fio_pid
+ local -a ports
+ local port
+ local ns
+
+ echo "Running ${TEST_NAME}"
+
+ _setup_nvmet
+
+ _nvmet_target_setup --ports 4
+
+ _get_nvmet_ports "${def_subsysnqn}" ports
+ failback "${ports[@]}"
+
+ for port in "${ports[@]}"; do
+ _nvme_connect_subsys --port "${port}"
+ done
+
+ # start fio job
+ ns=$(_find_nvme_ns "$def_subsys_uuid")
+ _run_fio_verify_io --filename="/dev/${ns}" \
+ --group_reporting --ramp_time=5 \
+ --time_based --runtime=1m &> "$FULL" &
+ fio_pid=$!
+ sleep 5
+
+ # switch port status
+ echo "ANA failover"
+ failover "${ports[@]}"
+
+ sleep 10
+
+ # switch back to original state
+ echo "ANA failback"
+ failback "${ports[@]}"
+
+ sleep 10
+
+ { kill "${fio_pid}"; wait; } &> /dev/null
+
+ _nvme_disconnect_subsys
+ _nvmet_target_cleanup
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/055.out b/tests/nvme/055.out
new file mode 100644
index 0000000..9937d40
--- /dev/null
+++ b/tests/nvme/055.out
@@ -0,0 +1,5 @@
+Running nvme/055
+ANA failover
+ANA failback
+disconnected 4 controller(s)
+Test complete
--
2.47.0