xref: /spdk/test/nvmf/host/async_init.sh (revision 927f1fd57bd004df581518466ec4c1b8083e5d23)
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
19nvmftestinit
20nvmfappstart -m 0x1
21
22# First create a null bdev and expose it over NVMeoF
23$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS
24$rpc_py bdev_null_create $null_bdev $null_bdev_size $null_block_size
25$rpc_py bdev_wait_for_examine
26$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode0 -a
27$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode0 $null_bdev -g $nguid
28$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode0 -t $TEST_TRANSPORT \
29	-a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
30
31# Then attach NVMe bdev by connecting back to itself, with the target app running on a single core.
32# This verifies that the initialization is completely asynchronous, as each blocking call would
33# stall the application.
34$rpc_py bdev_nvme_attach_controller -b $nvme_bdev -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \
35	-f ipv4 -s $NVMF_PORT -n nqn.2016-06.io.spdk:cnode0
36
37# Make sure the bdev was created successfully
38$rpc_py bdev_get_bdevs -b ${nvme_bdev}n1
39
40# Make sure the reset is also asynchronous
41$rpc_py bdev_nvme_reset_controller $nvme_bdev
42
43# And that the bdev is still available after a reset
44$rpc_py bdev_get_bdevs -b ${nvme_bdev}n1
45
46# Finally, detach the controller to verify the detach path
47$rpc_py bdev_nvme_detach_controller $nvme_bdev
48
49trap - SIGINT SIGTERM EXIT
50nvmftestfini
51