journal: Update the JournalFile path when archiving

When we archive a path, we rename the file to indicate this. However,
until now, we didn't actually update the path member of the corresponding
JournalFile instance. Let's make sure we also update this to avoid
misuse of the old path later on.

This change also requires we save the previous path in journal_file_rotate()
since we need to open a new file at the previous path.
This commit is contained in:
Daan De Meyer
2021-12-06 22:17:40 +01:00
parent bea29a4296
commit 461955ef4c
4 changed files with 13 additions and 5 deletions
+3 -2
View File
@@ -382,19 +382,20 @@ int journald_file_rotate(
bool seal,
Set *deferred_closes) {
_cleanup_free_ char *path = NULL;
JournaldFile *new_file = NULL;
int r;
assert(f);
assert(*f);
r = journal_file_archive((*f)->file);
r = journal_file_archive((*f)->file, &path);
if (r < 0)
return r;
r = journald_file_open(
-1,
(*f)->file->path,
path,
(*f)->file->flags,
(*f)->file->mode,
compress,
+1 -1
View File
@@ -602,7 +602,7 @@ static int vacuum_offline_user_journals(Server *s) {
TAKE_FD(fd); /* Donated to journald_file_open() */
r = journal_file_archive(f->file);
r = journal_file_archive(f->file, NULL);
if (r < 0)
log_debug_errno(r, "Failed to archive journal file '%s', ignoring: %m", full);
+8 -1
View File
@@ -3521,7 +3521,7 @@ fail:
return r;
}
int journal_file_archive(JournalFile *f) {
int journal_file_archive(JournalFile *f, char **ret_previous_path) {
_cleanup_free_ char *p = NULL;
assert(f);
@@ -3552,6 +3552,13 @@ int journal_file_archive(JournalFile *f) {
/* Sync the rename to disk */
(void) fsync_directory_of_file(f->fd);
if (ret_previous_path)
*ret_previous_path = f->path;
else
free(f->path);
f->path = TAKE_PTR(p);
/* Set as archive so offlining commits w/state=STATE_ARCHIVED. Previously we would set old_file->header->state
* to STATE_ARCHIVED directly here, but journal_file_set_offline() short-circuits when state != STATE_ONLINE,
* which would result in the rotated journal never getting fsync() called before closing. Now we simply queue
+1 -1
View File
@@ -232,7 +232,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
void journal_file_dump(JournalFile *f);
void journal_file_print_header(JournalFile *f);
int journal_file_archive(JournalFile *f);
int journal_file_archive(JournalFile *f, char **ret_previous_path);
int journal_file_dispose(int dir_fd, const char *fname);