zbd: fix write zone accounting of trim workload
[fio.git] / t / zbd / test-zbd-support
index 217fdd1048c164afa81a1b4758d5fe4eec1367bc..996160e769476bc8a070af2c40f4d442380ff4b0 100755 (executable)
@@ -12,9 +12,12 @@ usage() {
        echo -e "\t-v Run fio with valgrind --read-var-info option"
        echo -e "\t-l Test with libzbc ioengine"
        echo -e "\t-r Reset all zones before test start"
+       echo -e "\t-w Reset all zones before executing each write test case"
        echo -e "\t-o <max_open_zones> Run fio with max_open_zones limit"
        echo -e "\t-t <test #> Run only a single test case with specified number"
+       echo -e "\t-q Quit the test run after any failed test"
        echo -e "\t-z Run fio with debug=zbd option"
+       echo -e "\t-u Use io_uring ioengine in place of libaio"
 }
 
 max() {
@@ -36,6 +39,8 @@ min() {
 ioengine() {
        if [ -n "$use_libzbc" ]; then
                echo -n "--ioengine=libzbc"
+       elif [ "$1" = "libaio" -a -n "$force_io_uring" ]; then
+               echo -n "--ioengine=io_uring"
        else
                echo -n "--ioengine=$1"
        fi
@@ -161,7 +166,7 @@ write_and_run_one_fio_job() {
     shift 2
     r=$(((RANDOM << 16) | RANDOM))
     write_opts=(--name="write_job" --rw=write "$(ioengine "psync")" \
-                     --bs="${logical_block_size}" --zonemode=zbd \
+                     --bs="${min_seq_write_size}" --zonemode=zbd \
                      --zonesize="${zone_size}" --thread=1 --direct=1 \
                      --offset="${write_offset}" --size="${write_size}")
     write_opts+=("${job_var_opts[@]}")
@@ -181,13 +186,14 @@ run_fio_on_seq() {
     run_one_fio_job "${opts[@]}" "$@"
 }
 
-# Prepare for write test by resetting zones. When max_open_zones option is
-# specified, reset all zones of the test target to ensure that zones out of the
-# test target range do not have open zones. This allows the write test to the
-# target range to be able to open zones up to max_open_zones.
+# Prepare for write test by resetting zones. When reset_before_write or
+# max_open_zones option is specified, reset all zones of the test target to
+# ensure that zones out of the test target range do not have open zones. This
+# allows the write test to the target range to be able to open zones up to
+# max_open_zones limit specified as the option or obtained from sysfs.
 prep_write() {
-       [[ -n "${max_open_zones_opt}" && -n "${is_zbd}" ]] &&
-               reset_zone "${dev}" -1
+       [[ -n "${reset_before_write}" || -n "${max_open_zones_opt}" ]] &&
+               [[ -n "${is_zbd}" ]] && reset_zone "${dev}" -1
 }
 
 SKIP_TESTCASE=255
@@ -226,6 +232,14 @@ require_regular_block_dev() {
        return 0
 }
 
+require_block_dev() {
+       if [[ -b "$realdev" ]]; then
+               return 0
+       fi
+       SKIP_REASON="$dev is not a block device"
+       return 1
+}
+
 require_seq_zones() {
        local req_seq_zones=${1}
        local seq_bytes=$((disk_size - first_sequential_zone_sector * 512))
@@ -248,8 +262,19 @@ require_conv_zones() {
        return 0
 }
 
-# Check whether buffered writes are refused.
+require_max_open_zones() {
+       local min=${1}
+
+       if ((max_open_zones !=0 && max_open_zones < min)); then
+               SKIP_REASON="max_open_zones of $dev is smaller than $min"
+               return 1
+       fi
+       return 0
+}
+
+# Check whether buffered writes are refused for block devices.
 test1() {
+    require_block_dev || return $SKIP_TESTCASE
     run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K        \
            "$(ioengine "psync")" --size="${zone_size}" --thread=1      \
            --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
@@ -309,7 +334,8 @@ test4() {
     off=$((first_sequential_zone_sector * 512 + 129 * zone_size))
     size=$((zone_size))
     [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
-    opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=$size")
+    opts+=("--name=$dev" "--filename=$dev" "--offset=$off")
+    opts+=(--bs="$(min $((min_seq_write_size * 256)) $size)")
     opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1")
     opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--disable_lat=1")
     opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
@@ -319,15 +345,15 @@ test4() {
 
 # Sequential write to sequential zones.
 test5() {
-    local size off capacity
+    local size off capacity bs
 
     prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
     size=$((4 * zone_size))
+    bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
     run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write        \
-                  --bs="$(max $((zone_size / 64)) "$logical_block_size")"\
-                  --do_verify=1 --verify=md5                           \
+                  --bs="$bs" --do_verify=1 --verify=md5 \
                   >>"${logfile}.${test_number}" 2>&1 || return $?
     check_written $capacity || return $?
     check_read $capacity || return $?
@@ -335,18 +361,18 @@ test5() {
 
 # Sequential read from sequential zones.
 test6() {
-    local size off capacity
+    local size off capacity bs
 
     prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
     size=$((4 * zone_size))
+    bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
     write_and_run_one_fio_job \
            $((first_sequential_zone_sector * 512)) "${size}" \
            --offset="${off}" \
            --size="${size}" --zonemode=zbd --zonesize="${zone_size}" \
-           "$(ioengine "psync")" --iodepth=1 --rw=read \
-           --bs="$(max $((zone_size / 64)) "$logical_block_size")" \
+           "$(ioengine "psync")" --iodepth=1 --rw=read --bs="$bs" \
            >>"${logfile}.${test_number}" 2>&1 || return $?
     check_read $capacity || return $?
 }
@@ -449,6 +475,8 @@ test12() {
 test13() {
     local size off capacity
 
+    require_max_open_zones 4 || return $SKIP_TESTCASE
+
     prep_write
     size=$((8 * zone_size))
     off=$((first_sequential_zone_sector * 512))
@@ -463,15 +491,20 @@ test13() {
 
 # Random write to conventional zones.
 test14() {
-    local size
+    local off size
 
+    if ! result=($(first_online_zone "$dev")); then
+       echo "Failed to determine first online zone"
+       exit 1
+    fi
+    off=${result[0]}
     prep_write
     size=$((16 * 2**20)) # 20 MB
     require_conv_zone_bytes "${size}" || return $SKIP_TESTCASE
 
     run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
                    --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \
-                   --verify=md5 --size=$size                              \
+                   --verify=md5 --offset=$off --size=$size\
                    >>"${logfile}.${test_number}" 2>&1 || return $?
     check_written $((size)) || return $?
     check_read $((size)) || return $?
@@ -479,7 +512,7 @@ test14() {
 
 # Sequential read on a mix of empty and full zones.
 test15() {
-    local i off size
+    local i off size bs
     local w_off w_size w_capacity
 
     for ((i=0;i<4;i++)); do
@@ -493,8 +526,9 @@ test15() {
     w_capacity=$(total_zone_capacity 2 $w_off $dev)
     off=$((first_sequential_zone_sector * 512))
     size=$((4 * zone_size))
+    bs=$(min $((zone_size / 16)) "$zone_cap_bs")
     write_and_run_one_fio_job "${w_off}" "${w_size}" \
-                   "$(ioengine "psync")" --rw=read --bs=$((zone_size / 16)) \
+                   "$(ioengine "psync")" --rw=read --bs="$bs" \
                    --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
                    --size=$((size)) >>"${logfile}.${test_number}" 2>&1 ||
        return $?
@@ -528,17 +562,26 @@ test16() {
 
 # Random reads and writes in the last zone.
 test17() {
-    local io off read size written
+    local io off last read size written
 
     off=$(((disk_size / zone_size - 1) * zone_size))
     size=$((disk_size - off))
+    if ! last=($(last_online_zone "$dev")); then
+       echo "Failed to determine last online zone"
+       exit 1
+    fi
+    if [[ "$((last * 512))" -lt "$off" ]]; then
+       off=$((last * 512))
+       size=$zone_size
+    fi
     if [ -n "$is_zbd" ]; then
        reset_zone "$dev" $((off / 512)) || return $?
     fi
     prep_write
     run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
                    --zonemode=zbd --zonesize="${zone_size}"            \
-                   --offset=$off --loops=2 --norandommap=1\
+                   --offset=$off --loops=2 --norandommap=1 \
+                   --size="$size"\
                    >>"${logfile}.${test_number}" 2>&1 || return $?
     written=$(fio_written <"${logfile}.${test_number}")
     read=$(fio_read <"${logfile}.${test_number}")
@@ -705,7 +748,7 @@ test30() {
     prep_write
     off=$((first_sequential_zone_sector * 512))
     run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw     \
-                   --bs="$(max $((zone_size / 128)) "$logical_block_size")"\
+                   --bs="$(max $((zone_size / 128)) "$min_seq_write_size")"\
                    --zonemode=zbd --zonesize="${zone_size}" --offset=$off\
                    --loops=2 --time_based --runtime=30s --norandommap=1\
                    >>"${logfile}.${test_number}" 2>&1
@@ -716,26 +759,28 @@ test30() {
 test31() {
     local bs inc nz off opts size
 
-    prep_write
-    # Start with writing 128 KB to 128 sequential zones.
-    bs=128K
-    nz=128
-    # shellcheck disable=SC2017
-    inc=$(((disk_size - (first_sequential_zone_sector * 512)) / (nz * zone_size)
-          * zone_size))
-    opts=()
-    for ((off = first_sequential_zone_sector * 512; off < disk_size;
-         off += inc)); do
-       opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--io_size=$bs")
-       opts+=("--bs=$bs" "--size=$zone_size" "$(ioengine "libaio")")
-       opts+=("--rw=write" "--direct=1" "--thread=1" "--stats=0")
-       opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
-       opts+=(${job_var_opts[@]})
-    done
-    "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1
-    # Next, run the test.
+    [ -n "$is_zbd" ] && reset_zone "$dev" -1
+
+    # As preparation, write 128 KB to sequential write required zones. Limit
+    # write target zones up to max_open_zones to keep test time reasonable.
+    # To distribute the write target zones evenly, skip certain zones for every
+    # write. Utilize zonemode strided for such write patterns.
+    bs=$((128 * 1024))
+    nz=$((max_open_zones))
+    if [[ $nz -eq 0 ]]; then
+       nz=128
+    fi
     off=$((first_sequential_zone_sector * 512))
     size=$((disk_size - off))
+    inc=$(((size / nz / zone_size) * zone_size))
+    opts=("--name=$dev" "--filename=$dev" "--rw=write" "--bs=${bs}")
+    opts+=("--offset=$off" "--size=$((inc * nz))" "--io_size=$((bs * nz))")
+    opts+=("--zonemode=strided" "--zonesize=${bs}" "--zonerange=${inc}")
+    opts+=("--direct=1")
+    echo "fio ${opts[@]}" >> "${logfile}.${test_number}"
+    "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1
+
+    # Next, run the test.
     opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
     opts+=("--bs=$bs" "$(ioengine "psync")" "--rw=randread" "--direct=1")
     opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd")
@@ -768,7 +813,8 @@ test33() {
     local bs io_size size
     local off capacity=0;
 
-    prep_write
+    [ -n "$is_zbd" ] && reset_zone "$dev" -1
+
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 1 $off $dev)
     size=$((2 * zone_size))
@@ -777,20 +823,30 @@ test33() {
     run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write        \
                   --size=$size --io_size=$io_size --bs=$bs     \
                   >> "${logfile}.${test_number}" 2>&1 || return $?
-    check_written $(((io_size + bs - 1) / bs * bs)) || return $?
+    check_written $((io_size / bs * bs)) || return $?
 }
 
-# Write to sequential zones with a block size that is not a divisor of the
-# zone size and with data verification enabled.
+# Test repeated async write job with verify using two unaligned block sizes.
 test34() {
-    local size
+       local bs off zone_capacity
+       local -a block_sizes
 
-    prep_write
-    size=$((2 * zone_size))
-    run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write --size=$size \
-                  --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \
-                  >> "${logfile}.${test_number}" 2>&1 && return 1
-    grep -q 'not a divisor of' "${logfile}.${test_number}"
+       require_zbd || return $SKIP_TESTCASE
+       prep_write
+
+       off=$((first_sequential_zone_sector * 512))
+       zone_capacity=$(total_zone_capacity 1 $off $dev)
+       block_sizes=($((4096 * 7)) $(($(min ${zone_capacity} 4194304) - 4096)))
+
+       for bs in ${block_sizes[@]}; do
+               run_fio --name=job --filename="${dev}" --rw=randwrite \
+                       --bs="${bs}" --offset="${off}" \
+                       --size=$((4 * zone_size)) --iodepth=256 \
+                       "$(ioengine "libaio")" --time_based=1 --runtime=15s \
+                       --zonemode=zbd --direct=1 --zonesize="${zone_size}" \
+                       --verify=crc32c --do_verify=1 ${job_var_opts[@]} \
+                       >> "${logfile}.${test_number}" 2>&1 || return $?
+       done
 }
 
 # Test 1/4 for the I/O boundary rounding code: $size < $zone_size.
@@ -828,14 +884,14 @@ test37() {
     local bs off size capacity
 
     prep_write
-    capacity=$(total_zone_capacity 1 $first_sequential_zone_sector $dev)
+    capacity=$(total_zone_capacity 1 $((first_sequential_zone_sector*512)) $dev)
     if [ "$first_sequential_zone_sector" = 0 ]; then
        off=0
     else
        off=$(((first_sequential_zone_sector - 1) * 512))
     fi
     size=$((zone_size + 2 * 512))
-    bs=$((zone_size / 4))
+    bs=$(min $((zone_size / 4)) "$zone_cap_bs")
     run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")"   \
                    --iodepth=1 --rw=write --do_verify=1 --verify=md5   \
                    --bs=$bs --zonemode=zbd --zonesize="${zone_size}"   \
@@ -848,9 +904,9 @@ test38() {
     local bs off size
 
     prep_write
-    size=$((logical_block_size))
-    off=$((disk_size - logical_block_size))
-    bs=$((logical_block_size))
+    size=$((min_seq_write_size))
+    off=$((disk_size - min_seq_write_size))
+    bs=$((min_seq_write_size))
     run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")"   \
                    --iodepth=1 --rw=write --do_verify=1 --verify=md5   \
                    --bs=$bs --zonemode=zbd --zonesize="${zone_size}"   \
@@ -860,10 +916,17 @@ test38() {
 
 # Read one block from a block device.
 read_one_block() {
+    local off
     local bs
 
-    bs=$((logical_block_size))
-    run_one_fio_job --rw=read "$(ioengine "psync")" --bs=$bs --size=$bs "$@" 2>&1 |
+    if ! result=($(first_online_zone "$dev")); then
+       echo "Failed to determine first online zone"
+       exit 1
+    fi
+    off=${result[0]}
+    bs=$((min_seq_write_size))
+    run_one_fio_job --rw=read "$(ioengine "psync")" --offset=$off --bs=$bs \
+                   --size=$bs "$@" 2>&1 |
        tee -a "${logfile}.${test_number}"
 }
 
@@ -871,14 +934,14 @@ read_one_block() {
 test39() {
     require_zbd || return $SKIP_TESTCASE
     read_one_block --zonemode=none >/dev/null || return $?
-    check_read $((logical_block_size)) || return $?
+    check_read $((min_seq_write_size)) || return $?
 }
 
 # Check whether fio accepts --zonemode=strided for zoned block devices.
 test40() {
     local bs
 
-    bs=$((logical_block_size))
+    bs=$((min_seq_write_size))
     require_zbd || return $SKIP_TESTCASE
     read_one_block --zonemode=strided |
        grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
@@ -898,7 +961,7 @@ test41() {
 test42() {
     require_regular_block_dev || return $SKIP_TESTCASE
     read_one_block --zonemode=zbd --zonesize=0 |
-       grep -q 'Specifying the zone size is mandatory for regular block devices with --zonemode=zbd'
+       grep -q 'Specifying the zone size is mandatory for regular file/block device with --zonemode=zbd'
 }
 
 # Check whether fio handles --zonesize=1 correctly for regular block devices.
@@ -919,7 +982,7 @@ test45() {
 
     require_zbd || return $SKIP_TESTCASE
     prep_write
-    bs=$((logical_block_size))
+    bs=$((min_seq_write_size))
     run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite --bs=$bs\
                    --offset=$((first_sequential_zone_sector * 512)) \
                    --size="$zone_size" --do_verify=1 --verify=md5 2>&1 |
@@ -944,7 +1007,7 @@ test47() {
     local bs
 
     prep_write
-    bs=$((logical_block_size))
+    bs=$((min_seq_write_size))
     run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
                    >> "${logfile}.${test_number}" 2>&1 && return 1
     grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
@@ -980,7 +1043,7 @@ test48() {
 
     { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
 
-    timeout -v -s KILL 45s \
+    timeout -v -s KILL 180s \
            "${dynamic_analyzer[@]}" "$fio" "${opts[@]}" \
            >> "${logfile}.${test_number}" 2>&1 || return $?
 }
@@ -1047,8 +1110,8 @@ test51() {
        run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
 }
 
-# Verify that zone_reset_threshold only takes logical blocks from seq
-# zones into account, and logical blocks of conv zones are not counted.
+# Verify that zone_reset_threshold only accounts written bytes in seq
+# zones, and written data bytes of conv zones are not counted.
 test52() {
        local off io_size
 
@@ -1079,12 +1142,235 @@ test52() {
        check_reset_count -eq 0 || return $?
 }
 
+# Check both reads and writes are executed by random I/O to conventional zones.
+test53() {
+       local off capacity io read_b=0 written_b=0
+
+       require_zbd || return $SKIP_TESTCASE
+       require_conv_zones 4 || return $SKIP_TESTCASE
+
+       off=$((first_sequential_zone_sector * 512 - 4 * zone_size))
+       capacity=$(total_zone_capacity 4 $off $dev)
+       run_fio --name=job --filename=${dev} --rw=randrw --bs=64K \
+               --size=$((4 * zone_size)) "$(ioengine "psync")" --offset=${off}\
+               --zonemode=zbd --direct=1 --zonesize=${zone_size} \
+               ${job_var_opts[@]} \
+               >> "${logfile}.${test_number}" 2>&1 || return $?
+
+       written_b=$(fio_written <"${logfile}.${test_number}")
+       read_b=$(fio_read <"${logfile}.${test_number}")
+       io=$((written_b + read_b))
+       echo "Number of bytes read: $read_b" >>"${logfile}.${test_number}"
+       echo "Number of bytes written: $written_b" >>"${logfile}.${test_number}"
+       echo "Total number of bytes read and written: $io <> $capacity" \
+            >>"${logfile}.${test_number}"
+       if ((io==capacity && written_b != 0 && read_b != 0)); then
+               return 0
+       fi
+       return 1
+}
+
+# Test read/write mix with verify.
+test54() {
+       require_zbd || return $SKIP_TESTCASE
+       require_seq_zones 8 || return $SKIP_TESTCASE
+
+       run_fio --name=job --filename=${dev} "$(ioengine "libaio")" \
+               --time_based=1 --runtime=30s --continue_on_error=0 \
+               --offset=$((first_sequential_zone_sector * 512)) \
+               --size=$((8*zone_size)) --direct=1 --iodepth=1 \
+               --rw=randrw:2 --rwmixwrite=25 --bsrange=4k-${zone_size} \
+               --zonemode=zbd --zonesize=${zone_size} \
+               --verify=crc32c --do_verify=1 --verify_backlog=2 \
+               --alloc-size=65536 --random_generator=tausworthe64 \
+               ${job_var_opts[@]} --debug=zbd \
+               >> "${logfile}.${test_number}" 2>&1 || return $?
+}
+
+# test 'z' suffix parsing only
+test55() {
+       local bs
+       bs=$((min_seq_write_size))
+
+       require_zbd || return $SKIP_TESTCASE
+       # offset=1z + offset_increment=10z + size=2z
+       require_seq_zones 13 || return $SKIP_TESTCASE
+
+       run_fio --name=j                \
+               --filename=${dev}       \
+               --direct=1              \
+               "$(ioengine "psync")"   \
+               --zonemode=zbd          \
+               --zonesize=${zone_size} \
+               --rw=write              \
+               --bs=${bs}              \
+               --numjobs=2             \
+               --offset_increment=10z  \
+               --offset=1z             \
+               --size=2z               \
+               --io_size=3z            \
+               ${job_var_opts[@]} --debug=zbd \
+               >> "${logfile}.${test_number}" 2>&1 || return $?
+}
+
+# test 'z' suffix parsing only
+test56() {
+       local bs
+       bs=$((min_seq_write_size))
+
+       require_regular_block_dev || return $SKIP_TESTCASE
+       require_seq_zones 10 || return $SKIP_TESTCASE
+
+       run_fio --name=j                \
+               --filename=${dev}       \
+               --direct=1              \
+               "$(ioengine "psync")"   \
+               --zonemode=strided      \
+               --zonesize=${zone_size} \
+               --rw=write              \
+               --bs=${bs}              \
+               --size=10z              \
+               --zoneskip=2z           \
+               ${job_var_opts[@]} --debug=zbd \
+               >> "${logfile}.${test_number}" 2>&1 || return $?
+}
+
+# Test that repeated async write job does not cause zone reset during writes
+# in-flight, when the block size is not a divisor of the zone size.
+test57() {
+       local bs off
+
+       require_zbd || return $SKIP_TESTCASE
+
+       bs=$((4096 * 7))
+       off=$((first_sequential_zone_sector * 512))
+
+       run_fio --name=job --filename="${dev}" --rw=randwrite --bs="${bs}" \
+               --offset="${off}" --size=$((4 * zone_size)) --iodepth=256 \
+               "$(ioengine "libaio")" --time_based=1 --runtime=30s \
+               --zonemode=zbd --direct=1 --zonesize="${zone_size}" \
+               ${job_var_opts[@]} \
+               >> "${logfile}.${test_number}" 2>&1 || return $?
+}
+
+# Random writes and random trims to sequential write required zones for 30s.
+test58() {
+    local off size bs
+
+    require_seq_zones 128 || return $SKIP_TESTCASE
+
+    size=$((zone_size * 128))
+    bs="$(max $((zone_size / 128)) "$min_seq_write_size")"
+    prep_write
+    off=$((first_sequential_zone_sector * 512))
+    run_fio --zonemode=zbd --direct=1 --zonesize="${zone_size}" --thread=1 \
+           --filename="${dev}" --norandommap=1 \
+            --name="precondition"  --rw=write "$(ioengine "psync")" \
+            --offset="${off}" --size=$((zone_size * 16)) --bs="${bs}" \
+           "${job_var_opts[@]}" \
+           --name=wjob --wait_for="precondition" --rw=randwrite \
+           "$(ioengine "libaio")" --iodepth=8 \
+           --offset="${off}" --size="${size}" --bs="${bs}" \
+           --time_based --runtime=30s --flow=128 "${job_var_opts[@]}" \
+           --name=trimjob --wait_for="precondition" --rw=randtrim \
+           "$(ioengine "psync")" \
+           --offset="${off}" --size="${size}" --bs="${zone_size}" \
+           --time_based --runtime=30s --flow=1 "${job_var_opts[@]}" \
+           >>"${logfile}.${test_number}" 2>&1
+}
+
+# Test zone_reset_threshold with verify.
+test59() {
+       local off bs loops=2 size=$((zone_size)) w
+       local -a workloads=(write randwrite rw randrw)
+
+       prep_write
+       off=$((first_sequential_zone_sector * 512))
+
+       bs=$(min $((256*1024)) "$zone_size")
+       for w in "${workloads[@]}"; do
+               run_fio_on_seq "$(ioengine "psync")" --rw=${w} --bs="$bs" \
+                              --size=$size --loops=$loops --do_verify=1 \
+                              --verify=md5 --zone_reset_frequency=.9 \
+                              --zone_reset_threshold=.1 \
+                              >> "${logfile}.${test_number}" 2>&1 || return $?
+       done
+}
+
+# Test fio errors out experimental_verify option with zonemode=zbd.
+test60() {
+       run_fio_on_seq "$(ioengine "psync")" --rw=write --size=$zone_size \
+                      --do_verify=1 --verify=md5 --experimental_verify=1 \
+                      >> "${logfile}.${test_number}" 2>&1 && return 1
+       grep -q 'not support experimental verify' "${logfile}.${test_number}"
+}
+
+# Test fio errors out zone_reset_threshold option for multiple jobs with
+# different write ranges.
+test61() {
+       run_fio_on_seq "$(ioengine "psync")" --rw=write --size="$zone_size" \
+                      --numjobs=2 --offset_increment="$zone_size" \
+                      --zone_reset_threshold=0.1 --zone_reset_frequency=1 \
+                      --exitall_on_error=1 \
+                      >> "${logfile}.${test_number}" 2>&1 && return 1
+       grep -q 'different write ranges' "${logfile}.${test_number}"
+}
+
+# Test zone_reset_threshold option works for multiple jobs with same write
+# range.
+test62() {
+       local bs loops=2 size=$((zone_size))
+
+       [ -n "$is_zbd" ] && reset_zone "$dev" -1
+
+       # Two jobs write to single zone twice. Reset zone happens at next write
+       # after half of the zone gets filled. So 2 * 2 * 2 - 1 = 7 times zone
+       # resets are expected.
+       bs=$(min $((256*1024)) $((zone_size / 4)))
+       run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
+                      --size=$size --loops=$loops --numjobs=2 \
+                      --zone_reset_frequency=1 --zone_reset_threshold=.5 \
+                      --group_reporting=1 \
+                      >> "${logfile}.${test_number}" 2>&1 || return $?
+       check_written $((size * loops * 2)) || return $?
+       check_reset_count -eq 7 || return $?
+}
+
+# Test zone_reset_threshold option works for a read job and a write job with
+# different IO range.
+test63() {
+       local bs loops=2 size=$((zone_size)) off1 off2
+
+       [ -n "$is_zbd" ] && reset_zone "$dev" -1
+
+       off1=$((first_sequential_zone_sector * 512))
+       off2=$((off1 + zone_size))
+       bs=$(min $((256*1024)) $((zone_size / 4)))
+
+       # One job writes to single zone twice. Reset zone happens at next write
+       # after half of the zone gets filled. So 2 * 2 - 1 = 3 times zone resets
+       # are expected.
+       run_fio "$(ioengine "psync")" --bs="$bs" --size=$size --loops=$loops \
+               --filename="$dev" --group_reporting=1 \
+               --zonemode=zbd --zonesize="$zone_size" --direct=1 \
+               --zone_reset_frequency=1 --zone_reset_threshold=.5 \
+               --name=r --rw=read --offset=$off1 "${job_var_opts[@]}" \
+               --name=w --rw=write --offset=$off2 "${job_var_opts[@]}" \
+                      >> "${logfile}.${test_number}" 2>&1 || return $?
+       check_written $((size * loops)) || return $?
+       check_reset_count -eq 3 || return $?
+}
+
+SECONDS=0
 tests=()
 dynamic_analyzer=()
 reset_all_zones=
+reset_before_write=
 use_libzbc=
 zbd_debug=
 max_open_zones_opt=
+quit_on_err=
+force_io_uring=
 
 while [ "${1#-}" != "$1" ]; do
   case "$1" in
@@ -1095,12 +1381,16 @@ while [ "${1#-}" != "$1" ]; do
        shift;;
     -l) use_libzbc=1; shift;;
     -r) reset_all_zones=1; shift;;
+    -w) reset_before_write=1; shift;;
     -t) tests+=("$2"); shift; shift;;
     -o) max_open_zones_opt="${2}"; shift; shift;;
     -v) dynamic_analyzer=(valgrind "--read-var-info=yes");
        shift;;
+    -q) quit_on_err=1; shift;;
     -z) zbd_debug=1; shift;;
+    -u) force_io_uring=1; shift;;
     --) shift; break;;
+     *) usage; exit 1;;
   esac
 done
 
@@ -1109,6 +1399,11 @@ if [ $# != 1 ]; then
     exit 1
 fi
 
+if [ -n "$use_libzbc" -a -n "$force_io_uring" ]; then
+    echo "Please specify only one of -l and -u options"
+    exit 1
+fi
+
 # shellcheck source=functions
 source "$(dirname "$0")/functions" || exit $?
 
@@ -1132,7 +1427,7 @@ if [[ -b "$realdev" ]]; then
                realsysfs=$(readlink "/sys/dev/block/$major:$minor")
                basename=$(basename "${realsysfs%/*}")
        fi
-       logical_block_size=$(<"/sys/block/$basename/queue/logical_block_size")
+       min_seq_write_size=$(min_seq_write_size "$basename")
        case "$(<"/sys/class/block/$basename/queue/zoned")" in
        host-managed|host-aware)
                is_zbd=true
@@ -1157,8 +1452,8 @@ if [[ -b "$realdev" ]]; then
                ;;
        *)
                first_sequential_zone_sector=$(((disk_size / 2) &
-                                               (logical_block_size - 1)))
-               zone_size=$(max 65536 "$logical_block_size")
+                                               (min_seq_write_size - 1)))
+               zone_size=$(max 65536 "$min_seq_write_size")
                sectors_per_zone=$((zone_size / 512))
                max_open_zones=128
                set_io_scheduler "$basename" none || exit $?
@@ -1181,8 +1476,8 @@ elif [[ -c "$realdev" ]]; then
                echo "Failed to determine disk size"
                exit 1
        fi
-       if ! logical_block_size=($(zbc_logical_block_size "$dev")); then
-               echo "Failed to determine logical block size"
+       if ! min_seq_write_size=($(zbc_physical_block_size "$dev")); then
+               echo "Failed to determine physical block size"
                exit 1
        fi
        if ! result=($(first_sequential_zone "$dev")); then
@@ -1204,12 +1499,15 @@ fi
 if [[ -n ${max_open_zones_opt} ]]; then
        # Override max_open_zones with the script option value
        max_open_zones="${max_open_zones_opt}"
+       global_var_opts+=("--ignore_zone_limits=1")
        job_var_opts+=("--max_open_zones=${max_open_zones_opt}")
 fi
 
 echo -n "First sequential zone starts at sector $first_sequential_zone_sector;"
 echo " zone size: $((zone_size >> 20)) MB"
 
+zone_cap_bs=$(zone_cap_bs "$dev" "$zone_size")
+
 if [ "${#tests[@]}" = 0 ]; then
     readarray -t tests < <(declare -F | grep "test[0-9]*" | \
                                   tr -c -d "[:digit:]\n" | sort -n)
@@ -1260,6 +1558,7 @@ for test_number in "${tests[@]}"; do
     echo -e "$cc_status"
     echo "$status" >> "${logfile}.${test_number}"
     [ $intr -ne 0 ] && exit 1
+    [ -n "$quit_on_err" -a "$rc" -ne 0 ] && exit 1
 done
 
 echo "$passed tests passed"
@@ -1269,4 +1568,5 @@ fi
 if [ $failed -gt 0 ]; then
     echo " $failed tests failed"
 fi
+echo "Run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )"
 exit $rc