diff --git a/app/nvmf_tgt/nvmf_tgt.c b/app/nvmf_tgt/nvmf_tgt.c index ae813c19f..14fbf3506 100644 --- a/app/nvmf_tgt/nvmf_tgt.c +++ b/app/nvmf_tgt/nvmf_tgt.c @@ -69,6 +69,7 @@ subsystem_delete_event(void *arg1, void *arg2) struct nvmf_tgt_subsystem *app_subsys = arg1; struct spdk_nvmf_subsystem *subsystem = app_subsys->subsystem; + TAILQ_REMOVE(&g_subsystems, app_subsys, tailq); free(app_subsys); spdk_nvmf_delete_subsystem(subsystem); @@ -111,7 +112,6 @@ shutdown_subsystems(void) g_subsystems_shutdown = true; TAILQ_FOREACH_SAFE(app_subsys, &g_subsystems, tailq, tmp) { - TAILQ_REMOVE(&g_subsystems, app_subsys, tailq); nvmf_tgt_delete_subsystem(app_subsys); } } @@ -286,7 +286,6 @@ nvmf_tgt_shutdown_subsystem_by_nqn(const char *nqn) TAILQ_FOREACH_SAFE(tgt_subsystem, &g_subsystems, tailq, subsys_tmp) { if (strcmp(tgt_subsystem->subsystem->subnqn, nqn) == 0) { - TAILQ_REMOVE(&g_subsystems, tgt_subsystem, tailq); nvmf_tgt_delete_subsystem(tgt_subsystem); return 0; } diff --git a/autotest.sh b/autotest.sh index 88c7ef0c1..50515f98e 100755 --- a/autotest.sh +++ b/autotest.sh @@ -118,6 +118,7 @@ run_test test/nvmf/fio/fio.sh run_test test/nvmf/filesystem/filesystem.sh run_test test/nvmf/discovery/discovery.sh run_test test/nvmf/nvme_cli/nvme_cli.sh +run_test test/nvmf/shutdown/shutdown.sh if [ $RUN_NIGHTLY -eq 1 ]; then run_test test/nvmf/multiconnection/multiconnection.sh diff --git a/test/nvmf/shutdown/shutdown.sh b/test/nvmf/shutdown/shutdown.sh new file mode 100755 index 000000000..b738e0a60 --- /dev/null +++ b/test/nvmf/shutdown/shutdown.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../../..) +source $rootdir/scripts/autotest_common.sh +source $rootdir/test/nvmf/common.sh + +MALLOC_BDEV_SIZE=128 +MALLOC_BLOCK_SIZE=512 + +rpc_py="python $rootdir/scripts/rpc.py" + +set -e + +if ! rdma_nic_available; then + echo "no NIC for nvmf test" + exit 0 +fi + +timing_enter shutdown + +# Start up the NVMf target in another process +$rootdir/app/nvmf_tgt/nvmf_tgt -c $testdir/../nvmf.conf & +pid=$! + +trap "killprocess $pid; exit 1" SIGINT SIGTERM EXIT + +waitforlisten $pid ${RPC_PORT} + +# Create 12 subsystems +for i in `seq 1 12` +do + bdevs="$($rpc_py construct_malloc_bdev $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE)" + $rpc_py construct_nvmf_subsystem Virtual nqn.2016-06.io.spdk:cnode${i} "transport:RDMA traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" '' -s SPDK${i} -n "$bdevs" +done + +# Kill nvmf tgt without removing any subsystem to check whether it can shutdown correctly +rm -f ./local-job0-0-verify.state + +trap - SIGINT SIGTERM EXIT + +killprocess $pid +timing_exit shutdown