From 62ab6b9074f61cc50cf8bc7a9dc0ae0862552b17 Mon Sep 17 00:00:00 2001 From: Sergey Truschev Date: Mon, 24 Nov 2025 11:48:45 +0300 Subject: [PATCH] fio: add sync capability for file operations The patch adds support for sync operations to the fileoperations, ftruncate, and falloc ioengines. Signed-off-by: Sergei Truschev --- engines/falloc.c | 20 ++++++++++++-------- engines/fileoperations.c | 2 ++ engines/ftruncate.c | 11 ++++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/engines/falloc.c b/engines/falloc.c index 290b980f37..5bd5aa54cd 100644 --- a/engines/falloc.c +++ b/engines/falloc.c @@ -76,14 +76,18 @@ static enum fio_q_status fio_fallocate_queue(struct thread_data *td, fio_ro_check(td, io_u); - if (io_u->ddir == DDIR_READ) - flags = FALLOC_FL_KEEP_SIZE; - else if (io_u->ddir == DDIR_WRITE) - flags = 0; - else if (io_u->ddir == DDIR_TRIM) - flags = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; - - ret = fallocate(f->fd, flags, io_u->offset, io_u->xfer_buflen); + if (io_u->ddir != DDIR_SYNC) { + if (io_u->ddir == DDIR_READ) + flags = FALLOC_FL_KEEP_SIZE; + else if (io_u->ddir == DDIR_WRITE) + flags = 0; + else if (io_u->ddir == DDIR_TRIM) + flags = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; + + ret = fallocate(f->fd, flags, io_u->offset, io_u->xfer_buflen); + } else { + ret = do_io_u_sync(td, io_u); + } if (ret) io_u->error = errno; diff --git a/engines/fileoperations.c b/engines/fileoperations.c index e530335958..ce3e7c39b1 100644 --- a/engines/fileoperations.c +++ b/engines/fileoperations.c @@ -264,6 +264,8 @@ static int invalidate_do_nothing(struct thread_data *td, struct fio_file *f) static enum fio_q_status queue_io(struct thread_data *td, struct io_u *io_u) { + if (io_u->ddir == DDIR_SYNC && do_io_u_sync(td, io_u)) + io_u->error = errno; return FIO_Q_COMPLETED; } diff --git a/engines/ftruncate.c b/engines/ftruncate.c index d1757b79c6..70211e0705 100644 --- a/engines/ftruncate.c +++ b/engines/ftruncate.c @@ -15,16 +15,17 @@ static enum fio_q_status fio_ftruncate_queue(struct thread_data *td, struct io_u *io_u) { struct fio_file *f = io_u->file; - int ret; + int ret = 0; fio_ro_check(td, io_u); - if (io_u->ddir != DDIR_WRITE) { + if (io_u->ddir == DDIR_WRITE) + ret = ftruncate(f->fd, io_u->offset); + else if (io_u->ddir == DDIR_SYNC) + ret = do_io_u_sync(td, io_u); + else io_u->error = EINVAL; - return FIO_Q_COMPLETED; - } - ret = ftruncate(f->fd, io_u->offset); if (ret) io_u->error = errno;