xref: /spdk/test/nvmf/host/multipath_status.sh (revision c6c1234de9e0015e670dd0b51bf6ce39ee0e07bd)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2020 Intel Corporation
4#  Copyright (C) 2024 Samsung Electronics Co., Ltd.
5#  All rights reserved.
6#
7testdir=$(readlink -f "$(dirname $0)")
8rootdir=$(readlink -f "$testdir/../../..")
9source "$rootdir/test/common/autotest_common.sh"
10source "$rootdir/test/nvmf/common.sh"
11
12MALLOC_BDEV_SIZE=64
13MALLOC_BLOCK_SIZE=512
14
15rpc_py="$rootdir/scripts/rpc.py"
16bpf_sh="$rootdir/scripts/bpftrace.sh"
17
18bdevperf_rpc_sock=/var/tmp/bdevperf.sock
19
20# NQN prefix to use for subsystem NQNs
21NQN=nqn.2016-06.io.spdk:cnode1
22
23cleanup() {
24	process_shm --id $NVMF_APP_SHM_ID || true
25	cat "$testdir/try.txt"
26	rm -f "$testdir/try.txt"
27	killprocess $bdevperf_pid
28	nvmftestfini
29}
30
31nvmftestinit
32
33nvmfappstart -m 0x3
34nvmfapp_pid=$!
35
36$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS -u 8192
37$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0
38# Set -r to enable ANA reporting feature
39$rpc_py nvmf_create_subsystem $NQN -a -s SPDK00000000000001 -r -m 2
40$rpc_py nvmf_subsystem_add_ns $NQN Malloc0
41$rpc_py nvmf_subsystem_add_listener $NQN -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
42$rpc_py nvmf_subsystem_add_listener $NQN -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT
43
44"$rootdir/build/examples/bdevperf" -m 0x4 -z -r $bdevperf_rpc_sock -q 128 -o 4096 -w verify -t 90 &> "$testdir/try.txt" &
45bdevperf_pid=$!
46
47trap 'cleanup; exit 1' SIGINT SIGTERM EXIT
48waitforlisten $bdevperf_pid $bdevperf_rpc_sock
49
50# Create a controller and set multipath behavior
51# bdev_retry_count is set to -1 means infinite reconnects
52$rpc_py -s $bdevperf_rpc_sock bdev_nvme_set_options -r -1
53# -l -1 ctrlr_loss_timeout_sec -1 means infinite reconnects
54# -o 10 reconnect_delay_sec time to delay a reconnect retry is limited to 10 sec
55$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b Nvme0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n $NQN -l -1 -o 10
56$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b Nvme0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT -f ipv4 -n $NQN -x multipath -l -1 -o 10
57
58function set_ANA_state() {
59	$rpc_py nvmf_subsystem_listener_set_ana_state $NQN -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -n $1
60	$rpc_py nvmf_subsystem_listener_set_ana_state $NQN -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT -n $2
61}
62
63function port_status() {
64	[[ $($rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_io_paths | jq -r ".poll_groups[].io_paths[] | select (.transport.trsvcid==\"$1\").$2") == "$3" ]]
65}
66
67function check_status() {
68	port_status $NVMF_PORT current $1
69	port_status $NVMF_SECOND_PORT current $2
70	port_status $NVMF_PORT connected $3
71	port_status $NVMF_SECOND_PORT connected $4
72	port_status $NVMF_PORT accessible $5
73	port_status $NVMF_SECOND_PORT accessible $6
74}
75
76"$rootdir/examples/bdev/bdevperf/bdevperf.py" -t 120 -s $bdevperf_rpc_sock perform_tests &
77
78sleep 2
79
80# check_status takes 6 parameters for expected values:
81# 1: "current" for port 1
82# 2: "current" for port 2
83# 3: "connected" for port 1
84# 4: "connected" for port 2
85# 5: "accessible" for port 1
86# 6: "accessible" for port 2
87
88# Set ANA state to each listener
89# For active/passive, only the first available path should be current
90set_ANA_state optimized optimized
91sleep 1
92check_status true false true true true true
93
94set_ANA_state non_optimized optimized
95sleep 1
96check_status false true true true true true
97
98# For active/passive, if all paths are non_optimized the first available
99# path should be current
100set_ANA_state non_optimized non_optimized
101sleep 1
102check_status true false true true true true
103
104set_ANA_state non_optimized inaccessible
105sleep 1
106check_status true false true true true false
107
108set_ANA_state inaccessible inaccessible
109sleep 1
110check_status false false true true false false
111
112set_ANA_state inaccessible optimized
113sleep 1
114check_status false true true true false true
115
116$rpc_py -s $bdevperf_rpc_sock bdev_nvme_set_multipath_policy -b Nvme0n1 -p active_active
117
118# For active/active, all optimized paths should be current
119set_ANA_state optimized optimized
120sleep 1
121check_status true true true true true true
122
123set_ANA_state non_optimized optimized
124sleep 1
125check_status false true true true true true
126
127# For active/active, all non-optimized paths should be current if there are
128# no optimized paths
129set_ANA_state non_optimized non_optimized
130sleep 1
131check_status true true true true true true
132
133set_ANA_state non_optimized inaccessible
134sleep 1
135check_status true false true true true false
136
137killprocess $bdevperf_pid
138# Make sure we catch bdevperf's exit status
139wait $bdevperf_pid
140
141cat "$testdir/try.txt"
142
143$rpc_py nvmf_delete_subsystem $NQN
144
145trap - SIGINT SIGTERM EXIT
146
147rm -f "$testdir/try.txt"
148nvmftestfini
149