xref: /spdk/test/nvmf/host/async_init.sh (revision c39647df83e4be9bcc49025132c48bf2414ef8b1)
1#!/usr/bin/env bash
2
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../../..)
5rpc_py=$rootdir/scripts/rpc.py
6
7source $rootdir/test/common/autotest_common.sh
8source $rootdir/test/nvmf/common.sh
9
10null_bdev_size=1024
11null_block_size=512
12null_bdev=null0
13nvme_bdev=nvme0
14
15# Since we're connecting the same bdev, we need to use a different NGUID to avoid errors when
16# registering the bdev during bdev_nvme_attach_controller
17nguid=$(uuidgen | tr -d '-')
18
19if [ "$TEST_TRANSPORT" != "tcp" ]; then
20	echo "This test can only be executed with TCP for now"
21	exit 0
22fi
23
24nvmftestinit
25nvmfappstart -m 0x1
26
27# First create a null bdev and expose it over NVMeoF
28$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS
29$rpc_py bdev_null_create $null_bdev $null_bdev_size $null_block_size
30$rpc_py bdev_wait_for_examine
31$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode0 -a
32$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode0 $null_bdev -g $nguid
33$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode0 -t $TEST_TRANSPORT \
34	-a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
35
36# Then attach NVMe bdev by connecting back to itself, with the target app running on a single core.
37# This verifies that the initialization is completely asynchronous, as each blocking call would
38# stall the application.
39$rpc_py bdev_nvme_attach_controller -b $nvme_bdev -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \
40	-f ipv4 -s $NVMF_PORT -n nqn.2016-06.io.spdk:cnode0
41
42# Make sure the bdev was created successfully
43$rpc_py bdev_get_bdevs -b ${nvme_bdev}n1
44
45# Make sure the reset is also asynchronous
46$rpc_py bdev_nvme_reset_controller $nvme_bdev
47
48# And that the bdev is still available after a reset
49$rpc_py bdev_get_bdevs -b ${nvme_bdev}n1
50
51# Finally, detach the controller to verify the detach path
52$rpc_py bdev_nvme_detach_controller $nvme_bdev
53
54trap - SIGINT SIGTERM EXIT
55nvmftestfini
56