xref: /spdk/test/nvmf/host/discovery_remove_ifc.sh (revision 6932167e6f2f138e1e7c9634e194e94a7d22fb75)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2021 Intel Corporation
4#  All rights reserved.
5#
6
7# This test is a regression test for issue #2901
8
9testdir=$(readlink -f $(dirname $0))
10rootdir=$(readlink -f $testdir/../../..)
11source $rootdir/test/common/autotest_common.sh
12source $rootdir/test/nvmf/common.sh
13
14if [ "$TEST_TRANSPORT" == "rdma" ]; then
15	echo "Skipping tests on RDMA because the rdma stack fails to configure the same IP for host and target."
16	exit 0
17fi
18
19discovery_port=8009
20discovery_nqn=nqn.2014-08.org.nvmexpress.discovery
21
22# nqn prefix to use for subsystem nqns
23nqn=nqn.2016-06.io.spdk:cnode
24
25host_nqn=nqn.2021-12.io.spdk:test
26host_sock=/tmp/host.sock
27
28function get_bdev_list() {
29	$rpc_py -s $host_sock bdev_get_bdevs | jq -r '.[].name' | sort | xargs
30}
31
32function wait_for_bdev() {
33	while [[ $(get_bdev_list) != "$1" ]]; do
34		sleep 1
35	done
36}
37
38# Start test that check discovery service reconnect ability
39nvmftestinit
40nvmfappstart -m 0x2
41
42# Start target with single null bdev
43$rpc_py << CFG
44	log_set_flag bdev_null
45	nvmf_create_transport $NVMF_TRANSPORT_OPTS -u 8192
46	nvmf_subsystem_add_listener $discovery_nqn -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \
47		-s $discovery_port
48	bdev_null_create null0 1000 512
49	nvmf_create_subsystem ${nqn}0 -i 1 -I 100
50	nvmf_subsystem_add_ns ${nqn}0 null0 -n 1
51	nvmf_subsystem_add_listener ${nqn}0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \
52		-s $NVMF_PORT
53	nvmf_subsystem_add_listener discovery -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \
54		-s $NVMF_PORT
55	nvmf_subsystem_add_host ${nqn}0 $host_nqn
56CFG
57
58$SPDK_BIN_DIR/nvmf_tgt -m 0x1 -r $host_sock --wait-for-rpc -L bdev_nvme &
59hostpid=$!
60waitforlisten $hostpid $host_sock
61
62trap 'process_shm --id $NVMF_APP_SHM_ID; killprocess $hostpid; nvmftestfini; exit 1' SIGINT SIGTERM EXIT
63
64# set TRANSPORT_ACK_TIMEOUT for spdk to recognize disconnections
65$rpc_py -s $host_sock bdev_nvme_set_options -e 1
66$rpc_py -s $host_sock framework_start_init
67
68# start discovery controller with CTRLR_LOSS_TIMEOUT_SEC
69$rpc_py -s $host_sock bdev_nvme_start_discovery -b nvme -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \
70	-s $discovery_port -f ipv4 -q $host_nqn --ctrlr-loss-timeout-sec 2 \
71	--reconnect-delay-sec 1 --fast-io-fail-timeout-sec 1 --wait-for-attach
72wait_for_bdev "nvme0n1"
73
74# Delete network interface to trigger reconnection attempts
75"${NVMF_TARGET_NS_CMD[@]}" ip addr del $NVMF_FIRST_TARGET_IP/24 dev $NVMF_TARGET_INTERFACE
76"${NVMF_TARGET_NS_CMD[@]}" ip link set $NVMF_TARGET_INTERFACE down
77
78# Wait a few sec to ensure that ctrlr is removed and ctrlr_loss_timeout_sec exceeded
79wait_for_bdev ""
80
81# Resume network connection
82"${NVMF_TARGET_NS_CMD[@]}" ip addr add $NVMF_FIRST_TARGET_IP/24 dev $NVMF_TARGET_INTERFACE
83"${NVMF_TARGET_NS_CMD[@]}" ip link set $NVMF_TARGET_INTERFACE up
84
85# Wait some more for discovery controller to reattached bdev
86wait_for_bdev "nvme1n1"
87
88trap - SIGINT SIGTERM EXIT
89
90killprocess $hostpid
91nvmftestfini
92