3 # Copyright (C) 2018 Western Digital Corporation or its affiliates.
5 # This file is released under the GPL.
8 echo "Usage: $(basename "$0") [OPTIONS] <test target device file>"
10 echo -e "\t-d Run fio with valgrind using DRD tool"
11 echo -e "\t-e Run fio with valgrind using helgrind tool"
12 echo -e "\t-v Run fio with valgrind --read-var-info option"
13 echo -e "\t-l Test with libzbc ioengine"
14 echo -e "\t-r Reset all zones before test start"
15 echo -e "\t-o <max_open_zones> Run fio with max_open_zones limit"
16 echo -e "\t-t <test #> Run only a single test case with specified number"
17 echo -e "\t-z Run fio with debug=zbd option"
21 if [ "$1" -gt "$2" ]; then
29 if [ "$1" -lt "$2" ]; then
37 if [ -n "$use_libzbc" ]; then
38 echo -n "--ioengine=libzbc"
40 echo -n "--ioengine=$1"
47 [ -e "/sys/block/$dev" ] || return $?
48 if [ -e "/sys/block/$dev/mq" ]; then
51 deadline) sched=mq-deadline;;
56 mq-deadline) sched=deadline;;
60 echo "$sched" >"/sys/block/$dev/queue/scheduler"
66 read=$(fio_read <"${logfile}.${test_number}")
67 echo "read: $read <> $1" >> "${logfile}.${test_number}"
74 written=$(fio_written <"${logfile}.${test_number}")
75 echo "written: $written <> $1" >> "${logfile}.${test_number}"
79 # Compare the reset count from the log file with reset count $2 using operator
80 # $1 (=, -ge, -gt, -le, -lt).
84 reset_count=$(fio_reset_count <"${logfile}.${test_number}")
85 echo "reset_count: test $reset_count $1 $2" >> "${logfile}.${test_number}"
86 eval "[ '$reset_count' '$1' '$2' ]"
89 # Check log for failed assertions and crashes. Without these checks,
90 # a test can succeed even when these events happen, but it must fail.
92 [ ! -f "${logfile}.${1}" ] && return 0
93 ! grep -q -e "Assertion " -e "Aborted " "${logfile}.${1}"
96 # Whether or not $1 (/dev/...) is a SCSI device.
101 for f in /sys/class/scsi_device/*/device/block/"$d"; do
102 [ -e "$f" ] && return 0
107 job_var_opts_exclude() {
111 for o in "${job_var_opts[@]}"; do
112 if [[ ${o} =~ "${ex_key}" ]]; then
119 has_max_open_zones() {
121 if [[ ${1} =~ "--max_open_zones" ]]; then
132 fio=$(dirname "$0")/../../fio
134 opts=(${global_var_opts[@]})
135 opts+=("--max-jobs=16" "--aux-path=/tmp" "--allow_file_create=0" \
136 "--significant_figures=10" "$@")
137 # When max_open_zones option is specified to this test script, add
138 # max_open_zones option to fio command unless the test case already add it.
139 if [[ -n ${max_open_zones_opt} ]] && ! has_max_open_zones "${opts[@]}"; then
140 opts+=("--max_open_zones=${max_open_zones_opt}")
142 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
144 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}"
150 r=$(((RANDOM << 16) | RANDOM))
151 run_fio --name="$dev" --filename="$dev" "$@" --randseed="$r" \
152 --thread=1 --direct=1
155 write_and_run_one_fio_job() {
157 local write_offset="${1}"
158 local write_size="${2}"
162 r=$(((RANDOM << 16) | RANDOM))
163 write_opts=(--name="write_job" --rw=write "$(ioengine "psync")" \
164 --bs="${logical_block_size}" --zonemode=zbd \
165 --zonesize="${zone_size}" --thread=1 --direct=1 \
166 --offset="${write_offset}" --size="${write_size}")
167 write_opts+=("${job_var_opts[@]}")
168 run_fio --filename="$dev" --randseed="$r" "${write_opts[@]}" \
169 --name="$dev" --wait_for="write_job" "$@" --thread=1 --direct=1
172 # Run fio on the first four sequential zones of the disk.
176 opts+=("--offset=$((first_sequential_zone_sector * 512))")
177 opts+=("--size=$((4 * zone_size))" "--zonemode=zbd")
178 if [ -z "$is_zbd" ]; then
179 opts+=("--zonesize=${zone_size}")
181 run_one_fio_job "${opts[@]}" "$@"
184 # Check whether buffered writes are refused.
186 run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K \
187 "$(ioengine "psync")" --size="${zone_size}" --thread=1 \
188 --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
189 tee -a "${logfile}.${test_number}" |
190 grep -q 'Using direct I/O is mandatory for writing to ZBD drives'
191 local fio_rc=${PIPESTATUS[0]} grep_rc=${PIPESTATUS[2]}
196 if [ -n "$is_zbd" ]; then
203 # Block size exceeds zone size.
205 local bs off opts=() rc
207 off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
208 bs=$((2 * zone_size))
209 opts+=("$(ioengine "psync")")
210 opts+=("--name=job1" "--filename=$dev" "--rw=write" "--direct=1")
211 opts+=("--zonemode=zbd" "--offset=$off" "--bs=$bs" "--size=$bs")
212 if [ -z "$is_zbd" ]; then
213 opts+=("--zonesize=${zone_size}")
215 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
216 ! grep -q 'WRITE:' "${logfile}.${test_number}"
219 # Run fio against an empty zone. This causes fio to report "No I/O performed".
223 off=$((first_sequential_zone_sector * 512 + 128 * zone_size))
225 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
226 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=4K")
227 opts+=("--size=$size" "--zonemode=zbd")
228 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--thread=1")
229 if [ -z "$is_zbd" ]; then
230 opts+=("--zonesize=${zone_size}")
232 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
233 ! grep -q 'READ:' "${logfile}.${test_number}"
236 # Run fio with --read_beyond_wp=1 against an empty zone.
240 off=$((first_sequential_zone_sector * 512 + 129 * zone_size))
242 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
243 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=$size")
244 opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1")
245 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--disable_lat=1")
246 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
247 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
248 check_read $size || return $?
251 # Sequential write to sequential zones.
253 local size off capacity
255 off=$((first_sequential_zone_sector * 512))
256 capacity=$(total_zone_capacity 4 $off $dev)
257 size=$((4 * zone_size))
258 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
259 --bs="$(max $((zone_size / 64)) "$logical_block_size")"\
260 --do_verify=1 --verify=md5 \
261 >>"${logfile}.${test_number}" 2>&1 || return $?
262 check_written $capacity || return $?
263 check_read $capacity || return $?
266 # Sequential read from sequential zones.
268 local size off capacity
270 off=$((first_sequential_zone_sector * 512))
271 capacity=$(total_zone_capacity 4 $off $dev)
272 size=$((4 * zone_size))
273 write_and_run_one_fio_job \
274 $((first_sequential_zone_sector * 512)) "${size}" \
276 --size="${size}" --zonemode=zbd --zonesize="${zone_size}" \
277 "$(ioengine "psync")" --iodepth=1 --rw=read \
278 --bs="$(max $((zone_size / 64)) "$logical_block_size")" \
279 >>"${logfile}.${test_number}" 2>&1 || return $?
280 check_read $capacity || return $?
283 # Random write to sequential zones, libaio, queue depth 1.
285 local size=$((zone_size))
288 off=$((first_sequential_zone_sector * 512))
289 capacity=$(total_zone_capacity 1 $off $dev)
290 run_fio_on_seq "$(ioengine "libaio")" --iodepth=1 --rw=randwrite \
291 --bs="$(min 16384 "${zone_size}")" \
292 --do_verify=1 --verify=md5 --size="$size" \
293 >>"${logfile}.${test_number}" 2>&1 || return $?
294 check_written $capacity || return $?
295 check_read $capacity || return $?
298 # Random write to sequential zones, libaio, queue depth 64.
300 local size off capacity
302 size=$((4 * zone_size))
303 off=$((first_sequential_zone_sector * 512))
304 capacity=$(total_zone_capacity 4 $off $dev)
305 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
306 --bs="$(min 16384 "${zone_size}")" \
307 --do_verify=1 --verify=md5 \
308 >>"${logfile}.${test_number}" 2>&1 || return $?
309 check_written $capacity || return $?
310 check_read $capacity || return $?
313 # Random write to sequential zones, sg, queue depth 1.
317 if ! is_scsi_device "$dev"; then
318 echo "$dev is not a SCSI device" >>"${logfile}.${test_number}"
322 size=$((4 * zone_size))
323 run_fio_on_seq --ioengine=sg \
324 --iodepth=1 --rw=randwrite --bs=16K \
325 --do_verify=1 --verify=md5 \
326 >>"${logfile}.${test_number}" 2>&1 || return $?
327 check_written $size || return $?
328 check_read $size || return $?
331 # Random write to sequential zones, sg, queue depth 64.
335 if ! is_scsi_device "$dev"; then
336 echo "$dev is not a SCSI device" >>"${logfile}.${test_number}"
340 size=$((4 * zone_size))
341 run_fio_on_seq --ioengine=sg \
342 --iodepth=64 --rw=randwrite --bs=16K \
343 --do_verify=1 --verify=md5 \
344 >>"${logfile}.${test_number}" 2>&1 || return $?
345 check_written $size || return $?
346 check_read $size || return $?
349 # Random write to sequential zones, libaio, queue depth 64, random block size.
351 local size off capacity
353 size=$((4 * zone_size))
354 off=$((first_sequential_zone_sector * 512))
355 capacity=$(total_zone_capacity 4 $off $dev)
356 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
357 --bsrange=4K-64K --do_verify=1 --verify=md5 \
358 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
359 check_written $capacity || return $?
360 check_read $capacity || return $?
363 # Random write to sequential zones, libaio, queue depth 64, max 1 open zone.
365 local size off capacity
367 size=$((8 * zone_size))
368 off=$((first_sequential_zone_sector * 512))
369 capacity=$(total_zone_capacity 8 $off $dev)
370 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
371 --max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \
372 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
373 check_written $capacity || return $?
374 check_read $capacity || return $?
377 # Random write to sequential zones, libaio, queue depth 64, max 4 open zones.
379 local size off capacity
381 size=$((8 * zone_size))
382 off=$((first_sequential_zone_sector * 512))
383 capacity=$(total_zone_capacity 8 $off $dev)
384 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
385 --max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \
387 >>"${logfile}.${test_number}" 2>&1 || return $?
388 check_written $capacity || return $?
389 check_read $capacity || return $?
392 # Random write to conventional zones.
396 size=$((16 * 2**20)) # 20 MB
397 if [ $size -gt $((first_sequential_zone_sector * 512)) ]; then
398 echo "$dev does not have enough sequential zones" \
399 >>"${logfile}.${test_number}"
402 run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
403 --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \
404 --verify=md5 --size=$size \
405 >>"${logfile}.${test_number}" 2>&1 || return $?
406 check_written $((size)) || return $?
407 check_read $((size)) || return $?
410 # Sequential read on a mix of empty and full zones.
413 local w_off w_size w_capacity
415 for ((i=0;i<4;i++)); do
417 reset_zone "$dev" $((first_sequential_zone_sector +
420 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
421 w_size=$((2 * zone_size))
422 w_capacity=$(total_zone_capacity 2 $w_off $dev)
423 off=$((first_sequential_zone_sector * 512))
424 size=$((4 * zone_size))
425 write_and_run_one_fio_job "${w_off}" "${w_size}" \
426 "$(ioengine "psync")" --rw=read --bs=$((zone_size / 16)) \
427 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
428 --size=$((size)) >>"${logfile}.${test_number}" 2>&1 ||
430 check_written $((w_capacity)) || return $?
431 check_read $((w_capacity))
434 # Random read on a mix of empty and full zones.
437 local i w_off w_size w_capacity
439 for ((i=0;i<4;i++)); do
441 reset_zone "$dev" $((first_sequential_zone_sector +
444 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
445 w_size=$((2 * zone_size))
446 w_capacity=$(total_zone_capacity 2 $w_off $dev)
447 off=$((first_sequential_zone_sector * 512))
448 size=$((4 * zone_size))
449 write_and_run_one_fio_job "${w_off}" "${w_size}" \
450 "$(ioengine "libaio")" --iodepth=64 --rw=randread --bs=16K \
451 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
452 --size=$size >>"${logfile}.${test_number}" 2>&1 || return $?
453 check_written $w_capacity || return $?
454 check_read $size || return $?
457 # Random reads and writes in the last zone.
459 local io off read size written
461 off=$(((disk_size / zone_size - 1) * zone_size))
462 size=$((disk_size - off))
463 if [ -n "$is_zbd" ]; then
464 reset_zone "$dev" $((off / 512)) || return $?
466 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
467 --zonemode=zbd --zonesize="${zone_size}" \
468 --offset=$off --loops=2 --norandommap=1\
469 >>"${logfile}.${test_number}" 2>&1 || return $?
470 written=$(fio_written <"${logfile}.${test_number}")
471 read=$(fio_read <"${logfile}.${test_number}")
472 io=$((written + read))
473 echo "Total number of bytes read and written: $io <> $size" \
474 >>"${logfile}.${test_number}"
475 [ $io = $((size * 2)) ];
478 # Out-of-range zone reset threshold and frequency parameters.
480 run_fio_on_seq --zone_reset_threshold=-1 |&
481 tee -a "${logfile}.${test_number}" |
482 grep -q 'value out of range' || return $?
486 run_fio_on_seq --zone_reset_threshold=2 |&
487 tee -a "${logfile}.${test_number}" |
488 grep -q 'value out of range' || return $?
492 run_fio_on_seq --zone_reset_threshold=.4:.6 |&
493 tee -a "${logfile}.${test_number}" |
494 grep -q 'the list exceeding max length' || return $?
498 run_fio_on_seq --zone_reset_frequency=-1 |&
499 tee -a "${logfile}.${test_number}" |
500 grep -q 'value out of range' || return $?
504 run_fio_on_seq --zone_reset_frequency=2 |&
505 tee -a "${logfile}.${test_number}" |
506 grep -q 'value out of range' || return $?
510 run_fio_on_seq --zone_reset_frequency=.4:.6 |&
511 tee -a "${logfile}.${test_number}" |
512 grep -q 'the list exceeding max length' || return $?
516 local bs loops=9 size=$((zone_size))
519 off=$((first_sequential_zone_sector * 512))
520 capacity=$(total_zone_capacity 1 $off $dev)
522 bs=$(min $((256*1024)) "$zone_size")
523 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
524 --size=$size --loops=$loops \
525 --zone_reset_frequency=.01 --zone_reset_threshold=.90 \
526 >> "${logfile}.${test_number}" 2>&1 || return $?
527 check_written $((capacity * loops)) || return $?
528 check_reset_count -eq 8 ||
529 check_reset_count -eq 9 ||
530 check_reset_count -eq 10 || return $?
533 # Multiple non-overlapping sequential write jobs for the same drive.
537 for ((i=0;i<16;i++)); do
539 reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone))
541 for ((i=0;i<16;i++)); do
542 opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1")
543 opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))")
544 opts+=("--size=$zone_size" "$(ioengine "psync")" "--rw=write" "--bs=16K")
545 opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1")
546 opts+=(${job_var_opts[@]})
548 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
551 write_to_first_seq_zone() {
555 off=$((first_sequential_zone_sector * 512))
556 capacity=$(total_zone_capacity 1 $off $dev)
558 r=$(((RANDOM << 16) | RANDOM))
559 run_fio --name="$dev" --filename="$dev" "$(ioengine "psync")" --rw="$1" \
560 --thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \
562 --size=$zone_size --loops=$loops --randseed="$r" \
563 --zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \
564 --gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $?
565 check_written $((loops * capacity)) || return $?
568 # Overwrite the first sequential zone four times sequentially.
570 write_to_first_seq_zone write
573 # Overwrite the first sequential zone four times using random writes.
575 write_to_first_seq_zone randwrite
578 # Multiple overlapping random write jobs for the same drive.
580 local i jobs=16 off opts
582 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
583 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
585 capacity=$(total_zone_capacity 1 $off $dev)
586 for ((i=0;i<jobs;i++)); do
587 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
588 opts+=("--size=$zone_size" "--io_size=$capacity" "$(ioengine "psync")" "--rw=randwrite")
589 opts+=("--thread=1" "--direct=1" "--zonemode=zbd")
590 opts+=("--zonesize=${zone_size}" "--group_reporting=1")
591 opts+=(${job_var_opts[@]})
593 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
594 check_written $((jobs * $capacity)) || return $?
595 check_reset_count -eq $jobs ||
596 check_reset_count -eq $((jobs - 1)) ||
600 # Multiple overlapping random write jobs for the same drive and with a limited
601 # number of open zones.
603 local i jobs=16 off opts=()
605 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
606 size=$((16*zone_size))
607 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
609 for ((i=0;i<jobs;i++)); do
610 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
611 opts+=("--size=$size" "--io_size=$zone_size" "--thread=1")
612 opts+=("$(ioengine "psync")" "--rw=randwrite" "--direct=1")
613 opts+=("--max_open_zones=4" "--group_reporting=1")
614 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
615 # max_open_zones is already specified
616 opts+=($(job_var_opts_exclude "--max_open_zones"))
618 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
619 check_written $((jobs * zone_size)) || return $?
622 # Random reads and writes across the entire disk for 30s.
626 off=$((first_sequential_zone_sector * 512))
627 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw \
628 --bs="$(max $((zone_size / 128)) "$logical_block_size")"\
629 --zonemode=zbd --zonesize="${zone_size}" --offset=$off\
630 --loops=2 --time_based --runtime=30s --norandommap=1\
631 >>"${logfile}.${test_number}" 2>&1
634 # Random reads across all sequential zones for 30s. This is not only a fio
635 # test but also allows to verify the performance of a drive.
637 local bs inc nz off opts size
639 # Start with writing 128 KB to 128 sequential zones.
642 # shellcheck disable=SC2017
643 inc=$(((disk_size - (first_sequential_zone_sector * 512)) / (nz * zone_size)
646 for ((off = first_sequential_zone_sector * 512; off < disk_size;
648 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--io_size=$bs")
649 opts+=("--bs=$bs" "--size=$zone_size" "$(ioengine "libaio")")
650 opts+=("--rw=write" "--direct=1" "--thread=1" "--stats=0")
651 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
652 opts+=(${job_var_opts[@]})
654 "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1
655 # Next, run the test.
656 off=$((first_sequential_zone_sector * 512))
657 size=$((disk_size - off))
658 opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
659 opts+=("--bs=$bs" "$(ioengine "psync")" "--rw=randread" "--direct=1")
660 opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd")
661 opts+=("--zonesize=${zone_size}")
662 opts+=(${job_var_opts[@]})
663 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
666 # Random writes across all sequential zones. This is not only a fio test but
667 # also allows to verify the performance of a drive.
669 local off opts=() size
671 off=$((first_sequential_zone_sector * 512))
672 size=$((disk_size - off))
673 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
674 opts+=("--bs=128K" "$(ioengine "psync")" "--rw=randwrite" "--direct=1")
675 opts+=("--thread=1" "--time_based" "--runtime=30")
676 opts+=("--max_open_zones=$max_open_zones" "--zonemode=zbd")
677 opts+=("--zonesize=${zone_size}")
678 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
681 # Write to sequential zones with a block size that is not a divisor of the
684 local bs io_size size
685 local off capacity=0;
687 off=$((first_sequential_zone_sector * 512))
688 capacity=$(total_zone_capacity 1 $off $dev)
689 size=$((2 * zone_size))
690 io_size=$((5 * capacity))
691 bs=$((3 * capacity / 4))
692 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
693 --size=$size --io_size=$io_size --bs=$bs \
694 >> "${logfile}.${test_number}" 2>&1 || return $?
695 check_written $(((io_size + bs - 1) / bs * bs)) || return $?
698 # Write to sequential zones with a block size that is not a divisor of the
699 # zone size and with data verification enabled.
703 size=$((2 * zone_size))
704 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write --size=$size \
705 --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \
706 >> "${logfile}.${test_number}" 2>&1 && return 1
707 grep -q 'not a divisor of' "${logfile}.${test_number}"
710 # Test 1/4 for the I/O boundary rounding code: $size < $zone_size.
712 local bs off io_size size
714 off=$(((first_sequential_zone_sector + 1) * 512))
715 size=$((zone_size - 2 * 512))
716 bs=$((zone_size / 4))
717 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
718 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
719 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
720 >> "${logfile}.${test_number}" 2>&1 && return 1
721 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
724 # Test 2/4 for the I/O boundary rounding code: $size < $zone_size.
726 local bs off io_size size
728 off=$(((first_sequential_zone_sector) * 512))
729 size=$((zone_size - 512))
730 bs=$((zone_size / 4))
731 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
732 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
733 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
734 >> "${logfile}.${test_number}" 2>&1 && return 1
735 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
738 # Test 3/4 for the I/O boundary rounding code: $size > $zone_size.
740 local bs off size capacity
742 capacity=$(total_zone_capacity 1 $first_sequential_zone_sector $dev)
743 if [ "$first_sequential_zone_sector" = 0 ]; then
746 off=$(((first_sequential_zone_sector - 1) * 512))
748 size=$((zone_size + 2 * 512))
749 bs=$((zone_size / 4))
750 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
751 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
752 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
753 >> "${logfile}.${test_number}" 2>&1
754 check_written $capacity || return $?
757 # Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size
761 size=$((logical_block_size))
762 off=$((disk_size - logical_block_size))
763 bs=$((logical_block_size))
764 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
765 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
766 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
767 >> "${logfile}.${test_number}" 2>&1 && return 1
768 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
771 # Read one block from a block device.
775 bs=$((logical_block_size))
776 run_one_fio_job --rw=read "$(ioengine "psync")" --bs=$bs --size=$bs "$@" 2>&1 |
777 tee -a "${logfile}.${test_number}"
780 # Check whether fio accepts --zonemode=none for zoned block devices.
782 [ -n "$is_zbd" ] || return 0
783 read_one_block --zonemode=none >/dev/null || return $?
784 check_read $((logical_block_size)) || return $?
787 # Check whether fio accepts --zonemode=strided for zoned block devices.
791 bs=$((logical_block_size))
792 [ -n "$is_zbd" ] || return 0
793 read_one_block --zonemode=strided |
794 grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
796 read_one_block --zonemode=strided --zonesize=$bs >/dev/null || return $?
797 check_read $bs || return $?
800 # Check whether fio checks the zone size for zoned block devices.
802 [ -n "$is_zbd" ] || return 0
803 read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) |
804 grep -q 'job parameter zonesize.*does not match disk zone size'
807 # Check whether fio handles --zonesize=0 correctly for regular block devices.
809 [ -n "$is_zbd" ] && return 0
810 read_one_block --zonemode=zbd --zonesize=0 |
811 grep -q 'Specifying the zone size is mandatory for regular block devices with --zonemode=zbd'
814 # Check whether fio handles --zonesize=1 correctly for regular block devices.
816 [ -n "$is_zbd" ] && return 0
817 read_one_block --zonemode=zbd --zonesize=1 |
818 grep -q 'zone size must be at least 512 bytes for --zonemode=zbd'
821 # Check whether fio handles --zonemode=none --zonesize=1 correctly.
823 read_one_block --zonemode=none --zonesize=1 |
824 grep -q 'fio: --zonemode=none and --zonesize are not compatible'
830 [ -z "$is_zbd" ] && return 0
831 bs=$((logical_block_size))
832 run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite --bs=$bs\
833 --offset=$((first_sequential_zone_sector * 512)) \
834 --size="$zone_size" --do_verify=1 --verify=md5 2>&1 |
835 tee -a "${logfile}.${test_number}" |
836 grep -q "fio: first I/O failed. If .* is a zoned block device, consider --zonemode=zbd"
839 # Random write to sequential zones, libaio, 8 jobs, queue depth 64 per job
843 size=$((4 * zone_size))
844 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=4K \
845 --group_reporting=1 --numjobs=8 \
846 >> "${logfile}.${test_number}" 2>&1 || return $?
847 check_written $((size * 8)) || return $?
850 # Check whether fio handles --zonemode=zbd --zoneskip=1 correctly.
854 bs=$((logical_block_size))
855 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
856 >> "${logfile}.${test_number}" 2>&1 && return 1
857 grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
860 # Multiple overlapping random write jobs for the same drive and with a
861 # limited number of open zones. This is similar to test29, but uses libaio
862 # to stress test zone locking.
864 local i jobs=16 off opts=()
866 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
867 size=$((16*zone_size))
868 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
869 opts=("--aux-path=/tmp" "--allow_file_create=0" "--significant_figures=10")
870 opts+=("--debug=zbd")
871 opts+=("$(ioengine "libaio")" "--rw=randwrite" "--direct=1")
872 opts+=("--time_based" "--runtime=30")
873 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
874 opts+=("--max_open_zones=4")
875 for ((i=0;i<jobs;i++)); do
876 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
877 opts+=("--io_size=$zone_size" "--iodepth=256" "--thread=1")
878 opts+=("--group_reporting=1")
879 # max_open_zones is already specified
880 opts+=($(job_var_opts_exclude "--max_open_zones"))
883 fio=$(dirname "$0")/../../fio
885 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
887 timeout -v -s KILL 45s \
888 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}" \
889 >> "${logfile}.${test_number}" 2>&1 || return $?
892 # Check if fio handles --zonecapacity on a normal block device correctly
895 if [ -n "$is_zbd" ]; then
896 echo "$dev is not a regular block device" \
897 >>"${logfile}.${test_number}"
901 size=$((2 * zone_size))
902 capacity=$((zone_size * 3 / 4))
904 run_one_fio_job "$(ioengine "psync")" --rw=write \
905 --zonemode=zbd --zonesize="${zone_size}" \
906 --zonecapacity=${capacity} \
907 --verify=md5 --size=${size} >>"${logfile}.${test_number}" 2>&1 ||
909 check_written $((capacity * 2)) || return $?
910 check_read $((capacity * 2)) || return $?
920 while [ "${1#-}" != "$1" ]; do
922 -d) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=drd"
923 "--show-confl-seg=no");
925 -e) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=helgrind");
927 -l) use_libzbc=1; shift;;
928 -r) reset_all_zones=1; shift;;
929 -t) tests+=("$2"); shift; shift;;
930 -o) max_open_zones_opt="${2}"; shift; shift;;
931 -v) dynamic_analyzer=(valgrind "--read-var-info=yes");
933 -z) zbd_debug=1; shift;;
943 # shellcheck source=functions
944 source "$(dirname "$0")/functions" || exit $?
948 if [ -n "$zbd_debug" ]; then
949 global_var_opts+=("--debug=zbd")
952 realdev=$(readlink -f "$dev")
953 basename=$(basename "$realdev")
955 if [[ -b "$realdev" ]]; then
956 major=$((0x$(stat -L -c '%t' "$realdev"))) || exit $?
957 minor=$((0x$(stat -L -c '%T' "$realdev"))) || exit $?
958 disk_size=$(($(<"/sys/dev/block/$major:$minor/size")*512))
960 # When the target is a partition device, get basename of its
961 # holder device to access sysfs path of the holder device
962 if [[ -r "/sys/dev/block/$major:$minor/partition" ]]; then
963 realsysfs=$(readlink "/sys/dev/block/$major:$minor")
964 basename=$(basename "${realsysfs%/*}")
966 logical_block_size=$(<"/sys/block/$basename/queue/logical_block_size")
967 case "$(<"/sys/class/block/$basename/queue/zoned")" in
968 host-managed|host-aware)
970 if ! check_blkzone "${dev}"; then
973 if ! result=($(first_sequential_zone "$dev")); then
974 echo "Failed to determine first sequential zone"
977 first_sequential_zone_sector=${result[0]}
978 sectors_per_zone=${result[1]}
979 zone_size=$((sectors_per_zone * 512))
980 if ! max_open_zones=$(max_open_zones "$dev"); then
981 echo "Failed to determine maximum number of open zones"
984 set_io_scheduler "$basename" deadline || exit $?
985 if [ -n "$reset_all_zones" ]; then
990 first_sequential_zone_sector=$(((disk_size / 2) &
991 (logical_block_size - 1)))
992 zone_size=$(max 65536 "$logical_block_size")
993 sectors_per_zone=$((zone_size / 512))
995 set_io_scheduler "$basename" none || exit $?
998 elif [[ -c "$realdev" ]]; then
999 # For an SG node, we must have libzbc option specified
1000 if [[ ! -n "$use_libzbc" ]]; then
1001 echo "Character device files can only be used with -l (libzbc) option"
1005 if ! $(is_zbc "$dev"); then
1006 echo "Device is not a ZBC disk"
1011 if ! disk_size=($(( $(zbc_disk_sectors "$dev") * 512))); then
1012 echo "Failed to determine disk size"
1015 if ! logical_block_size=($(zbc_logical_block_size "$dev")); then
1016 echo "Failed to determine logical block size"
1019 if ! result=($(first_sequential_zone "$dev")); then
1020 echo "Failed to determine first sequential zone"
1023 first_sequential_zone_sector=${result[0]}
1024 sectors_per_zone=${result[1]}
1025 zone_size=$((sectors_per_zone * 512))
1026 if ! max_open_zones=$(max_open_zones "$dev"); then
1027 echo "Failed to determine maximum number of open zones"
1030 if [ -n "$reset_all_zones" ]; then
1031 reset_zone "$dev" -1
1035 if [[ -n ${max_open_zones_opt} ]]; then
1036 # Override max_open_zones with the script option value
1037 max_open_zones="${max_open_zones_opt}"
1038 job_var_opts+=("--max_open_zones=${max_open_zones_opt}")
1041 echo -n "First sequential zone starts at sector $first_sequential_zone_sector;"
1042 echo " zone size: $((zone_size >> 20)) MB"
1044 if [ "${#tests[@]}" = 0 ]; then
1045 readarray -t tests < <(declare -F | grep "test[0-9]*" | \
1046 tr -c -d "[:digit:]\n" | sort -n)
1065 trap 'intr=1' SIGINT
1067 for test_number in "${tests[@]}"; do
1068 rm -f "${logfile}.${test_number}"
1069 echo -n "Running test $(printf "%02d" $test_number) ... "
1070 if eval "test$test_number" && check_log $test_number; then
1072 cc_status="${green}${status}${end}"
1076 cc_status="${red}${status}${end}"
1080 echo -e "$cc_status"
1081 echo "$status" >> "${logfile}.${test_number}"
1082 [ $intr -ne 0 ] && exit 1
1085 echo "$passed tests passed"
1086 if [ $failed -gt 0 ]; then
1087 echo " and $failed tests failed"