]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald: close runtime journal earlier
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 24 May 2024 20:57:03 +0000 (05:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 25 May 2024 18:11:14 +0000 (03:11 +0900)
Then, we can use SD_JOURNAL_ASSUME_IMMUTABLE flag, and the performance
of reading runtime journal should be improved.

src/journal/journald-server.c

index d1dc4b6ea977e5f75cab32039474bd03184cf616..514ed09566df7961f09b3d4435a677e556710319 100644 (file)
@@ -1321,6 +1321,10 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
         if (!s->system_journal)
                 return 0;
 
+        /* Offline and close the 'main' runtime journal file to allow the runtime journal to be opened with
+         * the SD_JOURNAL_ASSUME_IMMUTABLE flag in the below. */
+        s->runtime_journal = journal_file_offline_close(s->runtime_journal);
+
         /* Reset current seqnum data to avoid unnecessary rotation when switching to system journal.
          * See issue #30092. */
         zero(*s->seqnum);
@@ -1329,7 +1333,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
 
         start = now(CLOCK_MONOTONIC);
 
-        r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY);
+        r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE);
         if (r < 0)
                 return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                                  "Failed to read runtime journal: %m");
@@ -1405,9 +1409,6 @@ finish:
         /* First, close all runtime journals opened in the above. */
         sd_journal_close(j);
 
-        /* Offline and close the 'main' runtime journal file. */
-        s->runtime_journal = journal_file_offline_close(s->runtime_journal);
-
         /* Remove the runtime directory if the all entries are successfully flushed to /var/. */
         if (r >= 0) {
                 (void) rm_rf(s->runtime_storage.path, REMOVE_ROOT);