[glib] Bug 637544 - Skip fsync() on btrfs



commit 99fe4b1da7560e1df2d9352ddbd845a5d9a62429
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Dec 18 18:52:32 2010 -0500

    Bug 637544 - Skip fsync() on btrfs
    
    For g_file_set_contents() we fsync() before renaming the file over the
    original in order to ensure that we don't end up with an invalid file.
    btrfs provides this guarantee for us without the fsync() so skip it
    there.

 glib/gfileutils.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index 185a756..fff6492 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -53,6 +53,10 @@
 #include "gstdio.h"
 #include "glibintl.h"
 
+#ifdef __linux__ /* for btrfs check */
+#include <linux/magic.h>
+#include <sys/vfs.h>
+#endif
 
 /**
  * g_mkdir_with_parents:
@@ -963,6 +967,20 @@ write_to_temp_file (const gchar  *contents,
       
       goto out;
     }
+
+#ifdef __linux__
+  {
+    struct statfs buf;
+
+    /* On Linux, on btrfs, skip the fsync since rename-over-existing is
+     * guaranteed to be atomic and this is the only case in which we
+     * would fsync() anyway.
+     */
+
+    if (fstatfs (fd, &buf) == 0 && buf.f_type == BTRFS_SUPER_MAGIC)
+      goto no_fsync;
+  }
+#endif
   
 #ifdef HAVE_FSYNC
   {
@@ -994,6 +1012,7 @@ write_to_temp_file (const gchar  *contents,
       }
   }
 #endif
+ no_fsync:
   
   errno = 0;
   if (fclose (file) == EOF)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]