From: Shin'ichiro Kawasaki Date: Fri, 25 Apr 2025 05:21:41 +0000 (+0900) Subject: oslib: blkzoned: add blkzoned_move_zone_wp() helper function X-Git-Tag: fio-3.40~26 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=4175f4dbec5d1d9e5e0490026e98b1806188e098;p=fio.git oslib: blkzoned: add blkzoned_move_zone_wp() helper function As a preparation for continue_on_error option support for zonemode=zbd, introduce a new function blkzoned_move_zone_wp(). It moves the write pointer by data write. If data buffer is provided, call pwrite() system call. If data buffer is not provided, call fallocate() to write zero data. Signed-off-by: Shin'ichiro Kawasaki Reviewed-by: Damien Le Moal Link: https://lore.kernel.org/r/20250425052148.126788-2-shinichiro.kawasaki@wdc.com Signed-off-by: Jens Axboe --- diff --git a/oslib/blkzoned.h b/oslib/blkzoned.h index e598bd4f..3a4c73c2 100644 --- a/oslib/blkzoned.h +++ b/oslib/blkzoned.h @@ -16,6 +16,9 @@ extern int blkzoned_report_zones(struct thread_data *td, struct zbd_zone *zones, unsigned int nr_zones); extern int blkzoned_reset_wp(struct thread_data *td, struct fio_file *f, uint64_t offset, uint64_t length); +extern int blkzoned_move_zone_wp(struct thread_data *td, struct fio_file *f, + struct zbd_zone *z, uint64_t length, + const char *buf); extern int blkzoned_get_max_open_zones(struct thread_data *td, struct fio_file *f, unsigned int *max_open_zones); extern int blkzoned_get_max_active_zones(struct thread_data *td, diff --git a/oslib/linux-blkzoned.c b/oslib/linux-blkzoned.c index 1cc8d288..78e25fca 100644 --- a/oslib/linux-blkzoned.c +++ b/oslib/linux-blkzoned.c @@ -370,3 +370,32 @@ int blkzoned_finish_zone(struct thread_data *td, struct fio_file *f, return ret; } + +int blkzoned_move_zone_wp(struct thread_data *td, struct fio_file *f, + struct zbd_zone *z, uint64_t length, const char *buf) +{ + int fd, ret = 0; + + /* If the file is not yet open, open it for this function */ + fd = f->fd; + if (fd < 0) { + fd = open(f->file_name, O_WRONLY | O_DIRECT); + if (fd < 0) + return -errno; + } + + /* If write data is not provided, fill zero to move the write pointer */ + if (!buf) { + ret = fallocate(fd, FALLOC_FL_ZERO_RANGE, z->wp, length); + goto out; + } + + if (pwrite(fd, buf, length, z->wp) < 0) + ret = -errno; + +out: + if (f->fd < 0) + close(fd); + + return ret; +}