2018-05-08 02:11:10 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
testdir=$(readlink -f $(dirname $0))
|
|
|
|
rootdir=$(readlink -f $testdir/../../..)
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
|
|
|
source $rootdir/test/iscsi_tgt/common.sh
|
|
|
|
|
|
|
|
function check_qos_works_well() {
|
|
|
|
local enable_limit=$1
|
2018-11-06 12:34:17 +00:00
|
|
|
local qos_limit=$2
|
2019-03-06 20:02:15 +00:00
|
|
|
local check_qos=$4
|
2018-05-08 02:11:10 +00:00
|
|
|
local retval=0
|
2018-08-24 20:14:26 +00:00
|
|
|
|
2018-11-06 12:34:17 +00:00
|
|
|
if [ $LIMIT_TYPE = BANDWIDTH ]; then
|
|
|
|
qos_limit=$((qos_limit*1024*1024))
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $LIMIT_TYPE = IOPS ]; then
|
|
|
|
start_io_count=$($rpc_py get_bdevs_iostat -b $3 | jq -r '.[1].num_read_ops')
|
|
|
|
else
|
|
|
|
start_io_count=$($rpc_py get_bdevs_iostat -b $3 | jq -r '.[1].bytes_read')
|
|
|
|
fi
|
|
|
|
|
2019-04-22 18:37:52 +00:00
|
|
|
$fio_py iscsi 1024 128 randread 5 1
|
2018-08-27 22:12:49 +00:00
|
|
|
|
2018-11-06 12:34:17 +00:00
|
|
|
if [ $LIMIT_TYPE = IOPS ]; then
|
|
|
|
end_io_count=$($rpc_py get_bdevs_iostat -b $3 | jq -r '.[1].num_read_ops')
|
|
|
|
else
|
|
|
|
end_io_count=$($rpc_py get_bdevs_iostat -b $3 | jq -r '.[1].bytes_read')
|
|
|
|
fi
|
|
|
|
|
|
|
|
read_result=$(((end_io_count-start_io_count)/5))
|
2018-08-24 20:14:26 +00:00
|
|
|
|
2018-05-08 02:11:10 +00:00
|
|
|
if [ $enable_limit = true ]; then
|
2018-11-06 12:34:17 +00:00
|
|
|
#qos realization is related with bytes transfered.It currently have like 5% variation.
|
2019-02-13 20:16:51 +00:00
|
|
|
retval=$(echo "$qos_limit*0.85 < $read_result && $read_result < $qos_limit*1.05" | bc)
|
2018-05-08 02:11:10 +00:00
|
|
|
if [ $retval -eq 0 ]; then
|
|
|
|
echo "Failed to limit the io read rate of malloc bdev by qos"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
2018-11-06 12:34:17 +00:00
|
|
|
retval=$(echo "$read_result > $qos_limit" | bc)
|
2018-05-08 02:11:10 +00:00
|
|
|
if [ $retval -eq 0 ]; then
|
2019-03-06 20:02:15 +00:00
|
|
|
if [ $check_qos = true ]; then
|
|
|
|
echo "$read_result less than $qos_limit - exit QoS testing"
|
|
|
|
ENABLE_QOS=false
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "$read_result less than $qos_limit - expected greater than"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-05-08 02:11:10 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "$TARGET_IP" ]; then
|
|
|
|
echo "TARGET_IP not defined in environment"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$INITIATOR_IP" ]; then
|
|
|
|
echo "INITIATOR_IP not defined in environment"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
timing_enter qos
|
|
|
|
|
|
|
|
MALLOC_BDEV_SIZE=64
|
2018-08-27 20:51:55 +00:00
|
|
|
MALLOC_BLOCK_SIZE=512
|
2019-03-06 20:02:15 +00:00
|
|
|
ENABLE_QOS=true
|
2018-05-08 02:11:10 +00:00
|
|
|
IOPS_LIMIT=20000
|
2018-06-22 02:15:02 +00:00
|
|
|
BANDWIDTH_LIMIT=20
|
|
|
|
READ_BANDWIDTH_LIMIT=10
|
2018-11-06 12:34:17 +00:00
|
|
|
LIMIT_TYPE=IOPS
|
2018-09-11 13:26:14 +00:00
|
|
|
rpc_py="$rootdir/scripts/rpc.py"
|
|
|
|
fio_py="$rootdir/scripts/fio.py"
|
2018-05-08 02:11:10 +00:00
|
|
|
|
|
|
|
timing_enter start_iscsi_tgt
|
|
|
|
|
|
|
|
$ISCSI_APP &
|
|
|
|
pid=$!
|
|
|
|
echo "Process pid: $pid"
|
|
|
|
trap "killprocess $pid; exit 1" SIGINT SIGTERM EXIT
|
|
|
|
waitforlisten $pid
|
|
|
|
echo "iscsi_tgt is listening. Running tests..."
|
|
|
|
|
|
|
|
timing_exit start_iscsi_tgt
|
|
|
|
|
|
|
|
$rpc_py add_portal_group $PORTAL_TAG $TARGET_IP:$ISCSI_PORT
|
|
|
|
$rpc_py add_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK
|
|
|
|
$rpc_py construct_malloc_bdev $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE
|
|
|
|
# "Malloc0:0" ==> use Malloc0 blockdev for LUN0
|
|
|
|
# "1:2" ==> map PortalGroup1 to InitiatorGroup2
|
|
|
|
# "64" ==> iSCSI queue depth 64
|
|
|
|
# "-d" ==> disable CHAP authentication
|
|
|
|
$rpc_py construct_target_node Target1 Target1_alias 'Malloc0:0' $PORTAL_TAG:$INITIATOR_TAG 64 -d
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT
|
|
|
|
iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT
|
|
|
|
|
2018-08-27 22:12:49 +00:00
|
|
|
trap "iscsicleanup; killprocess $pid; exit 1" SIGINT SIGTERM EXIT
|
2018-05-08 02:11:10 +00:00
|
|
|
|
2019-03-06 20:02:15 +00:00
|
|
|
# Check whether to enable the QoS testing.
|
|
|
|
check_qos_works_well false $IOPS_LIMIT Malloc0 true
|
|
|
|
|
|
|
|
if [ $ENABLE_QOS = true ]; then
|
|
|
|
# Limit the I/O rate by RPC, then confirm the observed rate matches.
|
|
|
|
$rpc_py set_bdev_qos_limit Malloc0 --rw_ios_per_sec $IOPS_LIMIT
|
|
|
|
check_qos_works_well true $IOPS_LIMIT Malloc0 false
|
2018-05-08 02:11:10 +00:00
|
|
|
|
2019-03-06 20:02:15 +00:00
|
|
|
# Now disable the rate limiting, and confirm the observed rate is not limited anymore.
|
|
|
|
$rpc_py set_bdev_qos_limit Malloc0 --rw_ios_per_sec 0
|
|
|
|
check_qos_works_well false $IOPS_LIMIT Malloc0 false
|
2018-05-08 02:11:10 +00:00
|
|
|
|
2019-03-06 20:02:15 +00:00
|
|
|
# Limit the I/O rate again.
|
|
|
|
$rpc_py set_bdev_qos_limit Malloc0 --rw_ios_per_sec $IOPS_LIMIT
|
|
|
|
check_qos_works_well true $IOPS_LIMIT Malloc0 false
|
|
|
|
echo "I/O rate limiting tests successful"
|
2018-05-08 02:11:10 +00:00
|
|
|
|
2019-03-06 20:02:15 +00:00
|
|
|
# Limit the I/O bandwidth rate by RPC, then confirm the observed rate matches.
|
|
|
|
LIMIT_TYPE=BANDWIDTH
|
|
|
|
$rpc_py set_bdev_qos_limit Malloc0 --rw_ios_per_sec 0 --rw_mbytes_per_sec $BANDWIDTH_LIMIT
|
|
|
|
check_qos_works_well true $BANDWIDTH_LIMIT Malloc0 false
|
2018-11-06 12:34:17 +00:00
|
|
|
|
2019-03-06 20:02:15 +00:00
|
|
|
# Now disable the bandwidth rate limiting, and confirm the observed rate is not limited anymore.
|
|
|
|
$rpc_py set_bdev_qos_limit Malloc0 --rw_mbytes_per_sec 0
|
|
|
|
check_qos_works_well false $BANDWIDTH_LIMIT Malloc0 false
|
2018-11-06 12:34:17 +00:00
|
|
|
|
2019-03-06 20:02:15 +00:00
|
|
|
# Limit the I/O bandwidth rate again with both read/write and read/only.
|
|
|
|
$rpc_py set_bdev_qos_limit Malloc0 --rw_mbytes_per_sec $BANDWIDTH_LIMIT --r_mbytes_per_sec $READ_BANDWIDTH_LIMIT
|
|
|
|
check_qos_works_well true $READ_BANDWIDTH_LIMIT Malloc0 false
|
|
|
|
echo "I/O bandwidth limiting tests successful"
|
|
|
|
fi
|
2018-11-06 12:34:17 +00:00
|
|
|
|
2018-05-08 02:11:10 +00:00
|
|
|
iscsicleanup
|
|
|
|
$rpc_py delete_target_node 'iqn.2016-06.io.spdk:Target1'
|
|
|
|
|
|
|
|
rm -f ./local-job0-0-verify.state
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
killprocess $pid
|
|
|
|
|
|
|
|
timing_exit qos
|