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-w Reset all zones before executing each write test case"
16 echo -e "\t-o <max_open_zones> Run fio with max_open_zones limit"
17 echo -e "\t-t <test #> Run only a single test case with specified number"
18 echo -e "\t-q Quit the test run after any failed test"
19 echo -e "\t-z Run fio with debug=zbd option"
20 echo -e "\t-u Use io_uring ioengine in place of libaio"
24 if [ "$1" -gt "$2" ]; then
32 if [ "$1" -lt "$2" ]; then
40 if [ -n "$use_libzbc" ]; then
41 echo -n "--ioengine=libzbc"
42 elif [ "$1" = "libaio" -a -n "$force_io_uring" ]; then
43 echo -n "--ioengine=io_uring"
45 echo -n "--ioengine=$1"
49 get_dev_path_by_id() {
50 for d in /sys/block/* /sys/block/*/*; do
51 if [[ ! -r "${d}/dev" ]]; then
54 if [[ "${1}" == "$(<"${d}/dev")" ]]; then
62 dm_destination_dev_set_io_scheduler() {
64 local dest_dev_id dest_dev path
66 has_command dmsetup || return 1
68 while read -r dest_dev_id; do
69 if ! dest_dev=$(get_dev_path_by_id "${dest_dev_id}"); then
72 path=${dest_dev/dev/sys\/block}/queue/scheduler
73 if [[ ! -w ${path} ]]; then
74 echo "Can not set scheduler of device mapper destination: ${dest_dev}"
77 echo "${2}" > "${path}"
78 done < <(dmsetup table "$(<"/sys/block/$dev/dm/name")" |
79 sed -n 's/.* \([0-9]*:[0-9]*\).*/\1/p')
83 local dev=${1} target_type=${2}
86 has_command dmsetup || return 1
88 dm_name=$(<"/sys/block/$dev/dm/name")
89 if ! dmsetup status "${dm_name}" | grep -qe "${target_type}"; then
92 if dmsetup status "${dm_name}" | grep -v "${target_type}"; then
101 [ -e "/sys/block/$dev" ] || return $?
102 if [ -e "/sys/block/$dev/mq" ]; then
105 deadline) sched=mq-deadline;;
110 mq-deadline) sched=deadline;;
114 if [ -w "/sys/block/$dev/queue/scheduler" ]; then
115 echo "$sched" >"/sys/block/$dev/queue/scheduler"
116 elif [ -r "/sys/block/$dev/dm/name" ] &&
117 ( dev_has_dm_map "$dev" linear ||
118 dev_has_dm_map "$dev" flakey ||
119 dev_has_dm_map "$dev" crypt ); then
120 dm_destination_dev_set_io_scheduler "$dev" "$sched"
122 echo "can not set io scheduler"
130 read=$(fio_read <"${logfile}.${test_number}")
131 echo "read: $read <> $1" >> "${logfile}.${test_number}"
138 written=$(fio_written <"${logfile}.${test_number}")
139 echo "written: $written <> $1" >> "${logfile}.${test_number}"
140 [ "$written" = "$1" ]
143 # Compare the reset count from the log file with reset count $2 using operator
144 # $1 (=, -ge, -gt, -le, -lt).
145 check_reset_count() {
148 reset_count=$(fio_reset_count <"${logfile}.${test_number}")
149 echo "reset_count: test $reset_count $1 $2" >> "${logfile}.${test_number}"
150 eval "[ '$reset_count' '$1' '$2' ]"
153 # Check log for failed assertions and crashes. Without these checks,
154 # a test can succeed even when these events happen, but it must fail.
156 [ ! -f "${logfile}.${1}" ] && return 0
157 ! grep -q -e "Assertion " -e "Aborted " "${logfile}.${1}"
160 # Whether or not $1 (/dev/...) is a SCSI device.
165 for f in /sys/class/scsi_device/*/device/block/"$d"; do
166 [ -e "$f" ] && return 0
171 job_var_opts_exclude() {
175 for o in "${job_var_opts[@]}"; do
176 if [[ ${o} =~ "${ex_key}" ]]; then
183 has_max_open_zones() {
185 if [[ ${1} =~ "--max_open_zones" ]]; then
196 fio=$(dirname "$0")/../../fio
198 opts=(${global_var_opts[@]})
199 opts+=("--max-jobs=16" "--aux-path=/tmp" "--allow_file_create=0" \
200 "--significant_figures=10" "$@")
201 # When max_open_zones option is specified to this test script, add
202 # max_open_zones option to fio command unless the test case already add it.
203 if [[ -n ${max_open_zones_opt} ]] && ! has_max_open_zones "${opts[@]}"; then
204 opts+=("--max_open_zones=${max_open_zones_opt}")
206 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
208 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}"
214 r=$(((RANDOM << 16) | RANDOM))
215 run_fio --name="$dev" --filename="$dev" "$@" --randseed="$r" \
216 --thread=1 --direct=1
219 write_and_run_one_fio_job() {
221 local write_offset="${1}"
222 local write_size="${2}"
226 r=$(((RANDOM << 16) | RANDOM))
227 write_opts=(--name="write_job" --rw=write "$(ioengine "psync")" \
228 --bs="${min_seq_write_size}" --zonemode=zbd \
229 --zonesize="${zone_size}" --thread=1 --direct=1 \
230 --offset="${write_offset}" --size="${write_size}")
231 write_opts+=("${job_var_opts[@]}")
232 run_fio --filename="$dev" --randseed="$r" "${write_opts[@]}" \
233 --name="$dev" --wait_for="write_job" "$@" --thread=1 --direct=1
236 # Run fio on the first four sequential zones of the disk.
240 opts+=("--offset=$((first_sequential_zone_sector * 512))")
241 opts+=("--size=$((4 * zone_size))" "--zonemode=zbd")
242 if [ -z "$is_zbd" ]; then
243 opts+=("--zonesize=${zone_size}")
245 run_one_fio_job "${opts[@]}" "$@"
248 # Prepare for write test by resetting zones. When reset_before_write or
249 # max_open_zones option is specified, reset all zones of the test target to
250 # ensure that zones out of the test target range do not have open zones. This
251 # allows the write test to the target range to be able to open zones up to
252 # max_open_zones limit specified as the option or obtained from sysfs.
254 [[ -n "${reset_before_write}" || -n "${max_open_zones_opt}" ]] &&
255 [[ -n "${is_zbd}" ]] && reset_zone "${dev}" -1
261 if ! is_scsi_device "$dev"; then
262 SKIP_REASON="$dev is not a SCSI device"
268 require_conv_zone_bytes() {
271 if ((req_bytes > first_sequential_zone_sector * 512)); then
272 SKIP_REASON="$dev does not have enough conventional zones"
279 if [[ -z ${is_zbd} ]]; then
280 SKIP_REASON="$dev is not a zoned block device"
286 require_regular_block_dev() {
287 if [[ -n ${is_zbd} ]]; then
288 SKIP_REASON="$dev is not a regular block device"
294 require_block_dev() {
295 if [[ -b "$realdev" ]]; then
298 SKIP_REASON="$dev is not a block device"
302 require_seq_zones() {
303 local req_seq_zones=${1}
304 local seq_bytes=$((disk_size - first_sequential_zone_sector * 512))
306 if ((req_seq_zones > seq_bytes / zone_size)); then
307 SKIP_REASON="$dev does not have $req_seq_zones sequential zones"
313 require_conv_zones() {
314 local req_c_zones=${1}
315 local conv_bytes=$((first_sequential_zone_sector * 512))
317 if ((req_c_zones > conv_bytes / zone_size)); then
318 SKIP_REASON="$dev does not have $req_c_zones conventional zones"
324 require_max_open_zones() {
327 if ((max_open_zones !=0 && max_open_zones < min)); then
328 SKIP_REASON="max_open_zones of $dev is smaller than $min"
334 require_max_active_zones() {
337 if ((max_active_zones == 0)); then
338 SKIP_REASON="$dev does not have max_active_zones limit"
341 if ((max_active_zones < min)); then
342 SKIP_REASON="max_active_zones of $dev is smaller than $min"
348 # Check whether buffered writes are refused for block devices.
350 require_block_dev || return $SKIP_TESTCASE
351 run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K \
352 "$(ioengine "psync")" --size="${zone_size}" --thread=1 \
353 --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
354 tee -a "${logfile}.${test_number}" |
355 grep -q 'Using direct I/O is mandatory for writing to ZBD drives'
356 local fio_rc=${PIPESTATUS[0]} grep_rc=${PIPESTATUS[2]}
361 if [ -n "$is_zbd" ]; then
368 # Block size exceeds zone size.
370 local bs off opts=() rc
372 off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
373 bs=$((2 * zone_size))
374 opts+=("$(ioengine "psync")")
375 opts+=("--name=job1" "--filename=$dev" "--rw=write" "--direct=1")
376 opts+=("--zonemode=zbd" "--offset=$off" "--bs=$bs" "--size=$bs")
377 if [ -z "$is_zbd" ]; then
378 opts+=("--zonesize=${zone_size}")
380 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 && return 1
381 grep -q 'buflen exceeds zone size' "${logfile}.${test_number}"
384 # Run fio against an empty zone. This causes fio to report "No I/O performed".
388 require_seq_zones 129 || return $SKIP_TESTCASE
389 off=$((first_sequential_zone_sector * 512 + 128 * zone_size))
391 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
392 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=4K")
393 opts+=("--size=$size" "--zonemode=zbd")
394 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--thread=1")
395 if [ -z "$is_zbd" ]; then
396 opts+=("--zonesize=${zone_size}")
398 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
399 ! grep -q 'READ:' "${logfile}.${test_number}"
402 # Run fio with --read_beyond_wp=1 against an empty zone.
406 require_seq_zones 130 || return $SKIP_TESTCASE
407 off=$((first_sequential_zone_sector * 512 + 129 * zone_size))
409 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
410 opts+=("--name=$dev" "--filename=$dev" "--offset=$off")
411 opts+=(--bs="$(min $((min_seq_write_size * 256)) $size)")
412 opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1")
413 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--disable_lat=1")
414 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
415 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1
417 if [[ $unrestricted_reads != 0 ]]; then
418 if [[ $fio_rc != 0 ]]; then
421 check_read $size || return $?
423 [ $fio_rc == 0 ] && return 1 || return 0
427 # Sequential write to sequential zones.
429 local size off capacity bs
432 off=$((first_sequential_zone_sector * 512))
433 capacity=$(total_zone_capacity 4 $off $dev)
434 size=$((4 * zone_size))
435 bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
436 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
437 --bs="$bs" --do_verify=1 --verify=md5 \
438 >>"${logfile}.${test_number}" 2>&1 || return $?
439 check_written $capacity || return $?
440 check_read $capacity || return $?
443 # Sequential read from sequential zones.
445 local size off capacity bs
448 off=$((first_sequential_zone_sector * 512))
449 capacity=$(total_zone_capacity 4 $off $dev)
450 size=$((4 * zone_size))
451 bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
452 write_and_run_one_fio_job \
453 $((first_sequential_zone_sector * 512)) "${size}" \
455 --size="${size}" --zonemode=zbd --zonesize="${zone_size}" \
456 "$(ioengine "psync")" --iodepth=1 --rw=read --bs="$bs" \
457 >>"${logfile}.${test_number}" 2>&1 || return $?
458 check_read $capacity || return $?
461 # Random write to sequential zones, libaio, queue depth 1.
463 local size=$((zone_size))
467 off=$((first_sequential_zone_sector * 512))
468 capacity=$(total_zone_capacity 1 $off $dev)
469 run_fio_on_seq "$(ioengine "libaio")" --iodepth=1 --rw=randwrite \
470 --bs="$(min 16384 "${zone_size}")" \
471 --do_verify=1 --verify=md5 --size="$size" \
472 >>"${logfile}.${test_number}" 2>&1 || return $?
473 check_written $capacity || return $?
474 check_read $capacity || return $?
477 # Random write to sequential zones, libaio, queue depth 64.
479 local size off capacity
482 size=$((4 * zone_size))
483 off=$((first_sequential_zone_sector * 512))
484 capacity=$(total_zone_capacity 4 $off $dev)
485 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
486 --bs="$(min 16384 "${zone_size}")" \
487 --do_verify=1 --verify=md5 \
488 >>"${logfile}.${test_number}" 2>&1 || return $?
489 check_written $capacity || return $?
490 check_read $capacity || return $?
493 # Random write to sequential zones, sg, queue depth 1.
497 require_scsi_dev || return $SKIP_TESTCASE
500 size=$((4 * zone_size))
501 run_fio_on_seq --ioengine=sg \
502 --iodepth=1 --rw=randwrite --bs=16K \
503 --do_verify=1 --verify=md5 \
504 >>"${logfile}.${test_number}" 2>&1 || return $?
505 check_written $size || return $?
506 check_read $size || return $?
509 # Random write to sequential zones, sg, queue depth 64.
513 require_scsi_dev || return $SKIP_TESTCASE
516 size=$((4 * zone_size))
517 run_fio_on_seq --ioengine=sg \
518 --iodepth=64 --rw=randwrite --bs=16K \
519 --do_verify=1 --verify=md5 \
520 >>"${logfile}.${test_number}" 2>&1 || return $?
521 check_written $size || return $?
522 check_read $size || return $?
525 # Random write to sequential zones, libaio, queue depth 64, random block size.
527 local size off capacity
530 size=$((4 * zone_size))
531 off=$((first_sequential_zone_sector * 512))
532 capacity=$(total_zone_capacity 4 $off $dev)
533 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
534 --bsrange=4K-64K --do_verify=1 --verify=md5 \
535 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
536 check_written $capacity || return $?
537 check_read $capacity || return $?
540 # Random write to sequential zones, libaio, queue depth 64, max 1 open zone.
542 local size off capacity
544 [ -n "$is_zbd" ] && reset_zone "$dev" -1
546 size=$((8 * zone_size))
547 off=$((first_sequential_zone_sector * 512))
548 capacity=$(total_zone_capacity 8 $off $dev)
549 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
550 --max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \
551 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
552 check_written $capacity || return $?
553 check_read $capacity || return $?
556 # Random write to sequential zones, libaio, queue depth 64, max 4 open zones.
558 local size off capacity
560 require_max_open_zones 4 || return $SKIP_TESTCASE
562 [ -n "$is_zbd" ] && reset_zone "$dev" -1
564 size=$((8 * zone_size))
565 off=$((first_sequential_zone_sector * 512))
566 capacity=$(total_zone_capacity 8 $off $dev)
567 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
568 --max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \
570 >>"${logfile}.${test_number}" 2>&1 || return $?
571 check_written $capacity || return $?
572 check_read $capacity || return $?
575 # Random write to conventional zones.
579 if ! result=($(first_online_zone "$dev")); then
580 echo "Failed to determine first online zone"
585 size=$((16 * 2**20)) # 20 MB
586 require_conv_zone_bytes "${size}" || return $SKIP_TESTCASE
588 run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
589 --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \
590 --verify=md5 --offset=$off --size=$size\
591 >>"${logfile}.${test_number}" 2>&1 || return $?
592 check_written $((size)) || return $?
593 check_read $((size)) || return $?
596 # Sequential read on a mix of empty and full zones.
599 local w_off w_size w_capacity
601 for ((i=0;i<4;i++)); do
603 reset_zone "$dev" $((first_sequential_zone_sector +
607 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
608 w_size=$((2 * zone_size))
609 w_capacity=$(total_zone_capacity 2 $w_off $dev)
610 off=$((first_sequential_zone_sector * 512))
611 size=$((4 * zone_size))
612 bs=$(min $((zone_size / 16)) "$zone_cap_bs")
613 write_and_run_one_fio_job "${w_off}" "${w_size}" \
614 "$(ioengine "psync")" --rw=read --bs="$bs" \
615 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
616 --size=$((size)) >>"${logfile}.${test_number}" 2>&1 ||
618 check_written $((w_capacity)) || return $?
619 check_read $((w_capacity))
622 # Random read on a mix of empty and full zones.
625 local i w_off w_size w_capacity
627 for ((i=0;i<4;i++)); do
629 reset_zone "$dev" $((first_sequential_zone_sector +
633 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
634 w_size=$((2 * zone_size))
635 w_capacity=$(total_zone_capacity 2 $w_off $dev)
636 off=$((first_sequential_zone_sector * 512))
637 size=$((4 * zone_size))
638 write_and_run_one_fio_job "${w_off}" "${w_size}" \
639 "$(ioengine "libaio")" --iodepth=64 --rw=randread --bs=16K \
640 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
641 --size=$size >>"${logfile}.${test_number}" 2>&1 || return $?
642 check_written $w_capacity || return $?
643 check_read $size || return $?
646 # Random reads and writes in the last zone.
648 local io off last read size written
650 off=$(((disk_size / zone_size - 1) * zone_size))
651 size=$((disk_size - off))
652 if ! last=($(last_online_zone "$dev")); then
653 echo "Failed to determine last online zone"
656 if [[ "$((last * 512))" -lt "$off" ]]; then
660 if [ -n "$is_zbd" ]; then
661 reset_zone "$dev" $((off / 512)) || return $?
664 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
665 --zonemode=zbd --zonesize="${zone_size}" \
666 --offset=$off --loops=2 --norandommap=1 \
668 >>"${logfile}.${test_number}" 2>&1 || return $?
669 written=$(fio_written <"${logfile}.${test_number}")
670 read=$(fio_read <"${logfile}.${test_number}")
671 io=$((written + read))
672 echo "Total number of bytes read and written: $io <> $size" \
673 >>"${logfile}.${test_number}"
674 [ $io = $((size * 2)) ];
677 # Out-of-range zone reset threshold and frequency parameters.
679 run_fio_on_seq --zone_reset_threshold=-1 |&
680 tee -a "${logfile}.${test_number}" |
681 grep -q 'value out of range' || return $?
685 run_fio_on_seq --zone_reset_threshold=2 |&
686 tee -a "${logfile}.${test_number}" |
687 grep -q 'value out of range' || return $?
691 run_fio_on_seq --zone_reset_threshold=.4:.6 |&
692 tee -a "${logfile}.${test_number}" |
693 grep -q 'the list exceeding max length' || return $?
697 run_fio_on_seq --zone_reset_frequency=-1 |&
698 tee -a "${logfile}.${test_number}" |
699 grep -q 'value out of range' || return $?
703 run_fio_on_seq --zone_reset_frequency=2 |&
704 tee -a "${logfile}.${test_number}" |
705 grep -q 'value out of range' || return $?
709 run_fio_on_seq --zone_reset_frequency=.4:.6 |&
710 tee -a "${logfile}.${test_number}" |
711 grep -q 'the list exceeding max length' || return $?
715 local bs loops=9 size=$((zone_size))
719 off=$((first_sequential_zone_sector * 512))
720 capacity=$(total_zone_capacity 1 $off $dev)
722 bs=$(min $((256*1024)) "$zone_size")
723 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
724 --size=$size --loops=$loops \
725 --zone_reset_frequency=.01 --zone_reset_threshold=.90 \
726 >> "${logfile}.${test_number}" 2>&1 || return $?
727 check_written $((capacity * loops)) || return $?
728 check_reset_count -eq 8 ||
729 check_reset_count -eq 9 ||
730 check_reset_count -eq 10 || return $?
733 # Multiple non-overlapping sequential write jobs for the same drive.
737 for ((i=0;i<16;i++)); do
739 reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone))
742 for ((i=0;i<16;i++)); do
743 opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1")
744 opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))")
745 opts+=("--size=$zone_size" "$(ioengine "psync")" "--rw=write" "--bs=16K")
746 opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1")
747 opts+=(${job_var_opts[@]})
749 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
752 write_to_first_seq_zone() {
757 off=$((first_sequential_zone_sector * 512))
758 capacity=$(total_zone_capacity 1 $off $dev)
760 r=$(((RANDOM << 16) | RANDOM))
761 run_fio --name="$dev" --filename="$dev" "$(ioengine "psync")" --rw="$1" \
762 --thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \
764 --size=$zone_size --loops=$loops --randseed="$r" \
765 --zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \
766 --gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $?
767 check_written $((loops * capacity)) || return $?
770 # Overwrite the first sequential zone four times sequentially.
772 write_to_first_seq_zone write
775 # Overwrite the first sequential zone four times using random writes.
777 write_to_first_seq_zone randwrite
780 # Multiple overlapping random write jobs for the same drive.
782 local i jobs=16 off opts
784 require_seq_zones 65 || return $SKIP_TESTCASE
785 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
786 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
789 capacity=$(total_zone_capacity 1 $off $dev)
790 for ((i=0;i<jobs;i++)); do
791 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
792 opts+=("--size=$zone_size" "--io_size=$capacity" "$(ioengine "psync")" "--rw=randwrite")
793 opts+=("--thread=1" "--direct=1" "--zonemode=zbd")
794 opts+=("--zonesize=${zone_size}" "--group_reporting=1")
795 opts+=(${job_var_opts[@]})
797 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
798 check_written $((jobs * $capacity)) || return $?
799 check_reset_count -eq $jobs ||
800 check_reset_count -eq $((jobs - 1)) ||
804 # Multiple overlapping random write jobs for the same drive and with a limited
805 # number of open zones.
807 local i jobs=16 off opts=()
809 require_seq_zones 80 || return $SKIP_TESTCASE
810 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
811 size=$((16*zone_size))
813 [ -n "$is_zbd" ] && reset_zone "$dev" -1
816 for ((i=0;i<jobs;i++)); do
817 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
818 opts+=("--size=$size" "--io_size=$zone_size" "--thread=1")
819 opts+=("$(ioengine "psync")" "--rw=randwrite" "--direct=1")
820 opts+=("--max_open_zones=4" "--group_reporting=1")
821 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
822 # max_open_zones is already specified
823 opts+=($(job_var_opts_exclude "--max_open_zones"))
825 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
826 check_written $((jobs * zone_size)) || return $?
829 # Random reads and writes across the entire disk for 30s.
834 off=$((first_sequential_zone_sector * 512))
835 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw \
836 --bs="$(max $((zone_size / 128)) "$min_seq_write_size")"\
837 --zonemode=zbd --zonesize="${zone_size}" --offset=$off\
838 --loops=2 --time_based --runtime=30s --norandommap=1\
839 >>"${logfile}.${test_number}" 2>&1
842 # Random reads across all sequential zones for 30s. This is not only a fio
843 # test but also allows to verify the performance of a drive.
845 local bs inc nz off opts size
847 [ -n "$is_zbd" ] && reset_zone "$dev" -1
849 # As preparation, write 128 KB to sequential write required zones. Limit
850 # write target zones up to max_open_zones to keep test time reasonable.
851 # To distribute the write target zones evenly, skip certain zones for every
852 # write. Utilize zonemode strided for such write patterns.
854 nz=$((max_open_zones))
855 if [[ $nz -eq 0 ]]; then
858 off=$((first_sequential_zone_sector * 512))
859 size=$((disk_size - off))
860 inc=$(((size / nz / zone_size) * zone_size))
861 opts=("--name=$dev" "--filename=$dev" "--rw=write" "--bs=${bs}")
862 opts+=("--offset=$off" "--size=$((inc * nz))" "--io_size=$((bs * nz))")
863 opts+=("--zonemode=strided" "--zonesize=${bs}" "--zonerange=${inc}")
864 opts+=("--direct=1" "$(ioengine "psync")")
865 echo "fio ${opts[@]}" >> "${logfile}.${test_number}"
866 "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" \
869 # Next, run the test.
870 opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
871 opts+=("--bs=$bs" "$(ioengine "psync")" "--rw=randread" "--direct=1")
872 opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd")
873 opts+=("--zonesize=${zone_size}")
874 opts+=(${job_var_opts[@]})
875 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
878 # Random writes across all sequential zones. This is not only a fio test but
879 # also allows to verify the performance of a drive.
881 local off opts=() size
883 require_zbd || return $SKIP_TESTCASE
885 [ -n "$is_zbd" ] && reset_zone "$dev" -1
887 off=$((first_sequential_zone_sector * 512))
888 size=$((disk_size - off))
889 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
890 opts+=("--bs=128K" "$(ioengine "psync")" "--rw=randwrite" "--direct=1")
891 opts+=("--thread=1" "--time_based" "--runtime=30")
892 opts+=("--max_open_zones=$max_open_zones" "--zonemode=zbd")
893 opts+=("--zonesize=${zone_size}")
894 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
897 # Write to sequential zones with a block size that is not a divisor of the
900 local bs io_size size
901 local off capacity=0;
903 [ -n "$is_zbd" ] && reset_zone "$dev" -1
905 off=$((first_sequential_zone_sector * 512))
906 capacity=$(total_zone_capacity 1 $off $dev)
907 size=$((2 * zone_size))
908 io_size=$((5 * capacity))
909 bs=$((3 * capacity / 4))
910 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
911 --size=$size --io_size=$io_size --bs=$bs \
912 >> "${logfile}.${test_number}" 2>&1 || return $?
913 check_written $((io_size / bs * bs)) || return $?
916 # Test repeated async write job with verify using two unaligned block sizes.
918 local bs off zone_capacity
921 require_zbd || return $SKIP_TESTCASE
924 off=$((first_sequential_zone_sector * 512))
925 zone_capacity=$(total_zone_capacity 1 $off $dev)
926 block_sizes=($((4096 * 7)) $(($(min ${zone_capacity} 4194304) - 4096)))
928 for bs in ${block_sizes[@]}; do
929 run_fio --name=job --filename="${dev}" --rw=randwrite \
930 --bs="${bs}" --offset="${off}" \
931 --size=$((4 * zone_size)) --iodepth=256 \
932 "$(ioengine "libaio")" --time_based=1 --runtime=15s \
933 --zonemode=zbd --direct=1 --zonesize="${zone_size}" \
934 --verify=crc32c --do_verify=1 ${job_var_opts[@]} \
935 >> "${logfile}.${test_number}" 2>&1 || return $?
939 # Test 1/4 for the I/O boundary rounding code: $size < $zone_size.
941 local bs off io_size size
944 off=$(((first_sequential_zone_sector + 1) * 512))
945 size=$((zone_size - 2 * 512))
946 bs=$((zone_size / 4))
947 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
948 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
949 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
950 >> "${logfile}.${test_number}" 2>&1 && return 1
951 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
954 # Test 2/4 for the I/O boundary rounding code: $size < $zone_size.
956 local bs off io_size size
959 off=$(((first_sequential_zone_sector) * 512))
960 size=$((zone_size - 512))
961 bs=$((zone_size / 4))
962 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
963 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
964 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
965 >> "${logfile}.${test_number}" 2>&1 && return 1
966 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
969 # Test 3/4 for the I/O boundary rounding code: $size > $zone_size.
971 local bs off size capacity
974 capacity=$(total_zone_capacity 1 $((first_sequential_zone_sector*512)) $dev)
975 if [ "$first_sequential_zone_sector" = 0 ]; then
978 off=$(((first_sequential_zone_sector - 1) * 512))
980 size=$((zone_size + 2 * 512))
981 bs=$(min $((zone_size / 4)) "$zone_cap_bs")
982 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
983 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
984 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
985 >> "${logfile}.${test_number}" 2>&1
986 check_written $capacity || return $?
989 # Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size
994 size=$((min_seq_write_size))
995 off=$((disk_size - min_seq_write_size))
996 bs=$((min_seq_write_size))
997 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
998 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
999 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
1000 >> "${logfile}.${test_number}" 2>&1 && return 1
1001 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
1004 # Read one block from a block device.
1009 if ! result=($(first_online_zone "$dev")); then
1010 echo "Failed to determine first online zone"
1014 bs=$((min_seq_write_size))
1015 run_one_fio_job --rw=read "$(ioengine "psync")" --offset=$off --bs=$bs \
1016 --size=$bs "$@" 2>&1 |
1017 tee -a "${logfile}.${test_number}"
1020 # Check whether fio accepts --zonemode=none for zoned block devices.
1022 require_zbd || return $SKIP_TESTCASE
1023 read_one_block --zonemode=none >/dev/null || return $?
1024 check_read $((min_seq_write_size)) || return $?
1027 # Check whether fio accepts --zonemode=strided for zoned block devices.
1031 bs=$((min_seq_write_size))
1032 require_zbd || return $SKIP_TESTCASE
1033 read_one_block --zonemode=strided |
1034 grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
1036 read_one_block --zonemode=strided --zonesize=$bs >/dev/null || return $?
1037 check_read $bs || return $?
1040 # Check whether fio checks the zone size for zoned block devices.
1042 require_zbd || return $SKIP_TESTCASE
1043 read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) |
1044 grep -q 'job parameter zonesize.*does not match disk zone size'
1047 # Check whether fio handles --zonesize=0 correctly for regular block devices.
1049 require_regular_block_dev || return $SKIP_TESTCASE
1050 read_one_block --zonemode=zbd --zonesize=0 |
1051 grep -q 'Specifying the zone size is mandatory for regular file/block device with --zonemode=zbd'
1054 # Check whether fio handles --zonesize=1 correctly for regular block devices.
1056 require_regular_block_dev || return $SKIP_TESTCASE
1057 read_one_block --zonemode=zbd --zonesize=1 |
1058 grep -q 'zone size must be at least 512 bytes for --zonemode=zbd'
1061 # Check whether fio handles --zonemode=none --zonesize=1 correctly.
1063 read_one_block --zonemode=none --zonesize=1 |
1064 grep -q 'fio: --zonemode=none and --zonesize are not compatible'
1069 local grep_str="fio: first I/O failed. If .* is a zoned block device, consider --zonemode=zbd"
1071 require_zbd || return $SKIP_TESTCASE
1073 bs=$((min_seq_write_size))
1074 for ((i = 0; i < 10; i++)); do
1075 run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite \
1076 --offset=$((first_sequential_zone_sector * 512)) \
1077 --bs="$bs" --time_based --runtime=1s \
1078 --do_verify=1 --verify=md5 \
1079 >> "${logfile}.${test_number}" 2>&1
1080 grep -qe "$grep_str" "${logfile}.${test_number}" && return 0
1085 # Random write to sequential zones, libaio, 8 jobs, queue depth 64 per job
1090 size=$((4 * zone_size))
1091 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=4K \
1092 --group_reporting=1 --numjobs=8 \
1093 >> "${logfile}.${test_number}" 2>&1 || return $?
1094 check_written $((size * 8)) || return $?
1097 # Check whether fio handles --zonemode=zbd --zoneskip=1 correctly.
1102 bs=$((min_seq_write_size))
1103 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
1104 >> "${logfile}.${test_number}" 2>&1 && return 1
1105 grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
1108 # Multiple overlapping random write jobs for the same drive and with a
1109 # limited number of open zones. This is similar to test29, but uses libaio
1110 # to stress test zone locking.
1112 local i jobs=16 off opts=()
1114 require_zbd || return $SKIP_TESTCASE
1115 require_seq_zones 80 || return $SKIP_TESTCASE
1117 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
1118 size=$((16*zone_size))
1120 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1122 opts=("--aux-path=/tmp" "--allow_file_create=0" "--significant_figures=10")
1123 opts+=("--debug=zbd")
1124 opts+=("$(ioengine "libaio")" "--rw=randwrite" "--direct=1")
1125 opts+=("--time_based" "--runtime=30")
1126 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
1127 opts+=("--max_open_zones=4")
1128 for ((i=0;i<jobs;i++)); do
1129 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
1130 opts+=("--io_size=$zone_size" "--iodepth=256" "--thread=1")
1131 opts+=("--size=$size" "--group_reporting=1")
1132 # max_open_zones is already specified
1133 opts+=($(job_var_opts_exclude "--max_open_zones"))
1136 fio=$(dirname "$0")/../../fio
1138 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
1140 timeout -v -s KILL 180s \
1141 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}" \
1142 >> "${logfile}.${test_number}" 2>&1 || return $?
1145 # Check if fio handles --zonecapacity on a normal block device correctly
1148 require_regular_block_dev || return $SKIP_TESTCASE
1150 size=$((2 * zone_size))
1151 capacity=$((zone_size * 3 / 4))
1153 run_one_fio_job "$(ioengine "psync")" --rw=write \
1154 --zonemode=zbd --zonesize="${zone_size}" \
1155 --zonecapacity=${capacity} \
1156 --verify=md5 --size=${size} >>"${logfile}.${test_number}" 2>&1 ||
1158 check_written $((capacity * 2)) || return $?
1159 check_read $((capacity * 2)) || return $?
1162 # Verify that conv zones are not locked and only seq zones are locked during
1163 # random read on conv-seq mixed zones.
1167 require_zbd || return $SKIP_TESTCASE
1168 require_conv_zones 8 || return $SKIP_TESTCASE
1169 require_seq_zones 8 || return $SKIP_TESTCASE
1171 reset_zone "${dev}" -1
1173 off=$((first_sequential_zone_sector * 512 - 8 * zone_size))
1174 run_fio --name=job --filename=${dev} --offset=${off} --bs=64K \
1175 --size=$((16 * zone_size)) "$(ioengine "libaio")" --rw=randread\
1176 --time_based --runtime=3 --zonemode=zbd --zonesize=${zone_size}\
1177 --direct=1 --group_reporting=1 ${job_var_opts[@]} \
1178 >> "${logfile}.${test_number}" 2>&1 || return $?
1181 # Verify that conv zones are neither locked nor opened during random write on
1182 # conv-seq mixed zones. Zone lock and zone open shall happen only on seq zones.
1187 require_zbd || return $SKIP_TESTCASE
1188 require_conv_zones 8 || return $SKIP_TESTCASE
1189 require_seq_zones 8 || return $SKIP_TESTCASE
1191 reset_zone "$dev" -1
1193 off=$((first_sequential_zone_sector * 512 - 8 * zone_size))
1194 opts+=("--size=$((16 * zone_size))" "$(ioengine "libaio")")
1195 opts+=("--zonemode=zbd" "--direct=1" "--zonesize=${zone_size}")
1196 opts+=("--max_open_zones=2" "--offset=$off")
1197 opts+=("--thread=1" "--group_reporting=1")
1198 opts+=("--time_based" "--runtime=30" "--rw=randwrite")
1199 for ((i=0;i<jobs;i++)); do
1200 opts+=("--name=job${i}" "--filename=$dev")
1201 opts+=("--bs=$(((i+1)*16))K")
1202 opts+=($(job_var_opts_exclude "--max_open_zones"))
1204 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
1207 # Verify that zone_reset_threshold only accounts written bytes in seq
1208 # zones, and written data bytes of conv zones are not counted.
1212 require_zbd || return $SKIP_TESTCASE
1213 require_conv_zones 8 || return $SKIP_TESTCASE
1214 require_seq_zones 8 || return $SKIP_TESTCASE
1216 reset_zone "${dev}" -1
1218 # Total I/O size is 1/8 = 0.125 of the I/O range of cont + seq zones.
1219 # Set zone_reset_threshold as 0.1. The threshold size is less than
1220 # 0.125, then, reset count zero is expected.
1221 # On the other hand, half of the I/O range is covered by conv zones.
1222 # If fio would count the conv zones for zone_reset_threshold, the ratio
1223 # were more than 0.5 and would trigger zone resets.
1225 off=$((first_sequential_zone_sector * 512 - 8 * zone_size))
1226 io_size=$((zone_size * 16 / 8))
1227 run_fio --name=job --filename=$dev --rw=randwrite --bs=$((zone_size/16))\
1228 --size=$((zone_size * 16)) --softrandommap=1 \
1229 --io_size=$((io_size)) "$(ioengine "psync")" --offset=$off \
1230 --zonemode=zbd --direct=1 --zonesize=${zone_size} \
1231 --zone_reset_threshold=.1 --zone_reset_frequency=1.0 \
1232 ${job_var_opts[@]} --debug=zbd \
1233 >> "${logfile}.${test_number}" 2>&1 || return $?
1235 check_written ${io_size} || return $?
1236 check_reset_count -eq 0 || return $?
1239 # Check both reads and writes are executed by random I/O to conventional zones.
1241 local off capacity io read_b=0 written_b=0
1243 require_zbd || return $SKIP_TESTCASE
1244 require_conv_zones 4 || return $SKIP_TESTCASE
1246 off=$((first_sequential_zone_sector * 512 - 4 * zone_size))
1247 capacity=$(total_zone_capacity 4 $off $dev)
1248 run_fio --name=job --filename=${dev} --rw=randrw --bs=64K \
1249 --size=$((4 * zone_size)) "$(ioengine "psync")" --offset=${off}\
1250 --zonemode=zbd --direct=1 --zonesize=${zone_size} \
1251 ${job_var_opts[@]} \
1252 >> "${logfile}.${test_number}" 2>&1 || return $?
1254 written_b=$(fio_written <"${logfile}.${test_number}")
1255 read_b=$(fio_read <"${logfile}.${test_number}")
1256 io=$((written_b + read_b))
1257 echo "Number of bytes read: $read_b" >>"${logfile}.${test_number}"
1258 echo "Number of bytes written: $written_b" >>"${logfile}.${test_number}"
1259 echo "Total number of bytes read and written: $io <> $capacity" \
1260 >>"${logfile}.${test_number}"
1261 if ((io==capacity && written_b != 0 && read_b != 0)); then
1267 # Test read/write mix with verify.
1269 require_zbd || return $SKIP_TESTCASE
1270 require_seq_zones 8 || return $SKIP_TESTCASE
1273 run_fio --name=job --filename=${dev} "$(ioengine "libaio")" \
1274 --time_based=1 --runtime=30s --continue_on_error=0 \
1275 --offset=$((first_sequential_zone_sector * 512)) \
1276 --size=$((8*zone_size)) --direct=1 --iodepth=1 \
1277 --rw=randrw:2 --rwmixwrite=25 --bsrange=4k-${zone_size} \
1278 --zonemode=zbd --zonesize=${zone_size} \
1279 --verify=crc32c --do_verify=1 --verify_backlog=2 \
1280 --alloc-size=65536 --random_generator=tausworthe64 \
1281 ${job_var_opts[@]} --debug=zbd \
1282 >> "${logfile}.${test_number}" 2>&1 || return $?
1285 # test 'z' suffix parsing only
1288 bs=$((min_seq_write_size))
1290 require_zbd || return $SKIP_TESTCASE
1291 # offset=1z + offset_increment=10z + size=2z
1292 require_seq_zones 13 || return $SKIP_TESTCASE
1298 "$(ioengine "psync")" \
1300 --zonesize=${zone_size} \
1304 --offset_increment=10z \
1308 ${job_var_opts[@]} --debug=zbd \
1309 >> "${logfile}.${test_number}" 2>&1 || return $?
1312 # test 'z' suffix parsing only
1315 bs=$((min_seq_write_size))
1317 require_regular_block_dev || return $SKIP_TESTCASE
1318 require_seq_zones 10 || return $SKIP_TESTCASE
1324 "$(ioengine "psync")" \
1325 --zonemode=strided \
1326 --zonesize=${zone_size} \
1331 ${job_var_opts[@]} --debug=zbd \
1332 >> "${logfile}.${test_number}" 2>&1 || return $?
1335 # Test that repeated async write job does not cause zone reset during writes
1336 # in-flight, when the block size is not a divisor of the zone size.
1340 require_zbd || return $SKIP_TESTCASE
1344 off=$((first_sequential_zone_sector * 512))
1346 run_fio --name=job --filename="${dev}" --rw=randwrite --bs="${bs}" \
1347 --offset="${off}" --size=$((4 * zone_size)) --iodepth=256 \
1348 "$(ioengine "libaio")" --time_based=1 --runtime=30s \
1349 --zonemode=zbd --direct=1 --zonesize="${zone_size}" \
1350 ${job_var_opts[@]} \
1351 >> "${logfile}.${test_number}" 2>&1 || return $?
1354 # Random writes and random trims to sequential write required zones for 30s.
1358 require_seq_zones 128 || return $SKIP_TESTCASE
1360 size=$((zone_size * 128))
1361 bs="$(max $((zone_size / 128)) "$min_seq_write_size")"
1363 off=$((first_sequential_zone_sector * 512))
1364 run_fio --zonemode=zbd --direct=1 --zonesize="${zone_size}" --thread=1 \
1365 --filename="${dev}" --norandommap=1 \
1366 --name="precondition" --rw=write "$(ioengine "psync")" \
1367 --offset="${off}" --size=$((zone_size * 16)) --bs="${bs}" \
1368 "${job_var_opts[@]}" \
1369 --name=wjob --wait_for="precondition" --rw=randwrite \
1370 "$(ioengine "libaio")" --iodepth=8 \
1371 --offset="${off}" --size="${size}" --bs="${bs}" \
1372 --time_based --runtime=30s --flow=128 "${job_var_opts[@]}" \
1373 --name=trimjob --wait_for="precondition" --rw=randtrim \
1374 "$(ioengine "psync")" \
1375 --offset="${off}" --size="${size}" --bs="${zone_size}" \
1376 --time_based --runtime=30s --flow=1 "${job_var_opts[@]}" \
1377 >>"${logfile}.${test_number}" 2>&1
1380 # Test zone_reset_threshold with verify.
1382 local off bs loops=2 size=$((zone_size)) w
1383 local -a workloads=(write randwrite rw randrw)
1386 off=$((first_sequential_zone_sector * 512))
1388 bs=$(min $((256*1024)) "$zone_size")
1389 for w in "${workloads[@]}"; do
1390 run_fio_on_seq "$(ioengine "psync")" --rw=${w} --bs="$bs" \
1391 --size=$size --loops=$loops --do_verify=1 \
1392 --verify=md5 --zone_reset_frequency=.9 \
1393 --zone_reset_threshold=.1 \
1394 >> "${logfile}.${test_number}" 2>&1 || return $?
1398 # Test fio errors out experimental_verify option with zonemode=zbd.
1400 run_fio_on_seq "$(ioengine "psync")" --rw=write --size=$zone_size \
1401 --do_verify=1 --verify=md5 --experimental_verify=1 \
1402 >> "${logfile}.${test_number}" 2>&1 && return 1
1403 grep -q 'not support experimental verify' "${logfile}.${test_number}"
1406 # Test fio errors out zone_reset_threshold option for multiple jobs with
1407 # different write ranges.
1409 run_fio_on_seq "$(ioengine "psync")" --rw=write --size="$zone_size" \
1410 --numjobs=2 --offset_increment="$zone_size" \
1411 --zone_reset_threshold=0.1 --zone_reset_frequency=1 \
1412 --exitall_on_error=1 \
1413 >> "${logfile}.${test_number}" 2>&1 && return 1
1414 grep -q 'different write ranges' "${logfile}.${test_number}"
1417 # Test zone_reset_threshold option works for multiple jobs with same write
1420 local bs loops=2 size=$((zone_size))
1422 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1424 # Two jobs write to single zone twice. Reset zone happens at next write
1425 # after half of the zone gets filled. So 2 * 2 * 2 - 1 = 7 times zone
1426 # resets are expected.
1427 bs=$(min $((256*1024)) $((zone_size / 4)))
1428 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
1429 --size=$size --loops=$loops --numjobs=2 \
1430 --zone_reset_frequency=1 --zone_reset_threshold=.5 \
1431 --group_reporting=1 \
1432 >> "${logfile}.${test_number}" 2>&1 || return $?
1433 check_written $((size * loops * 2)) || return $?
1434 check_reset_count -eq 7 || return $?
1437 # Test zone_reset_threshold option works for a read job and a write job with
1438 # different IO range.
1440 local bs loops=2 size=$((zone_size)) off1 off2
1442 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1444 off1=$((first_sequential_zone_sector * 512))
1445 off2=$((off1 + zone_size))
1446 bs=$(min $((256*1024)) $((zone_size / 4)))
1448 # One job writes to single zone twice. Reset zone happens at next write
1449 # after half of the zone gets filled. So 2 * 2 - 1 = 3 times zone resets
1451 run_fio "$(ioengine "psync")" --bs="$bs" --size=$size --loops=$loops \
1452 --filename="$dev" --group_reporting=1 \
1453 --zonemode=zbd --zonesize="$zone_size" --direct=1 \
1454 --zone_reset_frequency=1 --zone_reset_threshold=.5 \
1455 --name=r --rw=read --offset=$off1 "${job_var_opts[@]}" \
1456 --name=w --rw=write --offset=$off2 "${job_var_opts[@]}" \
1457 >> "${logfile}.${test_number}" 2>&1 || return $?
1458 check_written $((size * loops)) || return $?
1459 check_reset_count -eq 3 || return $?
1462 # Test write zone accounting handles almost full zones correctly. Prepare an
1463 # almost full, but not full zone. Write to the zone with verify using larger
1464 # block size. Then confirm fio does not report write zone accounting failure.
1468 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1470 bs=$((zone_size / 8))
1471 cap=$(total_zone_capacity 1 $((first_sequential_zone_sector*512)) $dev)
1472 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
1473 --size=$((zone_size)) \
1474 --io_size=$((cap - bs)) \
1475 >> "${logfile}.${test_number}" 2>&1 || return $?
1477 bs=$((zone_size / 2))
1478 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
1479 --size=$((zone_size)) --do_verify=1 --verify=md5 \
1480 >> "${logfile}.${test_number}" 2>&1 || return $?
1483 # Test open zone accounting handles trim workload correctly. Prepare open zones
1484 # as many as max_open_zones=4. Trim one of the 4 zones. Then write to another
1485 # zone and check the write amount is expected size.
1489 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1491 off=$((first_sequential_zone_sector * 512))
1492 capacity=$(total_zone_capacity 1 $off "$dev")
1493 run_fio --zonemode=zbd --direct=1 --zonesize="$zone_size" --thread=1 \
1494 --filename="$dev" --group_reporting=1 --max_open_zones=4 \
1495 "$(ioengine "psync")" \
1496 --name="prep_open_zones" --rw=randwrite --offset="$off" \
1497 --size="$((zone_size * 4))" --bs=4096 --io_size="$zone_size" \
1498 --name=trimjob --wait_for="prep_open_zones" --rw=trim \
1499 --bs="$zone_size" --offset="$off" --size="$zone_size" \
1500 --name=write --wait_for="trimjob" --rw=write --bs=4096 \
1501 --offset="$((off + zone_size * 4))" --size="$zone_size" \
1502 >> "${logfile}.${test_number}" 2>&1
1504 check_written $((zone_size + capacity))
1507 # Test closed zones are handled as open zones. This test case requires zoned
1508 # block devices which has same max_open_zones and max_active_zones.
1512 require_zbd || return $SKIP_TESTCASE
1513 require_max_active_zones 2 || return $SKIP_TESTCASE
1514 require_max_open_zones "${max_active_zones}" || return $SKIP_TESTCASE
1515 require_seq_zones $((max_active_zones * 16)) || return $SKIP_TESTCASE
1517 reset_zone "$dev" -1
1519 # Prepare max_active_zones in closed condition.
1520 off=$((first_sequential_zone_sector * 512))
1521 run_fio --name=w --filename="$dev" --zonemod=zbd --direct=1 \
1522 --offset=$((off)) --zonesize="${zone_size}" --rw=randwrite \
1523 --bs=4096 --size="$((zone_size * max_active_zones))" \
1524 --io_size="${zone_size}" "$(ioengine "psync")" \
1525 >> "${logfile}.${test_number}" 2>&1 || return $?
1526 for ((i = 0; i < max_active_zones; i++)); do
1527 close_zone "$dev" $((off / 512)) || return $?
1528 off=$((off + zone_size))
1531 # Run random write to the closed zones and empty zones. This confirms
1532 # that fio handles closed zones as write target open zones. Otherwise,
1533 # fio writes to the empty zones and hit the max_active_zones limit.
1534 off=$((first_sequential_zone_sector * 512))
1535 run_one_fio_job --zonemod=zbd --direct=1 \
1536 "$(ioengine "psync")" --rw=randwrite --bs=4096 \
1537 --max_open_zones="$max_active_zones" --offset=$((off)) \
1538 --size=$((max_active_zones * 16 * zone_size)) \
1539 --io_size=$((zone_size)) --zonesize="${zone_size}" \
1540 --time_based --runtime=5s \
1541 >> "${logfile}.${test_number}" 2>&1
1544 # Test max_active_zones limit failure is reported with good error message.
1548 require_zbd || return $SKIP_TESTCASE
1549 require_max_active_zones 2 || return $SKIP_TESTCASE
1550 require_max_open_zones "${max_active_zones}" || return $SKIP_TESTCASE
1551 require_seq_zones $((max_active_zones + 1)) || return $SKIP_TESTCASE
1553 reset_zone "$dev" -1
1555 # Prepare max_active_zones in open condition.
1556 off=$((first_sequential_zone_sector * 512))
1557 run_fio --name=w --filename="$dev" --zonemod=zbd --direct=1 \
1558 --offset=$((off)) --zonesize="${zone_size}" --rw=randwrite \
1559 --bs=4096 --size="$((zone_size * max_active_zones))" \
1560 --io_size="${zone_size}" "$(ioengine "psync")" \
1561 >> "${logfile}.${test_number}" 2>&1 || return $?
1563 # Write to antoher zone and trigger max_active_zones limit error.
1564 off=$((off + zone_size * max_active_zones))
1565 run_one_fio_job --zonemod=zbd --direct=1 "$(ioengine "psync")" \
1566 --rw=write --bs=$min_seq_write_size --offset=$((off)) \
1567 --size=$((zone_size)) --zonesize="${zone_size}" \
1568 >> "${logfile}.${test_number}" 2>&1 && return $?
1569 grep -q 'Exceeded max_active_zones limit' "${logfile}.${test_number}"
1572 # Test rw=randrw and rwmixwrite=0 options do not issue write I/O unit
1576 require_zbd || return "$SKIP_TESTCASE"
1578 reset_zone "${dev}" -1
1580 # Write some data as preparation
1581 off=$((first_sequential_zone_sector * 512))
1582 size=$min_seq_write_size
1583 run_one_fio_job "$(ioengine "psync")" --rw=write --offset="$off" \
1584 --io_size="$size" --zonemode=strided \
1585 --zonesize="$zone_size" --zonerange="$zone_size" \
1586 >> "${logfile}.${test_number}" 2>&1 || return $?
1587 # Run random mixed read and write specifying zero write ratio
1588 run_fio_on_seq "$(ioengine "psync")" --rw=randrw --rwmixwrite=0 \
1589 --time_based --runtime=1s \
1590 >> "${logfile}.${test_number}" 2>&1 || return $?
1591 # "WRITE:" shall be recoreded only once for the preparation
1592 [[ $(grep -c "WRITE:" "${logfile}.${test_number}") == 1 ]]
1606 while [ "${1#-}" != "$1" ]; do
1608 -d) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=drd"
1609 "--show-confl-seg=no");
1611 -e) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=helgrind");
1613 -l) use_libzbc=1; shift;;
1614 -r) reset_all_zones=1; shift;;
1615 -w) reset_before_write=1; shift;;
1616 -t) tests+=("$2"); shift; shift;;
1617 -o) max_open_zones_opt="${2}"; shift; shift;;
1618 -v) dynamic_analyzer=(valgrind "--read-var-info=yes");
1620 -q) quit_on_err=1; shift;;
1621 -z) zbd_debug=1; shift;;
1622 -u) force_io_uring=1; shift;;
1628 if [ $# != 1 ]; then
1633 if [ -n "$use_libzbc" -a -n "$force_io_uring" ]; then
1634 echo "Please specify only one of -l and -u options"
1638 # shellcheck source=functions
1639 source "$(dirname "$0")/functions" || exit $?
1643 if [ -n "$zbd_debug" ]; then
1644 global_var_opts+=("--debug=zbd")
1647 realdev=$(readlink -f "$dev")
1648 basename=$(basename "$realdev")
1650 if [[ -b "$realdev" ]]; then
1651 major=$((0x$(stat -L -c '%t' "$realdev"))) || exit $?
1652 minor=$((0x$(stat -L -c '%T' "$realdev"))) || exit $?
1653 disk_size=$(($(<"/sys/dev/block/$major:$minor/size")*512))
1655 # When the target is a partition device, get basename of its
1656 # holder device to access sysfs path of the holder device
1657 if [[ -r "/sys/dev/block/$major:$minor/partition" ]]; then
1658 realsysfs=$(readlink "/sys/dev/block/$major:$minor")
1659 basename=$(basename "${realsysfs%/*}")
1661 min_seq_write_size=$(min_seq_write_size "$basename")
1662 case "$(<"/sys/class/block/$basename/queue/zoned")" in
1663 host-managed|host-aware)
1665 if ! check_blkzone "${dev}"; then
1668 if ! result=($(first_sequential_zone "$dev")); then
1669 echo "Failed to determine first sequential zone"
1672 first_sequential_zone_sector=${result[0]}
1673 sectors_per_zone=${result[1]}
1674 zone_size=$((sectors_per_zone * 512))
1675 unrestricted_reads=$(urswrz "$dev")
1676 if ! max_open_zones=$(max_open_zones "$dev"); then
1677 echo "Failed to determine maximum number of open zones"
1680 max_active_zones=$(max_active_zones "$dev")
1681 set_io_scheduler "$basename" deadline || exit $?
1682 if [ -n "$reset_all_zones" ]; then
1683 reset_zone "$dev" -1
1687 first_sequential_zone_sector=$(((disk_size / 2) &
1688 (min_seq_write_size - 1)))
1689 zone_size=$(max 65536 "$min_seq_write_size")
1690 sectors_per_zone=$((zone_size / 512))
1693 unrestricted_reads=1
1694 set_io_scheduler "$basename" none || exit $?
1697 elif [[ -c "$realdev" ]]; then
1698 # For an SG node, we must have libzbc option specified
1699 if [[ ! -n "$use_libzbc" ]]; then
1700 echo "Character device files can only be used with -l (libzbc) option"
1704 if ! $(is_zbc "$dev"); then
1705 echo "Device is not a ZBC disk"
1710 if ! disk_size=($(( $(zbc_disk_sectors "$dev") * 512))); then
1711 echo "Failed to determine disk size"
1714 if ! min_seq_write_size=($(zbc_physical_block_size "$dev")); then
1715 echo "Failed to determine physical block size"
1718 if ! result=($(first_sequential_zone "$dev")); then
1719 echo "Failed to determine first sequential zone"
1722 first_sequential_zone_sector=${result[0]}
1723 sectors_per_zone=${result[1]}
1724 zone_size=$((sectors_per_zone * 512))
1725 unrestricted_reads=$(urswrz "$dev")
1726 if ! max_open_zones=$(max_open_zones "$dev"); then
1727 echo "Failed to determine maximum number of open zones"
1731 if [ -n "$reset_all_zones" ]; then
1732 reset_zone "$dev" -1
1736 if [[ -n ${max_open_zones_opt} ]]; then
1737 # Override max_open_zones with the script option value
1738 max_open_zones="${max_open_zones_opt}"
1739 global_var_opts+=("--ignore_zone_limits=1")
1740 job_var_opts+=("--max_open_zones=${max_open_zones_opt}")
1743 echo -n "First sequential zone starts at sector $first_sequential_zone_sector;"
1744 echo " zone size: $((zone_size >> 20)) MB"
1746 zone_cap_bs=$(zone_cap_bs "$dev" "$zone_size")
1748 if [ "${#tests[@]}" = 0 ]; then
1749 readarray -t tests < <(declare -F | grep "test[0-9]*" | \
1750 tr -c -d "[:digit:]\n" | sort -n)
1771 trap 'intr=1' SIGINT
1774 for test_number in "${tests[@]}"; do
1775 rm -f "${logfile}.${test_number}"
1777 echo -n "Running test $(printf "%02d" $test_number) ... "
1778 eval "test$test_number"
1780 if ((!ret)) && check_log $test_number; then
1782 cc_status="${green}${status}${end}"
1784 elif ((ret==SKIP_TESTCASE)); then
1786 echo "${SKIP_REASON}" >> "${logfile}.${test_number}"
1787 cc_status="${cyan}${status}${end} ${SKIP_REASON}"
1791 cc_status="${red}${status}${end}"
1795 echo -e "$cc_status"
1796 echo "$status" >> "${logfile}.${test_number}"
1797 [ $intr -ne 0 ] && exit 1
1798 [ -n "$quit_on_err" -a "$rc" -ne 0 ] && exit 1
1801 echo "$passed tests passed"
1802 if [ $skipped -gt 0 ]; then
1803 echo " $skipped tests skipped"
1805 if [ $failed -gt 0 ]; then
1806 echo " $failed tests failed"
1808 echo "Run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )"