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 67waitforiscsidevices 1 68 69trap "remove_backends; umount /mnt/device; rm -rf /mnt/device; iscsicleanup; killprocess $pid; iscsitestfini $1 $2; exit 1" SIGINT SIGTERM EXIT 70 71mkdir -p /mnt/device 72 73dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}') 74 75waitforfile /dev/$dev 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 waitforiscsidevices 0 95 iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT 96 waitforiscsidevices 1 97 98 dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}') 99 100 waitforfile /dev/${dev}1 101 mount -o rw /dev/${dev}1 /mnt/device 102 if [ -f "/mnt/device/test" ]; then 103 echo "File existed." 104 fio -filename=/mnt/device/test -direct=1 -iodepth 64 -thread=1 -invalidate=1 -rw=randread \ 105 -ioengine=libaio -bs=4k -runtime=20 -time_based=1 -name=job0 106 else 107 echo "File doesn't exist." 108 exit 1 109 fi 110 111 rm -rf /mnt/device/test 112 umount /mnt/device 113 else 114 touch /mnt/device/aaa 115 umount /mnt/device 116 117 iscsiadm -m node --logout 118 waitforiscsidevices 0 119 iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT 120 waitforiscsidevices 1 121 122 dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}') 123 124 waitforfile /dev/${dev}1 125 mount -o rw /dev/${dev}1 /mnt/device 126 127 if [ -f "/mnt/device/aaa" ]; then 128 echo "File existed." 129 else 130 echo "File doesn't exist." 131 exit 1 132 fi 133 134 rm -rf /mnt/device/aaa 135 umount /mnt/device 136 fi 137done 138 139rm -rf /mnt/device 140 141trap - SIGINT SIGTERM EXIT 142 143iscsicleanup 144remove_backends 145killprocess $pid 146iscsitestfini $1 $2 147timing_exit filesystem 148