1#!/usr/bin/env bash 2 3testdir=$(readlink -f $(dirname $0)) 4rootdir=$(readlink -f $testdir/../../..) 5source $rootdir/test/common/autotest_common.sh 6source $rootdir/test/nvmf/common.sh 7 8PLUGIN_DIR=$rootdir/examples/nvme/fio_plugin 9 10MALLOC_BDEV_SIZE=64 11MALLOC_BLOCK_SIZE=512 12 13rpc_py="$rootdir/scripts/rpc.py" 14 15function disconnect_init() { 16 nvmfappstart -m 0xF0 17 18 $rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0 19 20 $rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS 21 $rpc_py nvmf_subsystem_create nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 22 23 $rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0 24 $rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $1 -s $NVMF_PORT 25} 26 27# Test to make sure we don't segfault or access null pointers when we try to connect to 28# a discovery controller that doesn't exist yet. 29function nvmf_target_disconnect_tc1() { 30 set +e 31 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 32 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" 33 # If the program crashes, the high bit of $? will be set so we will get a value in the hundreds. 34 # But if the reconnect code detects errors and exits normally it will return 1. 35 if [ $? != 1 ]; then 36 set -e 37 exit 1 38 fi 39 set -e 40} 41 42function nvmf_target_disconnect_tc2() { 43 disconnect_init $NVMF_FIRST_TARGET_IP 44 45 # If perf doesn't shut down, this test will time out. 46 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 47 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" & 48 reconnectpid=$! 49 50 sleep 2 51 kill -9 $nvmfpid 52 53 sleep 2 54 disconnect_init $NVMF_FIRST_TARGET_IP 55 56 wait $reconnectpid 57 sync 58} 59 60function nvmf_target_disconnect_tc3() { 61 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 62 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT alt_traddr:$NVMF_SECOND_TARGET_IP" & 63 reconnectpid=$! 64 65 sleep 2 66 kill -9 $nvmfpid 67 68 sleep 2 69 disconnect_init $NVMF_SECOND_TARGET_IP 70 71 wait $reconnectpid 72 sync 73} 74 75nvmftestinit 76# There is an intermittent error relating to this test and Soft-RoCE. for now, just 77# skip this test if we are using rxe. TODO: get to the bottom of GitHub issue #1043 78if [ $TEST_TRANSPORT == "rdma" ] && check_ip_is_soft_roce $NVMF_FIRST_TARGET_IP; then 79 echo "Using software RDMA, skipping the target disconnect tests." 80else 81 run_test "nvmf_target_disconnect_tc1" nvmf_target_disconnect_tc1 82 run_test "nvmf_target_disconnect_tc2" nvmf_target_disconnect_tc2 83 if [ -n "$NVMF_SECOND_TARGET_IP" ]; then 84 run_test "nvmf_target_disconnect_tc3" nvmf_target_disconnect_tc3 85 fi 86fi 87 88trap - SIGINT SIGTERM EXIT 89nvmftestfini 90