]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/usr/bin/env bash |
2 | ||
3 | testdir=$(readlink -f $(dirname $0)) | |
4 | rootdir=$(readlink -f $testdir/../../..) | |
5 | source $rootdir/test/common/autotest_common.sh | |
6 | source $rootdir/test/iscsi_tgt/common.sh | |
7 | ||
9f95a23c TL |
8 | # $1 = "iso" - triggers isolation mode (setting up required environment). |
9 | # $2 = test type posix or vpp. defaults to posix. | |
10 | iscsitestinit $1 $2 | |
11 | ||
12 | function run_fio() { | |
13 | local bdev_name=$1 | |
f67539c2 TL |
14 | local iostats |
15 | local start_io_count | |
16 | local start_bytes_read | |
17 | local end_io_count | |
18 | local end_bytes_read | |
9f95a23c TL |
19 | local run_time=5 |
20 | ||
f67539c2 TL |
21 | iostats=$($rpc_py bdev_get_iostat -b $bdev_name) |
22 | start_io_count=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats") | |
23 | start_bytes_read=$(jq -r '.bdevs[0].bytes_read' <<< "$iostats") | |
9f95a23c TL |
24 | |
25 | $fio_py -p iscsi -i 1024 -d 128 -t randread -r $run_time | |
26 | ||
f67539c2 TL |
27 | iostats=$($rpc_py bdev_get_iostat -b $bdev_name) |
28 | end_io_count=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats") | |
29 | end_bytes_read=$(jq -r '.bdevs[0].bytes_read' <<< "$iostats") | |
9f95a23c | 30 | |
f67539c2 TL |
31 | IOPS_RESULT=$(((end_io_count - start_io_count) / run_time)) |
32 | BANDWIDTH_RESULT=$(((end_bytes_read - start_bytes_read) / run_time)) | |
9f95a23c TL |
33 | } |
34 | ||
35 | function verify_qos_limits() { | |
36 | local result=$1 | |
37 | local limit=$2 | |
38 | ||
f67539c2 TL |
39 | [ "$(bc <<< "$result > $limit*0.85")" -eq 1 ] \ |
40 | && [ "$(bc <<< "$result < $limit*1.05")" -eq 1 ] | |
11fdf7f2 TL |
41 | } |
42 | ||
43 | if [ -z "$TARGET_IP" ]; then | |
44 | echo "TARGET_IP not defined in environment" | |
45 | exit 1 | |
46 | fi | |
47 | ||
48 | if [ -z "$INITIATOR_IP" ]; then | |
49 | echo "INITIATOR_IP not defined in environment" | |
50 | exit 1 | |
51 | fi | |
52 | ||
11fdf7f2 TL |
53 | MALLOC_BDEV_SIZE=64 |
54 | MALLOC_BLOCK_SIZE=512 | |
9f95a23c TL |
55 | IOPS_RESULT= |
56 | BANDWIDTH_RESULT= | |
11fdf7f2 TL |
57 | rpc_py="$rootdir/scripts/rpc.py" |
58 | fio_py="$rootdir/scripts/fio.py" | |
59 | ||
60 | timing_enter start_iscsi_tgt | |
61 | ||
f67539c2 | 62 | "${ISCSI_APP[@]}" & |
11fdf7f2 TL |
63 | pid=$! |
64 | echo "Process pid: $pid" | |
f67539c2 | 65 | trap 'killprocess $pid; iscsitestfini $1 $2; exit 1' SIGINT SIGTERM EXIT |
11fdf7f2 TL |
66 | waitforlisten $pid |
67 | echo "iscsi_tgt is listening. Running tests..." | |
68 | ||
69 | timing_exit start_iscsi_tgt | |
70 | ||
f67539c2 TL |
71 | $rpc_py iscsi_create_portal_group $PORTAL_TAG $TARGET_IP:$ISCSI_PORT |
72 | $rpc_py iscsi_create_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK | |
73 | $rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE | |
11fdf7f2 TL |
74 | # "Malloc0:0" ==> use Malloc0 blockdev for LUN0 |
75 | # "1:2" ==> map PortalGroup1 to InitiatorGroup2 | |
76 | # "64" ==> iSCSI queue depth 64 | |
77 | # "-d" ==> disable CHAP authentication | |
f67539c2 | 78 | $rpc_py iscsi_create_target_node Target1 Target1_alias 'Malloc0:0' $PORTAL_TAG:$INITIATOR_TAG 64 -d |
11fdf7f2 TL |
79 | sleep 1 |
80 | ||
81 | iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT | |
82 | iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT | |
83 | ||
f67539c2 | 84 | trap 'iscsicleanup; killprocess $pid; iscsitestfini $1 $2; exit 1' SIGINT SIGTERM EXIT |
9f95a23c TL |
85 | |
86 | # Run FIO without any QOS limits to determine the raw performance | |
87 | run_fio Malloc0 | |
88 | ||
89 | # Set IOPS/bandwidth limit to 50% of the actual unrestrained performance. | |
f67539c2 TL |
90 | IOPS_LIMIT=$((IOPS_RESULT / 2)) |
91 | BANDWIDTH_LIMIT=$((BANDWIDTH_RESULT / 2)) | |
9f95a23c TL |
92 | # Set READ bandwidth limit to 50% of the RW bandwidth limit to be able |
93 | # to differentiate those two. | |
f67539c2 | 94 | READ_BANDWIDTH_LIMIT=$((BANDWIDTH_LIMIT / 2)) |
9f95a23c TL |
95 | |
96 | # Also round them down to nearest multiple of either 1000 IOPS or 1MB BW | |
97 | # which are the minimal QoS granularities | |
f67539c2 TL |
98 | IOPS_LIMIT=$((IOPS_LIMIT / 1000 * 1000)) |
99 | BANDWIDTH_LIMIT_MB=$((BANDWIDTH_LIMIT / 1024 / 1024)) | |
100 | BANDWIDTH_LIMIT=$((BANDWIDTH_LIMIT_MB * 1024 * 1024)) | |
101 | READ_BANDWIDTH_LIMIT_MB=$((READ_BANDWIDTH_LIMIT / 1024 / 1024)) | |
102 | READ_BANDWIDTH_LIMIT=$((READ_BANDWIDTH_LIMIT_MB * 1024 * 1024)) | |
11fdf7f2 TL |
103 | |
104 | # Limit the I/O rate by RPC, then confirm the observed rate matches. | |
f67539c2 | 105 | $rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec $IOPS_LIMIT |
9f95a23c TL |
106 | run_fio Malloc0 |
107 | verify_qos_limits $IOPS_RESULT $IOPS_LIMIT | |
11fdf7f2 TL |
108 | |
109 | # Now disable the rate limiting, and confirm the observed rate is not limited anymore. | |
f67539c2 | 110 | $rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec 0 |
9f95a23c TL |
111 | run_fio Malloc0 |
112 | [ "$IOPS_RESULT" -gt "$IOPS_LIMIT" ] | |
11fdf7f2 TL |
113 | |
114 | # Limit the I/O rate again. | |
f67539c2 | 115 | $rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec $IOPS_LIMIT |
9f95a23c TL |
116 | run_fio Malloc0 |
117 | verify_qos_limits $IOPS_RESULT $IOPS_LIMIT | |
118 | ||
11fdf7f2 TL |
119 | echo "I/O rate limiting tests successful" |
120 | ||
9f95a23c | 121 | # Limit the I/O bandwidth rate by RPC, then confirm the observed rate matches. |
f67539c2 | 122 | $rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec 0 --rw_mbytes_per_sec $BANDWIDTH_LIMIT_MB |
9f95a23c TL |
123 | run_fio Malloc0 |
124 | verify_qos_limits $BANDWIDTH_RESULT $BANDWIDTH_LIMIT | |
125 | ||
126 | # Now disable the bandwidth rate limiting, and confirm the observed rate is not limited anymore. | |
f67539c2 | 127 | $rpc_py bdev_set_qos_limit Malloc0 --rw_mbytes_per_sec 0 |
9f95a23c TL |
128 | run_fio Malloc0 |
129 | [ "$BANDWIDTH_RESULT" -gt "$BANDWIDTH_LIMIT" ] | |
130 | ||
131 | # Limit the I/O bandwidth rate again with both read/write and read/only. | |
f67539c2 | 132 | $rpc_py bdev_set_qos_limit Malloc0 --rw_mbytes_per_sec $BANDWIDTH_LIMIT_MB --r_mbytes_per_sec $READ_BANDWIDTH_LIMIT_MB |
9f95a23c TL |
133 | run_fio Malloc0 |
134 | verify_qos_limits $BANDWIDTH_RESULT $READ_BANDWIDTH_LIMIT | |
135 | ||
136 | echo "I/O bandwidth limiting tests successful" | |
137 | ||
11fdf7f2 | 138 | iscsicleanup |
f67539c2 | 139 | $rpc_py iscsi_delete_target_node 'iqn.2016-06.io.spdk:Target1' |
11fdf7f2 TL |
140 | |
141 | rm -f ./local-job0-0-verify.state | |
142 | trap - SIGINT SIGTERM EXIT | |
143 | killprocess $pid | |
144 | ||
9f95a23c | 145 | iscsitestfini $1 $2 |