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