| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2018 Western Digital Corporation or its affiliates. |
| 4 | # |
| 5 | # This file is released under the GPL. |
| 6 | |
| 7 | usage() { |
| 8 | echo "Usage: $(basename "$0") [-d] [-e] [-r] [-v] [-t <test>] <SMR drive device node>" |
| 9 | } |
| 10 | |
| 11 | max() { |
| 12 | if [ "$1" -gt "$2" ]; then |
| 13 | echo "$1" |
| 14 | else |
| 15 | echo "$2" |
| 16 | fi |
| 17 | } |
| 18 | |
| 19 | min() { |
| 20 | if [ "$1" -lt "$2" ]; then |
| 21 | echo "$1" |
| 22 | else |
| 23 | echo "$2" |
| 24 | fi |
| 25 | } |
| 26 | |
| 27 | set_io_scheduler() { |
| 28 | local dev=$1 sched=$2 |
| 29 | |
| 30 | [ -e "/sys/block/$dev" ] || return $? |
| 31 | if [ -e "/sys/block/$dev/mq" ]; then |
| 32 | case "$sched" in |
| 33 | noop) sched=none;; |
| 34 | deadline) sched=mq-deadline;; |
| 35 | esac |
| 36 | else |
| 37 | case "$sched" in |
| 38 | none) sched=noop;; |
| 39 | mq-deadline) sched=deadline;; |
| 40 | esac |
| 41 | fi |
| 42 | |
| 43 | echo "$sched" >"/sys/block/$dev/queue/scheduler" |
| 44 | } |
| 45 | |
| 46 | check_read() { |
| 47 | local read |
| 48 | |
| 49 | read=$(fio_read <"${logfile}.${test_number}") |
| 50 | echo "read: $read <> $1" >> "${logfile}.${test_number}" |
| 51 | [ "$read" = "$1" ] |
| 52 | } |
| 53 | |
| 54 | check_written() { |
| 55 | local written |
| 56 | |
| 57 | written=$(fio_written <"${logfile}.${test_number}") |
| 58 | echo "written: $written <> $1" >> "${logfile}.${test_number}" |
| 59 | [ "$written" = "$1" ] |
| 60 | } |
| 61 | |
| 62 | # Compare the reset count from the log file with reset count $2 using operator |
| 63 | # $1 (=, -ge, -gt, -le, -lt). |
| 64 | check_reset_count() { |
| 65 | local reset_count |
| 66 | |
| 67 | reset_count=$(fio_reset_count <"${logfile}.${test_number}") |
| 68 | echo "reset_count: test $reset_count $1 $2" >> "${logfile}.${test_number}" |
| 69 | eval "[ '$reset_count' '$1' '$2' ]" |
| 70 | } |
| 71 | |
| 72 | # Whether or not $1 (/dev/...) is a SCSI device. |
| 73 | is_scsi_device() { |
| 74 | local d f |
| 75 | |
| 76 | d=$(basename "$dev") |
| 77 | for f in /sys/class/scsi_device/*/device/block/"$d"; do |
| 78 | [ -e "$f" ] && return 0 |
| 79 | done |
| 80 | return 1 |
| 81 | } |
| 82 | |
| 83 | run_fio() { |
| 84 | local fio opts |
| 85 | |
| 86 | fio=$(dirname "$0")/../../fio |
| 87 | |
| 88 | opts=("--aux-path=/tmp" "--allow_file_create=0" "$@") |
| 89 | { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}" |
| 90 | |
| 91 | "${dynamic_analyzer[@]}" "$fio" "${opts[@]}" |
| 92 | } |
| 93 | |
| 94 | run_one_fio_job() { |
| 95 | local r |
| 96 | |
| 97 | r=$(((RANDOM << 16) | RANDOM)) |
| 98 | run_fio --name="$dev" --filename="$dev" "$@" --randseed="$r" \ |
| 99 | --thread=1 --direct=1 |
| 100 | } |
| 101 | |
| 102 | # Run fio on the first four sequential zones of the disk. |
| 103 | run_fio_on_seq() { |
| 104 | local opts=() |
| 105 | |
| 106 | opts+=("--offset=$((first_sequential_zone_sector * 512))") |
| 107 | opts+=("--size=$((4 * zone_size))" "--zonemode=zbd") |
| 108 | if [ -z "$is_zbd" ]; then |
| 109 | opts+=("--zonesize=${zone_size}") |
| 110 | fi |
| 111 | run_one_fio_job "${opts[@]}" "$@" |
| 112 | } |
| 113 | |
| 114 | # Check whether buffered writes are refused. |
| 115 | test1() { |
| 116 | run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K \ |
| 117 | --size="${zone_size}" --thread=1 \ |
| 118 | --zonemode=zbd --zonesize="${zone_size}" 2>&1 | |
| 119 | tee -a "${logfile}.${test_number}" | |
| 120 | grep -q 'Using direct I/O is mandatory for writing to ZBD drives' |
| 121 | local fio_rc=${PIPESTATUS[0]} grep_rc=${PIPESTATUS[2]} |
| 122 | case "$fio_rc" in |
| 123 | 0|1) ;; |
| 124 | *) return "$fio_rc" |
| 125 | esac |
| 126 | if [ -n "$is_zbd" ]; then |
| 127 | [ "$grep_rc" = 0 ] |
| 128 | else |
| 129 | [ "$grep_rc" != 0 ] |
| 130 | fi |
| 131 | } |
| 132 | |
| 133 | # Block size exceeds zone size. |
| 134 | test2() { |
| 135 | local bs off opts=() rc |
| 136 | |
| 137 | off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512)) |
| 138 | bs=$((2 * zone_size)) |
| 139 | opts+=("--name=job1" "--filename=$dev" "--rw=write" "--direct=1") |
| 140 | opts+=("--zonemode=zbd" "--offset=$off" "--bs=$bs" "--size=$bs") |
| 141 | if [ -z "$is_zbd" ]; then |
| 142 | opts+=("--zonesize=${zone_size}") |
| 143 | fi |
| 144 | run_fio "${opts[@]}" 2>&1 | |
| 145 | tee -a "${logfile}.${test_number}" | |
| 146 | grep -q 'No I/O performed' |
| 147 | } |
| 148 | |
| 149 | # Run fio against an empty zone. This causes fio to report "No I/O performed". |
| 150 | test3() { |
| 151 | local off opts=() rc |
| 152 | |
| 153 | off=$((first_sequential_zone_sector * 512 + 128 * zone_size)) |
| 154 | size=$((zone_size)) |
| 155 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) |
| 156 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=4K") |
| 157 | opts+=("--size=$size" "--zonemode=zbd") |
| 158 | opts+=("--ioengine=psync" "--rw=read" "--direct=1" "--thread=1") |
| 159 | if [ -z "$is_zbd" ]; then |
| 160 | opts+=("--zonesize=${zone_size}") |
| 161 | fi |
| 162 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? |
| 163 | grep -q "No I/O performed" "${logfile}.${test_number}" |
| 164 | rc=$? |
| 165 | if [ -n "$is_zbd" ]; then |
| 166 | [ $rc = 0 ] |
| 167 | else |
| 168 | [ $rc != 0 ] |
| 169 | fi |
| 170 | } |
| 171 | |
| 172 | # Run fio with --read_beyond_wp=1 against an empty zone. |
| 173 | test4() { |
| 174 | local off opts=() |
| 175 | |
| 176 | off=$((first_sequential_zone_sector * 512 + 129 * zone_size)) |
| 177 | size=$((zone_size)) |
| 178 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) |
| 179 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=$size") |
| 180 | opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1") |
| 181 | opts+=("--ioengine=psync" "--rw=read" "--direct=1" "--disable_lat=1") |
| 182 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}") |
| 183 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? |
| 184 | check_read $size || return $? |
| 185 | } |
| 186 | |
| 187 | # Sequential write to sequential zones. |
| 188 | test5() { |
| 189 | local size |
| 190 | |
| 191 | size=$((4 * zone_size)) |
| 192 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=write \ |
| 193 | --bs="$(max $((zone_size / 64)) "$logical_block_size")"\ |
| 194 | --do_verify=1 --verify=md5 \ |
| 195 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 196 | check_written $size || return $? |
| 197 | check_read $size || return $? |
| 198 | } |
| 199 | |
| 200 | # Sequential read from sequential zones. Must be run after test5. |
| 201 | test6() { |
| 202 | local size |
| 203 | |
| 204 | size=$((4 * zone_size)) |
| 205 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=read \ |
| 206 | --bs="$(max $((zone_size / 64)) "$logical_block_size")"\ |
| 207 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 208 | check_read $size || return $? |
| 209 | } |
| 210 | |
| 211 | # Random write to sequential zones, libaio, queue depth 1. |
| 212 | test7() { |
| 213 | local size=$((zone_size)) |
| 214 | |
| 215 | run_fio_on_seq --ioengine=libaio --iodepth=1 --rw=randwrite \ |
| 216 | --bs="$(min 16384 "${zone_size}")" \ |
| 217 | --do_verify=1 --verify=md5 --size="$size" \ |
| 218 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 219 | check_written $size || return $? |
| 220 | check_read $size || return $? |
| 221 | } |
| 222 | |
| 223 | # Random write to sequential zones, libaio, queue depth 64. |
| 224 | test8() { |
| 225 | local size |
| 226 | |
| 227 | size=$((4 * zone_size)) |
| 228 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite \ |
| 229 | --bs="$(min 16384 "${zone_size}")" \ |
| 230 | --do_verify=1 --verify=md5 \ |
| 231 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 232 | check_written $size || return $? |
| 233 | check_read $size || return $? |
| 234 | } |
| 235 | |
| 236 | # Random write to sequential zones, sg, queue depth 1. |
| 237 | test9() { |
| 238 | local size |
| 239 | |
| 240 | if ! is_scsi_device "$dev"; then |
| 241 | echo "$dev is not a SCSI device" >>"${logfile}.${test_number}" |
| 242 | return 0 |
| 243 | fi |
| 244 | |
| 245 | size=$((4 * zone_size)) |
| 246 | run_fio_on_seq --ioengine=sg --iodepth=1 --rw=randwrite --bs=16K \ |
| 247 | --do_verify=1 --verify=md5 \ |
| 248 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 249 | check_written $size || return $? |
| 250 | check_read $size || return $? |
| 251 | } |
| 252 | |
| 253 | # Random write to sequential zones, sg, queue depth 64. |
| 254 | test10() { |
| 255 | local size |
| 256 | |
| 257 | if ! is_scsi_device "$dev"; then |
| 258 | echo "$dev is not a SCSI device" >>"${logfile}.${test_number}" |
| 259 | return 0 |
| 260 | fi |
| 261 | |
| 262 | size=$((4 * zone_size)) |
| 263 | run_fio_on_seq --ioengine=sg --iodepth=64 --rw=randwrite --bs=16K \ |
| 264 | --do_verify=1 --verify=md5 \ |
| 265 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 266 | check_written $size || return $? |
| 267 | check_read $size || return $? |
| 268 | } |
| 269 | |
| 270 | # Random write to sequential zones, libaio, queue depth 64, random block size. |
| 271 | test11() { |
| 272 | local size |
| 273 | |
| 274 | size=$((4 * zone_size)) |
| 275 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite \ |
| 276 | --bsrange=4K-64K --do_verify=1 --verify=md5 \ |
| 277 | --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $? |
| 278 | check_written $size || return $? |
| 279 | check_read $size || return $? |
| 280 | } |
| 281 | |
| 282 | # Random write to sequential zones, libaio, queue depth 64, max 1 open zone. |
| 283 | test12() { |
| 284 | local size |
| 285 | |
| 286 | size=$((8 * zone_size)) |
| 287 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite --bs=16K \ |
| 288 | --max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \ |
| 289 | --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $? |
| 290 | check_written $size || return $? |
| 291 | check_read $size || return $? |
| 292 | } |
| 293 | |
| 294 | # Random write to sequential zones, libaio, queue depth 64, max 4 open zones. |
| 295 | test13() { |
| 296 | local size |
| 297 | |
| 298 | size=$((8 * zone_size)) |
| 299 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite --bs=16K \ |
| 300 | --max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \ |
| 301 | --debug=zbd \ |
| 302 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 303 | check_written $size || return $? |
| 304 | check_read $size || return $? |
| 305 | } |
| 306 | |
| 307 | # Random write to conventional zones. |
| 308 | test14() { |
| 309 | local size |
| 310 | |
| 311 | size=$((16 * 2**20)) # 20 MB |
| 312 | if [ $size -gt $((first_sequential_zone_sector * 512)) ]; then |
| 313 | echo "$dev does not have enough sequential zones" \ |
| 314 | >>"${logfile}.${test_number}" |
| 315 | return 0 |
| 316 | fi |
| 317 | run_one_fio_job --ioengine=libaio --iodepth=64 --rw=randwrite --bs=16K \ |
| 318 | --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \ |
| 319 | --verify=md5 --size=$size \ |
| 320 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 321 | check_written $((size)) || return $? |
| 322 | check_read $((size)) || return $? |
| 323 | } |
| 324 | |
| 325 | # Sequential read on a mix of empty and full zones. |
| 326 | test15() { |
| 327 | local i off size |
| 328 | |
| 329 | for ((i=0;i<4;i++)); do |
| 330 | [ -n "$is_zbd" ] && |
| 331 | reset_zone "$dev" $((first_sequential_zone_sector + |
| 332 | i*sectors_per_zone)) |
| 333 | done |
| 334 | off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512)) |
| 335 | size=$((2 * zone_size)) |
| 336 | run_one_fio_job --ioengine=psync --rw=write --bs=$((zone_size / 16))\ |
| 337 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off \ |
| 338 | --size=$size >>"${logfile}.${test_number}" 2>&1 || |
| 339 | return $? |
| 340 | check_written $size || return $? |
| 341 | off=$((first_sequential_zone_sector * 512)) |
| 342 | size=$((4 * zone_size)) |
| 343 | run_one_fio_job --ioengine=psync --rw=read --bs=$((zone_size / 16)) \ |
| 344 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off \ |
| 345 | --size=$((size)) >>"${logfile}.${test_number}" 2>&1 || |
| 346 | return $? |
| 347 | if [ -n "$is_zbd" ]; then |
| 348 | check_read $((size / 2)) |
| 349 | else |
| 350 | check_read $size |
| 351 | fi |
| 352 | } |
| 353 | |
| 354 | # Random read on a mix of empty and full zones. Must be run after test15. |
| 355 | test16() { |
| 356 | local off size |
| 357 | |
| 358 | off=$((first_sequential_zone_sector * 512)) |
| 359 | size=$((4 * zone_size)) |
| 360 | run_one_fio_job --ioengine=libaio --iodepth=64 --rw=randread --bs=16K \ |
| 361 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off \ |
| 362 | --size=$size >>"${logfile}.${test_number}" 2>&1 || return $? |
| 363 | check_read $size || return $? |
| 364 | } |
| 365 | |
| 366 | # Random reads and writes in the last zone. |
| 367 | test17() { |
| 368 | local io off read size written |
| 369 | |
| 370 | off=$(((disk_size / zone_size - 1) * zone_size)) |
| 371 | size=$((disk_size - off)) |
| 372 | # Overwrite the last zone to avoid that reading from that zone fails. |
| 373 | if [ -n "$is_zbd" ]; then |
| 374 | reset_zone "$dev" $((off / 512)) || return $? |
| 375 | fi |
| 376 | run_one_fio_job --ioengine=psync --rw=write --offset="$off" \ |
| 377 | --zonemode=zbd --zonesize="${zone_size}" \ |
| 378 | --bs="$zone_size" --size="$zone_size" \ |
| 379 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 380 | check_written "$zone_size" || return $? |
| 381 | run_one_fio_job --ioengine=libaio --iodepth=8 --rw=randrw --bs=4K \ |
| 382 | --zonemode=zbd --zonesize="${zone_size}" \ |
| 383 | --offset=$off --loops=2 --norandommap=1\ |
| 384 | >>"${logfile}.${test_number}" 2>&1 || return $? |
| 385 | written=$(fio_written <"${logfile}.${test_number}") |
| 386 | read=$(fio_read <"${logfile}.${test_number}") |
| 387 | io=$((written + read)) |
| 388 | echo "Total number of bytes read and written: $io <> $size" \ |
| 389 | >>"${logfile}.${test_number}" |
| 390 | [ $io = $((size * 2)) ]; |
| 391 | } |
| 392 | |
| 393 | # Out-of-range zone reset threshold and frequency parameters. |
| 394 | test18() { |
| 395 | run_fio_on_seq --zone_reset_threshold=-1 |& |
| 396 | tee -a "${logfile}.${test_number}" | |
| 397 | grep -q 'value out of range' || return $? |
| 398 | } |
| 399 | |
| 400 | test19() { |
| 401 | run_fio_on_seq --zone_reset_threshold=2 |& |
| 402 | tee -a "${logfile}.${test_number}" | |
| 403 | grep -q 'value out of range' || return $? |
| 404 | } |
| 405 | |
| 406 | test20() { |
| 407 | run_fio_on_seq --zone_reset_threshold=.4:.6 |& |
| 408 | tee -a "${logfile}.${test_number}" | |
| 409 | grep -q 'the list exceeding max length' || return $? |
| 410 | } |
| 411 | |
| 412 | test21() { |
| 413 | run_fio_on_seq --zone_reset_frequency=-1 |& |
| 414 | tee -a "${logfile}.${test_number}" | |
| 415 | grep -q 'value out of range' || return $? |
| 416 | } |
| 417 | |
| 418 | test22() { |
| 419 | run_fio_on_seq --zone_reset_frequency=2 |& |
| 420 | tee -a "${logfile}.${test_number}" | |
| 421 | grep -q 'value out of range' || return $? |
| 422 | } |
| 423 | |
| 424 | test23() { |
| 425 | run_fio_on_seq --zone_reset_frequency=.4:.6 |& |
| 426 | tee -a "${logfile}.${test_number}" | |
| 427 | grep -q 'the list exceeding max length' || return $? |
| 428 | } |
| 429 | |
| 430 | test24() { |
| 431 | local bs loops=9 size=$((zone_size)) |
| 432 | |
| 433 | bs=$(min $((256*1024)) "$zone_size") |
| 434 | run_fio_on_seq --ioengine=psync --rw=write --bs="$bs" --size=$size \ |
| 435 | --loops=$loops \ |
| 436 | --zone_reset_frequency=.01 --zone_reset_threshold=.90 \ |
| 437 | >> "${logfile}.${test_number}" 2>&1 || return $? |
| 438 | check_written $((size * loops)) || return $? |
| 439 | check_reset_count -eq 8 || |
| 440 | check_reset_count -eq 9 || |
| 441 | check_reset_count -eq 10 || return $? |
| 442 | } |
| 443 | |
| 444 | # Multiple non-overlapping sequential write jobs for the same drive. |
| 445 | test25() { |
| 446 | local i opts=() |
| 447 | |
| 448 | for ((i=0;i<16;i++)); do |
| 449 | [ -n "$is_zbd" ] && |
| 450 | reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone)) |
| 451 | done |
| 452 | for ((i=0;i<16;i++)); do |
| 453 | opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1") |
| 454 | opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))") |
| 455 | opts+=("--size=$zone_size" "--ioengine=psync" "--rw=write" "--bs=16K") |
| 456 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1") |
| 457 | done |
| 458 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? |
| 459 | } |
| 460 | |
| 461 | write_to_first_seq_zone() { |
| 462 | local loops=4 r |
| 463 | |
| 464 | r=$(((RANDOM << 16) | RANDOM)) |
| 465 | run_fio --name="$dev" --filename="$dev" --ioengine=psync --rw="$1" \ |
| 466 | --thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \ |
| 467 | --offset=$((first_sequential_zone_sector * 512)) \ |
| 468 | "--size=$zone_size" --loops=$loops --randseed="$r" \ |
| 469 | --zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \ |
| 470 | --gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $? |
| 471 | check_written $((loops * zone_size)) || return $? |
| 472 | } |
| 473 | |
| 474 | # Overwrite the first sequential zone four times sequentially. |
| 475 | test26() { |
| 476 | write_to_first_seq_zone write |
| 477 | } |
| 478 | |
| 479 | # Overwrite the first sequential zone four times using random writes. |
| 480 | test27() { |
| 481 | write_to_first_seq_zone randwrite |
| 482 | } |
| 483 | |
| 484 | # Multiple overlapping random write jobs for the same drive. |
| 485 | test28() { |
| 486 | local i jobs=16 off opts |
| 487 | |
| 488 | off=$((first_sequential_zone_sector * 512 + 64 * zone_size)) |
| 489 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) |
| 490 | opts=("--debug=zbd") |
| 491 | for ((i=0;i<jobs;i++)); do |
| 492 | opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K") |
| 493 | opts+=("--size=$zone_size" "--ioengine=psync" "--rw=randwrite") |
| 494 | opts+=("--thread=1" "--direct=1" "--zonemode=zbd") |
| 495 | opts+=("--zonesize=${zone_size}" "--group_reporting=1") |
| 496 | done |
| 497 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? |
| 498 | check_written $((jobs * zone_size)) || return $? |
| 499 | check_reset_count -eq $jobs || |
| 500 | check_reset_count -eq $((jobs - 1)) || |
| 501 | return $? |
| 502 | } |
| 503 | |
| 504 | # Multiple overlapping random write jobs for the same drive and with a limited |
| 505 | # number of open zones. |
| 506 | test29() { |
| 507 | local i jobs=16 off opts=() |
| 508 | |
| 509 | off=$((first_sequential_zone_sector * 512 + 64 * zone_size)) |
| 510 | size=$((16*zone_size)) |
| 511 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) |
| 512 | opts=("--debug=zbd") |
| 513 | for ((i=0;i<jobs;i++)); do |
| 514 | opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K") |
| 515 | opts+=("--size=$size" "--io_size=$zone_size" "--thread=1") |
| 516 | opts+=("--ioengine=psync" "--rw=randwrite" "--direct=1") |
| 517 | opts+=("--max_open_zones=4" "--group_reporting=1") |
| 518 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}") |
| 519 | done |
| 520 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? |
| 521 | check_written $((jobs * zone_size)) || return $? |
| 522 | } |
| 523 | |
| 524 | # Random reads and writes across the entire disk for 30s. |
| 525 | test30() { |
| 526 | local off |
| 527 | |
| 528 | off=$((first_sequential_zone_sector * 512)) |
| 529 | run_one_fio_job --ioengine=libaio --iodepth=8 --rw=randrw \ |
| 530 | --bs="$(max $((zone_size / 128)) "$logical_block_size")"\ |
| 531 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off\ |
| 532 | --loops=2 --time_based --runtime=30s --norandommap=1\ |
| 533 | >>"${logfile}.${test_number}" 2>&1 |
| 534 | } |
| 535 | |
| 536 | # Random reads across all sequential zones for 30s. This is not only a fio |
| 537 | # test but also allows to verify the performance of a drive. |
| 538 | test31() { |
| 539 | local bs inc nz off opts size |
| 540 | |
| 541 | # Start with writing 128 KB to 128 sequential zones. |
| 542 | bs=128K |
| 543 | nz=128 |
| 544 | # shellcheck disable=SC2017 |
| 545 | inc=$(((disk_size - (first_sequential_zone_sector * 512)) / (nz * zone_size) |
| 546 | * zone_size)) |
| 547 | opts=() |
| 548 | for ((off = first_sequential_zone_sector * 512; off < disk_size; |
| 549 | off += inc)); do |
| 550 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--io_size=$bs") |
| 551 | opts+=("--bs=$bs" "--size=$zone_size" "--ioengine=libaio") |
| 552 | opts+=("--rw=write" "--direct=1" "--thread=1" "--stats=0") |
| 553 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}") |
| 554 | done |
| 555 | "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 |
| 556 | # Next, run the test. |
| 557 | off=$((first_sequential_zone_sector * 512)) |
| 558 | size=$((disk_size - off)) |
| 559 | opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size") |
| 560 | opts+=("--bs=$bs" "--ioengine=psync" "--rw=randread" "--direct=1") |
| 561 | opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd") |
| 562 | opts+=("--zonesize=${zone_size}") |
| 563 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? |
| 564 | } |
| 565 | |
| 566 | # Random writes across all sequential zones. This is not only a fio test but |
| 567 | # also allows to verify the performance of a drive. |
| 568 | test32() { |
| 569 | local off opts=() size |
| 570 | |
| 571 | off=$((first_sequential_zone_sector * 512)) |
| 572 | size=$((disk_size - off)) |
| 573 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size") |
| 574 | opts+=("--bs=128K" "--ioengine=psync" "--rw=randwrite" "--direct=1") |
| 575 | opts+=("--thread=1" "--time_based" "--runtime=30") |
| 576 | opts+=("--max_open_zones=$max_open_zones" "--zonemode=zbd") |
| 577 | opts+=("--zonesize=${zone_size}") |
| 578 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? |
| 579 | } |
| 580 | |
| 581 | # Write to sequential zones with a block size that is not a divisor of the |
| 582 | # zone size. |
| 583 | test33() { |
| 584 | local bs io_size size |
| 585 | |
| 586 | size=$((2 * zone_size)) |
| 587 | io_size=$((5 * zone_size)) |
| 588 | bs=$((3 * zone_size / 4)) |
| 589 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=write --size=$size \ |
| 590 | --io_size=$io_size --bs=$bs \ |
| 591 | >> "${logfile}.${test_number}" 2>&1 || return $? |
| 592 | check_written $(((io_size + bs - 1) / bs * bs)) || return $? |
| 593 | } |
| 594 | |
| 595 | # Write to sequential zones with a block size that is not a divisor of the |
| 596 | # zone size and with data verification enabled. |
| 597 | test34() { |
| 598 | local size |
| 599 | |
| 600 | size=$((2 * zone_size)) |
| 601 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=write --size=$size \ |
| 602 | --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \ |
| 603 | >> "${logfile}.${test_number}" 2>&1 && return 1 |
| 604 | grep -q 'not a divisor of' "${logfile}.${test_number}" |
| 605 | } |
| 606 | |
| 607 | # Test 1/4 for the I/O boundary rounding code: $size < $zone_size. |
| 608 | test35() { |
| 609 | local bs off io_size size |
| 610 | |
| 611 | off=$(((first_sequential_zone_sector + 1) * 512)) |
| 612 | size=$((zone_size - 2 * 512)) |
| 613 | bs=$((zone_size / 4)) |
| 614 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ |
| 615 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ |
| 616 | --zonemode=zbd --zonesize="${zone_size}" \ |
| 617 | >> "${logfile}.${test_number}" 2>&1 && return 1 |
| 618 | grep -q 'io_size must be at least one zone' "${logfile}.${test_number}" |
| 619 | } |
| 620 | |
| 621 | # Test 2/4 for the I/O boundary rounding code: $size < $zone_size. |
| 622 | test36() { |
| 623 | local bs off io_size size |
| 624 | |
| 625 | off=$(((first_sequential_zone_sector) * 512)) |
| 626 | size=$((zone_size - 512)) |
| 627 | bs=$((zone_size / 4)) |
| 628 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ |
| 629 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ |
| 630 | --zonemode=zbd --zonesize="${zone_size}" \ |
| 631 | >> "${logfile}.${test_number}" 2>&1 && return 1 |
| 632 | grep -q 'io_size must be at least one zone' "${logfile}.${test_number}" |
| 633 | } |
| 634 | |
| 635 | # Test 3/4 for the I/O boundary rounding code: $size > $zone_size. |
| 636 | test37() { |
| 637 | local bs off size |
| 638 | |
| 639 | if [ "$first_sequential_zone_sector" = 0 ]; then |
| 640 | off=0 |
| 641 | else |
| 642 | off=$(((first_sequential_zone_sector - 1) * 512)) |
| 643 | fi |
| 644 | size=$((zone_size + 2 * 512)) |
| 645 | bs=$((zone_size / 4)) |
| 646 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ |
| 647 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ |
| 648 | --zonemode=zbd --zonesize="${zone_size}" \ |
| 649 | >> "${logfile}.${test_number}" 2>&1 |
| 650 | check_written $((zone_size)) || return $? |
| 651 | } |
| 652 | |
| 653 | # Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size |
| 654 | test38() { |
| 655 | local bs off size |
| 656 | |
| 657 | size=$((logical_block_size)) |
| 658 | off=$((disk_size - logical_block_size)) |
| 659 | bs=$((logical_block_size)) |
| 660 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ |
| 661 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ |
| 662 | --zonemode=zbd --zonesize="${zone_size}" \ |
| 663 | >> "${logfile}.${test_number}" 2>&1 && return 1 |
| 664 | grep -q 'io_size must be at least one zone' "${logfile}.${test_number}" |
| 665 | } |
| 666 | |
| 667 | # Read one block from a block device. |
| 668 | read_one_block() { |
| 669 | local bs |
| 670 | |
| 671 | bs=$((logical_block_size)) |
| 672 | run_one_fio_job --rw=read --ioengine=psync --bs=$bs --size=$bs "$@" 2>&1 | |
| 673 | tee -a "${logfile}.${test_number}" |
| 674 | } |
| 675 | |
| 676 | # Check whether fio accepts --zonemode=none for zoned block devices. |
| 677 | test39() { |
| 678 | [ -n "$is_zbd" ] || return 0 |
| 679 | read_one_block --zonemode=none >/dev/null || return $? |
| 680 | check_read $((logical_block_size)) || return $? |
| 681 | } |
| 682 | |
| 683 | # Check whether fio accepts --zonemode=strided for zoned block devices. |
| 684 | test40() { |
| 685 | local bs |
| 686 | |
| 687 | bs=$((logical_block_size)) |
| 688 | [ -n "$is_zbd" ] || return 0 |
| 689 | read_one_block --zonemode=strided | |
| 690 | grep -q 'fio: --zonesize must be specified when using --zonemode=strided' || |
| 691 | return $? |
| 692 | read_one_block --zonemode=strided --zonesize=$bs >/dev/null || return $? |
| 693 | check_read $bs || return $? |
| 694 | } |
| 695 | |
| 696 | # Check whether fio checks the zone size for zoned block devices. |
| 697 | test41() { |
| 698 | [ -n "$is_zbd" ] || return 0 |
| 699 | read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) | |
| 700 | grep -q 'job parameter zonesize.*does not match disk zone size' |
| 701 | } |
| 702 | |
| 703 | # Check whether fio handles --zonesize=0 correctly for regular block devices. |
| 704 | test42() { |
| 705 | [ -n "$is_zbd" ] && return 0 |
| 706 | read_one_block --zonemode=zbd --zonesize=0 | |
| 707 | grep -q 'Specifying the zone size is mandatory for regular block devices with --zonemode=zbd' |
| 708 | } |
| 709 | |
| 710 | # Check whether fio handles --zonesize=1 correctly. |
| 711 | test43() { |
| 712 | read_one_block --zonemode=zbd --zonesize=1 | |
| 713 | grep -q 'zone size must be at least 512 bytes for --zonemode=zbd' |
| 714 | } |
| 715 | |
| 716 | # Check whether fio handles --zonemode=none --zonesize=1 correctly. |
| 717 | test44() { |
| 718 | read_one_block --zonemode=none --zonesize=1 | |
| 719 | grep -q 'fio: --zonemode=none and --zonesize are not compatible' |
| 720 | } |
| 721 | |
| 722 | test45() { |
| 723 | local bs i |
| 724 | |
| 725 | [ -z "$is_zbd" ] && return 0 |
| 726 | bs=$((logical_block_size)) |
| 727 | run_one_fio_job --ioengine=psync --iodepth=1 --rw=randwrite --bs=$bs\ |
| 728 | --offset=$((first_sequential_zone_sector * 512)) \ |
| 729 | --size="$zone_size" --do_verify=1 --verify=md5 2>&1 | |
| 730 | tee -a "${logfile}.${test_number}" | |
| 731 | grep -q "fio: first I/O failed. If .* is a zoned block device, consider --zonemode=zbd" |
| 732 | } |
| 733 | |
| 734 | tests=() |
| 735 | dynamic_analyzer=() |
| 736 | reset_all_zones= |
| 737 | |
| 738 | while [ "${1#-}" != "$1" ]; do |
| 739 | case "$1" in |
| 740 | -d) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=drd" |
| 741 | "--show-confl-seg=no"); |
| 742 | shift;; |
| 743 | -e) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=helgrind"); |
| 744 | shift;; |
| 745 | -r) reset_all_zones=1; shift;; |
| 746 | -t) tests+=("$2"); shift; shift;; |
| 747 | -v) dynamic_analyzer=(valgrind "--read-var-info=yes"); |
| 748 | shift;; |
| 749 | --) shift; break;; |
| 750 | esac |
| 751 | done |
| 752 | |
| 753 | if [ $# != 1 ]; then |
| 754 | usage |
| 755 | exit 1 |
| 756 | fi |
| 757 | |
| 758 | # shellcheck source=functions |
| 759 | source "$(dirname "$0")/functions" || exit $? |
| 760 | |
| 761 | dev=$1 |
| 762 | realdev=$(readlink -f "$dev") |
| 763 | basename=$(basename "$realdev") |
| 764 | disk_size=$(($(<"/sys/block/$basename/size")*512)) |
| 765 | logical_block_size=$(<"/sys/block/$basename/queue/logical_block_size") |
| 766 | case "$(<"/sys/class/block/$basename/queue/zoned")" in |
| 767 | host-managed|host-aware) |
| 768 | is_zbd=true |
| 769 | if ! result=($(first_sequential_zone "$dev")); then |
| 770 | echo "Failed to determine first sequential zone" |
| 771 | exit 1 |
| 772 | fi |
| 773 | first_sequential_zone_sector=${result[0]} |
| 774 | sectors_per_zone=${result[1]} |
| 775 | zone_size=$((sectors_per_zone * 512)) |
| 776 | if ! max_open_zones=$(max_open_zones "$dev"); then |
| 777 | echo "Failed to determine maximum number of open zones" |
| 778 | exit 1 |
| 779 | fi |
| 780 | echo "First sequential zone starts at sector $first_sequential_zone_sector; zone size: $((zone_size >> 20)) MB" |
| 781 | set_io_scheduler "$basename" deadline || exit $? |
| 782 | if [ -n "$reset_all_zones" ]; then |
| 783 | reset_zone "$dev" -1 |
| 784 | fi |
| 785 | ;; |
| 786 | *) |
| 787 | first_sequential_zone_sector=$(((disk_size / 2) & |
| 788 | (logical_block_size - 1))) |
| 789 | zone_size=$(max 65536 "$logical_block_size") |
| 790 | sectors_per_zone=$((zone_size / 512)) |
| 791 | max_open_zones=128 |
| 792 | set_io_scheduler "$basename" none || exit $? |
| 793 | ;; |
| 794 | esac |
| 795 | |
| 796 | if [ "${#tests[@]}" = 0 ]; then |
| 797 | for ((i=1;i<=45;i++)); do |
| 798 | tests+=("$i") |
| 799 | done |
| 800 | fi |
| 801 | |
| 802 | logfile=$0.log |
| 803 | |
| 804 | passed=0 |
| 805 | failed=0 |
| 806 | rc=0 |
| 807 | for test_number in "${tests[@]}"; do |
| 808 | rm -f "${logfile}.${test_number}" |
| 809 | echo -n "Running test $test_number ... " |
| 810 | if eval "test$test_number"; then |
| 811 | status="PASS" |
| 812 | ((passed++)) |
| 813 | else |
| 814 | status="FAIL" |
| 815 | ((failed++)) |
| 816 | rc=1 |
| 817 | fi |
| 818 | echo "$status" |
| 819 | echo "$status" >> "${logfile}.${test_number}" |
| 820 | done |
| 821 | |
| 822 | echo "$passed tests passed" |
| 823 | if [ $failed -gt 0 ]; then |
| 824 | echo " and $failed tests failed" |
| 825 | fi |
| 826 | exit $rc |