xref: /spdk/test/nvmf/target/ns_hotplug_stress.sh (revision c6c1234de9e0015e670dd0b51bf6ce39ee0e07bd)
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
11rpc_py="$rootdir/scripts/rpc.py"
12
13add_remove() {
14	local nsid=$1 bdev=$2
15
16	for ((i = 0; i < 10; ++i)); do
17		"$rpc_py" nvmf_subsystem_add_ns -n "$nsid" "nqn.2016-06.io.spdk:cnode1" "$bdev"
18		"$rpc_py" nvmf_subsystem_remove_ns "nqn.2016-06.io.spdk:cnode1" "$nsid"
19	done
20}
21
22nvmftestinit
23nvmfappstart -m 0xE
24
25null_size=1000
26
27$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS -u 8192
28
29$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 -m 10
30$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
31$rpc_py nvmf_subsystem_add_listener discovery -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
32$rpc_py bdev_malloc_create 32 512 -b Malloc0
33$rpc_py bdev_delay_create -b Malloc0 -d Delay0 -r 1000000 -t 1000000 -w 1000000 -n 1000000
34$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Delay0
35$rpc_py bdev_null_create NULL1 $null_size 512
36$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 NULL1
37
38# Note: use -Q option to rate limit the error messages that perf will spew due to the
39# namespace hotplugs
40$SPDK_BIN_DIR/spdk_nvme_perf -c 0x1 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" \
41	-t 30 -q 128 -w randread -o 512 -Q 1000 "${NO_HUGE[@]}" &
42PERF_PID=$!
43
44while kill -0 $PERF_PID; do
45	$rpc_py nvmf_subsystem_remove_ns nqn.2016-06.io.spdk:cnode1 1
46	$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Delay0
47	# Also test bdev/namespace resizing here, since it has a similar
48	# effect on subsystem/namespace handling in the nvmf target
49	null_size=$((null_size + 1))
50	$rpc_py bdev_null_resize NULL1 $null_size
51done
52
53wait $PERF_PID
54"$rpc_py" nvmf_subsystem_remove_ns nqn.2016-06.io.spdk:cnode1 1
55"$rpc_py" nvmf_subsystem_remove_ns nqn.2016-06.io.spdk:cnode1 2
56
57# Run several subsystem_{add,remove}_ns RPCs in parallel to ensure they'll get queued
58nthreads=8 pids=()
59for ((i = 0; i < nthreads; ++i)); do
60	"$rpc_py" bdev_null_create "null$i" 100 4096
61done
62for ((i = 0; i < nthreads; ++i)); do
63	add_remove $((i + 1)) "null$i" &
64	pids+=($!)
65done
66wait "${pids[@]}"
67
68trap - SIGINT SIGTERM EXIT
69
70nvmftestfini
71