anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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