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
193 # Check whether buffered writes are refused.
195 run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K \
196 "$(ioengine "psync")" --size="${zone_size}" --thread=1 \
197 --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
198 tee -a "${logfile}.${test_number}" |
199 grep -q 'Using direct I/O is mandatory for writing to ZBD drives'
200 local fio_rc=${PIPESTATUS[0]} grep_rc=${PIPESTATUS[2]}
205 if [ -n "$is_zbd" ]; then
212 # Block size exceeds zone size.
214 local bs off opts=() rc
216 off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
217 bs=$((2 * zone_size))
218 opts+=("$(ioengine "psync")")
219 opts+=("--name=job1" "--filename=$dev" "--rw=write" "--direct=1")
220 opts+=("--zonemode=zbd" "--offset=$off" "--bs=$bs" "--size=$bs")
221 if [ -z "$is_zbd" ]; then
222 opts+=("--zonesize=${zone_size}")
224 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
225 ! grep -q 'WRITE:' "${logfile}.${test_number}"
228 # Run fio against an empty zone. This causes fio to report "No I/O performed".
232 off=$((first_sequential_zone_sector * 512 + 128 * zone_size))
234 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
235 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=4K")
236 opts+=("--size=$size" "--zonemode=zbd")
237 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--thread=1")
238 if [ -z "$is_zbd" ]; then
239 opts+=("--zonesize=${zone_size}")
241 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
242 ! grep -q 'READ:' "${logfile}.${test_number}"
245 # Run fio with --read_beyond_wp=1 against an empty zone.
249 off=$((first_sequential_zone_sector * 512 + 129 * zone_size))
251 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
252 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=$size")
253 opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1")
254 opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--disable_lat=1")
255 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
256 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
257 check_read $size || return $?
260 # Sequential write to sequential zones.
262 local size off capacity
265 off=$((first_sequential_zone_sector * 512))
266 capacity=$(total_zone_capacity 4 $off $dev)
267 size=$((4 * zone_size))
268 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
269 --bs="$(max $((zone_size / 64)) "$logical_block_size")"\
270 --do_verify=1 --verify=md5 \
271 >>"${logfile}.${test_number}" 2>&1 || return $?
272 check_written $capacity || return $?
273 check_read $capacity || return $?
276 # Sequential read from sequential zones.
278 local size off capacity
281 off=$((first_sequential_zone_sector * 512))
282 capacity=$(total_zone_capacity 4 $off $dev)
283 size=$((4 * zone_size))
284 write_and_run_one_fio_job \
285 $((first_sequential_zone_sector * 512)) "${size}" \
287 --size="${size}" --zonemode=zbd --zonesize="${zone_size}" \
288 "$(ioengine "psync")" --iodepth=1 --rw=read \
289 --bs="$(max $((zone_size / 64)) "$logical_block_size")" \
290 >>"${logfile}.${test_number}" 2>&1 || return $?
291 check_read $capacity || return $?
294 # Random write to sequential zones, libaio, queue depth 1.
296 local size=$((zone_size))
300 off=$((first_sequential_zone_sector * 512))
301 capacity=$(total_zone_capacity 1 $off $dev)
302 run_fio_on_seq "$(ioengine "libaio")" --iodepth=1 --rw=randwrite \
303 --bs="$(min 16384 "${zone_size}")" \
304 --do_verify=1 --verify=md5 --size="$size" \
305 >>"${logfile}.${test_number}" 2>&1 || return $?
306 check_written $capacity || return $?
307 check_read $capacity || return $?
310 # Random write to sequential zones, libaio, queue depth 64.
312 local size off capacity
315 size=$((4 * zone_size))
316 off=$((first_sequential_zone_sector * 512))
317 capacity=$(total_zone_capacity 4 $off $dev)
318 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
319 --bs="$(min 16384 "${zone_size}")" \
320 --do_verify=1 --verify=md5 \
321 >>"${logfile}.${test_number}" 2>&1 || return $?
322 check_written $capacity || return $?
323 check_read $capacity || return $?
326 # Random write to sequential zones, sg, queue depth 1.
330 if ! is_scsi_device "$dev"; then
331 echo "$dev is not a SCSI device" >>"${logfile}.${test_number}"
336 size=$((4 * zone_size))
337 run_fio_on_seq --ioengine=sg \
338 --iodepth=1 --rw=randwrite --bs=16K \
339 --do_verify=1 --verify=md5 \
340 >>"${logfile}.${test_number}" 2>&1 || return $?
341 check_written $size || return $?
342 check_read $size || return $?
345 # Random write to sequential zones, sg, queue depth 64.
349 if ! is_scsi_device "$dev"; then
350 echo "$dev is not a SCSI device" >>"${logfile}.${test_number}"
355 size=$((4 * zone_size))
356 run_fio_on_seq --ioengine=sg \
357 --iodepth=64 --rw=randwrite --bs=16K \
358 --do_verify=1 --verify=md5 \
359 >>"${logfile}.${test_number}" 2>&1 || return $?
360 check_written $size || return $?
361 check_read $size || return $?
364 # Random write to sequential zones, libaio, queue depth 64, random block size.
366 local size off capacity
369 size=$((4 * zone_size))
370 off=$((first_sequential_zone_sector * 512))
371 capacity=$(total_zone_capacity 4 $off $dev)
372 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
373 --bsrange=4K-64K --do_verify=1 --verify=md5 \
374 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
375 check_written $capacity || return $?
376 check_read $capacity || return $?
379 # Random write to sequential zones, libaio, queue depth 64, max 1 open zone.
381 local size off capacity
384 size=$((8 * zone_size))
385 off=$((first_sequential_zone_sector * 512))
386 capacity=$(total_zone_capacity 8 $off $dev)
387 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
388 --max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \
389 --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
390 check_written $capacity || return $?
391 check_read $capacity || return $?
394 # Random write to sequential zones, libaio, queue depth 64, max 4 open zones.
396 local size off capacity
399 size=$((8 * zone_size))
400 off=$((first_sequential_zone_sector * 512))
401 capacity=$(total_zone_capacity 8 $off $dev)
402 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
403 --max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \
405 >>"${logfile}.${test_number}" 2>&1 || return $?
406 check_written $capacity || return $?
407 check_read $capacity || return $?
410 # Random write to conventional zones.
415 size=$((16 * 2**20)) # 20 MB
416 if [ $size -gt $((first_sequential_zone_sector * 512)) ]; then
417 echo "$dev does not have enough sequential zones" \
418 >>"${logfile}.${test_number}"
421 run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
422 --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \
423 --verify=md5 --size=$size \
424 >>"${logfile}.${test_number}" 2>&1 || return $?
425 check_written $((size)) || return $?
426 check_read $((size)) || return $?
429 # Sequential read on a mix of empty and full zones.
432 local w_off w_size w_capacity
434 for ((i=0;i<4;i++)); do
436 reset_zone "$dev" $((first_sequential_zone_sector +
440 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
441 w_size=$((2 * zone_size))
442 w_capacity=$(total_zone_capacity 2 $w_off $dev)
443 off=$((first_sequential_zone_sector * 512))
444 size=$((4 * zone_size))
445 write_and_run_one_fio_job "${w_off}" "${w_size}" \
446 "$(ioengine "psync")" --rw=read --bs=$((zone_size / 16)) \
447 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
448 --size=$((size)) >>"${logfile}.${test_number}" 2>&1 ||
450 check_written $((w_capacity)) || return $?
451 check_read $((w_capacity))
454 # Random read on a mix of empty and full zones.
457 local i w_off w_size w_capacity
459 for ((i=0;i<4;i++)); do
461 reset_zone "$dev" $((first_sequential_zone_sector +
465 w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
466 w_size=$((2 * zone_size))
467 w_capacity=$(total_zone_capacity 2 $w_off $dev)
468 off=$((first_sequential_zone_sector * 512))
469 size=$((4 * zone_size))
470 write_and_run_one_fio_job "${w_off}" "${w_size}" \
471 "$(ioengine "libaio")" --iodepth=64 --rw=randread --bs=16K \
472 --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
473 --size=$size >>"${logfile}.${test_number}" 2>&1 || return $?
474 check_written $w_capacity || return $?
475 check_read $size || return $?
478 # Random reads and writes in the last zone.
480 local io off read size written
482 off=$(((disk_size / zone_size - 1) * zone_size))
483 size=$((disk_size - off))
484 if [ -n "$is_zbd" ]; then
485 reset_zone "$dev" $((off / 512)) || return $?
488 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
489 --zonemode=zbd --zonesize="${zone_size}" \
490 --offset=$off --loops=2 --norandommap=1\
491 >>"${logfile}.${test_number}" 2>&1 || return $?
492 written=$(fio_written <"${logfile}.${test_number}")
493 read=$(fio_read <"${logfile}.${test_number}")
494 io=$((written + read))
495 echo "Total number of bytes read and written: $io <> $size" \
496 >>"${logfile}.${test_number}"
497 [ $io = $((size * 2)) ];
500 # Out-of-range zone reset threshold and frequency parameters.
502 run_fio_on_seq --zone_reset_threshold=-1 |&
503 tee -a "${logfile}.${test_number}" |
504 grep -q 'value out of range' || return $?
508 run_fio_on_seq --zone_reset_threshold=2 |&
509 tee -a "${logfile}.${test_number}" |
510 grep -q 'value out of range' || return $?
514 run_fio_on_seq --zone_reset_threshold=.4:.6 |&
515 tee -a "${logfile}.${test_number}" |
516 grep -q 'the list exceeding max length' || return $?
520 run_fio_on_seq --zone_reset_frequency=-1 |&
521 tee -a "${logfile}.${test_number}" |
522 grep -q 'value out of range' || return $?
526 run_fio_on_seq --zone_reset_frequency=2 |&
527 tee -a "${logfile}.${test_number}" |
528 grep -q 'value out of range' || return $?
532 run_fio_on_seq --zone_reset_frequency=.4:.6 |&
533 tee -a "${logfile}.${test_number}" |
534 grep -q 'the list exceeding max length' || return $?
538 local bs loops=9 size=$((zone_size))
542 off=$((first_sequential_zone_sector * 512))
543 capacity=$(total_zone_capacity 1 $off $dev)
545 bs=$(min $((256*1024)) "$zone_size")
546 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
547 --size=$size --loops=$loops \
548 --zone_reset_frequency=.01 --zone_reset_threshold=.90 \
549 >> "${logfile}.${test_number}" 2>&1 || return $?
550 check_written $((capacity * loops)) || return $?
551 check_reset_count -eq 8 ||
552 check_reset_count -eq 9 ||
553 check_reset_count -eq 10 || return $?
556 # Multiple non-overlapping sequential write jobs for the same drive.
560 for ((i=0;i<16;i++)); do
562 reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone))
565 for ((i=0;i<16;i++)); do
566 opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1")
567 opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))")
568 opts+=("--size=$zone_size" "$(ioengine "psync")" "--rw=write" "--bs=16K")
569 opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1")
570 opts+=(${job_var_opts[@]})
572 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
575 write_to_first_seq_zone() {
580 off=$((first_sequential_zone_sector * 512))
581 capacity=$(total_zone_capacity 1 $off $dev)
583 r=$(((RANDOM << 16) | RANDOM))
584 run_fio --name="$dev" --filename="$dev" "$(ioengine "psync")" --rw="$1" \
585 --thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \
587 --size=$zone_size --loops=$loops --randseed="$r" \
588 --zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \
589 --gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $?
590 check_written $((loops * capacity)) || return $?
593 # Overwrite the first sequential zone four times sequentially.
595 write_to_first_seq_zone write
598 # Overwrite the first sequential zone four times using random writes.
600 write_to_first_seq_zone randwrite
603 # Multiple overlapping random write jobs for the same drive.
605 local i jobs=16 off opts
607 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
608 [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
611 capacity=$(total_zone_capacity 1 $off $dev)
612 for ((i=0;i<jobs;i++)); do
613 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
614 opts+=("--size=$zone_size" "--io_size=$capacity" "$(ioengine "psync")" "--rw=randwrite")
615 opts+=("--thread=1" "--direct=1" "--zonemode=zbd")
616 opts+=("--zonesize=${zone_size}" "--group_reporting=1")
617 opts+=(${job_var_opts[@]})
619 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
620 check_written $((jobs * $capacity)) || return $?
621 check_reset_count -eq $jobs ||
622 check_reset_count -eq $((jobs - 1)) ||
626 # Multiple overlapping random write jobs for the same drive and with a limited
627 # number of open zones.
629 local i jobs=16 off opts=()
631 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
632 size=$((16*zone_size))
635 for ((i=0;i<jobs;i++)); do
636 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
637 opts+=("--size=$size" "--io_size=$zone_size" "--thread=1")
638 opts+=("$(ioengine "psync")" "--rw=randwrite" "--direct=1")
639 opts+=("--max_open_zones=4" "--group_reporting=1")
640 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
641 # max_open_zones is already specified
642 opts+=($(job_var_opts_exclude "--max_open_zones"))
644 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
645 check_written $((jobs * zone_size)) || return $?
648 # Random reads and writes across the entire disk for 30s.
653 off=$((first_sequential_zone_sector * 512))
654 run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw \
655 --bs="$(max $((zone_size / 128)) "$logical_block_size")"\
656 --zonemode=zbd --zonesize="${zone_size}" --offset=$off\
657 --loops=2 --time_based --runtime=30s --norandommap=1\
658 >>"${logfile}.${test_number}" 2>&1
661 # Random reads across all sequential zones for 30s. This is not only a fio
662 # test but also allows to verify the performance of a drive.
664 local bs inc nz off opts size
667 # Start with writing 128 KB to 128 sequential zones.
670 # shellcheck disable=SC2017
671 inc=$(((disk_size - (first_sequential_zone_sector * 512)) / (nz * zone_size)
674 for ((off = first_sequential_zone_sector * 512; off < disk_size;
676 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--io_size=$bs")
677 opts+=("--bs=$bs" "--size=$zone_size" "$(ioengine "libaio")")
678 opts+=("--rw=write" "--direct=1" "--thread=1" "--stats=0")
679 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
680 opts+=(${job_var_opts[@]})
682 "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1
683 # Next, run the test.
684 off=$((first_sequential_zone_sector * 512))
685 size=$((disk_size - off))
686 opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
687 opts+=("--bs=$bs" "$(ioengine "psync")" "--rw=randread" "--direct=1")
688 opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd")
689 opts+=("--zonesize=${zone_size}")
690 opts+=(${job_var_opts[@]})
691 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
694 # Random writes across all sequential zones. This is not only a fio test but
695 # also allows to verify the performance of a drive.
697 local off opts=() size
700 off=$((first_sequential_zone_sector * 512))
701 size=$((disk_size - off))
702 opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
703 opts+=("--bs=128K" "$(ioengine "psync")" "--rw=randwrite" "--direct=1")
704 opts+=("--thread=1" "--time_based" "--runtime=30")
705 opts+=("--max_open_zones=$max_open_zones" "--zonemode=zbd")
706 opts+=("--zonesize=${zone_size}")
707 run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
710 # Write to sequential zones with a block size that is not a divisor of the
713 local bs io_size size
714 local off capacity=0;
717 off=$((first_sequential_zone_sector * 512))
718 capacity=$(total_zone_capacity 1 $off $dev)
719 size=$((2 * zone_size))
720 io_size=$((5 * capacity))
721 bs=$((3 * capacity / 4))
722 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
723 --size=$size --io_size=$io_size --bs=$bs \
724 >> "${logfile}.${test_number}" 2>&1 || return $?
725 check_written $(((io_size + bs - 1) / bs * bs)) || return $?
728 # Write to sequential zones with a block size that is not a divisor of the
729 # zone size and with data verification enabled.
734 size=$((2 * zone_size))
735 run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write --size=$size \
736 --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \
737 >> "${logfile}.${test_number}" 2>&1 && return 1
738 grep -q 'not a divisor of' "${logfile}.${test_number}"
741 # Test 1/4 for the I/O boundary rounding code: $size < $zone_size.
743 local bs off io_size size
746 off=$(((first_sequential_zone_sector + 1) * 512))
747 size=$((zone_size - 2 * 512))
748 bs=$((zone_size / 4))
749 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
750 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
751 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
752 >> "${logfile}.${test_number}" 2>&1 && return 1
753 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
756 # Test 2/4 for the I/O boundary rounding code: $size < $zone_size.
758 local bs off io_size size
761 off=$(((first_sequential_zone_sector) * 512))
762 size=$((zone_size - 512))
763 bs=$((zone_size / 4))
764 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
765 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
766 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
767 >> "${logfile}.${test_number}" 2>&1 && return 1
768 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
771 # Test 3/4 for the I/O boundary rounding code: $size > $zone_size.
773 local bs off size capacity
776 capacity=$(total_zone_capacity 1 $first_sequential_zone_sector $dev)
777 if [ "$first_sequential_zone_sector" = 0 ]; then
780 off=$(((first_sequential_zone_sector - 1) * 512))
782 size=$((zone_size + 2 * 512))
783 bs=$((zone_size / 4))
784 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
785 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
786 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
787 >> "${logfile}.${test_number}" 2>&1
788 check_written $capacity || return $?
791 # Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size
796 size=$((logical_block_size))
797 off=$((disk_size - logical_block_size))
798 bs=$((logical_block_size))
799 run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")" \
800 --iodepth=1 --rw=write --do_verify=1 --verify=md5 \
801 --bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
802 >> "${logfile}.${test_number}" 2>&1 && return 1
803 grep -q 'io_size must be at least one zone' "${logfile}.${test_number}"
806 # Read one block from a block device.
810 bs=$((logical_block_size))
811 run_one_fio_job --rw=read "$(ioengine "psync")" --bs=$bs --size=$bs "$@" 2>&1 |
812 tee -a "${logfile}.${test_number}"
815 # Check whether fio accepts --zonemode=none for zoned block devices.
817 [ -n "$is_zbd" ] || return 0
818 read_one_block --zonemode=none >/dev/null || return $?
819 check_read $((logical_block_size)) || return $?
822 # Check whether fio accepts --zonemode=strided for zoned block devices.
826 bs=$((logical_block_size))
827 [ -n "$is_zbd" ] || return 0
828 read_one_block --zonemode=strided |
829 grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
831 read_one_block --zonemode=strided --zonesize=$bs >/dev/null || return $?
832 check_read $bs || return $?
835 # Check whether fio checks the zone size for zoned block devices.
837 [ -n "$is_zbd" ] || return 0
838 read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) |
839 grep -q 'job parameter zonesize.*does not match disk zone size'
842 # Check whether fio handles --zonesize=0 correctly for regular block devices.
844 [ -n "$is_zbd" ] && return 0
845 read_one_block --zonemode=zbd --zonesize=0 |
846 grep -q 'Specifying the zone size is mandatory for regular block devices with --zonemode=zbd'
849 # Check whether fio handles --zonesize=1 correctly for regular block devices.
851 [ -n "$is_zbd" ] && return 0
852 read_one_block --zonemode=zbd --zonesize=1 |
853 grep -q 'zone size must be at least 512 bytes for --zonemode=zbd'
856 # Check whether fio handles --zonemode=none --zonesize=1 correctly.
858 read_one_block --zonemode=none --zonesize=1 |
859 grep -q 'fio: --zonemode=none and --zonesize are not compatible'
865 [ -z "$is_zbd" ] && return 0
867 bs=$((logical_block_size))
868 run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite --bs=$bs\
869 --offset=$((first_sequential_zone_sector * 512)) \
870 --size="$zone_size" --do_verify=1 --verify=md5 2>&1 |
871 tee -a "${logfile}.${test_number}" |
872 grep -q "fio: first I/O failed. If .* is a zoned block device, consider --zonemode=zbd"
875 # Random write to sequential zones, libaio, 8 jobs, queue depth 64 per job
880 size=$((4 * zone_size))
881 run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=4K \
882 --group_reporting=1 --numjobs=8 \
883 >> "${logfile}.${test_number}" 2>&1 || return $?
884 check_written $((size * 8)) || return $?
887 # Check whether fio handles --zonemode=zbd --zoneskip=1 correctly.
892 bs=$((logical_block_size))
893 run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
894 >> "${logfile}.${test_number}" 2>&1 && return 1
895 grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
898 # Multiple overlapping random write jobs for the same drive and with a
899 # limited number of open zones. This is similar to test29, but uses libaio
900 # to stress test zone locking.
902 local i jobs=16 off opts=()
904 off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
905 size=$((16*zone_size))
907 opts=("--aux-path=/tmp" "--allow_file_create=0" "--significant_figures=10")
908 opts+=("--debug=zbd")
909 opts+=("$(ioengine "libaio")" "--rw=randwrite" "--direct=1")
910 opts+=("--time_based" "--runtime=30")
911 opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
912 opts+=("--max_open_zones=4")
913 for ((i=0;i<jobs;i++)); do
914 opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
915 opts+=("--io_size=$zone_size" "--iodepth=256" "--thread=1")
916 opts+=("--size=$size" "--group_reporting=1")
917 # max_open_zones is already specified
918 opts+=($(job_var_opts_exclude "--max_open_zones"))
921 fio=$(dirname "$0")/../../fio
923 { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
925 timeout -v -s KILL 45s \
926 "${dynamic_analyzer[@]}" "$fio" "${opts[@]}" \
927 >> "${logfile}.${test_number}" 2>&1 || return $?
930 # Check if fio handles --zonecapacity on a normal block device correctly
933 if [ -n "$is_zbd" ]; then
934 echo "$dev is not a regular block device" \
935 >>"${logfile}.${test_number}"
939 size=$((2 * zone_size))
940 capacity=$((zone_size * 3 / 4))
942 run_one_fio_job "$(ioengine "psync")" --rw=write \
943 --zonemode=zbd --zonesize="${zone_size}" \
944 --zonecapacity=${capacity} \
945 --verify=md5 --size=${size} >>"${logfile}.${test_number}" 2>&1 ||
947 check_written $((capacity * 2)) || return $?
948 check_read $((capacity * 2)) || return $?
958 while [ "${1#-}" != "$1" ]; do
960 -d) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=drd"
961 "--show-confl-seg=no");
963 -e) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=helgrind");
965 -l) use_libzbc=1; shift;;
966 -r) reset_all_zones=1; shift;;
967 -t) tests+=("$2"); shift; shift;;
968 -o) max_open_zones_opt="${2}"; shift; shift;;
969 -v) dynamic_analyzer=(valgrind "--read-var-info=yes");
971 -z) zbd_debug=1; shift;;
981 # shellcheck source=functions
982 source "$(dirname "$0")/functions" || exit $?
986 if [ -n "$zbd_debug" ]; then
987 global_var_opts+=("--debug=zbd")
990 realdev=$(readlink -f "$dev")
991 basename=$(basename "$realdev")
993 if [[ -b "$realdev" ]]; then
994 major=$((0x$(stat -L -c '%t' "$realdev"))) || exit $?
995 minor=$((0x$(stat -L -c '%T' "$realdev"))) || exit $?
996 disk_size=$(($(<"/sys/dev/block/$major:$minor/size")*512))
998 # When the target is a partition device, get basename of its
999 # holder device to access sysfs path of the holder device
1000 if [[ -r "/sys/dev/block/$major:$minor/partition" ]]; then
1001 realsysfs=$(readlink "/sys/dev/block/$major:$minor")
1002 basename=$(basename "${realsysfs%/*}")
1004 logical_block_size=$(<"/sys/block/$basename/queue/logical_block_size")
1005 case "$(<"/sys/class/block/$basename/queue/zoned")" in
1006 host-managed|host-aware)
1008 if ! check_blkzone "${dev}"; then
1011 if ! result=($(first_sequential_zone "$dev")); then
1012 echo "Failed to determine first sequential zone"
1015 first_sequential_zone_sector=${result[0]}
1016 sectors_per_zone=${result[1]}
1017 zone_size=$((sectors_per_zone * 512))
1018 if ! max_open_zones=$(max_open_zones "$dev"); then
1019 echo "Failed to determine maximum number of open zones"
1022 set_io_scheduler "$basename" deadline || exit $?
1023 if [ -n "$reset_all_zones" ]; then
1024 reset_zone "$dev" -1
1028 first_sequential_zone_sector=$(((disk_size / 2) &
1029 (logical_block_size - 1)))
1030 zone_size=$(max 65536 "$logical_block_size")
1031 sectors_per_zone=$((zone_size / 512))
1033 set_io_scheduler "$basename" none || exit $?
1036 elif [[ -c "$realdev" ]]; then
1037 # For an SG node, we must have libzbc option specified
1038 if [[ ! -n "$use_libzbc" ]]; then
1039 echo "Character device files can only be used with -l (libzbc) option"
1043 if ! $(is_zbc "$dev"); then
1044 echo "Device is not a ZBC disk"
1049 if ! disk_size=($(( $(zbc_disk_sectors "$dev") * 512))); then
1050 echo "Failed to determine disk size"
1053 if ! logical_block_size=($(zbc_logical_block_size "$dev")); then
1054 echo "Failed to determine logical block size"
1057 if ! result=($(first_sequential_zone "$dev")); then
1058 echo "Failed to determine first sequential zone"
1061 first_sequential_zone_sector=${result[0]}
1062 sectors_per_zone=${result[1]}
1063 zone_size=$((sectors_per_zone * 512))
1064 if ! max_open_zones=$(max_open_zones "$dev"); then
1065 echo "Failed to determine maximum number of open zones"
1068 if [ -n "$reset_all_zones" ]; then
1069 reset_zone "$dev" -1
1073 if [[ -n ${max_open_zones_opt} ]]; then
1074 # Override max_open_zones with the script option value
1075 max_open_zones="${max_open_zones_opt}"
1076 job_var_opts+=("--max_open_zones=${max_open_zones_opt}")
1079 echo -n "First sequential zone starts at sector $first_sequential_zone_sector;"
1080 echo " zone size: $((zone_size >> 20)) MB"
1082 if [ "${#tests[@]}" = 0 ]; then
1083 readarray -t tests < <(declare -F | grep "test[0-9]*" | \
1084 tr -c -d "[:digit:]\n" | sort -n)
1103 trap 'intr=1' SIGINT
1105 for test_number in "${tests[@]}"; do
1106 rm -f "${logfile}.${test_number}"
1107 echo -n "Running test $(printf "%02d" $test_number) ... "
1108 if eval "test$test_number" && check_log $test_number; then
1110 cc_status="${green}${status}${end}"
1114 cc_status="${red}${status}${end}"
1118 echo -e "$cc_status"
1119 echo "$status" >> "${logfile}.${test_number}"
1120 [ $intr -ne 0 ] && exit 1
1123 echo "$passed tests passed"
1124 if [ $failed -gt 0 ]; then
1125 echo " and $failed tests failed"