[glib: 1/2] gfileutils: Remove outdated BTRFS fsync optimization from set_contents
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gfileutils: Remove outdated BTRFS fsync optimization from set_contents
- Date: Tue, 11 Jan 2022 18:58:14 +0000 (UTC)
commit d9e001e2cd3e8e88fbe877f9b529d703e9a816c8
Author: Sebastian Keller <skeller gnome org>
Date: Tue Jan 11 18:43:34 2022 +0100
gfileutils: Remove outdated BTRFS fsync optimization from set_contents
This code was skipping fsync on BTRFS because of an old guarantee about
the overwrite-by-rename behavior that no longer holds true. This has
been confirmed by the BTRFS developers to no longer be guaranteed since
Kernel 3.17 (August 2014), but it was guaranteed when this optimization
was first introduced in 2010.
This could result in empty files after crashes in applications using
g_file_set_contents(). Most prominently this might have been the cause
of dconf settings getting lost on BTRFS after crashes due to the
frequency with which such writes can happen in dconf.
See: https://gitlab.gnome.org/GNOME/dconf/-/issues/73
glib/gfileutils.c | 22 ----------------------
meson.build | 1 -
2 files changed, 23 deletions(-)
---
diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index fd5cd3b25..389414cd4 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -56,11 +56,6 @@
#include "gstdioprivate.h"
#include "glibintl.h"
-#ifdef HAVE_LINUX_MAGIC_H /* for btrfs check */
-#include <linux/magic.h>
-#include <sys/vfs.h>
-#endif
-
/**
* SECTION:fileutils
@@ -1091,23 +1086,6 @@ fd_should_be_fsynced (int fd,
#ifdef HAVE_FSYNC
struct stat statbuf;
-#ifdef BTRFS_SUPER_MAGIC
- {
- 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.
- *
- * See
https://btrfs.wiki.kernel.org/index.php/FAQ#What_are_the_crash_guarantees_of_overwrite-by-rename.3F
- */
-
- if ((flags & G_FILE_SET_CONTENTS_CONSISTENT) &&
- fstatfs (fd, &buf) == 0 && buf.f_type == BTRFS_SUPER_MAGIC)
- return FALSE;
- }
-#endif /* BTRFS_SUPER_MAGIC */
-
/* If the final destination exists and is > 0 bytes, we want to sync the
* newly written file to ensure the data is on disk when we rename over
* the destination. Otherwise if we get a system crash we can lose both
diff --git a/meson.build b/meson.build
index 6e566d483..082ab630f 100644
--- a/meson.build
+++ b/meson.build
@@ -282,7 +282,6 @@ headers = [
'grp.h',
'inttypes.h',
'limits.h',
- 'linux/magic.h',
'locale.h',
'mach/mach_time.h',
'memory.h',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]