xref: /spdk/test/iscsi_tgt/filesystem/filesystem.sh (revision c4d9daeb7bf491bc0eb6e8d417b75d44773cb009)
1 #!/usr/bin/env bash
2 
3 testdir=$(readlink -f $(dirname $0))
4 rootdir=$(readlink -f $testdir/../../..)
5 source $rootdir/test/common/autotest_common.sh
6 source $rootdir/test/iscsi_tgt/common.sh
7 source $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.
11 iscsitestinit $1 $2
12 
13 timing_enter filesystem
14 
15 rpc_py="$rootdir/scripts/rpc.py"
16 # Remove lvol bdevs and stores.
17 function 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 
30 timing_enter start_iscsi_tgt
31 
32 $ISCSI_APP -m $ISCSI_TEST_CORE_MASK --wait-for-rpc &
33 pid=$!
34 echo "Process pid: $pid"
35 
36 trap "killprocess $pid; iscsitestfini $1 $2; exit 1" SIGINT SIGTERM EXIT
37 
38 waitforlisten $pid
39 $rpc_py set_iscsi_options -o 30 -a 16
40 $rpc_py start_subsystem_init
41 echo "iscsi_tgt is listening. Running tests..."
42 
43 timing_exit start_iscsi_tgt
44 
45 bdf=$(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 
50 ls_guid=$($rpc_py construct_lvol_store Nvme0n1 lvs_0)
51 free_mb=$(get_lvs_free_mb "$ls_guid")
52 # Using maximum 2048MiB to reduce the test time
53 if [ $free_mb -gt 2048 ]; then
54 	$rpc_py construct_lvol_bdev -u $ls_guid lbd_0 2048
55 else
56 	$rpc_py construct_lvol_bdev -u $ls_guid lbd_0 $free_mb
57 fi
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
63 sleep 1
64 
65 iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT
66 iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT
67 
68 trap "remove_backends; umount /mnt/device; rm -rf /mnt/device; iscsicleanup; killprocess $pid; iscsitestfini $1 $2; exit 1" SIGINT SIGTERM EXIT
69 
70 sleep 1
71 
72 mkdir -p /mnt/device
73 
74 dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
75 
76 parted -s /dev/$dev mklabel msdos
77 parted -s /dev/$dev mkpart primary '0%' '100%'
78 sleep 1
79 
80 for 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
131 done
132 
133 rm -rf /mnt/device
134 
135 trap - SIGINT SIGTERM EXIT
136 
137 iscsicleanup
138 remove_backends
139 killprocess $pid
140 iscsitestfini $1 $2
141 timing_exit filesystem
142