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 || return $?
416 check_read $size || return $?
419 # Sequential write to sequential zones.
421 local size off capacity bs
424 off=$((first_sequential_zone_sector * 512))
425 capacity=$(total_zone_capacity 4 $off $dev)
426 size=$((4 * zone_size))
427 bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
428 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
429 --bs="$bs" --do_verify=1 --verify=md5 \
430 >>"${logfile}.${test_number}" 2>&1 || return $?
431 check_written $capacity || return $?
432 check_read $capacity || return $?
435 # Sequential read from sequential zones.
437 local size off capacity bs
440 off=$((first_sequential_zone_sector * 512))
441 capacity=$(total_zone_capacity 4 $off $dev)
442 size=$((4 * zone_size))
443 bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
444 write_and_run_one_fio_job \
445 $((first_sequential_zone_sector * 512)) "${size}" \
447 --size="${size}" --zonemode=zbd --zonesize="${zone_size}" \
448 "$(ioengine "psync")" --iodepth=1 --rw=read --bs="$bs" \
449 >>"${logfile}.${test_number}" 2>&1 || return $?
450 check_read $capacity || return $?
453 # Random write to sequential zones, libaio, queue depth 1.
455 local size=$((zone_size))
459 off=$((first_sequential_zone_sector * 512))
460 capacity=$(total_zone_capacity 1 $off $dev)
461 run_fio_on_seq "$(ioengine "libaio")" --iodepth=1 --rw=randwrite \
462 --bs="$(min 16384 "${zone_size}")" \
463 --do_verify=1 --verify=md5 --size="$size" \
464 >>"${logfile}.${test_number}" 2>&1 || return $?
465 check_written $capacity || return $?
466 check_read $capacity || return $?
469 # Random write to sequential zones, libaio, queue depth 64.
471 local size off capacity
474 size=$((4 * zone_size))
475 off=$((first_sequential_zone_sector * 512))
476 capacity=$(total_zone_capacity 4 $off $dev)
477 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
478 --bs="$(min 16384 "${zone_size}")" \
479 --do_verify=1 --verify=md5 \
480 >>"${logfile}.${test_number}" 2>&1 || return $?
481 check_written $capacity || return $?
482 check_read $capacity || return $?
485 # Random write to sequential zones, sg, queue depth 1.
489 require_scsi_dev || return $SKIP_TESTCASE
492 size=$((4 * zone_size))
493 run_fio_on_seq --ioengine=sg \
494 --iodepth=1 --rw=randwrite --bs=16K \
495 --do_verify=1 --verify=md5 \
496 >>"${logfile}.${test_number}" 2>&1 || return $?
497 check_written $size || return $?
498 check_read $size || return $?
501 # Random write to sequential zones, sg, queue depth 64.
505 require_scsi_dev || return $SKIP_TESTCASE
508 size=$((4 * zone_size))
509 run_fio_on_seq --ioengine=sg \
510 --iodepth=64 --rw=randwrite --bs=16K \
511 --do_verify=1 --verify=md5 \
512 >>"${logfile}.${test_number}" 2>&1 || return $?
513 check_written $size || return $?
514 check_read $size || return $?
517 # Random write to sequential zones, libaio, queue depth 64, random block size.
519 local size off capacity
522 size=$((4 * zone_size))
523 off=$((first_sequential_zone_sector * 512))
524 capacity=$(total_zone_capacity 4 $off $dev)
525 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
526 --bsrange=4K-64K --do_verify=1 --verify=md5 \
527 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
528 check_written $capacity || return $?
529 check_read $capacity || return $?
532 # Random write to sequential zones, libaio, queue depth 64, max 1 open zone.
534 local size off capacity
536 [ -n "$is_zbd" ] && reset_zone "$dev" -1
538 size=$((8 * zone_size))
539 off=$((first_sequential_zone_sector * 512))
540 capacity=$(total_zone_capacity 8 $off $dev)
541 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
542 --max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \
543 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
544 check_written $capacity || return $?
545 check_read $capacity || return $?
548 # Random write to sequential zones, libaio, queue depth 64, max 4 open zones.
550 local size off capacity
552 require_max_open_zones 4 || return $SKIP_TESTCASE
554 [ -n "$is_zbd" ] && reset_zone "$dev" -1
556 size=$((8 * zone_size))
557 off=$((first_sequential_zone_sector * 512))
558 capacity=$(total_zone_capacity 8 $off $dev)
559 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
560 --max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \
562 >>"${logfile}.${test_number}" 2>&1 || return $?
563 check_written $capacity || return $?
564 check_read $capacity || return $?
567 # Random write to conventional zones.
571 if ! result=($(first_online_zone "$dev")); then
572 echo "Failed to determine first online zone"
577 size=$((16 * 2**20)) # 20 MB
578 require_conv_zone_bytes "${size}" || return $SKIP_TESTCASE
580 run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
581 --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \
582 --verify=md5 --offset=$off --size=$size\
583 >>"${logfile}.${test_number}" 2>&1 || return $?
584 check_written $((size)) || return $?
585 check_read $((size)) || return $?
588 # Sequential read on a mix of empty and full zones.
591 local w_off w_size w_capacity
593 for ((i=0;i<4;i++)); do
595 reset_zone "$dev" $((first_sequential_zone_sector +
599 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
600 w_size=$((2 * zone_size))
601 w_capacity=$(total_zone_capacity 2 $w_off $dev)
602 off=$((first_sequential_zone_sector * 512))
603 size=$((4 * zone_size))
604 bs=$(min $((zone_size / 16)) "$zone_cap_bs")
605 write_and_run_one_fio_job "${w_off}" "${w_size}" \
606 "$(ioengine "psync")" --rw=read --bs="$bs" \
607 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
608 --size=$((size)) >>"${logfile}.${test_number}" 2>&1 ||
610 check_written $((w_capacity)) || return $?
611 check_read $((w_capacity))
614 # Random read on a mix of empty and full zones.
617 local i w_off w_size w_capacity
619 for ((i=0;i<4;i++)); do
621 reset_zone "$dev" $((first_sequential_zone_sector +
625 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
626 w_size=$((2 * zone_size))
627 w_capacity=$(total_zone_capacity 2 $w_off $dev)
628 off=$((first_sequential_zone_sector * 512))
629 size=$((4 * zone_size))
630 write_and_run_one_fio_job "${w_off}" "${w_size}" \
631 "$(ioengine "libaio")" --iodepth=64 --rw=randread --bs=16K \
632 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
633 --size=$size >>"${logfile}.${test_number}" 2>&1 || return $?
634 check_written $w_capacity || return $?
635 check_read $size || return $?
638 # Random reads and writes in the last zone.
640 local io off last read size written
642 off=$(((disk_size / zone_size - 1) * zone_size))
643 size=$((disk_size - off))
644 if ! last=($(last_online_zone "$dev")); then
645 echo "Failed to determine last online zone"
648 if [[ "$((last * 512))" -lt "$off" ]]; then
652 if [ -n "$is_zbd" ]; then
653 reset_zone "$dev" $((off / 512)) || return $?
656 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
657 --zonemode=zbd --zonesize="${zone_size}" \
658 --offset=$off --loops=2 --norandommap=1 \
660 >>"${logfile}.${test_number}" 2>&1 || return $?
661 written=$(fio_written <"${logfile}.${test_number}")
662 read=$(fio_read <"${logfile}.${test_number}")
663 io=$((written + read))
664 echo "Total number of bytes read and written: $io <> $size" \
665 >>"${logfile}.${test_number}"
666 [ $io = $((size * 2)) ];
669 # Out-of-range zone reset threshold and frequency parameters.
671 run_fio_on_seq --zone_reset_threshold=-1 |&
672 tee -a "${logfile}.${test_number}" |
673 grep -q 'value out of range' || return $?
677 run_fio_on_seq --zone_reset_threshold=2 |&
678 tee -a "${logfile}.${test_number}" |
679 grep -q 'value out of range' || return $?
683 run_fio_on_seq --zone_reset_threshold=.4:.6 |&
684 tee -a "${logfile}.${test_number}" |
685 grep -q 'the list exceeding max length' || return $?
689 run_fio_on_seq --zone_reset_frequency=-1 |&
690 tee -a "${logfile}.${test_number}" |
691 grep -q 'value out of range' || return $?
695 run_fio_on_seq --zone_reset_frequency=2 |&
696 tee -a "${logfile}.${test_number}" |
697 grep -q 'value out of range' || return $?
701 run_fio_on_seq --zone_reset_frequency=.4:.6 |&
702 tee -a "${logfile}.${test_number}" |
703 grep -q 'the list exceeding max length' || return $?
707 local bs loops=9 size=$((zone_size))
711 off=$((first_sequential_zone_sector * 512))
712 capacity=$(total_zone_capacity 1 $off $dev)
714 bs=$(min $((256*1024)) "$zone_size")
715 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
716 --size=$size --loops=$loops \
717 --zone_reset_frequency=.01 --zone_reset_threshold=.90 \
718 >> "${logfile}.${test_number}" 2>&1 || return $?
719 check_written $((capacity * loops)) || return $?
720 check_reset_count -eq 8 ||
721 check_reset_count -eq 9 ||
722 check_reset_count -eq 10 || return $?
725 # Multiple non-overlapping sequential write jobs for the same drive.
729 for ((i=0;i<16;i++)); do
731 reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone))
734 for ((i=0;i<16;i++)); do
735 opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1")
736 opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))")
737 opts+=("--size=$zone_size" "$(ioengine "psync")" "--rw=write" "--bs=16K")
738 opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1")
739 opts+=(${job_var_opts[@]})
741 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
744 write_to_first_seq_zone() {
749 off=$((first_sequential_zone_sector * 512))
750 capacity=$(total_zone_capacity 1 $off $dev)
752 r=$(((RANDOM << 16) | RANDOM))
753 run_fio --name="$dev" --filename="$dev" "$(ioengine "psync")" --rw="$1" \
754 --thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \
756 --size=$zone_size --loops=$loops --randseed="$r" \
757 --zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \
758 --gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $?
759 check_written $((loops * capacity)) || return $?
762 # Overwrite the first sequential zone four times sequentially.
764 write_to_first_seq_zone write
767 # Overwrite the first sequential zone four times using random writes.
769 write_to_first_seq_zone randwrite
772 # Multiple overlapping random write jobs for the same drive.
774 local i jobs=16 off opts
776 require_seq_zones 65 || return $SKIP_TESTCASE
777 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
778 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
781 capacity=$(total_zone_capacity 1 $off $dev)
782 for ((i=0;i<jobs;i++)); do
783 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
784 opts+=("--size=$zone_size" "--io_size=$capacity" "$(ioengine "psync")" "--rw=randwrite")
785 opts+=("--thread=1" "--direct=1" "--zonemode=zbd")
786 opts+=("--zonesize=${zone_size}" "--group_reporting=1")
787 opts+=(${job_var_opts[@]})
789 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
790 check_written $((jobs * $capacity)) || return $?
791 check_reset_count -eq $jobs ||
792 check_reset_count -eq $((jobs - 1)) ||
796 # Multiple overlapping random write jobs for the same drive and with a limited
797 # number of open zones.
799 local i jobs=16 off opts=()
801 require_seq_zones 80 || return $SKIP_TESTCASE
802 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
803 size=$((16*zone_size))
805 [ -n "$is_zbd" ] && reset_zone "$dev" -1
808 for ((i=0;i<jobs;i++)); do
809 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
810 opts+=("--size=$size" "--io_size=$zone_size" "--thread=1")
811 opts+=("$(ioengine "psync")" "--rw=randwrite" "--direct=1")
812 opts+=("--max_open_zones=4" "--group_reporting=1")
813 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
814 # max_open_zones is already specified
815 opts+=($(job_var_opts_exclude "--max_open_zones"))
817 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
818 check_written $((jobs * zone_size)) || return $?
821 # Random reads and writes across the entire disk for 30s.
826 off=$((first_sequential_zone_sector * 512))
827 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw \
828 --bs="$(max $((zone_size / 128)) "$min_seq_write_size")"\
829 --zonemode=zbd --zonesize="${zone_size}" --offset=$off\
830 --loops=2 --time_based --runtime=30s --norandommap=1\
831 >>"${logfile}.${test_number}" 2>&1
834 # Random reads across all sequential zones for 30s. This is not only a fio
835 # test but also allows to verify the performance of a drive.
837 local bs inc nz off opts size
839 [ -n "$is_zbd" ] && reset_zone "$dev" -1
841 # As preparation, write 128 KB to sequential write required zones. Limit
842 # write target zones up to max_open_zones to keep test time reasonable.
843 # To distribute the write target zones evenly, skip certain zones for every
844 # write. Utilize zonemode strided for such write patterns.
846 nz=$((max_open_zones))
847 if [[ $nz -eq 0 ]]; then
850 off=$((first_sequential_zone_sector * 512))
851 size=$((disk_size - off))
852 inc=$(((size / nz / zone_size) * zone_size))
853 opts=("--name=$dev" "--filename=$dev" "--rw=write" "--bs=${bs}")
854 opts+=("--offset=$off" "--size=$((inc * nz))" "--io_size=$((bs * nz))")
855 opts+=("--zonemode=strided" "--zonesize=${bs}" "--zonerange=${inc}")
856 opts+=("--direct=1" "$(ioengine "psync")")
857 echo "fio ${opts[@]}" >> "${logfile}.${test_number}"
858 "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" \
861 # Next, run the test.
862 opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
863 opts+=("--bs=$bs" "$(ioengine "psync")" "--rw=randread" "--direct=1")
864 opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd")
865 opts+=("--zonesize=${zone_size}")
866 opts+=(${job_var_opts[@]})
867 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
870 # Random writes across all sequential zones. This is not only a fio test but
871 # also allows to verify the performance of a drive.
873 local off opts=() size
875 require_zbd || return $SKIP_TESTCASE
877 [ -n "$is_zbd" ] && reset_zone "$dev" -1
879 off=$((first_sequential_zone_sector * 512))
880 size=$((disk_size - off))
881 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
882 opts+=("--bs=128K" "$(ioengine "psync")" "--rw=randwrite" "--direct=1")
883 opts+=("--thread=1" "--time_based" "--runtime=30")
884 opts+=("--max_open_zones=$max_open_zones" "--zonemode=zbd")
885 opts+=("--zonesize=${zone_size}")
886 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
889 # Write to sequential zones with a block size that is not a divisor of the
892 local bs io_size size
893 local off capacity=0;
895 [ -n "$is_zbd" ] && reset_zone "$dev" -1
897 off=$((first_sequential_zone_sector * 512))
898 capacity=$(total_zone_capacity 1 $off $dev)
899 size=$((2 * zone_size))
900 io_size=$((5 * capacity))
901 bs=$((3 * capacity / 4))
902 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
903 --size=$size --io_size=$io_size --bs=$bs \
904 >> "${logfile}.${test_number}" 2>&1 || return $?
905 check_written $((io_size / bs * bs)) || return $?
908 # Test repeated async write job with verify using two unaligned block sizes.
910 local bs off zone_capacity
913 require_zbd || return $SKIP_TESTCASE
916 off=$((first_sequential_zone_sector * 512))
917 zone_capacity=$(total_zone_capacity 1 $off $dev)
918 block_sizes=($((4096 * 7)) $(($(min ${zone_capacity} 4194304) - 4096)))
920 for bs in ${block_sizes[@]}; do
921 run_fio --name=job --filename="${dev}" --rw=randwrite \
922 --bs="${bs}" --offset="${off}" \
923 --size=$((4 * zone_size)) --iodepth=256 \
924 "$(ioengine "libaio")" --time_based=1 --runtime=15s \
925 --zonemode=zbd --direct=1 --zonesize="${zone_size}" \
926 --verify=crc32c --do_verify=1 ${job_var_opts[@]} \
927 >> "${logfile}.${test_number}" 2>&1 || return $?
931 # Test 1/4 for the I/O boundary rounding code: $size < $zone_size.
933 local bs off io_size size
936 off=$(((first_sequential_zone_sector + 1) * 512))
937 size=$((zone_size - 2 * 512))
938 bs=$((zone_size / 4))
939 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
940 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
941 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
942 >> "${logfile}.${test_number}" 2>&1 && return 1
943 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
946 # Test 2/4 for the I/O boundary rounding code: $size < $zone_size.
948 local bs off io_size size
951 off=$(((first_sequential_zone_sector) * 512))
952 size=$((zone_size - 512))
953 bs=$((zone_size / 4))
954 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
955 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
956 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
957 >> "${logfile}.${test_number}" 2>&1 && return 1
958 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
961 # Test 3/4 for the I/O boundary rounding code: $size > $zone_size.
963 local bs off size capacity
966 capacity=$(total_zone_capacity 1 $((first_sequential_zone_sector*512)) $dev)
967 if [ "$first_sequential_zone_sector" = 0 ]; then
970 off=$(((first_sequential_zone_sector - 1) * 512))
972 size=$((zone_size + 2 * 512))
973 bs=$(min $((zone_size / 4)) "$zone_cap_bs")
974 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
975 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
976 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
977 >> "${logfile}.${test_number}" 2>&1
978 check_written $capacity || return $?
981 # Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size
986 size=$((min_seq_write_size))
987 off=$((disk_size - min_seq_write_size))
988 bs=$((min_seq_write_size))
989 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
990 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
991 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
992 >> "${logfile}.${test_number}" 2>&1 && return 1
993 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
996 # Read one block from a block device.
1001 if ! result=($(first_online_zone "$dev")); then
1002 echo "Failed to determine first online zone"
1006 bs=$((min_seq_write_size))
1007 run_one_fio_job --rw=read "$(ioengine "psync")" --offset=$off --bs=$bs \
1008 --size=$bs "$@" 2>&1 |
1009 tee -a "${logfile}.${test_number}"
1012 # Check whether fio accepts --zonemode=none for zoned block devices.
1014 require_zbd || return $SKIP_TESTCASE
1015 read_one_block --zonemode=none >/dev/null || return $?
1016 check_read $((min_seq_write_size)) || return $?
1019 # Check whether fio accepts --zonemode=strided for zoned block devices.
1023 bs=$((min_seq_write_size))
1024 require_zbd || return $SKIP_TESTCASE
1025 read_one_block --zonemode=strided |
1026 grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
1028 read_one_block --zonemode=strided --zonesize=$bs >/dev/null || return $?
1029 check_read $bs || return $?
1032 # Check whether fio checks the zone size for zoned block devices.
1034 require_zbd || return $SKIP_TESTCASE
1035 read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) |
1036 grep -q 'job parameter zonesize.*does not match disk zone size'
1039 # Check whether fio handles --zonesize=0 correctly for regular block devices.
1041 require_regular_block_dev || return $SKIP_TESTCASE
1042 read_one_block --zonemode=zbd --zonesize=0 |
1043 grep -q 'Specifying the zone size is mandatory for regular file/block device with --zonemode=zbd'
1046 # Check whether fio handles --zonesize=1 correctly for regular block devices.
1048 require_regular_block_dev || return $SKIP_TESTCASE
1049 read_one_block --zonemode=zbd --zonesize=1 |
1050 grep -q 'zone size must be at least 512 bytes for --zonemode=zbd'
1053 # Check whether fio handles --zonemode=none --zonesize=1 correctly.
1055 read_one_block --zonemode=none --zonesize=1 |
1056 grep -q 'fio: --zonemode=none and --zonesize are not compatible'
1062 require_zbd || return $SKIP_TESTCASE
1064 bs=$((min_seq_write_size))
1065 run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite --bs=$bs\
1066 --offset=$((first_sequential_zone_sector * 512)) \
1067 --size="$zone_size" --do_verify=1 --verify=md5 2>&1 |
1068 tee -a "${logfile}.${test_number}" |
1069 grep -q "fio: first I/O failed. If .* is a zoned block device, consider --zonemode=zbd"
1072 # Random write to sequential zones, libaio, 8 jobs, queue depth 64 per job
1077 size=$((4 * zone_size))
1078 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=4K \
1079 --group_reporting=1 --numjobs=8 \
1080 >> "${logfile}.${test_number}" 2>&1 || return $?
1081 check_written $((size * 8)) || return $?
1084 # Check whether fio handles --zonemode=zbd --zoneskip=1 correctly.
1089 bs=$((min_seq_write_size))
1090 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
1091 >> "${logfile}.${test_number}" 2>&1 && return 1
1092 grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
1095 # Multiple overlapping random write jobs for the same drive and with a
1096 # limited number of open zones. This is similar to test29, but uses libaio
1097 # to stress test zone locking.
1099 local i jobs=16 off opts=()
1101 require_zbd || return $SKIP_TESTCASE
1102 require_seq_zones 80 || return $SKIP_TESTCASE
1104 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
1105 size=$((16*zone_size))
1107 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1109 opts=("--aux-path=/tmp" "--allow_file_create=0" "--significant_figures=10")
1110 opts+=("--debug=zbd")
1111 opts+=("$(ioengine "libaio")" "--rw=randwrite" "--direct=1")
1112 opts+=("--time_based" "--runtime=30")
1113 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
1114 opts+=("--max_open_zones=4")
1115 for ((i=0;i<jobs;i++)); do
1116 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
1117 opts+=("--io_size=$zone_size" "--iodepth=256" "--thread=1")
1118 opts+=("--size=$size" "--group_reporting=1")
1119 # max_open_zones is already specified
1120 opts+=($(job_var_opts_exclude "--max_open_zones"))
1123 fio=$(dirname "$0")/../../fio
1125 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
1127 timeout -v -s KILL 180s \
1128 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}" \
1129 >> "${logfile}.${test_number}" 2>&1 || return $?
1132 # Check if fio handles --zonecapacity on a normal block device correctly
1135 require_regular_block_dev || return $SKIP_TESTCASE
1137 size=$((2 * zone_size))
1138 capacity=$((zone_size * 3 / 4))
1140 run_one_fio_job "$(ioengine "psync")" --rw=write \
1141 --zonemode=zbd --zonesize="${zone_size}" \
1142 --zonecapacity=${capacity} \
1143 --verify=md5 --size=${size} >>"${logfile}.${test_number}" 2>&1 ||
1145 check_written $((capacity * 2)) || return $?
1146 check_read $((capacity * 2)) || return $?
1149 # Verify that conv zones are not locked and only seq zones are locked during
1150 # random read on conv-seq mixed zones.
1154 require_zbd || return $SKIP_TESTCASE
1155 require_conv_zones 8 || return $SKIP_TESTCASE
1156 require_seq_zones 8 || return $SKIP_TESTCASE
1158 reset_zone "${dev}" -1
1160 off=$((first_sequential_zone_sector * 512 - 8 * zone_size))
1161 run_fio --name=job --filename=${dev} --offset=${off} --bs=64K \
1162 --size=$((16 * zone_size)) "$(ioengine "libaio")" --rw=randread\
1163 --time_based --runtime=3 --zonemode=zbd --zonesize=${zone_size}\
1164 --direct=1 --group_reporting=1 ${job_var_opts[@]} \
1165 >> "${logfile}.${test_number}" 2>&1 || return $?
1168 # Verify that conv zones are neither locked nor opened during random write on
1169 # conv-seq mixed zones. Zone lock and zone open shall happen only on seq zones.
1174 require_zbd || return $SKIP_TESTCASE
1175 require_conv_zones 8 || return $SKIP_TESTCASE
1176 require_seq_zones 8 || return $SKIP_TESTCASE
1178 reset_zone "$dev" -1
1180 off=$((first_sequential_zone_sector * 512 - 8 * zone_size))
1181 opts+=("--size=$((16 * zone_size))" "$(ioengine "libaio")")
1182 opts+=("--zonemode=zbd" "--direct=1" "--zonesize=${zone_size}")
1183 opts+=("--max_open_zones=2" "--offset=$off")
1184 opts+=("--thread=1" "--group_reporting=1")
1185 opts+=("--time_based" "--runtime=30" "--rw=randwrite")
1186 for ((i=0;i<jobs;i++)); do
1187 opts+=("--name=job${i}" "--filename=$dev")
1188 opts+=("--bs=$(((i+1)*16))K")
1189 opts+=($(job_var_opts_exclude "--max_open_zones"))
1191 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
1194 # Verify that zone_reset_threshold only accounts written bytes in seq
1195 # zones, and written data bytes of conv zones are not counted.
1199 require_zbd || return $SKIP_TESTCASE
1200 require_conv_zones 8 || return $SKIP_TESTCASE
1201 require_seq_zones 8 || return $SKIP_TESTCASE
1203 reset_zone "${dev}" -1
1205 # Total I/O size is 1/8 = 0.125 of the I/O range of cont + seq zones.
1206 # Set zone_reset_threshold as 0.1. The threshold size is less than
1207 # 0.125, then, reset count zero is expected.
1208 # On the other hand, half of the I/O range is covered by conv zones.
1209 # If fio would count the conv zones for zone_reset_threshold, the ratio
1210 # were more than 0.5 and would trigger zone resets.
1212 off=$((first_sequential_zone_sector * 512 - 8 * zone_size))
1213 io_size=$((zone_size * 16 / 8))
1214 run_fio --name=job --filename=$dev --rw=randwrite --bs=$((zone_size/16))\
1215 --size=$((zone_size * 16)) --softrandommap=1 \
1216 --io_size=$((io_size)) "$(ioengine "psync")" --offset=$off \
1217 --zonemode=zbd --direct=1 --zonesize=${zone_size} \
1218 --zone_reset_threshold=.1 --zone_reset_frequency=1.0 \
1219 ${job_var_opts[@]} --debug=zbd \
1220 >> "${logfile}.${test_number}" 2>&1 || return $?
1222 check_written ${io_size} || return $?
1223 check_reset_count -eq 0 || return $?
1226 # Check both reads and writes are executed by random I/O to conventional zones.
1228 local off capacity io read_b=0 written_b=0
1230 require_zbd || return $SKIP_TESTCASE
1231 require_conv_zones 4 || return $SKIP_TESTCASE
1233 off=$((first_sequential_zone_sector * 512 - 4 * zone_size))
1234 capacity=$(total_zone_capacity 4 $off $dev)
1235 run_fio --name=job --filename=${dev} --rw=randrw --bs=64K \
1236 --size=$((4 * zone_size)) "$(ioengine "psync")" --offset=${off}\
1237 --zonemode=zbd --direct=1 --zonesize=${zone_size} \
1238 ${job_var_opts[@]} \
1239 >> "${logfile}.${test_number}" 2>&1 || return $?
1241 written_b=$(fio_written <"${logfile}.${test_number}")
1242 read_b=$(fio_read <"${logfile}.${test_number}")
1243 io=$((written_b + read_b))
1244 echo "Number of bytes read: $read_b" >>"${logfile}.${test_number}"
1245 echo "Number of bytes written: $written_b" >>"${logfile}.${test_number}"
1246 echo "Total number of bytes read and written: $io <> $capacity" \
1247 >>"${logfile}.${test_number}"
1248 if ((io==capacity && written_b != 0 && read_b != 0)); then
1254 # Test read/write mix with verify.
1256 require_zbd || return $SKIP_TESTCASE
1257 require_seq_zones 8 || return $SKIP_TESTCASE
1260 run_fio --name=job --filename=${dev} "$(ioengine "libaio")" \
1261 --time_based=1 --runtime=30s --continue_on_error=0 \
1262 --offset=$((first_sequential_zone_sector * 512)) \
1263 --size=$((8*zone_size)) --direct=1 --iodepth=1 \
1264 --rw=randrw:2 --rwmixwrite=25 --bsrange=4k-${zone_size} \
1265 --zonemode=zbd --zonesize=${zone_size} \
1266 --verify=crc32c --do_verify=1 --verify_backlog=2 \
1267 --alloc-size=65536 --random_generator=tausworthe64 \
1268 ${job_var_opts[@]} --debug=zbd \
1269 >> "${logfile}.${test_number}" 2>&1 || return $?
1272 # test 'z' suffix parsing only
1275 bs=$((min_seq_write_size))
1277 require_zbd || return $SKIP_TESTCASE
1278 # offset=1z + offset_increment=10z + size=2z
1279 require_seq_zones 13 || return $SKIP_TESTCASE
1285 "$(ioengine "psync")" \
1287 --zonesize=${zone_size} \
1291 --offset_increment=10z \
1295 ${job_var_opts[@]} --debug=zbd \
1296 >> "${logfile}.${test_number}" 2>&1 || return $?
1299 # test 'z' suffix parsing only
1302 bs=$((min_seq_write_size))
1304 require_regular_block_dev || return $SKIP_TESTCASE
1305 require_seq_zones 10 || return $SKIP_TESTCASE
1311 "$(ioengine "psync")" \
1312 --zonemode=strided \
1313 --zonesize=${zone_size} \
1318 ${job_var_opts[@]} --debug=zbd \
1319 >> "${logfile}.${test_number}" 2>&1 || return $?
1322 # Test that repeated async write job does not cause zone reset during writes
1323 # in-flight, when the block size is not a divisor of the zone size.
1327 require_zbd || return $SKIP_TESTCASE
1331 off=$((first_sequential_zone_sector * 512))
1333 run_fio --name=job --filename="${dev}" --rw=randwrite --bs="${bs}" \
1334 --offset="${off}" --size=$((4 * zone_size)) --iodepth=256 \
1335 "$(ioengine "libaio")" --time_based=1 --runtime=30s \
1336 --zonemode=zbd --direct=1 --zonesize="${zone_size}" \
1337 ${job_var_opts[@]} \
1338 >> "${logfile}.${test_number}" 2>&1 || return $?
1341 # Random writes and random trims to sequential write required zones for 30s.
1345 require_seq_zones 128 || return $SKIP_TESTCASE
1347 size=$((zone_size * 128))
1348 bs="$(max $((zone_size / 128)) "$min_seq_write_size")"
1350 off=$((first_sequential_zone_sector * 512))
1351 run_fio --zonemode=zbd --direct=1 --zonesize="${zone_size}" --thread=1 \
1352 --filename="${dev}" --norandommap=1 \
1353 --name="precondition" --rw=write "$(ioengine "psync")" \
1354 --offset="${off}" --size=$((zone_size * 16)) --bs="${bs}" \
1355 "${job_var_opts[@]}" \
1356 --name=wjob --wait_for="precondition" --rw=randwrite \
1357 "$(ioengine "libaio")" --iodepth=8 \
1358 --offset="${off}" --size="${size}" --bs="${bs}" \
1359 --time_based --runtime=30s --flow=128 "${job_var_opts[@]}" \
1360 --name=trimjob --wait_for="precondition" --rw=randtrim \
1361 "$(ioengine "psync")" \
1362 --offset="${off}" --size="${size}" --bs="${zone_size}" \
1363 --time_based --runtime=30s --flow=1 "${job_var_opts[@]}" \
1364 >>"${logfile}.${test_number}" 2>&1
1367 # Test zone_reset_threshold with verify.
1369 local off bs loops=2 size=$((zone_size)) w
1370 local -a workloads=(write randwrite rw randrw)
1373 off=$((first_sequential_zone_sector * 512))
1375 bs=$(min $((256*1024)) "$zone_size")
1376 for w in "${workloads[@]}"; do
1377 run_fio_on_seq "$(ioengine "psync")" --rw=${w} --bs="$bs" \
1378 --size=$size --loops=$loops --do_verify=1 \
1379 --verify=md5 --zone_reset_frequency=.9 \
1380 --zone_reset_threshold=.1 \
1381 >> "${logfile}.${test_number}" 2>&1 || return $?
1385 # Test fio errors out experimental_verify option with zonemode=zbd.
1387 run_fio_on_seq "$(ioengine "psync")" --rw=write --size=$zone_size \
1388 --do_verify=1 --verify=md5 --experimental_verify=1 \
1389 >> "${logfile}.${test_number}" 2>&1 && return 1
1390 grep -q 'not support experimental verify' "${logfile}.${test_number}"
1393 # Test fio errors out zone_reset_threshold option for multiple jobs with
1394 # different write ranges.
1396 run_fio_on_seq "$(ioengine "psync")" --rw=write --size="$zone_size" \
1397 --numjobs=2 --offset_increment="$zone_size" \
1398 --zone_reset_threshold=0.1 --zone_reset_frequency=1 \
1399 --exitall_on_error=1 \
1400 >> "${logfile}.${test_number}" 2>&1 && return 1
1401 grep -q 'different write ranges' "${logfile}.${test_number}"
1404 # Test zone_reset_threshold option works for multiple jobs with same write
1407 local bs loops=2 size=$((zone_size))
1409 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1411 # Two jobs write to single zone twice. Reset zone happens at next write
1412 # after half of the zone gets filled. So 2 * 2 * 2 - 1 = 7 times zone
1413 # resets are expected.
1414 bs=$(min $((256*1024)) $((zone_size / 4)))
1415 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
1416 --size=$size --loops=$loops --numjobs=2 \
1417 --zone_reset_frequency=1 --zone_reset_threshold=.5 \
1418 --group_reporting=1 \
1419 >> "${logfile}.${test_number}" 2>&1 || return $?
1420 check_written $((size * loops * 2)) || return $?
1421 check_reset_count -eq 7 || return $?
1424 # Test zone_reset_threshold option works for a read job and a write job with
1425 # different IO range.
1427 local bs loops=2 size=$((zone_size)) off1 off2
1429 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1431 off1=$((first_sequential_zone_sector * 512))
1432 off2=$((off1 + zone_size))
1433 bs=$(min $((256*1024)) $((zone_size / 4)))
1435 # One job writes to single zone twice. Reset zone happens at next write
1436 # after half of the zone gets filled. So 2 * 2 - 1 = 3 times zone resets
1438 run_fio "$(ioengine "psync")" --bs="$bs" --size=$size --loops=$loops \
1439 --filename="$dev" --group_reporting=1 \
1440 --zonemode=zbd --zonesize="$zone_size" --direct=1 \
1441 --zone_reset_frequency=1 --zone_reset_threshold=.5 \
1442 --name=r --rw=read --offset=$off1 "${job_var_opts[@]}" \
1443 --name=w --rw=write --offset=$off2 "${job_var_opts[@]}" \
1444 >> "${logfile}.${test_number}" 2>&1 || return $?
1445 check_written $((size * loops)) || return $?
1446 check_reset_count -eq 3 || return $?
1449 # Test write zone accounting handles almost full zones correctly. Prepare an
1450 # almost full, but not full zone. Write to the zone with verify using larger
1451 # block size. Then confirm fio does not report write zone accounting failure.
1455 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1457 bs=$((zone_size / 8))
1458 cap=$(total_zone_capacity 1 $((first_sequential_zone_sector*512)) $dev)
1459 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
1460 --size=$((zone_size)) \
1461 --io_size=$((cap - bs)) \
1462 >> "${logfile}.${test_number}" 2>&1 || return $?
1464 bs=$((zone_size / 2))
1465 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
1466 --size=$((zone_size)) --do_verify=1 --verify=md5 \
1467 >> "${logfile}.${test_number}" 2>&1 || return $?
1470 # Test open zone accounting handles trim workload correctly. Prepare open zones
1471 # as many as max_open_zones=4. Trim one of the 4 zones. Then write to another
1472 # zone and check the write amount is expected size.
1476 [ -n "$is_zbd" ] && reset_zone "$dev" -1
1478 off=$((first_sequential_zone_sector * 512))
1479 capacity=$(total_zone_capacity 1 $off "$dev")
1480 run_fio --zonemode=zbd --direct=1 --zonesize="$zone_size" --thread=1 \
1481 --filename="$dev" --group_reporting=1 --max_open_zones=4 \
1482 "$(ioengine "psync")" \
1483 --name="prep_open_zones" --rw=randwrite --offset="$off" \
1484 --size="$((zone_size * 4))" --bs=4096 --io_size="$zone_size" \
1485 --name=trimjob --wait_for="prep_open_zones" --rw=trim \
1486 --bs="$zone_size" --offset="$off" --size="$zone_size" \
1487 --name=write --wait_for="trimjob" --rw=write --bs=4096 \
1488 --offset="$((off + zone_size * 4))" --size="$zone_size" \
1489 >> "${logfile}.${test_number}" 2>&1
1491 check_written $((zone_size + capacity))
1494 # Test closed zones are handled as open zones. This test case requires zoned
1495 # block devices which has same max_open_zones and max_active_zones.
1499 require_zbd || return $SKIP_TESTCASE
1500 require_max_active_zones 2 || return $SKIP_TESTCASE
1501 require_max_open_zones "${max_active_zones}" || return $SKIP_TESTCASE
1502 require_seq_zones $((max_active_zones * 16)) || return $SKIP_TESTCASE
1504 reset_zone "$dev" -1
1506 # Prepare max_active_zones in closed condition.
1507 off=$((first_sequential_zone_sector * 512))
1508 run_fio --name=w --filename="$dev" --zonemod=zbd --direct=1 \
1509 --offset=$((off)) --zonesize="${zone_size}" --rw=randwrite \
1510 --bs=4096 --size="$((zone_size * max_active_zones))" \
1511 --io_size="${zone_size}" "$(ioengine "psync")" \
1512 >> "${logfile}.${test_number}" 2>&1 || return $?
1513 for ((i = 0; i < max_active_zones; i++)); do
1514 close_zone "$dev" $((off / 512)) || return $?
1515 off=$((off + zone_size))
1518 # Run random write to the closed zones and empty zones. This confirms
1519 # that fio handles closed zones as write target open zones. Otherwise,
1520 # fio writes to the empty zones and hit the max_active_zones limit.
1521 off=$((first_sequential_zone_sector * 512))
1522 run_one_fio_job --zonemod=zbd --direct=1 \
1523 "$(ioengine "psync")" --rw=randwrite --bs=4096 \
1524 --max_open_zones="$max_active_zones" --offset=$((off)) \
1525 --size=$((max_active_zones * 16 * zone_size)) \
1526 --io_size=$((zone_size)) --zonesize="${zone_size}" \
1527 --time_based --runtime=5s \
1528 >> "${logfile}.${test_number}" 2>&1
1531 # Test max_active_zones limit failure is reported with good error message.
1535 require_zbd || return $SKIP_TESTCASE
1536 require_max_active_zones 2 || return $SKIP_TESTCASE
1537 require_max_open_zones "${max_active_zones}" || return $SKIP_TESTCASE
1538 require_seq_zones $((max_active_zones + 1)) || return $SKIP_TESTCASE
1540 reset_zone "$dev" -1
1542 # Prepare max_active_zones in open condition.
1543 off=$((first_sequential_zone_sector * 512))
1544 run_fio --name=w --filename="$dev" --zonemod=zbd --direct=1 \
1545 --offset=$((off)) --zonesize="${zone_size}" --rw=randwrite \
1546 --bs=4096 --size="$((zone_size * max_active_zones))" \
1547 --io_size="${zone_size}" "$(ioengine "psync")" \
1548 >> "${logfile}.${test_number}" 2>&1 || return $?
1550 # Write to antoher zone and trigger max_active_zones limit error.
1551 off=$((off + zone_size * max_active_zones))
1552 run_one_fio_job --zonemod=zbd --direct=1 "$(ioengine "psync")" \
1553 --rw=write --bs=$min_seq_write_size --offset=$((off)) \
1554 --size=$((zone_size)) --zonesize="${zone_size}" \
1555 >> "${logfile}.${test_number}" 2>&1 && return $?
1556 grep -q 'Exceeded max_active_zones limit' "${logfile}.${test_number}"
1570 while [ "${1#-}" != "$1" ]; do
1572 -d) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=drd"
1573 "--show-confl-seg=no");
1575 -e) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=helgrind");
1577 -l) use_libzbc=1; shift;;
1578 -r) reset_all_zones=1; shift;;
1579 -w) reset_before_write=1; shift;;
1580 -t) tests+=("$2"); shift; shift;;
1581 -o) max_open_zones_opt="${2}"; shift; shift;;
1582 -v) dynamic_analyzer=(valgrind "--read-var-info=yes");
1584 -q) quit_on_err=1; shift;;
1585 -z) zbd_debug=1; shift;;
1586 -u) force_io_uring=1; shift;;
1592 if [ $# != 1 ]; then
1597 if [ -n "$use_libzbc" -a -n "$force_io_uring" ]; then
1598 echo "Please specify only one of -l and -u options"
1602 # shellcheck source=functions
1603 source "$(dirname "$0")/functions" || exit $?
1607 if [ -n "$zbd_debug" ]; then
1608 global_var_opts+=("--debug=zbd")
1611 realdev=$(readlink -f "$dev")
1612 basename=$(basename "$realdev")
1614 if [[ -b "$realdev" ]]; then
1615 major=$((0x$(stat -L -c '%t' "$realdev"))) || exit $?
1616 minor=$((0x$(stat -L -c '%T' "$realdev"))) || exit $?
1617 disk_size=$(($(<"/sys/dev/block/$major:$minor/size")*512))
1619 # When the target is a partition device, get basename of its
1620 # holder device to access sysfs path of the holder device
1621 if [[ -r "/sys/dev/block/$major:$minor/partition" ]]; then
1622 realsysfs=$(readlink "/sys/dev/block/$major:$minor")
1623 basename=$(basename "${realsysfs%/*}")
1625 min_seq_write_size=$(min_seq_write_size "$basename")
1626 case "$(<"/sys/class/block/$basename/queue/zoned")" in
1627 host-managed|host-aware)
1629 if ! check_blkzone "${dev}"; then
1632 if ! result=($(first_sequential_zone "$dev")); then
1633 echo "Failed to determine first sequential zone"
1636 first_sequential_zone_sector=${result[0]}
1637 sectors_per_zone=${result[1]}
1638 zone_size=$((sectors_per_zone * 512))
1639 if ! max_open_zones=$(max_open_zones "$dev"); then
1640 echo "Failed to determine maximum number of open zones"
1643 max_active_zones=$(max_active_zones "$dev")
1644 set_io_scheduler "$basename" deadline || exit $?
1645 if [ -n "$reset_all_zones" ]; then
1646 reset_zone "$dev" -1
1650 first_sequential_zone_sector=$(((disk_size / 2) &
1651 (min_seq_write_size - 1)))
1652 zone_size=$(max 65536 "$min_seq_write_size")
1653 sectors_per_zone=$((zone_size / 512))
1656 set_io_scheduler "$basename" none || exit $?
1659 elif [[ -c "$realdev" ]]; then
1660 # For an SG node, we must have libzbc option specified
1661 if [[ ! -n "$use_libzbc" ]]; then
1662 echo "Character device files can only be used with -l (libzbc) option"
1666 if ! $(is_zbc "$dev"); then
1667 echo "Device is not a ZBC disk"
1672 if ! disk_size=($(( $(zbc_disk_sectors "$dev") * 512))); then
1673 echo "Failed to determine disk size"
1676 if ! min_seq_write_size=($(zbc_physical_block_size "$dev")); then
1677 echo "Failed to determine physical block size"
1680 if ! result=($(first_sequential_zone "$dev")); then
1681 echo "Failed to determine first sequential zone"
1684 first_sequential_zone_sector=${result[0]}
1685 sectors_per_zone=${result[1]}
1686 zone_size=$((sectors_per_zone * 512))
1687 if ! max_open_zones=$(max_open_zones "$dev"); then
1688 echo "Failed to determine maximum number of open zones"
1692 if [ -n "$reset_all_zones" ]; then
1693 reset_zone "$dev" -1
1697 if [[ -n ${max_open_zones_opt} ]]; then
1698 # Override max_open_zones with the script option value
1699 max_open_zones="${max_open_zones_opt}"
1700 global_var_opts+=("--ignore_zone_limits=1")
1701 job_var_opts+=("--max_open_zones=${max_open_zones_opt}")
1704 echo -n "First sequential zone starts at sector $first_sequential_zone_sector;"
1705 echo " zone size: $((zone_size >> 20)) MB"
1707 zone_cap_bs=$(zone_cap_bs "$dev" "$zone_size")
1709 if [ "${#tests[@]}" = 0 ]; then
1710 readarray -t tests < <(declare -F | grep "test[0-9]*" | \
1711 tr -c -d "[:digit:]\n" | sort -n)
1732 trap 'intr=1' SIGINT
1735 for test_number in "${tests[@]}"; do
1736 rm -f "${logfile}.${test_number}"
1738 echo -n "Running test $(printf "%02d" $test_number) ... "
1739 eval "test$test_number"
1741 if ((!ret)) && check_log $test_number; then
1743 cc_status="${green}${status}${end}"
1745 elif ((ret==SKIP_TESTCASE)); then
1747 echo "${SKIP_REASON}" >> "${logfile}.${test_number}"
1748 cc_status="${cyan}${status}${end} ${SKIP_REASON}"
1752 cc_status="${red}${status}${end}"
1756 echo -e "$cc_status"
1757 echo "$status" >> "${logfile}.${test_number}"
1758 [ $intr -ne 0 ] && exit 1
1759 [ -n "$quit_on_err" -a "$rc" -ne 0 ] && exit 1
1762 echo "$passed tests passed"
1763 if [ $skipped -gt 0 ]; then
1764 echo " $skipped tests skipped"
1766 if [ $failed -gt 0 ]; then
1767 echo " $failed tests failed"
1769 echo "Run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )"