diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 6df2e736..5e9dfad1 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1514,6 +1514,7 @@ struct f2fs_configuration { unsigned int quota_bits; /* quota bits */ time_t fixed_time; int roll_forward; + bool need_fsync; /* mkfs parameters */ int fake_seed; diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c index d76da837..18a1a3c9 100644 --- a/lib/libf2fs_io.c +++ b/lib/libf2fs_io.c @@ -580,6 +580,7 @@ int dev_write(void *buf, __u64 offset, size_t len) return -1; if (write(fd, buf, len) < 0) return -1; + c.need_fsync = true; return 0; } @@ -616,6 +617,7 @@ int dev_fill(void *buf, __u64 offset, size_t len) return -1; if (write(fd, buf, len) < 0) return -1; + c.need_fsync = true; return 0; } @@ -639,6 +641,9 @@ int f2fs_fsync_device(void) #ifdef HAVE_FSYNC int i; + if (!c.need_fsync) + return 0; + for (i = 0; i < c.ndevs; i++) { if (fsync(c.devices[i].fd) < 0) { MSG(0, "\tError: Could not conduct fsync!!!\n"); @@ -786,10 +791,12 @@ int f2fs_finalize_device(void) */ for (i = 0; i < c.ndevs; i++) { #ifdef HAVE_FSYNC - ret = fsync(c.devices[i].fd); - if (ret < 0) { - MSG(0, "\tError: Could not conduct fsync!!!\n"); - break; + if (c.need_fsync) { + ret = fsync(c.devices[i].fd); + if (ret < 0) { + MSG(0, "\tError: Could not conduct fsync!!!\n"); + break; + } } #endif ret = close(c.devices[i].fd);