xref: /spdk/test/iscsi_tgt/filesystem/filesystem.sh (revision b30d57cdad6d2bc75cc1e4e2ebbcebcb0d98dcfa)
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
7source $rootdir/scripts/common.sh
8
9iscsitestinit
10
11rpc_py="$rootdir/scripts/rpc.py"
12# Remove lvol bdevs and stores.
13function remove_backends() {
14	echo "INFO: Removing lvol bdev"
15	$rpc_py bdev_lvol_delete "lvs_0/lbd_0"
16
17	echo "INFO: Removing lvol stores"
18	$rpc_py bdev_lvol_delete_lvstore -l lvs_0
19
20	echo "INFO: Removing NVMe"
21	$rpc_py bdev_nvme_detach_controller Nvme0
22
23	return 0
24}
25
26timing_enter start_iscsi_tgt
27
28"${ISCSI_APP[@]}" -m $ISCSI_TEST_CORE_MASK --wait-for-rpc &
29pid=$!
30echo "Process pid: $pid"
31
32trap 'killprocess $pid; iscsitestfini; exit 1' SIGINT SIGTERM EXIT
33
34waitforlisten $pid
35$rpc_py iscsi_set_options -o 30 -a 16
36$rpc_py framework_start_init
37echo "iscsi_tgt is listening. Running tests..."
38
39timing_exit start_iscsi_tgt
40
41bdf=$(get_first_nvme_bdf)
42$rpc_py iscsi_create_portal_group $PORTAL_TAG $TARGET_IP:$ISCSI_PORT
43$rpc_py iscsi_create_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK
44$rpc_py bdev_nvme_attach_controller -b "Nvme0" -t "pcie" -a $bdf
45
46ls_guid=$($rpc_py bdev_lvol_create_lvstore Nvme0n1 lvs_0)
47free_mb=$(get_lvs_free_mb "$ls_guid")
48# Using maximum 2048MiB to reduce the test time
49if [ $free_mb -gt 2048 ]; then
50	$rpc_py bdev_lvol_create -u $ls_guid lbd_0 2048
51else
52	$rpc_py bdev_lvol_create -u $ls_guid lbd_0 $free_mb
53fi
54# "lvs_0/lbd_0:0" ==> use lvs_0/lbd_0 blockdev for LUN0
55# "1:2" ==> map PortalGroup1 to InitiatorGroup2
56# "256" ==> iSCSI queue depth 256
57# "-d" ==> disable CHAP authentication
58$rpc_py iscsi_create_target_node Target1 Target1_alias 'lvs_0/lbd_0:0' $PORTAL_TAG:$INITIATOR_TAG 256 -d
59sleep 1
60
61iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT
62iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT
63waitforiscsidevices 1
64
65trap 'iscsicleanup; remove_backends; umount /mnt/device; rm -rf /mnt/device; killprocess $pid; iscsitestfini; exit 1' SIGINT SIGTERM EXIT
66
67mkdir -p /mnt/device
68
69dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
70
71waitforfile /dev/$dev
72parted -s /dev/$dev mklabel msdos
73parted -s /dev/$dev mkpart primary '0%' '100%'
74sleep 1
75
76function filesystem_test() {
77	fstype=$1
78
79	make_filesystem ${fstype} /dev/${dev}1
80	mount /dev/${dev}1 /mnt/device
81	if [ $RUN_NIGHTLY -eq 1 ]; then
82		fio -filename=/mnt/device/test -direct=1 -iodepth 64 -thread=1 -invalidate=1 -rw=randwrite -ioengine=libaio -bs=4k \
83			-size=1024M -name=job0
84		umount /mnt/device
85
86		iscsiadm -m node --logout
87		waitforiscsidevices 0
88		iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT
89		waitforiscsidevices 1
90
91		dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
92
93		waitforfile /dev/${dev}1
94		mount -o rw /dev/${dev}1 /mnt/device
95		if [ -f "/mnt/device/test" ]; then
96			echo "File existed."
97			fio -filename=/mnt/device/test -direct=1 -iodepth 64 -thread=1 -invalidate=1 -rw=randread \
98				-ioengine=libaio -bs=4k -runtime=20 -time_based=1 -name=job0
99		else
100			echo "File doesn't exist."
101			exit 1
102		fi
103
104		rm -rf /mnt/device/test
105		umount /mnt/device
106	else
107		touch /mnt/device/aaa
108		umount /mnt/device
109
110		iscsiadm -m node --logout
111		waitforiscsidevices 0
112		iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT
113		waitforiscsidevices 1
114
115		dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
116
117		waitforfile /dev/${dev}1
118		mount -o rw /dev/${dev}1 /mnt/device
119
120		if [ -f "/mnt/device/aaa" ]; then
121			echo "File existed."
122		else
123			echo "File doesn't exist."
124			exit 1
125		fi
126
127		rm -rf /mnt/device/aaa
128		umount /mnt/device
129	fi
130}
131
132run_test "iscsi_tgt_filesystem_ext4" filesystem_test "ext4"
133run_test "iscsi_tgt_filesystem_btrfs" filesystem_test "btrfs"
134run_test "iscsi_tgt_filesystem_xfs" filesystem_test "xfs"
135
136rm -rf /mnt/device
137
138trap - SIGINT SIGTERM EXIT
139
140iscsicleanup
141remove_backends
142killprocess $pid
143iscsitestfini
144