Use fcntl(..., F_FULLSYNC) if available
authorJens Axboe <axboe@kernel.dk>
Thu, 17 Feb 2022 19:08:41 +0000 (12:08 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 17 Feb 2022 19:08:41 +0000 (12:08 -0700)
Some operating systems don't perform a data integrity flush when
fsync() is done, but provide fcntl(fd, F_FULLSYNC) to provide that kind
of guarantee.

To ensure that comparisons between operating systems is fair, use
fcntl() to do a proper sync if available.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
configure
io_u.c

index 0efde7d6a84acf6887e81ec89eae6f8110cbcb0c..fd1d435b4d432f16bde69916ffd6f2fac7253fa6 100755 (executable)
--- a/configure
+++ b/configure
@@ -645,6 +645,25 @@ if compile_prog "" "-lz" "zlib" ; then
 fi
 print_config "zlib" "$zlib"
 
+##########################################
+# fcntl(F_FULLFSYNC) support
+if test "$fcntl_sync" != "yes" ; then
+  fcntl_sync="no"
+fi
+cat > $TMPC << EOF
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(int argc, char **argv)
+{
+  return fcntl(0, F_FULLSYNC);
+}
+EOF
+if compile_prog "" "" "fcntl(F_FULLSYNC)" ; then
+    fcntl_sync="yes"
+fi
+print_config "fcntl(F_FULLSYNC)" "$fcntl_sync"
+
 ##########################################
 # linux-aio probe
 if test "$libaio" != "yes" ; then
@@ -3174,6 +3193,9 @@ fi
 if test "$pdb" = yes; then
   output_sym "CONFIG_PDB"
 fi
+if test "$fcntl_sync" = "yes" ; then
+  output_sym "CONFIG_FCNTL_SYNC"
+fi
 
 print_config "Lib-based ioengines dynamic" "$dynamic_engines"
 cat > $TMPC << EOF
diff --git a/io_u.c b/io_u.c
index 059637e592d2b8f6d9b5bff8617be961ca919c0f..9d977d34e0c45017ddd36ed3bb357ce62886e040 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -2297,7 +2297,11 @@ int do_io_u_sync(const struct thread_data *td, struct io_u *io_u)
        int ret;
 
        if (io_u->ddir == DDIR_SYNC) {
+#ifdef CONFIG_FCNTL_SYNC
+               ret = fcntl(io_u->file->fd, F_FULLSYNC);
+#else
                ret = fsync(io_u->file->fd);
+#endif
        } else if (io_u->ddir == DDIR_DATASYNC) {
 #ifdef CONFIG_FDATASYNC
                ret = fdatasync(io_u->file->fd);