xref: /spdk/test/iscsi_tgt/resize/resize.sh (revision 18c8b52afa69f39481ebb75711b2f30b11693f9d)
1#!/usr/bin/env bash
2
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../../..)
5source $rootdir/test/common/autotest_common.sh
6source $rootdir/test/iscsi_tgt/common.sh
7
8iscsitestinit
9
10BDEV_SIZE=64
11BDEV_NEW_SIZE=128
12BLOCK_SIZE=512
13RESIZE_SOCK="/var/tmp/spdk-resize.sock"
14
15timing_enter start_iscsi_tgt
16
17# Remove the sock file first
18rm -f $RESIZE_SOCK
19
20"${ISCSI_APP[@]}" -m 0x2 -p 1 -s 512 --wait-for-rpc &
21pid=$!
22echo "iSCSI target launched. pid: $pid"
23trap 'killprocess $pid; iscsitestfini; exit 1' SIGINT SIGTERM EXIT
24waitforlisten $pid
25$rpc_py framework_start_init
26echo "iscsi_tgt is listening. Running tests..."
27
28timing_exit start_iscsi_tgt
29
30$rpc_py iscsi_create_portal_group $PORTAL_TAG $TARGET_IP:$ISCSI_PORT
31$rpc_py iscsi_create_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK
32$rpc_py bdev_null_create Null0 $BDEV_SIZE $BLOCK_SIZE
33# "Null0:0" ==> use Null0 blockdev for LUN0
34# "1:2" ==> map PortalGroup1 to InitiatorGroup2
35# "64" ==> iSCSI queue depth 64
36# "-d" ==> disable CHAP authentication
37$rpc_py iscsi_create_target_node disk1 disk1_alias 'Null0:0' $PORTAL_TAG:$INITIATOR_TAG 256 -d
38sleep 1
39trap 'killprocess $pid; iscsitestfini; exit 1' SIGINT SIGTERM EXIT
40
41# Start bdevperf with another sock file and iSCSI initiator
42"$rootdir/test/bdev/bdevperf/bdevperf" -r $RESIZE_SOCK --json <(initiator_json_config) -q 16 -o 4096 -w read -t 5 -R -s 128 -z &
43bdevperf_pid=$!
44waitforlisten $bdevperf_pid $RESIZE_SOCK
45# Resize the Bdev from iSCSI target
46$rpc_py bdev_null_resize Null0 $BDEV_NEW_SIZE
47# Obtain the Bdev from bdevperf with iSCSI initiator
48num_block=$($rpc_py -s $RESIZE_SOCK bdev_get_bdevs | grep num_blocks | sed 's/[^[:digit:]]//g')
49# Size is not changed as no IO sent yet and resize notification is deferred.
50total_size=$((num_block * BLOCK_SIZE / 1048576))
51if [ $total_size != $BDEV_SIZE ]; then
52	echo "resize failed"
53	exit 1
54fi
55sleep 2
56# Start the bdevperf IO
57$rootdir/test/bdev/bdevperf/bdevperf.py -s $RESIZE_SOCK perform_tests
58# Obtain the Bdev from bdevperf with iSCSI initiator
59num_block=$($rpc_py -s $RESIZE_SOCK bdev_get_bdevs | grep num_blocks | sed 's/[^[:digit:]]//g')
60# Get the new bdev size in MiB.
61total_size=$((num_block * BLOCK_SIZE / 1048576))
62if [ $total_size != $BDEV_NEW_SIZE ]; then
63	echo "resize failed"
64	exit 1
65fi
66
67trap - SIGINT SIGTERM EXIT
68killprocess $bdevperf_pid
69killprocess $pid
70
71iscsitestfini
72