changeset 21590:19c764379c83

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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 19 Feb 2017 15:54:53 +0200
parents 347734729a49
children f2d5416e0d7d
files src/lib-fs/fs-posix.c
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-fs/fs-posix.c	Sun Feb 19 14:49:20 2017 +0200
+++ b/src/lib-fs/fs-posix.c	Sun Feb 19 15:54:53 2017 +0200
@@ -36,6 +36,7 @@
 	mode_t mode;
 	bool mode_auto;
 	bool have_dirs;
+	bool disable_fsync;
 };
 
 struct posix_fs_file {
@@ -107,6 +108,8 @@
 			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 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);