summaryrefslogtreecommitdiff
path: root/src/journal-remote/journal-remote-write.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2021-11-30 16:18:56 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2021-12-06 22:17:38 +0100
commit035b0f8fe8c1883b17d864f15f99846ab206099d (patch)
treeb163a7dec28beb6a6c468f08d71b5bbe05faceff /src/journal-remote/journal-remote-write.c
parentef6bb4dd3e3bb9c210c310026b4d827a46acc762 (diff)
downloadsystemd-035b0f8fe8c1883b17d864f15f99846ab206099d.tar.gz
journal: Introduce journald-file.c for journal file write related logic
Currently, all the logic related to writing journal files lives in journal-file.c which is part of libsystemd (sd-journal). Because it's part of libsystemd, we can't depend on any code from src/shared. To allow using code from src/shared when writing journal files, let's gradually move the write related logic from journal-file.c to journald-file.c in src/journal. This directory is not part of libsystemd and as such can use code from src/shared. We can safely remove any journal write related logic from libsystemd as it's not used by any public APIs in libsystemd. This commit introduces the new file along with the JournaldFile struct which wraps an instance of JournalFile. The goal is to gradually move more functions from journal-file.c and fields from JournalFile to journald-file.c and JournaldFile respectively. This commit also modifies all call sites that write journal files to use JournaldFile instead of JournalFile. All sd-journal tests that write journal files are moved to src/journal so they can make use of journald-file.c. Because the deferred closes logic is only used by journald, we move it out of journal-file.c as well. In journal_file_open(), we would wait for any remaining deferred closes for the file we're about to open to complete before continuing if the file was not newly created. In journald_file_open(), we call this logic unconditionally since it stands that if a file is newly created, it can't have any outstanding deferred closes. No changes in behavior are introduced aside from the earlier execution of waiting for any deferred closes to complete when opening a new journal file.
Diffstat (limited to 'src/journal-remote/journal-remote-write.c')
-rw-r--r--src/journal-remote/journal-remote-write.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c
index c953a5e93e..fd7cb91f2c 100644
--- a/src/journal-remote/journal-remote-write.c
+++ b/src/journal-remote/journal-remote-write.c
@@ -3,11 +3,11 @@
#include "alloc-util.h"
#include "journal-remote.h"
-static int do_rotate(JournalFile **f, bool compress, bool seal) {
- int r = journal_file_rotate(f, compress, UINT64_MAX, seal, NULL);
+static int do_rotate(JournaldFile **f, bool compress, bool seal) {
+ int r = journald_file_rotate(f, compress, UINT64_MAX, seal, NULL);
if (r < 0) {
if (*f)
- log_error_errno(r, "Failed to rotate %s: %m", (*f)->path);
+ log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path);
else
log_error_errno(r, "Failed to create rotated journal: %m");
}
@@ -39,8 +39,8 @@ static Writer* writer_free(Writer *w) {
return NULL;
if (w->journal) {
- log_debug("Closing journal file %s.", w->journal->path);
- journal_file_close(w->journal);
+ log_debug("Closing journal file %s.", w->journal->file->path);
+ journald_file_close(w->journal);
}
if (w->server && w->hashmap_key)
@@ -68,15 +68,15 @@ int writer_write(Writer *w,
assert(iovw);
assert(iovw->count > 0);
- if (journal_file_rotate_suggested(w->journal, 0, LOG_DEBUG)) {
+ 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->path);
+ w->journal->file->path);
r = do_rotate(&w->journal, compress, seal);
if (r < 0)
return r;
}
- r = journal_file_append_entry(w->journal, ts, boot_id,
+ r = journal_file_append_entry(w->journal->file, ts, boot_id,
iovw->iovec, iovw->count,
&w->seqnum, NULL, NULL);
if (r >= 0) {
@@ -86,15 +86,15 @@ int writer_write(Writer *w,
} else if (r == -EBADMSG)
return r;
- log_debug_errno(r, "%s: Write failed, rotating: %m", w->journal->path);
+ log_debug_errno(r, "%s: Write failed, rotating: %m", w->journal->file->path);
r = do_rotate(&w->journal, compress, seal);
if (r < 0)
return r;
else
- log_debug("%s: Successfully rotated journal", w->journal->path);
+ log_debug("%s: Successfully rotated journal", w->journal->file->path);
log_debug("Retrying write.");
- r = journal_file_append_entry(w->journal, ts, boot_id,
+ r = journal_file_append_entry(w->journal->file, ts, boot_id,
iovw->iovec, iovw->count,
&w->seqnum, NULL, NULL);
if (r < 0)