]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Improve use of syncfs.
authorAlexandre Oliva <lxoliva@fsfla.org>
Wed, 9 Nov 2011 17:51:26 +0000 (15:51 -0200)
committerSage Weil <sage@newdream.net>
Wed, 9 Nov 2011 20:50:57 +0000 (12:50 -0800)
Test syncfs return value and fallback to btrfs sync and then sync.

Signed-off-by: Alexandre Oliva <oliva@lsd.ic.unicamp.br>
src/common/sync_filesystem.h

index 04cfc99939017470b2aa00f4dc5a5c8dee8642c4..3ad8c9e928d1afec4944267b4bf1b11a67fe2d99 100644 (file)
 
 #include <unistd.h>
 
+#ifndef __CYGWIN__
+# ifndef DARWIN
+#  include <sys/ioctl.h>
+#  include "../os/btrfs_ioctl.h"
+# endif
+#endif
+
 inline int sync_filesystem(int fd)
 {
   /* On Linux, newer versions of glibc have a function called syncfs that
@@ -24,11 +31,17 @@ inline int sync_filesystem(int fd)
    * have to fall back on sync(), which synchronizes every filesystem on the
    * computer. */
 #ifdef HAVE_SYS_SYNCFS
-  return syncfs(fd);
-#else
+  if (syncfs(fd) == 0)
+    return 0;
+#endif
+
+#ifdef BTRFS_IOC_SYNC
+  if (::ioctl(fd, BTRFS_IOC_SYNC) == 0)
+    return 0;
+#endif
+
   sync();
   return 0;
-#endif
 }
 
 #endif