oslib: blkzoned: add blkzoned_move_zone_wp() helper function
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fri, 25 Apr 2025 05:21:41 +0000 (14:21 +0900)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 May 2025 11:28:47 +0000 (05:28 -0600)
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 <shinichiro.kawasaki@wdc.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Link: https://lore.kernel.org/r/20250425052148.126788-2-shinichiro.kawasaki@wdc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
oslib/blkzoned.h
oslib/linux-blkzoned.c

index e598bd4f8026f74ad6e61771858710589b409e2b..3a4c73c2dfe63933c97e4bbad0b8a9182e986410 100644 (file)
@@ -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,
index 1cc8d288b49c9b80ea0cfb83d905934eab6e9419..78e25fca9132a96b41720eb79325420221bb7fd4 100644 (file)
@@ -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;
+}