xref: /spdk/test/nvmf/host/target_disconnect.sh (revision b24df7cfa6a591fc1d7a3c57b67cf80011ff3605)
1ecd108ebSSeth Howell#!/usr/bin/env bash
2eb53c232Spaul luse#  SPDX-License-Identifier: BSD-3-Clause
3eb53c232Spaul luse#  Copyright (C) 2019 Intel Corporation
4eb53c232Spaul luse#  All rights reserved.
5eb53c232Spaul luse#
6ecd108ebSSeth Howelltestdir=$(readlink -f $(dirname $0))
7ecd108ebSSeth Howellrootdir=$(readlink -f $testdir/../../..)
8ecd108ebSSeth Howellsource $rootdir/test/common/autotest_common.sh
9ecd108ebSSeth Howellsource $rootdir/test/nvmf/common.sh
10ecd108ebSSeth Howell
1116841920SBen WalkerPLUGIN_DIR=$rootdir/app/fio/nvme
12ecd108ebSSeth Howell
13ecd108ebSSeth HowellMALLOC_BDEV_SIZE=64
14ecd108ebSSeth HowellMALLOC_BLOCK_SIZE=512
15ecd108ebSSeth Howell
16844c8ec3SMichal Bergerfunction disconnect_init() {
178cc72fe4SMichal Berger	nvmfappstart -m 0xF0
18ecd108ebSSeth Howell
19ecd108ebSSeth Howell	$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0
20ecd108ebSSeth Howell
21ecd108ebSSeth Howell	$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS
22f4d2ba43SChangpeng Liu	$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001
23ecd108ebSSeth Howell
24ecd108ebSSeth Howell	$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0
25eb2dee24SSeth Howell	$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $1 -s $NVMF_PORT
26d98c3749SJim Harris	$rpc_py nvmf_subsystem_add_listener discovery -t $TEST_TRANSPORT -a $1 -s $NVMF_PORT
27ecd108ebSSeth Howell}
28ecd108ebSSeth Howell
29c4d4800aSSeth Howell# Test to make sure we don't segfault or access null pointers when we try to connect to
30c4d4800aSSeth Howell# a discovery controller that doesn't exist yet.
31844c8ec3SMichal Bergerfunction nvmf_target_disconnect_tc1() {
32*b24df7cfSMichal Berger	NOT "$SPDK_EXAMPLE_DIR/reconnect" -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \
33c4d4800aSSeth Howell		-r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT"
34c6767000SSeth Howell}
35c4d4800aSSeth Howell
36844c8ec3SMichal Bergerfunction nvmf_target_disconnect_tc2() {
37eb2dee24SSeth Howell	disconnect_init $NVMF_FIRST_TARGET_IP
38ecd108ebSSeth Howell
39ecd108ebSSeth Howell	# If perf doesn't shut down, this test will time out.
4085bdd43bSBen Walker	$SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \
41eb2dee24SSeth Howell		-r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" &
42eb2dee24SSeth Howell	reconnectpid=$!
43ecd108ebSSeth Howell
44eb2dee24SSeth Howell	sleep 2
45ecd108ebSSeth Howell	kill -9 $nvmfpid
46ecd108ebSSeth Howell
47ecd108ebSSeth Howell	sleep 2
48eb2dee24SSeth Howell	disconnect_init $NVMF_FIRST_TARGET_IP
49ecd108ebSSeth Howell
50eb2dee24SSeth Howell	wait $reconnectpid
51ecd108ebSSeth Howell	sync
52c6767000SSeth Howell}
53ecd108ebSSeth Howell
54844c8ec3SMichal Bergerfunction nvmf_target_disconnect_tc3() {
5585bdd43bSBen Walker	$SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \
56eb2dee24SSeth Howell		-r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT alt_traddr:$NVMF_SECOND_TARGET_IP" &
57eb2dee24SSeth Howell	reconnectpid=$!
58eb2dee24SSeth Howell
59eb2dee24SSeth Howell	sleep 2
60eb2dee24SSeth Howell	kill -9 $nvmfpid
61eb2dee24SSeth Howell
62eb2dee24SSeth Howell	sleep 2
63eb2dee24SSeth Howell	disconnect_init $NVMF_SECOND_TARGET_IP
64eb2dee24SSeth Howell
65eb2dee24SSeth Howell	wait $reconnectpid
66eb2dee24SSeth Howell	sync
67c6767000SSeth Howell}
68eb2dee24SSeth Howell
69c6767000SSeth Howellnvmftestinit
70cb90136cSSeth Howellrun_test "nvmf_target_disconnect_tc1" nvmf_target_disconnect_tc1
71cb90136cSSeth Howellrun_test "nvmf_target_disconnect_tc2" nvmf_target_disconnect_tc2
72c6767000SSeth Howellif [ -n "$NVMF_SECOND_TARGET_IP" ]; then
73cb90136cSSeth Howell	run_test "nvmf_target_disconnect_tc3" nvmf_target_disconnect_tc3
74eb2dee24SSeth Howellfi
75bad25cadSSeth Howell
76ecd108ebSSeth Howelltrap - SIGINT SIGTERM EXIT
77ecd108ebSSeth Howellnvmftestfini
78