Blame SOURCES/0527-journal-don-t-force-FS_NOCOW_FL-on-new-journal-files.patch

17b0f1
From 245ad27530ae9e99242ebfa1631bd7fc8f66a59c Mon Sep 17 00:00:00 2001
17b0f1
From: Lennart Poettering <lennart@poettering.net>
17b0f1
Date: Wed, 22 Apr 2015 13:20:49 +0200
17b0f1
Subject: [PATCH] journal: don't force FS_NOCOW_FL on new journal files, but
17b0f1
 warn if it is missing
17b0f1
17b0f1
This way users have the freedom to set or unset the FS_NOCOW_FL flag on
17b0f1
their journal files by setting it on the journal directory. Since our
17b0f1
default tmpfiles configuration now sets this flag on the directory the
17b0f1
flag is set by default on new files, however people can opt-out of this
17b0f1
by masking the tmpfiles file for it.
17b0f1
17b0f1
(cherry picked from commit fc68c92973e5437ee0489c1bc80d80f0a7b6ca0b)
17b0f1
17b0f1
Conflicts:
17b0f1
	src/journal/journal-file.c
17b0f1
17b0f1
Resolves: #1299714
17b0f1
---
17b0f1
 src/journal/journal-file.c | 46 +++++++++++++++++++++++++++++---------
17b0f1
 1 file changed, 36 insertions(+), 10 deletions(-)
17b0f1
17b0f1
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
17b0f1
index 8034b771de..0fd59ec073 100644
17b0f1
--- a/src/journal/journal-file.c
17b0f1
+++ b/src/journal/journal-file.c
17b0f1
@@ -2543,6 +2543,41 @@ void journal_file_print_header(JournalFile *f) {
17b0f1
                 printf("Disk usage: %s\n", format_bytes(bytes, sizeof(bytes), (off_t) st.st_blocks * 512ULL));
17b0f1
 }
17b0f1
 
17b0f1
+static int journal_file_warn_btrfs(JournalFile *f) {
17b0f1
+        unsigned attrs;
17b0f1
+        int r;
17b0f1
+
17b0f1
+        assert(f);
17b0f1
+
17b0f1
+        /* Before we write anything, check if the COW logic is turned
17b0f1
+         * off on btrfs. Given our write pattern that is quite
17b0f1
+         * unfriendly to COW file systems this should greatly improve
17b0f1
+         * performance on COW file systems, such as btrfs, at the
17b0f1
+         * expense of data integrity features (which shouldn't be too
17b0f1
+         * bad, given that we do our own checksumming). */
17b0f1
+
17b0f1
+        r = btrfs_is_filesystem(f->fd);
17b0f1
+        if (r < 0)
17b0f1
+                return log_warning_errno(r, "Failed to determine if journal is on btrfs: %m");
17b0f1
+        if (!r)
17b0f1
+                return 0;
17b0f1
+
17b0f1
+        r = read_attr_fd(f->fd, &attrs);
17b0f1
+        if (r < 0)
17b0f1
+                return log_warning_errno(r, "Failed to read file attributes: %m");
17b0f1
+
17b0f1
+        if (attrs & FS_NOCOW_FL) {
17b0f1
+                log_debug("Detected btrfs file system with copy-on-write disabled, all is good.");
17b0f1
+                return 0;
17b0f1
+        }
17b0f1
+
17b0f1
+        log_notice("Creating journal file %s on a btrfs file system, and copy-on-write is enabled. "
17b0f1
+                   "This is likely to slow down journal access substantially, please consider turning "
17b0f1
+                   "off the copy-on-write file attribute on the journal directory, using chattr +C.", f->path);
17b0f1
+
17b0f1
+        return 1;
17b0f1
+}
17b0f1
+
17b0f1
 int journal_file_open(
17b0f1
                 const char *fname,
17b0f1
                 int flags,
17b0f1
@@ -2623,16 +2658,7 @@ int journal_file_open(
17b0f1
 
17b0f1
         if (f->last_stat.st_size == 0 && f->writable) {
17b0f1
 
17b0f1
-                /* Before we write anything, turn off COW logic. Given
17b0f1
-                 * our write pattern that is quite unfriendly to COW
17b0f1
-                 * file systems this should greatly improve
17b0f1
-                 * performance on COW file systems, such as btrfs, at
17b0f1
-                 * the expense of data integrity features (which
17b0f1
-                 * shouldn't be too bad, given that we do our own
17b0f1
-                 * checksumming). */
17b0f1
-                r = chattr_fd(f->fd, true, FS_NOCOW_FL);
17b0f1
-                if (r < 0 && r != -ENOTTY)
17b0f1
-                        log_warning_errno(r, "Failed to set file attributes: %m");
17b0f1
+                (void) journal_file_warn_btrfs(f);
17b0f1
 
17b0f1
                 /* Let's attach the creation time to the journal file,
17b0f1
                  * so that the vacuuming code knows the age of this