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.
This commit is contained in:
Vito Caputo
2021-12-07 13:03:34 -08:00
parent 8b4fbbb0a1
commit a8da63309c
2 changed files with 11 additions and 10 deletions
+11 -9
View File
@@ -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;
-1
View File
@@ -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;