[systemd-devel] [PATCH 10/11] Avoid doubling the efforts for /var/log/journal

Werner Fink werner at suse.de
Fri Jun 13 07:41:09 PDT 2014


That is: set NOATIME, NOCOW, and NOCOMP for the journal directory

---
 src/journal/journald-server.c |   29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git src/journal/journald-server.c src/journal/journald-server.c
index eda5dcf..37d6dc3 100644
--- src/journal/journald-server.c
+++ src/journal/journald-server.c
@@ -21,6 +21,7 @@
 
 #include <sys/signalfd.h>
 #include <sys/ioctl.h>
+#include <linux/fs.h>
 #include <linux/sockios.h>
 #include <sys/statvfs.h>
 #include <sys/mman.h>
@@ -920,7 +921,7 @@ finish:
 
 
 static int system_journal_open(Server *s) {
-        int r;
+        int r, fd;
         char *fn;
         sd_id128_t machine;
         char ids[33];
@@ -947,7 +948,31 @@ static int system_journal_open(Server *s) {
                         (void) mkdir("/var/log/journal/", 0755);
 
                 fn = strappenda("/var/log/journal/", ids);
-                (void) mkdir(fn, 0755);
+                (void)mkdir(fn, 0755);
+
+                /*
+                 * On journaling and/or compressing file systems avoid doubling the
+                 * efforts for the system, that is set NOCOW and NOCOMP inode flags.
+                 * Check for every single flag as otherwise some of the file systems
+                 * may return EOPNOTSUPP on one unkown flag (like BtrFS does).
+                 */
+                if ((fd = open(fn, O_DIRECTORY)) >= 0) {
+                        long flags;
+                        if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == 0) {
+                                int old = flags;
+                                if (!(flags&FS_NOATIME_FL) && ioctl(fd, FS_IOC_SETFLAGS, flags|FS_NOATIME_FL) == 0)
+                                        flags |= FS_NOATIME_FL;
+                                if (!(flags&FS_NOCOW_FL) && ioctl(fd, FS_IOC_SETFLAGS, flags|FS_NOCOW_FL) == 0)
+                                        flags |= FS_NOCOW_FL;
+                                if (!(flags&FS_NOCOMP_FL) && s->compress) {
+                                        flags &= ~FS_COMPR_FL;
+                                        flags |= FS_NOCOMP_FL;
+                                }
+                                if (old != flags)
+                                        ioctl(fd, FS_IOC_SETFLAGS, flags);
+                        }
+                        close(fd);
+                }
 
                 fn = strappenda(fn, "/system.journal");
                 r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &s->system_journal);
-- 
1.7.9.2



More information about the systemd-devel mailing list