1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2020 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 11MALLOC_BDEV_SIZE=64 12MALLOC_BLOCK_SIZE=512 13NVMF_HOST_FIRST_PORT="60000" 14NVMF_HOST_SECOND_PORT="60001" 15 16bdevperf_rpc_sock=/var/tmp/bdevperf.sock 17 18if [ "$TEST_TRANSPORT" == "rdma" ]; then 19 echo "Skipping tests on RDMA because the rdma stack fails to configure the same IP for host and target." 20 exit 0 21fi 22 23nvmftestinit 24 25nvmfappstart -m 0xE 26 27$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS -u 8192 28 29$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0 30$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 31$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0 32 33$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT 34$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT 35 36$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc1 37$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode2 -a -s SPDK00000000000002 38$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode2 Malloc1 39 40$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode2 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT 41$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode2 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT 42 43$rootdir/build/examples/bdevperf -z -r $bdevperf_rpc_sock -q 128 -o 4096 -w write -t 1 -f &> $testdir/try.txt & 44bdevperf_pid=$! 45 46trap 'process_shm --id $NVMF_APP_SHM_ID; pap "$testdir/try.txt"; killprocess $bdevperf_pid; nvmftestfini; exit 1' SIGINT SIGTERM EXIT 47waitforlisten $bdevperf_pid $bdevperf_rpc_sock 48 49# Create a controller from the first IP/Port combination. 50$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 51 -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -i $NVMF_FIRST_INITIATOR_IP 52 53# wait for the first controller to show up. 54while ! $rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_controllers | grep -c NVMe; do 55 ((++bdev_nvme_get_controllers_timeout <= 10)) 56 sleep 1s 57done 58 59# try to attach with same controller name but different hostnqn. Should fail. 60NOT $rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 61 -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -i $NVMF_FIRST_INITIATOR_IP \ 62 -q nqn.2021-09-7.io.spdk:00001 63 64# try to attach with same controller name but different subnqn. Should fail. 65NOT $rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 66 -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode2 -i $NVMF_FIRST_INITIATOR_IP 67 68# try to attach with the same controller name and multipathing disabled. Should fail 69NOT $rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 70 -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -i $NVMF_FIRST_INITIATOR_IP \ 71 -x disable 72 73# Attempt to add an identical path as a failover path. Should fail. 74NOT $rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 75 -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -i $NVMF_FIRST_INITIATOR_IP \ 76 -x failover 77 78# Add a second path without specifying the host information. Should pass. 79$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 80 -s $NVMF_SECOND_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 81 82# Remove the second path 83$rpc_py -s $bdevperf_rpc_sock bdev_nvme_detach_controller NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 84 -s $NVMF_SECOND_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 85 86# Add a second controller by attaching to the same subsystem with a different controller name 87$rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ 88 -s $NVMF_SECOND_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -i $NVMF_FIRST_INITIATOR_IP 89 90if [ "$($rpc_py -s $bdevperf_rpc_sock bdev_nvme_get_controllers | grep -c NVMe)" != "2" ]; then 91 echo "actual number of controllers is not equal to expected count." 92 exit 1 93fi 94 95$rootdir/examples/bdev/bdevperf/bdevperf.py -s $bdevperf_rpc_sock perform_tests 96 97# Remove the second controller 98$rpc_py -s $bdevperf_rpc_sock bdev_nvme_detach_controller NVMe1 99 100if [[ -n "$NVMF_SECOND_INITIATOR_IP" ]]; then 101 # Verify that host address is respected 102 "$rpc_py" -s "$bdevperf_rpc_sock" bdev_nvme_attach_controller -b nvme1 -t $TEST_TRANSPORT \ 103 -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode2 \ 104 -i $NVMF_FIRST_INITIATOR_IP 105 [[ $("$rpc_py" nvmf_subsystem_get_qpairs nqn.2016-06.io.spdk:cnode2 \ 106 | jq -r '.[].peer_address.traddr') == "$NVMF_FIRST_INITIATOR_IP" ]] 107 "$rpc_py" -s "$bdevperf_rpc_sock" bdev_nvme_detach_controller nvme1 108 109 "$rpc_py" -s "$bdevperf_rpc_sock" bdev_nvme_attach_controller -b nvme1 -t $TEST_TRANSPORT \ 110 -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode2 \ 111 -i $NVMF_SECOND_INITIATOR_IP 112 [[ $("$rpc_py" nvmf_subsystem_get_qpairs nqn.2016-06.io.spdk:cnode2 \ 113 | jq -r '.[].peer_address.traddr') == "$NVMF_SECOND_INITIATOR_IP" ]] 114fi 115 116killprocess $bdevperf_pid 117 118$rpc_py nvmf_delete_subsystem nqn.2016-06.io.spdk:cnode1 119$rpc_py nvmf_delete_subsystem nqn.2016-06.io.spdk:cnode2 120 121trap - SIGINT SIGTERM EXIT 122 123pap "$testdir/try.txt" 124nvmftestfini 125