From: Daan De Meyer Date: Sat, 23 Oct 2021 21:43:00 +0000 (+0100) Subject: journal: Enable compact mode X-Git-Tag: v252-rc1~4^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=61297656c7677a0c8574b95581499b241bfd261f;p=thirdparty%2Fsystemd.git journal: Enable compact mode 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). --- diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index e229edc2aac..a840dd0c908 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -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. diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 8a8b92a36c0..906e69f3903 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -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);