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