t/zbd: add close_zone helper function
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Wed, 19 Jul 2023 10:57:48 +0000 (19:57 +0900)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 20 Jul 2023 13:52:37 +0000 (09:52 -0400)
Add a helper function which sets the specified zone in closed condition.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Link: https://lore.kernel.org/r/20230719105756.553146-6-shinichiro.kawasaki@wdc.com
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
t/zbd/functions

index 9a6d699910f2f94acfc95ac5d06aa8720c3ba238..fe5b3397f5a5688adaa2b9504667ab011100ef13 100644 (file)
@@ -4,6 +4,7 @@ blkzone=$(type -p blkzone 2>/dev/null)
 sg_inq=$(type -p sg_inq 2>/dev/null)
 zbc_report_zones=$(type -p zbc_report_zones 2>/dev/null)
 zbc_reset_zone=$(type -p zbc_reset_zone 2>/dev/null)
+zbc_close_zone=$(type -p zbc_close_zone 2>/dev/null)
 zbc_info=$(type -p zbc_info 2>/dev/null)
 if [ -z "${blkzone}" ] &&
        { [ -z "${zbc_report_zones}" ] || [ -z "${zbc_reset_zone}" ]; }; then
@@ -304,6 +305,18 @@ reset_zone() {
     fi
 }
 
+# Close the zone on device $1 at offset $2. The offset must be specified in
+# units of 512 byte sectors.
+close_zone() {
+       local dev=$1 offset=$2
+
+       if [ -n "${blkzone}" ] && [ -z "${use_libzbc}" ]; then
+               ${blkzone} close -o "${offset}" -c 1 "$dev"
+       else
+               ${zbc_close_zone} -sector "$dev" "${offset}" >/dev/null
+       fi
+}
+
 # Extract the number of bytes that have been transferred from a line like
 # READ: bw=6847KiB/s (7011kB/s), 6847KiB/s-6847KiB/s (7011kB/s-7011kB/s), io=257MiB (269MB), run=38406-38406msec
 fio_io() {