1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2019 Intel Corporation 4# All rights reserved. 5# 6testdir=$(readlink -f $(dirname $0)) 7rootdir=$(readlink -f $testdir/../../..) 8source $rootdir/test/common/autotest_common.sh 9source $rootdir/test/nvmf/common.sh 10 11PLUGIN_DIR=$rootdir/app/fio/nvme 12 13MALLOC_BDEV_SIZE=64 14MALLOC_BLOCK_SIZE=512 15 16function disconnect_init() { 17 nvmfappstart -m 0xF0 18 19 $rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0 20 21 $rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS 22 $rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 23 24 $rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0 25 $rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $1 -s $NVMF_PORT 26 $rpc_py nvmf_subsystem_add_listener discovery -t $TEST_TRANSPORT -a $1 -s $NVMF_PORT 27} 28 29# Test to make sure we don't segfault or access null pointers when we try to connect to 30# a discovery controller that doesn't exist yet. 31function nvmf_target_disconnect_tc1() { 32 NOT "$SPDK_EXAMPLE_DIR/reconnect" -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 33 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" 34} 35 36function nvmf_target_disconnect_tc2() { 37 disconnect_init $NVMF_FIRST_TARGET_IP 38 39 # If perf doesn't shut down, this test will time out. 40 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 41 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" & 42 reconnectpid=$! 43 44 sleep 2 45 kill -9 $nvmfpid 46 47 sleep 2 48 disconnect_init $NVMF_FIRST_TARGET_IP 49 50 wait $reconnectpid 51 sync 52} 53 54function nvmf_target_disconnect_tc3() { 55 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 56 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT alt_traddr:$NVMF_SECOND_TARGET_IP" & 57 reconnectpid=$! 58 59 sleep 2 60 kill -9 $nvmfpid 61 62 sleep 2 63 disconnect_init $NVMF_SECOND_TARGET_IP 64 65 wait $reconnectpid 66 sync 67} 68 69nvmftestinit 70run_test "nvmf_target_disconnect_tc1" nvmf_target_disconnect_tc1 71run_test "nvmf_target_disconnect_tc2" nvmf_target_disconnect_tc2 72if [ -n "$NVMF_SECOND_TARGET_IP" ]; then 73 run_test "nvmf_target_disconnect_tc3" nvmf_target_disconnect_tc3 74fi 75 76trap - SIGINT SIGTERM EXIT 77nvmftestfini 78