From cd7d2946f356c78d4d73f9667c9342a111678d7e Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 19 Feb 2017 15:54:53 +0200 Subject: [PATCH] fs-posix: Add "no-fsync" parameter. This disables calling fdatasync() when fs_write() was done with FS_OPEN_FLAG_FSYNC. Useful for making tests faster. --- src/lib-fs/fs-posix.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib-fs/fs-posix.c b/src/lib-fs/fs-posix.c index f884760204..4937cad7b1 100644 --- a/src/lib-fs/fs-posix.c +++ b/src/lib-fs/fs-posix.c @@ -36,6 +36,7 @@ struct posix_fs { mode_t mode; bool mode_auto; bool have_dirs; + bool disable_fsync; }; struct posix_fs_file { @@ -107,6 +108,8 @@ fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set) fs->mode_auto = TRUE; } else if (strcmp(arg, "dirs") == 0) { fs->have_dirs = TRUE; + } else if (strcmp(arg, "no-fsync") == 0) { + fs->disable_fsync = TRUE; } else if (strncmp(arg, "mode=", 5) == 0) { unsigned int mode; if (str_to_uint_oct(arg+5, &mode) < 0) { @@ -462,9 +465,11 @@ static void fs_posix_write_rename_if_needed(struct posix_fs_file *file) static int fs_posix_write_finish(struct posix_fs_file *file) { + struct posix_fs *fs = (struct posix_fs *)file->file.fs; int ret, old_errno; - if ((file->open_flags & FS_OPEN_FLAG_FSYNC) != 0) { + if ((file->open_flags & FS_OPEN_FLAG_FSYNC) != 0 && + !fs->disable_fsync) { if (fdatasync(file->fd) < 0) { fs_set_error(file->file.fs, "fdatasync(%s) failed: %m", file->full_path); -- 2.47.3