]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Rename JournaldFile to ManagedJournalFile 22373/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 2 Feb 2022 14:30:50 +0000 (14:30 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 2 Feb 2022 14:39:39 +0000 (14:39 +0000)
JournalFile and JournaldFile are hard to distinguish from each other.
Let's use ManagedJournalFile instead to make the distinction more clear.

14 files changed:
src/journal-remote/journal-remote-write.c
src/journal-remote/journal-remote-write.h
src/journal-remote/journal-remote.c
src/journal/journald-file.h [deleted file]
src/journal/journald-server.c
src/journal/journald-server.h
src/journal/managed-journal-file.c [moved from src/journal/journald-file.c with 86% similarity]
src/journal/managed-journal-file.h [new file with mode: 0644]
src/journal/meson.build
src/journal/test-journal-flush.c
src/journal/test-journal-interleaving.c
src/journal/test-journal-stream.c
src/journal/test-journal-verify.c
src/journal/test-journal.c

index b82cb101184b9692e1d758ffebc6530db026b1fc..5e47616504ade37316b50edc29914cfd37d37af8 100644 (file)
@@ -3,8 +3,8 @@
 #include "alloc-util.h"
 #include "journal-remote.h"
 
-static int do_rotate(JournaldFile **f, MMapCache *m, bool compress, bool seal) {
-        int r = journald_file_rotate(f, m, compress, UINT64_MAX, seal, NULL);
+static int do_rotate(ManagedJournalFile **f, MMapCache *m, bool compress, bool seal) {
+        int r = managed_journal_file_rotate(f, m, compress, UINT64_MAX, seal, NULL);
         if (r < 0) {
                 if (*f)
                         log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path);
@@ -40,7 +40,7 @@ static Writer* writer_free(Writer *w) {
 
         if (w->journal) {
                 log_debug("Closing journal file %s.", w->journal->file->path);
-                journald_file_close(w->journal);
+                managed_journal_file_close(w->journal);
         }
 
         if (w->server && w->hashmap_key)
index d97f6c674ba79f13019389981dfea9a05acdf879..ccbea29fbd2c4e516e181906ac7507fcc3cc9239 100644 (file)
@@ -1,13 +1,13 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "journald-file.h"
 #include "journal-importer.h"
+#include "managed-journal-file.h"
 
 typedef struct RemoteServer RemoteServer;
 
 typedef struct Writer {
-        JournaldFile *journal;
+        ManagedJournalFile *journal;
         JournalMetrics metrics;
 
         MMapCache *mmap;
index e91b46473be0e58077107da781d1ca190f888d26..67a0205bee4f08e956a2019250a18e65227ebc31 100644 (file)
 #include "errno-util.h"
 #include "escape.h"
 #include "fd-util.h"
-#include "journald-file.h"
 #include "journal-remote-write.h"
 #include "journal-remote.h"
 #include "journald-native.h"
 #include "macro.h"
+#include "managed-journal-file.h"
 #include "parse-util.h"
 #include "process-util.h"
 #include "socket-util.h"
@@ -61,7 +61,7 @@ static int open_output(RemoteServer *s, Writer *w, const char* host) {
                 assert_not_reached();
         }
 
-        r = journald_file_open_reliably(filename,
+        r = managed_journal_file_open_reliably(filename,
                                         O_RDWR|O_CREAT, 0640,
                                         s->compress, UINT64_MAX, s->seal,
                                         &w->metrics,
diff --git a/src/journal/journald-file.h b/src/journal/journald-file.h
deleted file mode 100644 (file)
index 79c0ef8..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-#include "journal-file.h"
-
-typedef struct {
-        JournalFile *file;
-} JournaldFile;
-
-int journald_file_open(
-                int fd,
-                const char *fname,
-                int flags,
-                mode_t mode,
-                bool compress,
-                uint64_t compress_threshold_bytes,
-                bool seal,
-                JournalMetrics *metrics,
-                MMapCache *mmap_cache,
-                Set *deferred_closes,
-                JournaldFile *template,
-                JournaldFile **ret);
-
-int journald_file_set_offline(JournaldFile *f, bool wait);
-bool journald_file_is_offlining(JournaldFile *f);
-JournaldFile* journald_file_close(JournaldFile *f);
-DEFINE_TRIVIAL_CLEANUP_FUNC(JournaldFile*, journald_file_close);
-
-int journald_file_open_reliably(
-                const char *fname,
-                int flags,
-                mode_t mode,
-                bool compress,
-                uint64_t compress_threshold_bytes,
-                bool seal,
-                JournalMetrics *metrics,
-                MMapCache *mmap_cache,
-                Set *deferred_closes,
-                JournaldFile *template,
-                JournaldFile **ret);
-
-JournaldFile* journald_file_initiate_close(JournaldFile *f, Set *deferred_closes);
-int journald_file_rotate(JournaldFile **f, MMapCache *mmap_cache, bool compress, uint64_t compress_threshold_bytes, bool seal, Set *deferred_closes);
index 9bfe22906a58349229cd9c0febb0b1874a696669..a7858eedff7307a104fdd69d4e30ced8dc878c56 100644 (file)
@@ -29,7 +29,6 @@
 #include "id128-util.h"
 #include "io-util.h"
 #include "journal-authenticate.h"
-#include "journald-file.h"
 #include "journal-internal.h"
 #include "journal-vacuum.h"
 #include "journald-audit.h"
@@ -242,7 +241,7 @@ static bool uid_for_system_journal(uid_t uid) {
         return uid_is_system(uid) || uid_is_dynamic(uid) || uid == UID_NOBODY;
 }
 
-static void server_add_acls(JournaldFile *f, uid_t uid) {
+static void server_add_acls(ManagedJournalFile *f, uid_t uid) {
         assert(f);
 
 #if HAVE_ACL
@@ -264,9 +263,9 @@ static int open_journal(
                 int flags,
                 bool seal,
                 JournalMetrics *metrics,
-                JournaldFile **ret) {
+                ManagedJournalFile **ret) {
 
-        _cleanup_(journald_file_closep) JournaldFile *f = NULL;
+        _cleanup_(managed_journal_file_closep) ManagedJournalFile *f = NULL;
         int r;
 
         assert(s);
@@ -274,11 +273,11 @@ static int open_journal(
         assert(ret);
 
         if (reliably)
-                r = journald_file_open_reliably(fname, flags, 0640, s->compress.enabled,
+                r = managed_journal_file_open_reliably(fname, flags, 0640, s->compress.enabled,
                                                 s->compress.threshold_bytes, seal, metrics, s->mmap,
                                                 s->deferred_closes, NULL, &f);
         else
-                r = journald_file_open(-1, fname, flags, 0640, s->compress.enabled,
+                r = managed_journal_file_open(-1, fname, flags, 0640, s->compress.enabled,
                                        s->compress.threshold_bytes, seal, metrics, s->mmap,
                                        s->deferred_closes, NULL, &f);
 
@@ -389,9 +388,9 @@ static int system_journal_open(Server *s, bool flush_requested, bool relinquish_
         return r;
 }
 
-static JournaldFile* find_journal(Server *s, uid_t uid) {
+static ManagedJournalFile* find_journal(Server *s, uid_t uid) {
         _cleanup_free_ char *p = NULL;
-        JournaldFile *f;
+        ManagedJournalFile *f;
         int r;
 
         assert(s);
@@ -434,7 +433,7 @@ static JournaldFile* find_journal(Server *s, uid_t uid) {
         /* Too many open? Then let's close one (or more) */
         while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
                 assert_se(f = ordered_hashmap_steal_first(s->user_journals));
-                (void) journald_file_close(f);
+                (void) managed_journal_file_close(f);
         }
 
         r = open_journal(s, true, p, O_RDWR|O_CREAT, s->seal, &s->system_storage.metrics, &f);
@@ -443,7 +442,7 @@ static JournaldFile* find_journal(Server *s, uid_t uid) {
 
         r = ordered_hashmap_put(s->user_journals, UID_TO_PTR(uid), f);
         if (r < 0) {
-                (void) journald_file_close(f);
+                (void) managed_journal_file_close(f);
                 return s->system_journal;
         }
 
@@ -453,7 +452,7 @@ static JournaldFile* find_journal(Server *s, uid_t uid) {
 
 static int do_rotate(
                 Server *s,
-                JournaldFile **f,
+                ManagedJournalFile **f,
                 const char* name,
                 bool seal,
                 uint32_t uid) {
@@ -464,7 +463,7 @@ static int do_rotate(
         if (!*f)
                 return -EINVAL;
 
-        r = journald_file_rotate(f, s->mmap, s->compress.enabled, s->compress.threshold_bytes, seal, s->deferred_closes);
+        r = managed_journal_file_rotate(f, s->mmap, s->compress.enabled, s->compress.threshold_bytes, seal, s->deferred_closes);
         if (r < 0) {
                 if (*f)
                         return log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path);
@@ -477,15 +476,15 @@ static int do_rotate(
 }
 
 static void server_process_deferred_closes(Server *s) {
-        JournaldFile *f;
+        ManagedJournalFile *f;
 
         /* Perform any deferred closes which aren't still offlining. */
         SET_FOREACH(f, s->deferred_closes) {
-                if (journald_file_is_offlining(f))
+                if (managed_journal_file_is_offlining(f))
                         continue;
 
                 (void) set_remove(s->deferred_closes, f);
-                (void) journald_file_close(f);
+                (void) managed_journal_file_close(f);
         }
 }
 
@@ -501,10 +500,10 @@ static void server_vacuum_deferred_closes(Server *s) {
 
         /* And now, let's close some more until we reach the limit again. */
         while (set_size(s->deferred_closes) >= DEFERRED_CLOSES_MAX) {
-                JournaldFile *f;
+                ManagedJournalFile *f;
 
                 assert_se(f = set_steal_first(s->deferred_closes));
-                journald_file_close(f);
+                managed_journal_file_close(f);
         }
 }
 
@@ -527,7 +526,7 @@ static int vacuum_offline_user_journals(Server *s) {
                 _cleanup_close_ int fd = -1;
                 const char *a, *b;
                 struct dirent *de;
-                JournaldFile *f;
+                ManagedJournalFile *f;
                 uid_t uid;
 
                 errno = 0;
@@ -575,7 +574,7 @@ static int vacuum_offline_user_journals(Server *s) {
                 server_vacuum_deferred_closes(s);
 
                 /* Open the file briefly, so that we can archive it */
-                r = journald_file_open(fd,
+                r = managed_journal_file_open(fd,
                                        full,
                                        O_RDWR,
                                        0640,
@@ -599,13 +598,13 @@ static int vacuum_offline_user_journals(Server *s) {
                         continue;
                 }
 
-                TAKE_FD(fd); /* Donated to journald_file_open() */
+                TAKE_FD(fd); /* Donated to managed_journal_file_open() */
 
                 r = journal_file_archive(f->file, NULL);
                 if (r < 0)
                         log_debug_errno(r, "Failed to archive journal file '%s', ignoring: %m", full);
 
-                journald_file_initiate_close(f, s->deferred_closes);
+                managed_journal_file_initiate_close(f, s->deferred_closes);
                 f = NULL;
         }
 
@@ -613,7 +612,7 @@ static int vacuum_offline_user_journals(Server *s) {
 }
 
 void server_rotate(Server *s) {
-        JournaldFile *f;
+        ManagedJournalFile *f;
         void *k;
         int r;
 
@@ -642,17 +641,17 @@ void server_rotate(Server *s) {
 }
 
 void server_sync(Server *s) {
-        JournaldFile *f;
+        ManagedJournalFile *f;
         int r;
 
         if (s->system_journal) {
-                r = journald_file_set_offline(s->system_journal, false);
+                r = managed_journal_file_set_offline(s->system_journal, false);
                 if (r < 0)
                         log_warning_errno(r, "Failed to sync system journal, ignoring: %m");
         }
 
         ORDERED_HASHMAP_FOREACH(f, s->user_journals) {
-                r = journald_file_set_offline(f, false);
+                r = managed_journal_file_set_offline(f, false);
                 if (r < 0)
                         log_warning_errno(r, "Failed to sync user journal, ignoring: %m");
         }
@@ -797,7 +796,7 @@ static bool shall_try_append_again(JournalFile *f, int r) {
 static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, size_t n, int priority) {
         bool vacuumed = false, rotate = false;
         struct dual_timestamp ts;
-        JournaldFile *f;
+        ManagedJournalFile *f;
         int r;
 
         assert(s);
@@ -1207,7 +1206,7 @@ finish:
         if (s->system_journal)
                 journal_file_post_change(s->system_journal->file);
 
-        s->runtime_journal = journald_file_close(s->runtime_journal);
+        s->runtime_journal = managed_journal_file_close(s->runtime_journal);
 
         if (r >= 0)
                 (void) rm_rf(s->runtime_storage.path, REMOVE_ROOT);
@@ -1247,9 +1246,9 @@ static int server_relinquish_var(Server *s) {
 
         (void) system_journal_open(s, false, true);
 
-        s->system_journal = journald_file_close(s->system_journal);
-        ordered_hashmap_clear_with_destructor(s->user_journals, journald_file_close);
-        set_clear_with_destructor(s->deferred_closes, journald_file_close);
+        s->system_journal = managed_journal_file_close(s->system_journal);
+        ordered_hashmap_clear_with_destructor(s->user_journals, managed_journal_file_close);
+        set_clear_with_destructor(s->deferred_closes, managed_journal_file_close);
 
         fn = strjoina(s->runtime_directory, "/flushed");
         if (unlink(fn) < 0 && errno != ENOENT)
@@ -2444,7 +2443,7 @@ int server_init(Server *s, const char *namespace) {
 
 void server_maybe_append_tags(Server *s) {
 #if HAVE_GCRYPT
-        JournaldFile *f;
+        ManagedJournalFile *f;
         usec_t n;
 
         n = now(CLOCK_REALTIME);
@@ -2463,17 +2462,17 @@ void server_done(Server *s) {
         free(s->namespace);
         free(s->namespace_field);
 
-        set_free_with_destructor(s->deferred_closes, journald_file_close);
+        set_free_with_destructor(s->deferred_closes, managed_journal_file_close);
 
         while (s->stdout_streams)
                 stdout_stream_free(s->stdout_streams);
 
         client_context_flush_all(s);
 
-        (void) journald_file_close(s->system_journal);
-        (void) journald_file_close(s->runtime_journal);
+        (void) managed_journal_file_close(s->system_journal);
+        (void) managed_journal_file_close(s->runtime_journal);
 
-        ordered_hashmap_free_with_destructor(s->user_journals, journald_file_close);
+        ordered_hashmap_free_with_destructor(s->user_journals, managed_journal_file_close);
 
         varlink_server_unref(s->varlink_server);
 
index 92c78a0d741ad8092b33124f84e3450dff156496..ea51515db3b6644aa07db20855c7cf066b7a3a64 100644 (file)
@@ -10,11 +10,11 @@ typedef struct Server Server;
 
 #include "conf-parser.h"
 #include "hashmap.h"
-#include "journald-file.h"
 #include "journald-context.h"
 #include "journald-rate-limit.h"
 #include "journald-stream.h"
 #include "list.h"
+#include "managed-journal-file.h"
 #include "prioq.h"
 #include "ratelimit.h"
 #include "time-util.h"
@@ -89,8 +89,8 @@ struct Server {
         sd_event_source *watchdog_event_source;
         sd_event_source *idle_event_source;
 
-        JournaldFile *runtime_journal;
-        JournaldFile *system_journal;
+        ManagedJournalFile *runtime_journal;
+        ManagedJournalFile *system_journal;
         OrderedHashmap *user_journals;
 
         uint64_t seqnum;
similarity index 86%
rename from src/journal/journald-file.c
rename to src/journal/managed-journal-file.c
index d4765b98df7af1983067a4ebabb8bcbc9080857e..8880329fa5ed25d619df8b30c114ff53c4eeac70 100644 (file)
@@ -8,7 +8,7 @@
 #include "fd-util.h"
 #include "format-util.h"
 #include "journal-authenticate.h"
-#include "journald-file.h"
+#include "managed-journal-file.h"
 #include "path-util.h"
 #include "random-util.h"
 #include "set.h"
@@ -18,7 +18,7 @@
 #define PAYLOAD_BUFFER_SIZE (16U * 1024U)
 #define MINIMUM_HOLE_SIZE (1U * 1024U * 1024U / 2U)
 
-static int journald_file_truncate(JournalFile *f) {
+static int managed_journal_file_truncate(JournalFile *f) {
         uint64_t p;
         int r;
 
@@ -36,7 +36,7 @@ static int journald_file_truncate(JournalFile *f) {
         return journal_file_fstat(f);
 }
 
-static int journald_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint64_t n_entries) {
+static int managed_journal_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint64_t n_entries) {
         Object o;
         uint64_t offset, sz, n_items = 0, n_unused;
         int r;
@@ -91,13 +91,13 @@ static int journald_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint
         return 0;
 }
 
-static int journald_file_punch_holes(JournalFile *f) {
+static int managed_journal_file_punch_holes(JournalFile *f) {
         HashItem items[PAYLOAD_BUFFER_SIZE / sizeof(HashItem)];
         uint64_t p, sz;
         ssize_t n = SSIZE_MAX;
         int r;
 
-        r = journald_file_entry_array_punch_hole(
+        r = managed_journal_file_entry_array_punch_hole(
                 f, le64toh(f->header->entry_array_offset), le64toh(f->header->n_entries));
         if (r < 0)
                 return r;
@@ -128,7 +128,7 @@ static int journald_file_punch_holes(JournalFile *f) {
                                 if (le64toh(o.data.n_entries) == 0)
                                         continue;
 
-                                (void) journald_file_entry_array_punch_hole(
+                                (void) managed_journal_file_entry_array_punch_hole(
                                         f, le64toh(o.data.entry_array_offset), le64toh(o.data.n_entries) - 1);
                         }
                 }
@@ -140,7 +140,7 @@ static int journald_file_punch_holes(JournalFile *f) {
 /* This may be called from a separate thread to prevent blocking the caller for the duration of fsync().
  * As a result we use atomic operations on f->offline_state for inter-thread communications with
  * journal_file_set_offline() and journal_file_set_online(). */
-static void journald_file_set_offline_internal(JournaldFile *f) {
+static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) {
         int r;
 
         assert(f);
@@ -166,8 +166,8 @@ static void journald_file_set_offline_internal(JournaldFile *f) {
 
                 case OFFLINE_SYNCING:
                         if (f->file->archive) {
-                                (void) journald_file_truncate(f->file);
-                                (void) journald_file_punch_holes(f->file);
+                                (void) managed_journal_file_truncate(f->file);
+                                (void) managed_journal_file_punch_holes(f->file);
                         }
 
                         (void) fsync(f->file->fd);
@@ -215,18 +215,18 @@ static void journald_file_set_offline_internal(JournaldFile *f) {
         }
 }
 
-static void * journald_file_set_offline_thread(void *arg) {
-        JournaldFile *f = arg;
+static void * managed_journal_file_set_offline_thread(void *arg) {
+        ManagedJournalFile *f = arg;
 
         (void) pthread_setname_np(pthread_self(), "journal-offline");
 
-        journald_file_set_offline_internal(f);
+        managed_journal_file_set_offline_internal(f);
 
         return NULL;
 }
 
 /* Trigger a restart if the offline thread is mid-flight in a restartable state. */
-static bool journald_file_set_offline_try_restart(JournaldFile *f) {
+static bool managed_journal_file_set_offline_try_restart(ManagedJournalFile *f) {
         for (;;) {
                 switch (f->file->offline_state) {
                 case OFFLINE_AGAIN_FROM_SYNCING:
@@ -264,7 +264,7 @@ static bool journald_file_set_offline_try_restart(JournaldFile *f) {
  * and joined, or if none exists the offline is simply performed in this
  * context without involving another thread.
  */
-int journald_file_set_offline(JournaldFile *f, bool wait) {
+int managed_journal_file_set_offline(ManagedJournalFile *f, bool wait) {
         int target_state;
         bool restarted;
         int r;
@@ -283,11 +283,11 @@ int journald_file_set_offline(JournaldFile *f, bool wait) {
          * we must also join any potentially lingering offline thread when already in
          * the desired offline state.
          */
-        if (!journald_file_is_offlining(f) && f->file->header->state == target_state)
+        if (!managed_journal_file_is_offlining(f) && f->file->header->state == target_state)
                 return journal_file_set_offline_thread_join(f->file);
 
         /* Restart an in-flight offline thread and wait if needed, or join a lingering done one. */
-        restarted = journald_file_set_offline_try_restart(f);
+        restarted = managed_journal_file_set_offline_try_restart(f);
         if ((restarted && wait) || !restarted) {
                 r = journal_file_set_offline_thread_join(f->file);
                 if (r < 0)
@@ -301,7 +301,7 @@ int journald_file_set_offline(JournaldFile *f, bool wait) {
         f->file->offline_state = OFFLINE_SYNCING;
 
         if (wait) /* Without using a thread if waiting. */
-                journald_file_set_offline_internal(f);
+                managed_journal_file_set_offline_internal(f);
         else {
                 sigset_t ss, saved_ss;
                 int k;
@@ -315,7 +315,7 @@ int journald_file_set_offline(JournaldFile *f, bool wait) {
                 if (r > 0)
                         return -r;
 
-                r = pthread_create(&f->file->offline_thread, NULL, journald_file_set_offline_thread, f);
+                r = pthread_create(&f->file->offline_thread, NULL, managed_journal_file_set_offline_thread, f);
 
                 k = pthread_sigmask(SIG_SETMASK, &saved_ss, NULL);
                 if (r > 0) {
@@ -329,7 +329,7 @@ int journald_file_set_offline(JournaldFile *f, bool wait) {
         return 0;
 }
 
-bool journald_file_is_offlining(JournaldFile *f) {
+bool managed_journal_file_is_offlining(ManagedJournalFile *f) {
         assert(f);
 
         __sync_synchronize();
@@ -340,7 +340,7 @@ bool journald_file_is_offlining(JournaldFile *f) {
         return true;
 }
 
-JournaldFile* journald_file_close(JournaldFile *f) {
+ManagedJournalFile* managed_journal_file_close(ManagedJournalFile *f) {
         if (!f)
                 return NULL;
 
@@ -362,14 +362,14 @@ JournaldFile* journald_file_close(JournaldFile *f) {
                 sd_event_source_disable_unref(f->file->post_change_timer);
         }
 
-        journald_file_set_offline(f, true);
+        managed_journal_file_set_offline(f, true);
 
         journal_file_close(f->file);
 
         return mfree(f);
 }
 
-int journald_file_open(
+int managed_journal_file_open(
                 int fd,
                 const char *fname,
                 int flags,
@@ -380,14 +380,14 @@ int journald_file_open(
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 Set *deferred_closes,
-                JournaldFile *template,
-                JournaldFile **ret) {
-        _cleanup_free_ JournaldFile *f = NULL;
+                ManagedJournalFile *template,
+                ManagedJournalFile **ret) {
+        _cleanup_free_ ManagedJournalFile *f = NULL;
         int r;
 
-        set_clear_with_destructor(deferred_closes, journald_file_close);
+        set_clear_with_destructor(deferred_closes, managed_journal_file_close);
 
-        f = new0(JournaldFile, 1);
+        f = new0(ManagedJournalFile, 1);
         if (!f)
                 return -ENOMEM;
 
@@ -402,7 +402,7 @@ int journald_file_open(
 }
 
 
-JournaldFile* journald_file_initiate_close(JournaldFile *f, Set *deferred_closes) {
+ManagedJournalFile* managed_journal_file_initiate_close(ManagedJournalFile *f, Set *deferred_closes) {
         int r;
 
         assert(f);
@@ -412,16 +412,16 @@ JournaldFile* journald_file_initiate_close(JournaldFile *f, Set *deferred_closes
                 if (r < 0)
                         log_debug_errno(r, "Failed to add file to deferred close set, closing immediately.");
                 else {
-                        (void) journald_file_set_offline(f, false);
+                        (void) managed_journal_file_set_offline(f, false);
                         return NULL;
                 }
         }
 
-        return journald_file_close(f);
+        return managed_journal_file_close(f);
 }
 
-int journald_file_rotate(
-                JournaldFile **f,
+int managed_journal_file_rotate(
+                ManagedJournalFile **f,
                 MMapCache *mmap_cache,
                 bool compress,
                 uint64_t compress_threshold_bytes,
@@ -429,7 +429,7 @@ int journald_file_rotate(
                 Set *deferred_closes) {
 
         _cleanup_free_ char *path = NULL;
-        JournaldFile *new_file = NULL;
+        ManagedJournalFile *new_file = NULL;
         int r;
 
         assert(f);
@@ -439,7 +439,7 @@ int journald_file_rotate(
         if (r < 0)
                 return r;
 
-        r = journald_file_open(
+        r = managed_journal_file_open(
                         -1,
                         path,
                         (*f)->file->flags,
@@ -453,13 +453,13 @@ int journald_file_rotate(
                         *f,              /* template */
                         &new_file);
 
-        journald_file_initiate_close(*f, deferred_closes);
+        managed_journal_file_initiate_close(*f, deferred_closes);
         *f = new_file;
 
         return r;
 }
 
-int journald_file_open_reliably(
+int managed_journal_file_open_reliably(
                 const char *fname,
                 int flags,
                 mode_t mode,
@@ -469,12 +469,12 @@ int journald_file_open_reliably(
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 Set *deferred_closes,
-                JournaldFile *template,
-                JournaldFile **ret) {
+                ManagedJournalFile *template,
+                ManagedJournalFile **ret) {
 
         int r;
 
-        r = journald_file_open(-1, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics,
+        r = managed_journal_file_open(-1, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics,
                                mmap_cache, deferred_closes, template, ret);
         if (!IN_SET(r,
                     -EBADMSG,           /* Corrupted */
@@ -504,6 +504,6 @@ int journald_file_open_reliably(
         if (r < 0)
                 return r;
 
-        return journald_file_open(-1, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics,
+        return managed_journal_file_open(-1, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics,
                                   mmap_cache, deferred_closes, template, ret);
 }
diff --git a/src/journal/managed-journal-file.h b/src/journal/managed-journal-file.h
new file mode 100644 (file)
index 0000000..6951b00
--- /dev/null
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "journal-file.h"
+
+typedef struct {
+        JournalFile *file;
+} ManagedJournalFile;
+
+int managed_journal_file_open(
+                int fd,
+                const char *fname,
+                int flags,
+                mode_t mode,
+                bool compress,
+                uint64_t compress_threshold_bytes,
+                bool seal,
+                JournalMetrics *metrics,
+                MMapCache *mmap_cache,
+                Set *deferred_closes,
+                ManagedJournalFile *template,
+                ManagedJournalFile **ret);
+
+int managed_journal_file_set_offline(ManagedJournalFile *f, bool wait);
+bool managed_journal_file_is_offlining(ManagedJournalFile *f);
+ManagedJournalFile* managed_journal_file_close(ManagedJournalFile *f);
+DEFINE_TRIVIAL_CLEANUP_FUNC(ManagedJournalFile*, managed_journal_file_close);
+
+int managed_journal_file_open_reliably(
+                const char *fname,
+                int flags,
+                mode_t mode,
+                bool compress,
+                uint64_t compress_threshold_bytes,
+                bool seal,
+                JournalMetrics *metrics,
+                MMapCache *mmap_cache,
+                Set *deferred_closes,
+                ManagedJournalFile *template,
+                ManagedJournalFile **ret);
+
+ManagedJournalFile* managed_journal_file_initiate_close(ManagedJournalFile *f, Set *deferred_closes);
+int managed_journal_file_rotate(ManagedJournalFile **f, MMapCache *mmap_cache, bool compress, uint64_t compress_threshold_bytes, bool seal, Set *deferred_closes);
index d767958f580b5d5824875ac6f97f0cd099719c33..73265e2c6d69fcb5afbb7d5c7eec5f53d44b0a39 100644 (file)
@@ -7,8 +7,6 @@ sources = files('''
         journald-console.h
         journald-context.c
         journald-context.h
-        journald-file.c
-        journald-file.h
         journald-kmsg.c
         journald-kmsg.h
         journald-native.c
@@ -23,6 +21,8 @@ sources = files('''
         journald-syslog.h
         journald-wall.c
         journald-wall.h
+        managed-journal-file.c
+        managed-journal-file.h
 '''.split())
 
 sources += custom_target(
index dc05126b5722969900d2c560de80fd0c1a2579d8..6af819f7339cf069a8221f1b226d9c9abc83db32 100644 (file)
@@ -7,9 +7,9 @@
 
 #include "alloc-util.h"
 #include "chattr-util.h"
-#include "journald-file.h"
 #include "journal-internal.h"
 #include "macro.h"
+#include "managed-journal-file.h"
 #include "path-util.h"
 #include "string-util.h"
 
@@ -17,7 +17,7 @@ int main(int argc, char *argv[]) {
         _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
         _cleanup_free_ char *fn = NULL;
         char dn[] = "/var/tmp/test-journal-flush.XXXXXX";
-        JournaldFile *new_journal = NULL;
+        ManagedJournalFile *new_journal = NULL;
         sd_journal *j = NULL;
         unsigned n = 0;
         int r;
@@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
 
         fn = path_join(dn, "test.journal");
 
-        r = journald_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, m, NULL, NULL, &new_journal);
+        r = managed_journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, m, NULL, NULL, &new_journal);
         assert_se(r >= 0);
 
         if (argc > 1)
@@ -66,7 +66,7 @@ int main(int argc, char *argv[]) {
 
         sd_journal_close(j);
 
-        (void) journald_file_close(new_journal);
+        (void) managed_journal_file_close(new_journal);
 
         unlink(fn);
         assert_se(rmdir(dn) == 0);
index c543b87b6954833ece973e6bcfb5496bb1a2afea..2d86e2a5a1f671374568f3fdb5cbe0a2a5e386e9 100644 (file)
@@ -8,9 +8,9 @@
 #include "alloc-util.h"
 #include "chattr-util.h"
 #include "io-util.h"
-#include "journald-file.h"
 #include "journal-vacuum.h"
 #include "log.h"
+#include "managed-journal-file.h"
 #include "parse-util.h"
 #include "rm-rf.h"
 #include "tests.h"
@@ -33,22 +33,22 @@ _noreturn_ static void log_assert_errno(const char *text, int error, const char
                         log_assert_errno(#expr, -_r_, PROJECT_FILE, __LINE__, __PRETTY_FUNCTION__); \
         } while (false)
 
-static JournaldFile *test_open(const char *name) {
+static ManagedJournalFile *test_open(const char *name) {
         _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
-        JournaldFile *f;
+        ManagedJournalFile *f;
 
         m = mmap_cache_new();
         assert_se(m != NULL);
 
-        assert_ret(journald_file_open(-1, name, O_RDWR|O_CREAT, 0644, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f));
+        assert_ret(managed_journal_file_open(-1, name, O_RDWR|O_CREAT, 0644, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f));
         return f;
 }
 
-static void test_close(JournaldFile *f) {
-        (void) journald_file_close(f);
+static void test_close(ManagedJournalFile *f) {
+        (void) managed_journal_file_close(f);
 }
 
-static void append_number(JournaldFile *f, int n, uint64_t *seqnum) {
+static void append_number(ManagedJournalFile *f, int n, uint64_t *seqnum) {
         char *p;
         dual_timestamp ts;
         static dual_timestamp previous_ts = {};
@@ -113,7 +113,7 @@ static void test_check_numbers_up (sd_journal *j, int count) {
 }
 
 static void setup_sequential(void) {
-        JournaldFile *one, *two;
+        ManagedJournalFile *one, *two;
         one = test_open("one.journal");
         two = test_open("two.journal");
         append_number(one, 1, NULL);
@@ -125,7 +125,7 @@ static void setup_sequential(void) {
 }
 
 static void setup_interleaved(void) {
-        JournaldFile *one, *two;
+        ManagedJournalFile *one, *two;
         one = test_open("one.journal");
         two = test_open("two.journal");
         append_number(one, 1, NULL);
@@ -205,7 +205,7 @@ static void test_sequence_numbers(void) {
 
         _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
         char t[] = "/var/tmp/journal-seq-XXXXXX";
-        JournaldFile *one, *two;
+        ManagedJournalFile *one, *two;
         uint64_t seqnum = 0;
         sd_id128_t seqnum_id;
 
@@ -214,7 +214,7 @@ static void test_sequence_numbers(void) {
 
         mkdtemp_chdir_chattr(t);
 
-        assert_se(journald_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0644,
+        assert_se(managed_journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0644,
                                      true, UINT64_MAX, false, NULL, m, NULL, NULL, &one) == 0);
 
         append_number(one, 1, &seqnum);
@@ -231,7 +231,7 @@ static void test_sequence_numbers(void) {
 
         memcpy(&seqnum_id, &one->file->header->seqnum_id, sizeof(sd_id128_t));
 
-        assert_se(journald_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0644,
+        assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0644,
                                      true, UINT64_MAX, false, NULL, m, NULL, one, &two) == 0);
 
         assert_se(two->file->header->state == STATE_ONLINE);
@@ -262,7 +262,7 @@ static void test_sequence_numbers(void) {
         /* restart server */
         seqnum = 0;
 
-        assert_se(journald_file_open(-1, "two.journal", O_RDWR, 0,
+        assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, 0,
                                      true, UINT64_MAX, false, NULL, m, NULL, NULL, &two) == 0);
 
         assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id));
@@ -290,7 +290,7 @@ static void test_sequence_numbers(void) {
 int main(int argc, char *argv[]) {
         test_setup_logging(LOG_DEBUG);
 
-        /* journald_file_open requires a valid machine id */
+        /* managed_journal_file_open requires a valid machine id */
         if (access("/etc/machine-id", F_OK) != 0)
                 return log_tests_skipped("/etc/machine-id not found");
 
index 115ce807c983819018e868cbbd3f55af6deb06c0..486a2f41c20df2f54a76b28105ae62d5e87d2b9b 100644 (file)
@@ -8,10 +8,10 @@
 #include "alloc-util.h"
 #include "chattr-util.h"
 #include "io-util.h"
-#include "journald-file.h"
 #include "journal-internal.h"
 #include "log.h"
 #include "macro.h"
+#include "managed-journal-file.h"
 #include "parse-util.h"
 #include "rm-rf.h"
 #include "tests.h"
@@ -61,7 +61,7 @@ static void verify_contents(sd_journal *j, unsigned skip) {
 
 static void run_test(void) {
         _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
-        JournaldFile *one, *two, *three;
+        ManagedJournalFile *one, *two, *three;
         char t[] = "/var/tmp/journal-stream-XXXXXX";
         unsigned i;
         _cleanup_(sd_journal_closep) sd_journal *j = NULL;
@@ -77,9 +77,9 @@ static void run_test(void) {
         assert_se(chdir(t) >= 0);
         (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
 
-        assert_se(journald_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &one) == 0);
-        assert_se(journald_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &two) == 0);
-        assert_se(journald_file_open(-1, "three.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &three) == 0);
+        assert_se(managed_journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &one) == 0);
+        assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &two) == 0);
+        assert_se(managed_journal_file_open(-1, "three.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &three) == 0);
 
         for (i = 0; i < N_ENTRIES; i++) {
                 char *p, *q;
@@ -116,9 +116,9 @@ static void run_test(void) {
                 free(q);
         }
 
-        (void) journald_file_close(one);
-        (void) journald_file_close(two);
-        (void) journald_file_close(three);
+        (void) managed_journal_file_close(one);
+        (void) managed_journal_file_close(two);
+        (void) managed_journal_file_close(three);
 
         assert_se(sd_journal_open_directory(&j, t, 0) >= 0);
 
@@ -178,7 +178,7 @@ static void run_test(void) {
 
 int main(int argc, char *argv[]) {
 
-        /* journald_file_open requires a valid machine id */
+        /* managed_journal_file_open requires a valid machine id */
         if (access("/etc/machine-id", F_OK) != 0)
                 return log_tests_skipped("/etc/machine-id not found");
 
index 6abfaeb0df975d5d07bb60b5ab8b996795c43c9e..323e495081df0c9afad3162aca8c9620ea767b92 100644 (file)
@@ -7,9 +7,9 @@
 #include "chattr-util.h"
 #include "fd-util.h"
 #include "io-util.h"
-#include "journald-file.h"
 #include "journal-verify.h"
 #include "log.h"
+#include "managed-journal-file.h"
 #include "mmap-cache.h"
 #include "rm-rf.h"
 #include "terminal-util.h"
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
         char t[] = "/var/tmp/journal-XXXXXX";
         unsigned n;
         JournalFile *f;
-        JournaldFile *df;
+        ManagedJournalFile *df;
         const char *verification_key = argv[1];
         usec_t from = 0, to = 0, total = 0;
         struct stat st;
@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
         m = mmap_cache_new();
         assert_se(m != NULL);
 
-        /* journald_file_open requires a valid machine id */
+        /* managed_journal_file_open requires a valid machine id */
         if (access("/etc/machine-id", F_OK) != 0)
                 return log_tests_skipped("/etc/machine-id not found");
 
@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
 
         log_info("Generating...");
 
-        assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, NULL, &df) == 0);
+        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, NULL, &df) == 0);
 
         for (n = 0; n < N_ENTRIES; n++) {
                 struct iovec iovec;
@@ -100,7 +100,7 @@ int main(int argc, char *argv[]) {
                 free(test);
         }
 
-        (void) journald_file_close(df);
+        (void) managed_journal_file_close(df);
 
         log_info("Verifying...");
 
index fbe4f0360ec87c8a9b9ba2b00ab6b056e8572a14..bfc1cf29603f8080e12f596046b4667a7184b021 100644 (file)
@@ -6,9 +6,9 @@
 #include "chattr-util.h"
 #include "io-util.h"
 #include "journal-authenticate.h"
-#include "journald-file.h"
 #include "journal-vacuum.h"
 #include "log.h"
+#include "managed-journal-file.h"
 #include "rm-rf.h"
 #include "tests.h"
 
@@ -26,7 +26,7 @@ static void mkdtemp_chdir_chattr(char *path) {
 static void test_non_empty(void) {
         _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
         dual_timestamp ts;
-        JournaldFile *f;
+        ManagedJournalFile *f;
         struct iovec iovec;
         static const char test[] = "TEST1=1", test2[] = "TEST2=2";
         Object *o, *d;
@@ -41,7 +41,7 @@ static void test_non_empty(void) {
 
         mkdtemp_chdir_chattr(t);
 
-        assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, m, NULL, NULL, &f) == 0);
+        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, m, NULL, NULL, &f) == 0);
 
         assert_se(dual_timestamp_get(&ts));
         assert_se(sd_id128_randomize(&fake_boot_id) == 0);
@@ -102,10 +102,10 @@ static void test_non_empty(void) {
 
         assert_se(journal_file_move_to_entry_by_seqnum(f->file, 10, DIRECTION_DOWN, &o, NULL) == 0);
 
-        journald_file_rotate(&f, m, true, UINT64_MAX, true, NULL);
-        journald_file_rotate(&f, m, true, UINT64_MAX, true, NULL);
+        managed_journal_file_rotate(&f, m, true, UINT64_MAX, true, NULL);
+        managed_journal_file_rotate(&f, m, true, UINT64_MAX, true, NULL);
 
-        (void) journald_file_close(f);
+        (void) managed_journal_file_close(f);
 
         log_info("Done...");
 
@@ -122,7 +122,7 @@ static void test_non_empty(void) {
 
 static void test_empty(void) {
         _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
-        JournaldFile *f1, *f2, *f3, *f4;
+        ManagedJournalFile *f1, *f2, *f3, *f4;
         char t[] = "/var/tmp/journal-XXXXXX";
 
         test_setup_logging(LOG_DEBUG);
@@ -132,10 +132,10 @@ static void test_empty(void) {
 
         mkdtemp_chdir_chattr(t);
 
-        assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, false, NULL, m, NULL, NULL, &f1) == 0);
-        assert_se(journald_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f2) == 0);
-        assert_se(journald_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, true, NULL, m, NULL, NULL, &f3) == 0);
-        assert_se(journald_file_open(-1, "test-seal-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, m, NULL, NULL, &f4) == 0);
+        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, false, NULL, m, NULL, NULL, &f1) == 0);
+        assert_se(managed_journal_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f2) == 0);
+        assert_se(managed_journal_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, true, NULL, m, NULL, NULL, &f3) == 0);
+        assert_se(managed_journal_file_open(-1, "test-seal-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, m, NULL, NULL, &f4) == 0);
 
         journal_file_print_header(f1->file);
         puts("");
@@ -156,17 +156,17 @@ static void test_empty(void) {
                 assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
         }
 
-        (void) journald_file_close(f1);
-        (void) journald_file_close(f2);
-        (void) journald_file_close(f3);
-        (void) journald_file_close(f4);
+        (void) managed_journal_file_close(f1);
+        (void) managed_journal_file_close(f2);
+        (void) managed_journal_file_close(f3);
+        (void) managed_journal_file_close(f4);
 }
 
 #if HAVE_COMPRESSION
 static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
         _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
         dual_timestamp ts;
-        JournaldFile *f;
+        ManagedJournalFile *f;
         struct iovec iovec;
         Object *o;
         uint64_t p;
@@ -184,7 +184,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
 
         mkdtemp_chdir_chattr(t);
 
-        assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, compress_threshold, true, NULL, m, NULL, NULL, &f) == 0);
+        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, compress_threshold, true, NULL, m, NULL, NULL, &f) == 0);
 
         dual_timestamp_get(&ts);
 
@@ -211,7 +211,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
 
         is_compressed = (o->object.flags & OBJECT_COMPRESSION_MASK) != 0;
 
-        (void) journald_file_close(f);
+        (void) managed_journal_file_close(f);
 
         log_info("Done...");
 
@@ -254,7 +254,7 @@ int main(int argc, char *argv[]) {
 
         test_setup_logging(LOG_INFO);
 
-        /* journald_file_open requires a valid machine id */
+        /* managed_journal_file_open requires a valid machine id */
         if (access("/etc/machine-id", F_OK) != 0)
                 return log_tests_skipped("/etc/machine-id not found");