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