]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: stop using JournalFile.mmap everywhere
authorVito Caputo <vcaputo@pengaru.com>
Thu, 25 Nov 2021 23:24:48 +0000 (15:24 -0800)
committerVito Caputo <vcaputo@pengaru.com>
Tue, 7 Dec 2021 21:00:25 +0000 (13:00 -0800)
Preparatory commit; before JournalFile can stop hanging onto its
copy of MMapCache, all these users need to find another way.

Most of the time these callers already have the MMapCache onhand,
so it's no big deal for them to just supply it.

journal_file_rotate() in particular needed to change, and it
seemed wise to not use the mmap_cache_fd_cache() accessor on
f->cache_fd, instead requiring the caller supply the cache to
use.  This was done with an eye towards a potential future where
the journal_file_archive() isolates the cache_fd to a private
cache, which the newly rotated-to file wouldn't be allowed to
use.  It's no biggie for the existing callers to just provide the
appropriate surviving cache.

Basically the mmap_cache_fd_cache() accessor was added just for
journal-verify.c's (ab)use of the mmap-cache.  Which, if the
ugly singleton MMapCache assumption ever goes away, can be
cleaned up to simply use a separate MMapCache for those search
arrays.

src/journal-remote/journal-remote-write.c
src/journal/journald-file.c
src/journal/journald-file.h
src/journal/journald-server.c
src/journal/test-journal.c
src/libsystemd/sd-journal/journal-file.h
src/libsystemd/sd-journal/journal-verify.c

index fd7cb91f2c017b0ca1d8d68ee3fdad60ff900f23..b82cb101184b9692e1d758ffebc6530db026b1fc 100644 (file)
@@ -3,8 +3,8 @@
 #include "alloc-util.h"
 #include "journal-remote.h"
 
-static int do_rotate(JournaldFile **f, bool compress, bool seal) {
-        int r = journald_file_rotate(f, compress, UINT64_MAX, seal, NULL);
+static int do_rotate(JournaldFile **f, MMapCache *m, bool compress, bool seal) {
+        int r = journald_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);
@@ -71,7 +71,7 @@ int writer_write(Writer *w,
         if (journal_file_rotate_suggested(w->journal->file, 0, LOG_DEBUG)) {
                 log_info("%s: Journal header limits reached or header out-of-date, rotating",
                          w->journal->file->path);
-                r = do_rotate(&w->journal, compress, seal);
+                r = do_rotate(&w->journal, w->mmap, compress, seal);
                 if (r < 0)
                         return r;
         }
@@ -87,7 +87,7 @@ int writer_write(Writer *w,
                 return r;
 
         log_debug_errno(r, "%s: Write failed, rotating: %m", w->journal->file->path);
-        r = do_rotate(&w->journal, compress, seal);
+        r = do_rotate(&w->journal, w->mmap, compress, seal);
         if (r < 0)
                 return r;
         else
index 7f607d4aa60f877426a545e37bbf555932453ebf..be3fc1615a821ed97f9771b54acbd5af6723a27d 100644 (file)
@@ -403,6 +403,7 @@ 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,
@@ -428,7 +429,7 @@ int journald_file_rotate(
                         compress_threshold_bytes,
                         seal,
                         NULL,            /* metrics */
-                        (*f)->file->mmap,
+                        mmap_cache,
                         deferred_closes,
                         *f,              /* template */
                         &new_file);
index 341043c8362a7f5a1429244e19b8ad20b579a2f7..79c0ef8240432454e42c776758c2141a5ccc23f3 100644 (file)
@@ -40,4 +40,4 @@ int journald_file_open_reliably(
                 JournaldFile **ret);
 
 JournaldFile* journald_file_initiate_close(JournaldFile *f, Set *deferred_closes);
-int journald_file_rotate(JournaldFile **f, bool compress, uint64_t compress_threshold_bytes, bool seal, 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 a13bbeeee9fc012137ff98b82879801ce751c180..c04801d9fcab06b954a09bf8b856ea9dcb1172c4 100644 (file)
@@ -465,7 +465,7 @@ static int do_rotate(
         if (!*f)
                 return -EINVAL;
 
-        r = journald_file_rotate(f, s->compress.enabled, s->compress.threshold_bytes, seal, s->deferred_closes);
+        r = journald_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);
index c2c4a75fef68ae69629ba3f1a64ae12f3a47d406..17c6a73db30a1c6f540d91a4162bc3c827f59e5a 100644 (file)
@@ -98,8 +98,8 @@ 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, true, UINT64_MAX, true, NULL);
-        journald_file_rotate(&f, true, UINT64_MAX, true, NULL);
+        journald_file_rotate(&f, NULL, true, UINT64_MAX, true, NULL);
+        journald_file_rotate(&f, NULL, true, UINT64_MAX, true, NULL);
 
         (void) journald_file_close(f);
 
index ecda2b3cc0c11d3ac6a05d6ad94fae4d6ab8da27..90c9dbe6374fdd29f2dd5b37bf034a64eee591c3 100644 (file)
@@ -232,6 +232,7 @@ void journal_file_dump(JournalFile *f);
 void journal_file_print_header(JournalFile *f);
 
 int journal_file_archive(JournalFile *f, char **ret_previous_path);
+JournalFile* journal_initiate_close(JournalFile *f, Set *deferred_closes);
 
 int journal_file_dispose(int dir_fd, const char *fname);
 
index b6427105c2296b846fc6e128a6d4e641ebd74129..8288ebcd6e91341a9c9d5329ab029cb85c0fe149 100644 (file)
@@ -885,6 +885,7 @@ int journal_file_verify(
         unsigned i;
         bool found_last = false;
         const char *tmp_dir = NULL;
+        MMapCache *m;
 
 #if HAVE_GCRYPT
         uint64_t last_tag = 0;
@@ -929,19 +930,20 @@ int journal_file_verify(
                 goto fail;
         }
 
-        cache_data_fd = mmap_cache_add_fd(f->mmap, data_fd, PROT_READ|PROT_WRITE);
+        m = mmap_cache_fd_cache(f->cache_fd);
+        cache_data_fd = mmap_cache_add_fd(m, data_fd, PROT_READ|PROT_WRITE);
         if (!cache_data_fd) {
                 r = log_oom();
                 goto fail;
         }
 
-        cache_entry_fd = mmap_cache_add_fd(f->mmap, entry_fd, PROT_READ|PROT_WRITE);
+        cache_entry_fd = mmap_cache_add_fd(m, entry_fd, PROT_READ|PROT_WRITE);
         if (!cache_entry_fd) {
                 r = log_oom();
                 goto fail;
         }
 
-        cache_entry_array_fd = mmap_cache_add_fd(f->mmap, entry_array_fd, PROT_READ|PROT_WRITE);
+        cache_entry_array_fd = mmap_cache_add_fd(m, entry_array_fd, PROT_READ|PROT_WRITE);
         if (!cache_entry_array_fd) {
                 r = log_oom();
                 goto fail;