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