]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Enable compact mode
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 23 Oct 2021 21:43:00 +0000 (22:43 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 7 Oct 2022 09:28:12 +0000 (11:28 +0200)
We also add an environment variable $SYSTEMD_JOURNAL_COMPACT that
can be used to disable compact mode if needed (similar to
$SYSTEMD_JOURNAL_KEYED_HASH).

docs/ENVIRONMENT.md
src/libsystemd/sd-journal/journal-file.c

index e229edc2aac9109a15e279ff6d73867e7ac1fab1..a840dd0c9085f0c82beb765b182ebf6da9a7783b 100644 (file)
@@ -468,3 +468,10 @@ SYSTEMD_HOME_DEBUG_SUFFIX=foo \
   when kernel-install is invoked. This can be useful if kernel-install is invoked
   unconditionally as a child process by another tool, such as package managers
   running kernel-install in a postinstall script.
+
+`systemd-journald`:
+
+* `$SYSTEMD_JOURNAL_COMPACT` - Takes a boolean. If enabled, journal files are written
+  in a more compact format that reduces the amount of disk space required by the
+  journal. Note that journal files in compact mode are limited to 4G to allow use of
+  32-bit offsets. Enabled by default.
index 8a8b92a36c0f2f526c02d01ff4972b8203e1a46e..906e69f39034112829771f6d4a15b6160023f083 100644 (file)
@@ -295,24 +295,38 @@ JournalFile* journal_file_close(JournalFile *f) {
         return mfree(f);
 }
 
+static bool keyed_hash_requested(void) {
+        int r;
+
+        r = getenv_bool("SYSTEMD_JOURNAL_KEYED_HASH");
+        if (r >= 0)
+                return r;
+        if (r != -ENXIO)
+                log_debug_errno(r, "Failed to parse $SYSTEMD_JOURNAL_KEYED_HASH environment variable, ignoring: %m");
+
+        return true;
+}
+
+static bool compact_mode_requested(void) {
+        int r;
+
+        r = getenv_bool("SYSTEMD_JOURNAL_COMPACT");
+        if (r >= 0)
+                return r;
+        if (r != -ENXIO)
+                log_debug_errno(r, "Failed to parse $SYSTEMD_JOURNAL_COMPACT environment variable, ignoring: %m");
+
+        return true;
+}
+
 static int journal_file_init_header(JournalFile *f, JournalFileFlags file_flags, JournalFile *template) {
         Header h = {};
         ssize_t k;
-        bool keyed_hash, seal = false;
+        bool seal = false;
         int r;
 
         assert(f);
 
-        /* We turn on keyed hashes by default, but provide an environment variable to turn them off, if
-         * people really want that */
-        r = getenv_bool("SYSTEMD_JOURNAL_KEYED_HASH");
-        if (r < 0) {
-                if (r != -ENXIO)
-                        log_debug_errno(r, "Failed to parse $SYSTEMD_JOURNAL_KEYED_HASH environment variable, ignoring: %m");
-                keyed_hash = true;
-        } else
-                keyed_hash = r;
-
 #if HAVE_GCRYPT
         /* Try to load the FSPRG state, and if we can't, then just don't do sealing */
         seal = FLAGS_SET(file_flags, JOURNAL_SEAL) && journal_file_fss_load(f) >= 0;
@@ -324,7 +338,8 @@ static int journal_file_init_header(JournalFile *f, JournalFileFlags file_flags,
         h.incompatible_flags |= htole32(
                         FLAGS_SET(file_flags, JOURNAL_COMPRESS) *
                         COMPRESSION_TO_HEADER_INCOMPATIBLE_FLAG(DEFAULT_COMPRESSION) |
-                        keyed_hash * HEADER_INCOMPATIBLE_KEYED_HASH);
+                        keyed_hash_requested() * HEADER_INCOMPATIBLE_KEYED_HASH |
+                        compact_mode_requested() * HEADER_INCOMPATIBLE_COMPACT);
 
         h.compatible_flags = htole32(seal * HEADER_COMPATIBLE_SEALED);