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