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