From: Vito Caputo Date: Thu, 25 Nov 2021 23:32:07 +0000 (-0800) Subject: journal-file: goodbye JournalFile.mmap X-Git-Tag: v250-rc1~27^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8da63309c9a288f741772d2fc35061f2a9babe4;p=thirdparty%2Fsystemd.git journal-file: goodbye JournalFile.mmap This gets rid of the manual MMapCache ref/unref goop in journal_file_{open,close}(), in favor of just letting the JournalFile.cache_fd MMapFileDescriptor carry the baton. --- diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 11b9da1cb54..4302a99f80d 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -217,15 +217,13 @@ JournalFile* journal_file_close(JournalFile *f) { if (!f) return NULL; - if (f->mmap && f->cache_fd) + if (f->cache_fd) mmap_cache_fd_free(f->cache_fd); if (f->close_fd) safe_close(f->fd); free(f->path); - mmap_cache_unref(f->mmap); - ordered_hashmap_free_free(f->chain_cache); #if HAVE_COMPRESSION @@ -3252,6 +3250,7 @@ int journal_file_open( JournalFile **ret) { bool newly_created = false; + MMapCache *m = mmap_cache; JournalFile *f; void *h; int r; @@ -3320,11 +3319,9 @@ int journal_file_open( } } - if (mmap_cache) - f->mmap = mmap_cache_ref(mmap_cache); - else { - f->mmap = mmap_cache_new(); - if (!f->mmap) { + if (!m) { + m = mmap_cache_new(); + if (!m) { r = -ENOMEM; goto fail; } @@ -3371,12 +3368,17 @@ int journal_file_open( goto fail; } - f->cache_fd = mmap_cache_add_fd(f->mmap, f->fd, prot_from_flags(flags)); + /* On success this incs refcnt on *m, which mmap_cache_fd_free() will dec. */ + f->cache_fd = mmap_cache_add_fd(m, f->fd, prot_from_flags(flags)); if (!f->cache_fd) { r = -ENOMEM; goto fail; } + /* If we created *m just for this file, unref *m so only f->cache_fd's ref remains */ + if (!mmap_cache) + (void) mmap_cache_unref(m); + r = journal_file_fstat(f); if (r < 0) goto fail; diff --git a/src/libsystemd/sd-journal/journal-file.h b/src/libsystemd/sd-journal/journal-file.h index 90c9dbe6374..b90e3a608ac 100644 --- a/src/libsystemd/sd-journal/journal-file.h +++ b/src/libsystemd/sd-journal/journal-file.h @@ -92,7 +92,6 @@ typedef struct JournalFile { uint64_t current_xor_hash; JournalMetrics metrics; - MMapCache *mmap; sd_event_source *post_change_timer; usec_t post_change_timer_period;