Skip to content

Commit

Permalink
fs-posix: Add "no-fsync" parameter.
Browse files Browse the repository at this point in the history
This disables calling fdatasync() when fs_write() was done with
FS_OPEN_FLAG_FSYNC. Useful for making tests faster.
  • Loading branch information
sirainen authored and GitLab committed Feb 19, 2017
1 parent 46e1740 commit 43b9547
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib-fs/fs-posix.c
Expand Up @@ -36,6 +36,7 @@ struct posix_fs {
mode_t mode;
bool mode_auto;
bool have_dirs;
bool disable_fsync;
};

struct posix_fs_file {
Expand Down Expand Up @@ -103,6 +104,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) {
Expand Down Expand Up @@ -458,9 +461,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);
Expand Down

0 comments on commit 43b9547

Please sign in to comment.