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=$(iter_pci_class_code 01 08 02 | head -1) 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 if [ "$fstype" == "ext4" ]; then 82 mkfs.${fstype} -F /dev/${dev}1 83 else 84 mkfs.${fstype} -f /dev/${dev}1 85 fi 86 mount /dev/${dev}1 /mnt/device 87 if [ $RUN_NIGHTLY -eq 1 ]; then 88 fio -filename=/mnt/device/test -direct=1 -iodepth 64 -thread=1 -invalidate=1 -rw=randwrite -ioengine=libaio -bs=4k \ 89 -size=1024M -name=job0 90 umount /mnt/device 91 92 iscsiadm -m node --logout 93 waitforiscsidevices 0 94 iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT 95 waitforiscsidevices 1 96 97 dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}') 98 99 waitforfile /dev/${dev}1 100 mount -o rw /dev/${dev}1 /mnt/device 101 if [ -f "/mnt/device/test" ]; then 102 echo "File existed." 103 fio -filename=/mnt/device/test -direct=1 -iodepth 64 -thread=1 -invalidate=1 -rw=randread \ 104 -ioengine=libaio -bs=4k -runtime=20 -time_based=1 -name=job0 105 else 106 echo "File doesn't exist." 107 exit 1 108 fi 109 110 rm -rf /mnt/device/test 111 umount /mnt/device 112 else 113 touch /mnt/device/aaa 114 umount /mnt/device 115 116 iscsiadm -m node --logout 117 waitforiscsidevices 0 118 iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT 119 waitforiscsidevices 1 120 121 dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}') 122 123 waitforfile /dev/${dev}1 124 mount -o rw /dev/${dev}1 /mnt/device 125 126 if [ -f "/mnt/device/aaa" ]; then 127 echo "File existed." 128 else 129 echo "File doesn't exist." 130 exit 1 131 fi 132 133 rm -rf /mnt/device/aaa 134 umount /mnt/device 135 fi 136} 137 138run_test "iscsi_tgt_filesystem_ext4" filesystem_test "ext4" 139run_test "iscsi_tgt_filesystem_btrfs" filesystem_test "btrfs" 140run_test "iscsi_tgt_filesystem_xfs" filesystem_test "xfs" 141 142rm -rf /mnt/device 143 144trap - SIGINT SIGTERM EXIT 145 146iscsicleanup 147remove_backends 148killprocess $pid 149iscsitestfini $1 $2 150