xref: /spdk/test/iscsi_tgt/filesystem/filesystem.sh (revision d1165a653907c85812beba21bf9cb6c657cf3bf1)
1#!/usr/bin/env bash
2
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../../..)
5source $rootdir/scripts/autotest_common.sh
6source $rootdir/test/iscsi_tgt/common.sh
7
8timing_enter filesystem
9
10# iSCSI target configuration
11PORT=3260
12INITIATOR_TAG=2
13INITIATOR_NAME=ANY
14NETMASK=$INITIATOR_IP/32
15MALLOC_BDEV_SIZE=256
16MALLOC_BLOCK_SIZE=512
17
18rpc_py="python $rootdir/scripts/rpc.py"
19
20timing_enter start_iscsi_tgt
21
22$ISCSI_APP -c $testdir/iscsi.conf -m $ISCSI_TEST_CORE_MASK &
23pid=$!
24echo "Process pid: $pid"
25
26trap "killprocess $pid; exit 1" SIGINT SIGTERM EXIT
27
28waitforlisten $pid
29echo "iscsi_tgt is listening. Running tests..."
30
31timing_exit start_iscsi_tgt
32
33$rpc_py add_portal_group 1 $TARGET_IP:$PORT
34$rpc_py add_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK
35$rpc_py construct_malloc_bdev $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE
36# "Malloc0:0" ==> use Malloc0 blockdev for LUN0
37# "1:2" ==> map PortalGroup1 to InitiatorGroup2
38# "64" ==> iSCSI queue depth 64
39# "1 0 0 0" ==> disable CHAP authentication
40$rpc_py construct_target_node Target3 Target3_alias 'Malloc0:0' '1:2' 256 -d
41sleep 1
42
43iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$PORT
44iscsiadm -m node --login -p $TARGET_IP:$PORT
45
46trap "umount /mnt/device; rm -rf /mnt/device; iscsicleanup; killprocess $pid; exit 1" SIGINT SIGTERM EXIT
47
48sleep 1
49
50mkdir -p  /mnt/device
51
52dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
53
54parted -s /dev/$dev mklabel msdos
55parted -s /dev/$dev mkpart primary '0%' '100%'
56sleep 1
57
58for fstype in "ext4" "btrfs" "xfs"; do
59
60	if [ "$fstype" == "ext4" ]; then
61		mkfs.${fstype} -F /dev/${dev}1
62	else
63		mkfs.${fstype} -f /dev/${dev}1
64	fi
65	mount /dev/${dev}1 /mnt/device
66	touch /mnt/device/aaa
67	umount /mnt/device
68
69	iscsiadm -m node --logout
70	sleep 1
71	iscsiadm -m node --login -p $TARGET_IP:$PORT
72	sleep 1
73	dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
74	mount -o rw /dev/${dev}1 /mnt/device
75
76	if [ -f "/mnt/device/aaa" ]; then
77		echo "File existed."
78	else
79		echo "File doesn't exist."
80		exit 1
81	fi
82
83	rm -rf /mnt/device/aaa
84	umount /mnt/device
85done
86
87rm -rf /mnt/device
88
89trap - SIGINT SIGTERM EXIT
90
91iscsicleanup
92killprocess $pid
93timing_exit filesystem
94