daandemeyer / rpms / systemd

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