3 # Copyright (C) 2018 Western Digital Corporation or its affiliates.
5 # This file is released under the GPL.
8 echo "Usage: $(basename "$0") [OPTIONS] <test target device file>"
10 echo -e "\t-d Run fio with valgrind using DRD tool"
11 echo -e "\t-e Run fio with valgrind using helgrind tool"
12 echo -e "\t-v Run fio with valgrind --read-var-info option"
13 echo -e "\t-l Test with libzbc ioengine"
14 echo -e "\t-r Reset all zones before test start"
15 echo -e "\t-o <max_open_zones> Run fio with max_open_zones limit"
16 echo -e "\t-t <test #> Run only a single test case with specified number"
17 echo -e "\t-z Run fio with debug=zbd option"
21 if [ "$1" -gt "$2" ]; then
29 if [ "$1" -lt "$2" ]; then
37 if [ -n "$use_libzbc" ]; then
38 echo -n "--ioengine=libzbc"
40 echo -n "--ioengine=$1"
47 [ -e "/sys/block/$dev" ] || return $?
48 if [ -e "/sys/block/$dev/mq" ]; then
51 deadline) sched=mq-deadline;;
56 mq-deadline) sched=deadline;;
60 echo "$sched" >"/sys/block/$dev/queue/scheduler"
66 read=$(fio_read <"${logfile}.${test_number}")
67 echo "read: $read <> $1" >> "${logfile}.${test_number}"
74 written=$(fio_written <"${logfile}.${test_number}")
75 echo "written: $written <> $1" >> "${logfile}.${test_number}"
79 # Compare the reset count from the log file with reset count $2 using operator
80 # $1 (=, -ge, -gt, -le, -lt).
84 reset_count=$(fio_reset_count <"${logfile}.${test_number}")
85 echo "reset_count: test $reset_count $1 $2" >> "${logfile}.${test_number}"
86 eval "[ '$reset_count' '$1' '$2' ]"
89 # Check log for failed assertions and crashes. Without these checks,
90 # a test can succeed even when these events happen, but it must fail.
92 [ ! -f "${logfile}.${1}" ] && return 0
93 ! grep -q -e "Assertion " -e "Aborted " "${logfile}.${1}"
96 # Whether or not $1 (/dev/...) is a SCSI device.
101 for f in /sys/class/scsi_device/*/device/block/"$d"; do
102 [ -e "$f" ] && return 0
107 job_var_opts_exclude() {
111 for o in "${job_var_opts[@]}"; do
112 if [[ ${o} =~ "${ex_key}" ]]; then
119 has_max_open_zones() {
121 if [[ ${1} =~ "--max_open_zones" ]]; then
132 fio=$(dirname "$0")/../../fio
134 opts=(${global_var_opts[@]})
135 opts+=("--max-jobs=16" "--aux-path=/tmp" "--allow_file_create=0" \
136 "--significant_figures=10" "$@")
137 # When max_open_zones option is specified to this test script, add
138 # max_open_zones option to fio command unless the test case already add it.
139 if [[ -n ${max_open_zones_opt} ]] && ! has_max_open_zones "${opts[@]}"; then
140 opts+=("--max_open_zones=${max_open_zones_opt}")
142 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
144 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}"
150 r=$(((RANDOM << 16) | RANDOM))
151 run_fio --name="$dev" --filename="$dev" "$@" --randseed="$r" \
152 --thread=1 --direct=1
155 write_and_run_one_fio_job() {
157 local write_offset="${1}"
158 local write_size="${2}"
162 r=$(((RANDOM << 16) | RANDOM))
163 write_opts=(--name="write_job" --rw=write "$(ioengine "psync")" \
164 --bs="${logical_block_size}" --zonemode=zbd \
165 --zonesize="${zone_size}" --thread=1 --direct=1 \
166 --offset="${write_offset}" --size="${write_size}")
167 write_opts+=("${job_var_opts[@]}")
168 run_fio --filename="$dev" --randseed="$r" "${write_opts[@]}" \
169 --name="$dev" --wait_for="write_job" "$@" --thread=1 --direct=1
172 # Run fio on the first four sequential zones of the disk.
176 opts+=("--offset=$((first_sequential_zone_sector * 512))")
177 opts+=("--size=$((4 * zone_size))" "--zonemode=zbd")
178 if [ -z "$is_zbd" ]; then
179 opts+=("--zonesize=${zone_size}")
181 run_one_fio_job "${opts[@]}" "$@"
184 # Prepare for write test by resetting zones. When max_open_zones option is
185 # specified, reset all zones of the test target to ensure that zones out of the
186 # test target range do not have open zones. This allows the write test to the
187 # target range to be able to open zones up to max_open_zones.
189 [[ -n "${max_open_zones_opt}" && -n "${is_zbd}" ]] &&
190 reset_zone "${dev}" -1
196 if ! is_scsi_device "$dev"; then
197 SKIP_REASON="$dev is not a SCSI device"
203 require_conv_zone_bytes() {
206 if ((req_bytes > first_sequential_zone_sector * 512)); then
207 SKIP_REASON="$dev does not have enough conventional zones"
214 if [[ -z ${is_zbd} ]]; then
215 SKIP_REASON="$dev is not a zoned block device"
221 require_regular_block_dev() {
222 if [[ -n ${is_zbd} ]]; then
223 SKIP_REASON="$dev is not a regular block device"
229 # Check whether buffered writes are refused.
231 run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K \
232 "$(ioengine "psync")" --size="${zone_size}" --thread=1 \
233 --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
234 tee -a "${logfile}.${test_number}" |
235 grep -q 'Using direct I/O is mandatory for writing to ZBD drives'
236 local fio_rc=${PIPESTATUS[0]} grep_rc=${PIPESTATUS[2]}
241 if [ -n "$is_zbd" ]; then
248 # Block size exceeds zone size.
250 local bs off opts=() rc
252 off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
253 bs=$((2 * zone_size))
254 opts+=("$(ioengine "psync")")
255 opts+=("--name=job1" "--filename=$dev" "--rw=write" "--direct=1")
256 opts+=("--zonemode=zbd" "--offset=$off" "--bs=$bs" "--size=$bs")
257 if [ -z "$is_zbd" ]; then
258 opts+=("--zonesize=${zone_size}")
260 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 && return 1
261 grep -q 'buflen exceeds zone size' "${logfile}.${test_number}"
264 # Run fio against an empty zone. This causes fio to report "No I/O performed".
268 off=$((first_sequential_zone_sector * 512 + 128 * zone_size))
270 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
271 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=4K")
272 opts+=("--size=$size" "--zonemode=zbd")
273 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--thread=1")
274 if [ -z "$is_zbd" ]; then
275 opts+=("--zonesize=${zone_size}")
277 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
278 ! grep -q 'READ:' "${logfile}.${test_number}"
281 # Run fio with --read_beyond_wp=1 against an empty zone.
285 off=$((first_sequential_zone_sector * 512 + 129 * zone_size))
287 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
288 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=$size")
289 opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1")
290 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--disable_lat=1")
291 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
292 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
293 check_read $size || return $?
296 # Sequential write to sequential zones.
298 local size off capacity
301 off=$((first_sequential_zone_sector * 512))
302 capacity=$(total_zone_capacity 4 $off $dev)
303 size=$((4 * zone_size))
304 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
305 --bs="$(max $((zone_size / 64)) "$logical_block_size")"\
306 --do_verify=1 --verify=md5 \
307 >>"${logfile}.${test_number}" 2>&1 || return $?
308 check_written $capacity || return $?
309 check_read $capacity || return $?
312 # Sequential read from sequential zones.
314 local size off capacity
317 off=$((first_sequential_zone_sector * 512))
318 capacity=$(total_zone_capacity 4 $off $dev)
319 size=$((4 * zone_size))
320 write_and_run_one_fio_job \
321 $((first_sequential_zone_sector * 512)) "${size}" \
323 --size="${size}" --zonemode=zbd --zonesize="${zone_size}" \
324 "$(ioengine "psync")" --iodepth=1 --rw=read \
325 --bs="$(max $((zone_size / 64)) "$logical_block_size")" \
326 >>"${logfile}.${test_number}" 2>&1 || return $?
327 check_read $capacity || return $?
330 # Random write to sequential zones, libaio, queue depth 1.
332 local size=$((zone_size))
336 off=$((first_sequential_zone_sector * 512))
337 capacity=$(total_zone_capacity 1 $off $dev)
338 run_fio_on_seq "$(ioengine "libaio")" --iodepth=1 --rw=randwrite \
339 --bs="$(min 16384 "${zone_size}")" \
340 --do_verify=1 --verify=md5 --size="$size" \
341 >>"${logfile}.${test_number}" 2>&1 || return $?
342 check_written $capacity || return $?
343 check_read $capacity || return $?
346 # Random write to sequential zones, libaio, queue depth 64.
348 local size off capacity
351 size=$((4 * zone_size))
352 off=$((first_sequential_zone_sector * 512))
353 capacity=$(total_zone_capacity 4 $off $dev)
354 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
355 --bs="$(min 16384 "${zone_size}")" \
356 --do_verify=1 --verify=md5 \
357 >>"${logfile}.${test_number}" 2>&1 || return $?
358 check_written $capacity || return $?
359 check_read $capacity || return $?
362 # Random write to sequential zones, sg, queue depth 1.
366 require_scsi_dev || return $SKIP_TESTCASE
369 size=$((4 * zone_size))
370 run_fio_on_seq --ioengine=sg \
371 --iodepth=1 --rw=randwrite --bs=16K \
372 --do_verify=1 --verify=md5 \
373 >>"${logfile}.${test_number}" 2>&1 || return $?
374 check_written $size || return $?
375 check_read $size || return $?
378 # Random write to sequential zones, sg, queue depth 64.
382 require_scsi_dev || return $SKIP_TESTCASE
385 size=$((4 * zone_size))
386 run_fio_on_seq --ioengine=sg \
387 --iodepth=64 --rw=randwrite --bs=16K \
388 --do_verify=1 --verify=md5 \
389 >>"${logfile}.${test_number}" 2>&1 || return $?
390 check_written $size || return $?
391 check_read $size || return $?
394 # Random write to sequential zones, libaio, queue depth 64, random block size.
396 local size off capacity
399 size=$((4 * zone_size))
400 off=$((first_sequential_zone_sector * 512))
401 capacity=$(total_zone_capacity 4 $off $dev)
402 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
403 --bsrange=4K-64K --do_verify=1 --verify=md5 \
404 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
405 check_written $capacity || return $?
406 check_read $capacity || return $?
409 # Random write to sequential zones, libaio, queue depth 64, max 1 open zone.
411 local size off capacity
414 size=$((8 * zone_size))
415 off=$((first_sequential_zone_sector * 512))
416 capacity=$(total_zone_capacity 8 $off $dev)
417 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
418 --max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \
419 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
420 check_written $capacity || return $?
421 check_read $capacity || return $?
424 # Random write to sequential zones, libaio, queue depth 64, max 4 open zones.
426 local size off capacity
429 size=$((8 * zone_size))
430 off=$((first_sequential_zone_sector * 512))
431 capacity=$(total_zone_capacity 8 $off $dev)
432 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
433 --max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \
435 >>"${logfile}.${test_number}" 2>&1 || return $?
436 check_written $capacity || return $?
437 check_read $capacity || return $?
440 # Random write to conventional zones.
445 size=$((16 * 2**20)) # 20 MB
446 require_conv_zone_bytes "${size}" || return $SKIP_TESTCASE
448 run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
449 --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \
450 --verify=md5 --size=$size \
451 >>"${logfile}.${test_number}" 2>&1 || return $?
452 check_written $((size)) || return $?
453 check_read $((size)) || return $?
456 # Sequential read on a mix of empty and full zones.
459 local w_off w_size w_capacity
461 for ((i=0;i<4;i++)); do
463 reset_zone "$dev" $((first_sequential_zone_sector +
467 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
468 w_size=$((2 * zone_size))
469 w_capacity=$(total_zone_capacity 2 $w_off $dev)
470 off=$((first_sequential_zone_sector * 512))
471 size=$((4 * zone_size))
472 write_and_run_one_fio_job "${w_off}" "${w_size}" \
473 "$(ioengine "psync")" --rw=read --bs=$((zone_size / 16)) \
474 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
475 --size=$((size)) >>"${logfile}.${test_number}" 2>&1 ||
477 check_written $((w_capacity)) || return $?
478 check_read $((w_capacity))
481 # Random read on a mix of empty and full zones.
484 local i w_off w_size w_capacity
486 for ((i=0;i<4;i++)); do
488 reset_zone "$dev" $((first_sequential_zone_sector +
492 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
493 w_size=$((2 * zone_size))
494 w_capacity=$(total_zone_capacity 2 $w_off $dev)
495 off=$((first_sequential_zone_sector * 512))
496 size=$((4 * zone_size))
497 write_and_run_one_fio_job "${w_off}" "${w_size}" \
498 "$(ioengine "libaio")" --iodepth=64 --rw=randread --bs=16K \
499 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
500 --size=$size >>"${logfile}.${test_number}" 2>&1 || return $?
501 check_written $w_capacity || return $?
502 check_read $size || return $?
505 # Random reads and writes in the last zone.
507 local io off read size written
509 off=$(((disk_size / zone_size - 1) * zone_size))
510 size=$((disk_size - off))
511 if [ -n "$is_zbd" ]; then
512 reset_zone "$dev" $((off / 512)) || return $?
515 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
516 --zonemode=zbd --zonesize="${zone_size}" \
517 --offset=$off --loops=2 --norandommap=1\
518 >>"${logfile}.${test_number}" 2>&1 || return $?
519 written=$(fio_written <"${logfile}.${test_number}")
520 read=$(fio_read <"${logfile}.${test_number}")
521 io=$((written + read))
522 echo "Total number of bytes read and written: $io <> $size" \
523 >>"${logfile}.${test_number}"
524 [ $io = $((size * 2)) ];
527 # Out-of-range zone reset threshold and frequency parameters.
529 run_fio_on_seq --zone_reset_threshold=-1 |&
530 tee -a "${logfile}.${test_number}" |
531 grep -q 'value out of range' || return $?
535 run_fio_on_seq --zone_reset_threshold=2 |&
536 tee -a "${logfile}.${test_number}" |
537 grep -q 'value out of range' || return $?
541 run_fio_on_seq --zone_reset_threshold=.4:.6 |&
542 tee -a "${logfile}.${test_number}" |
543 grep -q 'the list exceeding max length' || return $?
547 run_fio_on_seq --zone_reset_frequency=-1 |&
548 tee -a "${logfile}.${test_number}" |
549 grep -q 'value out of range' || return $?
553 run_fio_on_seq --zone_reset_frequency=2 |&
554 tee -a "${logfile}.${test_number}" |
555 grep -q 'value out of range' || return $?
559 run_fio_on_seq --zone_reset_frequency=.4:.6 |&
560 tee -a "${logfile}.${test_number}" |
561 grep -q 'the list exceeding max length' || return $?
565 local bs loops=9 size=$((zone_size))
569 off=$((first_sequential_zone_sector * 512))
570 capacity=$(total_zone_capacity 1 $off $dev)
572 bs=$(min $((256*1024)) "$zone_size")
573 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
574 --size=$size --loops=$loops \
575 --zone_reset_frequency=.01 --zone_reset_threshold=.90 \
576 >> "${logfile}.${test_number}" 2>&1 || return $?
577 check_written $((capacity * loops)) || return $?
578 check_reset_count -eq 8 ||
579 check_reset_count -eq 9 ||
580 check_reset_count -eq 10 || return $?
583 # Multiple non-overlapping sequential write jobs for the same drive.
587 for ((i=0;i<16;i++)); do
589 reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone))
592 for ((i=0;i<16;i++)); do
593 opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1")
594 opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))")
595 opts+=("--size=$zone_size" "$(ioengine "psync")" "--rw=write" "--bs=16K")
596 opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1")
597 opts+=(${job_var_opts[@]})
599 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
602 write_to_first_seq_zone() {
607 off=$((first_sequential_zone_sector * 512))
608 capacity=$(total_zone_capacity 1 $off $dev)
610 r=$(((RANDOM << 16) | RANDOM))
611 run_fio --name="$dev" --filename="$dev" "$(ioengine "psync")" --rw="$1" \
612 --thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \
614 --size=$zone_size --loops=$loops --randseed="$r" \
615 --zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \
616 --gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $?
617 check_written $((loops * capacity)) || return $?
620 # Overwrite the first sequential zone four times sequentially.
622 write_to_first_seq_zone write
625 # Overwrite the first sequential zone four times using random writes.
627 write_to_first_seq_zone randwrite
630 # Multiple overlapping random write jobs for the same drive.
632 local i jobs=16 off opts
634 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
635 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
638 capacity=$(total_zone_capacity 1 $off $dev)
639 for ((i=0;i<jobs;i++)); do
640 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
641 opts+=("--size=$zone_size" "--io_size=$capacity" "$(ioengine "psync")" "--rw=randwrite")
642 opts+=("--thread=1" "--direct=1" "--zonemode=zbd")
643 opts+=("--zonesize=${zone_size}" "--group_reporting=1")
644 opts+=(${job_var_opts[@]})
646 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
647 check_written $((jobs * $capacity)) || return $?
648 check_reset_count -eq $jobs ||
649 check_reset_count -eq $((jobs - 1)) ||
653 # Multiple overlapping random write jobs for the same drive and with a limited
654 # number of open zones.
656 local i jobs=16 off opts=()
658 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
659 size=$((16*zone_size))
662 for ((i=0;i<jobs;i++)); do
663 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
664 opts+=("--size=$size" "--io_size=$zone_size" "--thread=1")
665 opts+=("$(ioengine "psync")" "--rw=randwrite" "--direct=1")
666 opts+=("--max_open_zones=4" "--group_reporting=1")
667 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
668 # max_open_zones is already specified
669 opts+=($(job_var_opts_exclude "--max_open_zones"))
671 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
672 check_written $((jobs * zone_size)) || return $?
675 # Random reads and writes across the entire disk for 30s.
680 off=$((first_sequential_zone_sector * 512))
681 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw \
682 --bs="$(max $((zone_size / 128)) "$logical_block_size")"\
683 --zonemode=zbd --zonesize="${zone_size}" --offset=$off\
684 --loops=2 --time_based --runtime=30s --norandommap=1\
685 >>"${logfile}.${test_number}" 2>&1
688 # Random reads across all sequential zones for 30s. This is not only a fio
689 # test but also allows to verify the performance of a drive.
691 local bs inc nz off opts size
694 # Start with writing 128 KB to 128 sequential zones.
697 # shellcheck disable=SC2017
698 inc=$(((disk_size - (first_sequential_zone_sector * 512)) / (nz * zone_size)
701 for ((off = first_sequential_zone_sector * 512; off < disk_size;
703 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--io_size=$bs")
704 opts+=("--bs=$bs" "--size=$zone_size" "$(ioengine "libaio")")
705 opts+=("--rw=write" "--direct=1" "--thread=1" "--stats=0")
706 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
707 opts+=(${job_var_opts[@]})
709 "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1
710 # Next, run the test.
711 off=$((first_sequential_zone_sector * 512))
712 size=$((disk_size - off))
713 opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
714 opts+=("--bs=$bs" "$(ioengine "psync")" "--rw=randread" "--direct=1")
715 opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd")
716 opts+=("--zonesize=${zone_size}")
717 opts+=(${job_var_opts[@]})
718 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
721 # Random writes across all sequential zones. This is not only a fio test but
722 # also allows to verify the performance of a drive.
724 local off opts=() size
726 require_zbd || return $SKIP_TESTCASE
729 off=$((first_sequential_zone_sector * 512))
730 size=$((disk_size - off))
731 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
732 opts+=("--bs=128K" "$(ioengine "psync")" "--rw=randwrite" "--direct=1")
733 opts+=("--thread=1" "--time_based" "--runtime=30")
734 opts+=("--max_open_zones=$max_open_zones" "--zonemode=zbd")
735 opts+=("--zonesize=${zone_size}")
736 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
739 # Write to sequential zones with a block size that is not a divisor of the
742 local bs io_size size
743 local off capacity=0;
746 off=$((first_sequential_zone_sector * 512))
747 capacity=$(total_zone_capacity 1 $off $dev)
748 size=$((2 * zone_size))
749 io_size=$((5 * capacity))
750 bs=$((3 * capacity / 4))
751 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
752 --size=$size --io_size=$io_size --bs=$bs \
753 >> "${logfile}.${test_number}" 2>&1 || return $?
754 check_written $(((io_size + bs - 1) / bs * bs)) || return $?
757 # Write to sequential zones with a block size that is not a divisor of the
758 # zone size and with data verification enabled.
763 size=$((2 * zone_size))
764 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write --size=$size \
765 --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \
766 >> "${logfile}.${test_number}" 2>&1 && return 1
767 grep -q 'not a divisor of' "${logfile}.${test_number}"
770 # Test 1/4 for the I/O boundary rounding code: $size < $zone_size.
772 local bs off io_size size
775 off=$(((first_sequential_zone_sector + 1) * 512))
776 size=$((zone_size - 2 * 512))
777 bs=$((zone_size / 4))
778 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
779 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
780 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
781 >> "${logfile}.${test_number}" 2>&1 && return 1
782 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
785 # Test 2/4 for the I/O boundary rounding code: $size < $zone_size.
787 local bs off io_size size
790 off=$(((first_sequential_zone_sector) * 512))
791 size=$((zone_size - 512))
792 bs=$((zone_size / 4))
793 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
794 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
795 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
796 >> "${logfile}.${test_number}" 2>&1 && return 1
797 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
800 # Test 3/4 for the I/O boundary rounding code: $size > $zone_size.
802 local bs off size capacity
805 capacity=$(total_zone_capacity 1 $first_sequential_zone_sector $dev)
806 if [ "$first_sequential_zone_sector" = 0 ]; then
809 off=$(((first_sequential_zone_sector - 1) * 512))
811 size=$((zone_size + 2 * 512))
812 bs=$((zone_size / 4))
813 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
814 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
815 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
816 >> "${logfile}.${test_number}" 2>&1
817 check_written $capacity || return $?
820 # Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size
825 size=$((logical_block_size))
826 off=$((disk_size - logical_block_size))
827 bs=$((logical_block_size))
828 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
829 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
830 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
831 >> "${logfile}.${test_number}" 2>&1 && return 1
832 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
835 # Read one block from a block device.
839 bs=$((logical_block_size))
840 run_one_fio_job --rw=read "$(ioengine "psync")" --bs=$bs --size=$bs "$@" 2>&1 |
841 tee -a "${logfile}.${test_number}"
844 # Check whether fio accepts --zonemode=none for zoned block devices.
846 require_zbd || return $SKIP_TESTCASE
847 read_one_block --zonemode=none >/dev/null || return $?
848 check_read $((logical_block_size)) || return $?
851 # Check whether fio accepts --zonemode=strided for zoned block devices.
855 bs=$((logical_block_size))
856 require_zbd || return $SKIP_TESTCASE
857 read_one_block --zonemode=strided |
858 grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
860 read_one_block --zonemode=strided --zonesize=$bs >/dev/null || return $?
861 check_read $bs || return $?
864 # Check whether fio checks the zone size for zoned block devices.
866 require_zbd || return $SKIP_TESTCASE
867 read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) |
868 grep -q 'job parameter zonesize.*does not match disk zone size'
871 # Check whether fio handles --zonesize=0 correctly for regular block devices.
873 require_regular_block_dev || return $SKIP_TESTCASE
874 read_one_block --zonemode=zbd --zonesize=0 |
875 grep -q 'Specifying the zone size is mandatory for regular block devices with --zonemode=zbd'
878 # Check whether fio handles --zonesize=1 correctly for regular block devices.
880 require_regular_block_dev || return $SKIP_TESTCASE
881 read_one_block --zonemode=zbd --zonesize=1 |
882 grep -q 'zone size must be at least 512 bytes for --zonemode=zbd'
885 # Check whether fio handles --zonemode=none --zonesize=1 correctly.
887 read_one_block --zonemode=none --zonesize=1 |
888 grep -q 'fio: --zonemode=none and --zonesize are not compatible'
894 require_zbd || return $SKIP_TESTCASE
896 bs=$((logical_block_size))
897 run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite --bs=$bs\
898 --offset=$((first_sequential_zone_sector * 512)) \
899 --size="$zone_size" --do_verify=1 --verify=md5 2>&1 |
900 tee -a "${logfile}.${test_number}" |
901 grep -q "fio: first I/O failed. If .* is a zoned block device, consider --zonemode=zbd"
904 # Random write to sequential zones, libaio, 8 jobs, queue depth 64 per job
909 size=$((4 * zone_size))
910 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=4K \
911 --group_reporting=1 --numjobs=8 \
912 >> "${logfile}.${test_number}" 2>&1 || return $?
913 check_written $((size * 8)) || return $?
916 # Check whether fio handles --zonemode=zbd --zoneskip=1 correctly.
921 bs=$((logical_block_size))
922 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
923 >> "${logfile}.${test_number}" 2>&1 && return 1
924 grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
927 # Multiple overlapping random write jobs for the same drive and with a
928 # limited number of open zones. This is similar to test29, but uses libaio
929 # to stress test zone locking.
931 local i jobs=16 off opts=()
933 require_zbd || return $SKIP_TESTCASE
935 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
936 size=$((16*zone_size))
938 opts=("--aux-path=/tmp" "--allow_file_create=0" "--significant_figures=10")
939 opts+=("--debug=zbd")
940 opts+=("$(ioengine "libaio")" "--rw=randwrite" "--direct=1")
941 opts+=("--time_based" "--runtime=30")
942 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
943 opts+=("--max_open_zones=4")
944 for ((i=0;i<jobs;i++)); do
945 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
946 opts+=("--io_size=$zone_size" "--iodepth=256" "--thread=1")
947 opts+=("--size=$size" "--group_reporting=1")
948 # max_open_zones is already specified
949 opts+=($(job_var_opts_exclude "--max_open_zones"))
952 fio=$(dirname "$0")/../../fio
954 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
956 timeout -v -s KILL 45s \
957 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}" \
958 >> "${logfile}.${test_number}" 2>&1 || return $?
961 # Check if fio handles --zonecapacity on a normal block device correctly
964 require_regular_block_dev || return $SKIP_TESTCASE
966 size=$((2 * zone_size))
967 capacity=$((zone_size * 3 / 4))
969 run_one_fio_job "$(ioengine "psync")" --rw=write \
970 --zonemode=zbd --zonesize="${zone_size}" \
971 --zonecapacity=${capacity} \
972 --verify=md5 --size=${size} >>"${logfile}.${test_number}" 2>&1 ||
974 check_written $((capacity * 2)) || return $?
975 check_read $((capacity * 2)) || return $?
985 while [ "${1#-}" != "$1" ]; do
987 -d) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=drd"
988 "--show-confl-seg=no");
990 -e) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=helgrind");
992 -l) use_libzbc=1; shift;;
993 -r) reset_all_zones=1; shift;;
994 -t) tests+=("$2"); shift; shift;;
995 -o) max_open_zones_opt="${2}"; shift; shift;;
996 -v) dynamic_analyzer=(valgrind "--read-var-info=yes");
998 -z) zbd_debug=1; shift;;
1003 if [ $# != 1 ]; then
1008 # shellcheck source=functions
1009 source "$(dirname "$0")/functions" || exit $?
1013 if [ -n "$zbd_debug" ]; then
1014 global_var_opts+=("--debug=zbd")
1017 realdev=$(readlink -f "$dev")
1018 basename=$(basename "$realdev")
1020 if [[ -b "$realdev" ]]; then
1021 major=$((0x$(stat -L -c '%t' "$realdev"))) || exit $?
1022 minor=$((0x$(stat -L -c '%T' "$realdev"))) || exit $?
1023 disk_size=$(($(<"/sys/dev/block/$major:$minor/size")*512))
1025 # When the target is a partition device, get basename of its
1026 # holder device to access sysfs path of the holder device
1027 if [[ -r "/sys/dev/block/$major:$minor/partition" ]]; then
1028 realsysfs=$(readlink "/sys/dev/block/$major:$minor")
1029 basename=$(basename "${realsysfs%/*}")
1031 logical_block_size=$(<"/sys/block/$basename/queue/logical_block_size")
1032 case "$(<"/sys/class/block/$basename/queue/zoned")" in
1033 host-managed|host-aware)
1035 if ! check_blkzone "${dev}"; then
1038 if ! result=($(first_sequential_zone "$dev")); then
1039 echo "Failed to determine first sequential zone"
1042 first_sequential_zone_sector=${result[0]}
1043 sectors_per_zone=${result[1]}
1044 zone_size=$((sectors_per_zone * 512))
1045 if ! max_open_zones=$(max_open_zones "$dev"); then
1046 echo "Failed to determine maximum number of open zones"
1049 set_io_scheduler "$basename" deadline || exit $?
1050 if [ -n "$reset_all_zones" ]; then
1051 reset_zone "$dev" -1
1055 first_sequential_zone_sector=$(((disk_size / 2) &
1056 (logical_block_size - 1)))
1057 zone_size=$(max 65536 "$logical_block_size")
1058 sectors_per_zone=$((zone_size / 512))
1060 set_io_scheduler "$basename" none || exit $?
1063 elif [[ -c "$realdev" ]]; then
1064 # For an SG node, we must have libzbc option specified
1065 if [[ ! -n "$use_libzbc" ]]; then
1066 echo "Character device files can only be used with -l (libzbc) option"
1070 if ! $(is_zbc "$dev"); then
1071 echo "Device is not a ZBC disk"
1076 if ! disk_size=($(( $(zbc_disk_sectors "$dev") * 512))); then
1077 echo "Failed to determine disk size"
1080 if ! logical_block_size=($(zbc_logical_block_size "$dev")); then
1081 echo "Failed to determine logical block size"
1084 if ! result=($(first_sequential_zone "$dev")); then
1085 echo "Failed to determine first sequential zone"
1088 first_sequential_zone_sector=${result[0]}
1089 sectors_per_zone=${result[1]}
1090 zone_size=$((sectors_per_zone * 512))
1091 if ! max_open_zones=$(max_open_zones "$dev"); then
1092 echo "Failed to determine maximum number of open zones"
1095 if [ -n "$reset_all_zones" ]; then
1096 reset_zone "$dev" -1
1100 if [[ -n ${max_open_zones_opt} ]]; then
1101 # Override max_open_zones with the script option value
1102 max_open_zones="${max_open_zones_opt}"
1103 job_var_opts+=("--max_open_zones=${max_open_zones_opt}")
1106 echo -n "First sequential zone starts at sector $first_sequential_zone_sector;"
1107 echo " zone size: $((zone_size >> 20)) MB"
1109 if [ "${#tests[@]}" = 0 ]; then
1110 readarray -t tests < <(declare -F | grep "test[0-9]*" | \
1111 tr -c -d "[:digit:]\n" | sort -n)
1132 trap 'intr=1' SIGINT
1135 for test_number in "${tests[@]}"; do
1136 rm -f "${logfile}.${test_number}"
1138 echo -n "Running test $(printf "%02d" $test_number) ... "
1139 eval "test$test_number"
1141 if ((!ret)) && check_log $test_number; then
1143 cc_status="${green}${status}${end}"
1145 elif ((ret==SKIP_TESTCASE)); then
1147 echo "${SKIP_REASON}" >> "${logfile}.${test_number}"
1148 cc_status="${cyan}${status}${end} ${SKIP_REASON}"
1152 cc_status="${red}${status}${end}"
1156 echo -e "$cc_status"
1157 echo "$status" >> "${logfile}.${test_number}"
1158 [ $intr -ne 0 ] && exit 1
1161 echo "$passed tests passed"
1162 if [ $skipped -gt 0 ]; then
1163 echo " $skipped tests skipped"
1165 if [ $failed -gt 0 ]; then
1166 echo " $failed tests failed"