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