14a15c5fdSShuhei Matsumoto#!/usr/bin/env bash 2eb53c232Spaul luse# SPDX-License-Identifier: BSD-3-Clause 3eb53c232Spaul luse# Copyright (C) 2020 Intel Corporation 4eb53c232Spaul luse# All rights reserved. 5eb53c232Spaul luse# 64a15c5fdSShuhei Matsumototestdir=$(readlink -f $(dirname $0)) 74a15c5fdSShuhei Matsumotorootdir=$(readlink -f $testdir/../../..) 84a15c5fdSShuhei Matsumotosource $rootdir/test/common/autotest_common.sh 94a15c5fdSShuhei Matsumotosource $rootdir/test/nvmf/common.sh 104a15c5fdSShuhei Matsumoto 114a15c5fdSShuhei MatsumotoMALLOC_BDEV_SIZE=64 124a15c5fdSShuhei MatsumotoMALLOC_BLOCK_SIZE=512 134a15c5fdSShuhei Matsumoto 144a15c5fdSShuhei Matsumotorpc_py="$rootdir/scripts/rpc.py" 154a15c5fdSShuhei Matsumoto 164a15c5fdSShuhei Matsumotobdevperf_rpc_sock=/var/tmp/bdevperf.sock 174a15c5fdSShuhei Matsumoto 184a15c5fdSShuhei Matsumotonvmftestinit 194a15c5fdSShuhei Matsumoto 200af934b3SKrzysztof Karasnvmfappstart -m 0xE 214a15c5fdSShuhei Matsumoto 224a15c5fdSShuhei Matsumoto$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS -u 8192 234a15c5fdSShuhei Matsumoto$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0 244a15c5fdSShuhei Matsumoto$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 254a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0 264a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT 274a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT 284a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_THIRD_PORT 294a15c5fdSShuhei Matsumoto 3036bf59bcSKonrad Sztyber$rootdir/build/examples/bdevperf -z -r $bdevperf_rpc_sock -q 128 -o 4096 -w verify -t 15 -f &> $testdir/try.txt & 314a15c5fdSShuhei Matsumotobdevperf_pid=$! 324a15c5fdSShuhei Matsumoto 33ded1ba14SShuhei Matsumototrap 'process_shm --id $NVMF_APP_SHM_ID; cat $testdir/try.txt; rm -f $testdir/try.txt; killprocess $bdevperf_pid; nvmftestfini; exit 1' SIGINT SIGTERM EXIT 344a15c5fdSShuhei Matsumotowaitforlisten $bdevperf_pid $bdevperf_rpc_sock 35*a5cbb2b1SMarcin Spiewak$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -x failover 36*a5cbb2b1SMarcin Spiewak$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -x failover 374a15c5fdSShuhei Matsumoto 3829784f35SKrzysztof Karas$rootdir/examples/bdev/bdevperf/bdevperf.py -s $bdevperf_rpc_sock perform_tests & 39ded1ba14SShuhei Matsumotorun_test_pid=$! 404a15c5fdSShuhei Matsumoto 414a15c5fdSShuhei Matsumotosleep 1 424a15c5fdSShuhei Matsumoto 434a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_remove_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT 444a15c5fdSShuhei Matsumoto 454a15c5fdSShuhei Matsumotosleep 3 464a15c5fdSShuhei Matsumoto 47*a5cbb2b1SMarcin Spiewak$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_THIRD_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -x failover 484a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_remove_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT 494a15c5fdSShuhei Matsumoto 504a15c5fdSShuhei Matsumotosleep 3 514a15c5fdSShuhei Matsumoto 524a15c5fdSShuhei Matsumoto# Give the admin qpair time to fail before we add the new listener in. This prevents us from trying to connect to the wrong trid. 534a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT 544a15c5fdSShuhei Matsumoto 554a15c5fdSShuhei Matsumotosleep 1 564a15c5fdSShuhei Matsumoto 574a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_remove_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_THIRD_PORT 584a15c5fdSShuhei Matsumoto 59ded1ba14SShuhei Matsumotowait $run_test_pid 604a15c5fdSShuhei Matsumoto 614a15c5fdSShuhei Matsumotokillprocess $bdevperf_pid 624a15c5fdSShuhei Matsumoto 634a15c5fdSShuhei Matsumotocat $testdir/try.txt 644a15c5fdSShuhei Matsumoto# if this test fails it means we didn't fail over to the second 654a15c5fdSShuhei Matsumotocount="$(grep -c "Resetting controller successful" < $testdir/try.txt)" 664a15c5fdSShuhei Matsumoto 674a15c5fdSShuhei Matsumotoif ((count != 3)); then 684a15c5fdSShuhei Matsumoto false 694a15c5fdSShuhei Matsumotofi 704a15c5fdSShuhei Matsumoto 714a15c5fdSShuhei Matsumoto# Part 2 of the test. Start removing ports, starting with the one we are connected to, confirm that the ctrlr remains active until the final trid is removed. 7229784f35SKrzysztof Karas$rootdir/build/examples/bdevperf -z -r $bdevperf_rpc_sock -q 128 -o 4096 -w verify -t 1 -f &> $testdir/try.txt & 734a15c5fdSShuhei Matsumotobdevperf_pid=$! 744a15c5fdSShuhei Matsumoto 754a15c5fdSShuhei Matsumotowaitforlisten $bdevperf_pid $bdevperf_rpc_sock 764a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT 774a15c5fdSShuhei Matsumoto$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_THIRD_PORT 78*a5cbb2b1SMarcin Spiewak$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -x failover 79*a5cbb2b1SMarcin Spiewak$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -x failover 80*a5cbb2b1SMarcin Spiewak$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_THIRD_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -x failover 814a15c5fdSShuhei Matsumoto 824a15c5fdSShuhei Matsumoto$rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_controllers | grep -q NVMe0 834a15c5fdSShuhei Matsumoto 844a15c5fdSShuhei Matsumoto$rpc_py -s $bdevperf_rpc_sock bdev_nvme_detach_controller NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 854a15c5fdSShuhei Matsumoto 864a15c5fdSShuhei Matsumoto# Async operation since we need to reconnect with new TRID. 874a15c5fdSShuhei Matsumotosleep 3 884a15c5fdSShuhei Matsumoto$rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_controllers | grep -q NVMe0 8929784f35SKrzysztof Karas$rootdir/examples/bdev/bdevperf/bdevperf.py -s $bdevperf_rpc_sock perform_tests & 90ded1ba14SShuhei Matsumotorun_test_pid=$! 914a15c5fdSShuhei Matsumoto 92ded1ba14SShuhei Matsumotowait $run_test_pid 934a15c5fdSShuhei Matsumoto 944a15c5fdSShuhei Matsumotocat $testdir/try.txt 954a15c5fdSShuhei Matsumoto$rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_controllers | grep -q NVMe0 964a15c5fdSShuhei Matsumoto 974a15c5fdSShuhei Matsumoto# No need to wait here since we are deleting a TRID we aren't connected to. 984a15c5fdSShuhei Matsumoto$rpc_py -s $bdevperf_rpc_sock bdev_nvme_detach_controller NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_THIRD_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 994a15c5fdSShuhei Matsumoto$rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_controllers | grep -q NVMe0 1004a15c5fdSShuhei Matsumoto$rpc_py -s $bdevperf_rpc_sock bdev_nvme_detach_controller NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 1014a15c5fdSShuhei Matsumotosleep 3 1024a15c5fdSShuhei Matsumoto 1034a15c5fdSShuhei Matsumotoif $rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_controllers | grep -q NVMe0; then 1044a15c5fdSShuhei Matsumoto echo "Controller was not properly removed." 1054a15c5fdSShuhei Matsumoto false 1064a15c5fdSShuhei Matsumotofi 1074a15c5fdSShuhei Matsumoto 1084a15c5fdSShuhei Matsumotokillprocess $bdevperf_pid 1094a15c5fdSShuhei Matsumoto 1104a15c5fdSShuhei Matsumotosync 1114a15c5fdSShuhei Matsumoto$rpc_py nvmf_delete_subsystem nqn.2016-06.io.spdk:cnode1 1124a15c5fdSShuhei Matsumoto 1134a15c5fdSShuhei Matsumototrap - SIGINT SIGTERM EXIT 1144a15c5fdSShuhei Matsumoto 1154a15c5fdSShuhei Matsumotorm -f $testdir/try.txt 1164a15c5fdSShuhei Matsumotonvmftestfini 117