Skip to content

Commit 62ab6b9

Browse files
author
Sergey Truschev
committed
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 <[email protected]>
1 parent 7c8dbca commit 62ab6b9

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

engines/falloc.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,18 @@ static enum fio_q_status fio_fallocate_queue(struct thread_data *td,
7676

7777
fio_ro_check(td, io_u);
7878

79-
if (io_u->ddir == DDIR_READ)
80-
flags = FALLOC_FL_KEEP_SIZE;
81-
else if (io_u->ddir == DDIR_WRITE)
82-
flags = 0;
83-
else if (io_u->ddir == DDIR_TRIM)
84-
flags = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
85-
86-
ret = fallocate(f->fd, flags, io_u->offset, io_u->xfer_buflen);
79+
if (io_u->ddir != DDIR_SYNC) {
80+
if (io_u->ddir == DDIR_READ)
81+
flags = FALLOC_FL_KEEP_SIZE;
82+
else if (io_u->ddir == DDIR_WRITE)
83+
flags = 0;
84+
else if (io_u->ddir == DDIR_TRIM)
85+
flags = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
86+
87+
ret = fallocate(f->fd, flags, io_u->offset, io_u->xfer_buflen);
88+
} else {
89+
ret = do_io_u_sync(td, io_u);
90+
}
8791

8892
if (ret)
8993
io_u->error = errno;

engines/fileoperations.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ static int invalidate_do_nothing(struct thread_data *td, struct fio_file *f)
264264

265265
static enum fio_q_status queue_io(struct thread_data *td, struct io_u *io_u)
266266
{
267+
if (io_u->ddir == DDIR_SYNC && do_io_u_sync(td, io_u))
268+
io_u->error = errno;
267269
return FIO_Q_COMPLETED;
268270
}
269271

engines/ftruncate.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ static enum fio_q_status fio_ftruncate_queue(struct thread_data *td,
1515
struct io_u *io_u)
1616
{
1717
struct fio_file *f = io_u->file;
18-
int ret;
18+
int ret = 0;
1919

2020
fio_ro_check(td, io_u);
2121

22-
if (io_u->ddir != DDIR_WRITE) {
22+
if (io_u->ddir == DDIR_WRITE)
23+
ret = ftruncate(f->fd, io_u->offset);
24+
else if (io_u->ddir == DDIR_SYNC)
25+
ret = do_io_u_sync(td, io_u);
26+
else
2327
io_u->error = EINVAL;
24-
return FIO_Q_COMPLETED;
25-
}
2628

27-
ret = ftruncate(f->fd, io_u->offset);
2829
if (ret)
2930
io_u->error = errno;
3031

0 commit comments

Comments
 (0)