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