mirror of
https://github.com/systemd/systemd
synced 2024-10-14 12:04:49 +00:00
Revert "journal-file: truncate archived journals"
This reverts commit 592d419ce6
.
The commit makes journald unstable, and is just an optimization
for the size of journal. Hence, it is safe to revert the commit.
Fixes #19895.
This commit is contained in:
parent
e4948b0f0a
commit
0aa649b11d
|
@ -89,41 +89,6 @@
|
||||||
# pragma GCC diagnostic ignored "-Waddress-of-packed-member"
|
# pragma GCC diagnostic ignored "-Waddress-of-packed-member"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int journal_file_tail_end(JournalFile *f, uint64_t *ret_offset) {
|
|
||||||
Object *tail;
|
|
||||||
uint64_t p;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(f);
|
|
||||||
assert(f->header);
|
|
||||||
assert(ret_offset);
|
|
||||||
|
|
||||||
p = le64toh(f->header->tail_object_offset);
|
|
||||||
if (p == 0)
|
|
||||||
p = le64toh(f->header->header_size);
|
|
||||||
else {
|
|
||||||
uint64_t sz;
|
|
||||||
|
|
||||||
r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &tail);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
sz = le64toh(READ_NOW(tail->object.size));
|
|
||||||
if (sz > UINT64_MAX - sizeof(uint64_t) + 1)
|
|
||||||
return -EBADMSG;
|
|
||||||
|
|
||||||
sz = ALIGN64(sz);
|
|
||||||
if (p > UINT64_MAX - sz)
|
|
||||||
return -EBADMSG;
|
|
||||||
|
|
||||||
p += sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ret_offset = p;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This may be called from a separate thread to prevent blocking the caller for the duration of fsync().
|
/* This may be called from a separate thread to prevent blocking the caller for the duration of fsync().
|
||||||
* As a result we use atomic operations on f->offline_state for inter-thread communications with
|
* As a result we use atomic operations on f->offline_state for inter-thread communications with
|
||||||
* journal_file_set_offline() and journal_file_set_online(). */
|
* journal_file_set_offline() and journal_file_set_online(). */
|
||||||
|
@ -157,25 +122,6 @@ static void journal_file_set_offline_internal(JournalFile *f) {
|
||||||
|
|
||||||
f->header->state = f->archive ? STATE_ARCHIVED : STATE_OFFLINE;
|
f->header->state = f->archive ? STATE_ARCHIVED : STATE_OFFLINE;
|
||||||
(void) fsync(f->fd);
|
(void) fsync(f->fd);
|
||||||
|
|
||||||
if (f->archive) {
|
|
||||||
uint64_t p;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
/* truncate excess from the end of archives */
|
|
||||||
r = journal_file_tail_end(f, &p);
|
|
||||||
if (r < 0)
|
|
||||||
log_debug_errno(r, "Failed to determine end of tail object, ignoring: %m");
|
|
||||||
else {
|
|
||||||
/* arena_size can't exceed the file size, ensure it's updated before truncating */
|
|
||||||
f->header->arena_size = htole64(p - le64toh(f->header->header_size));
|
|
||||||
|
|
||||||
(void) fsync(f->fd);
|
|
||||||
|
|
||||||
if (ftruncate(f->fd, p) < 0)
|
|
||||||
log_debug_errno(errno, "Failed to truncate archive at end of tail object, ignoring: %m");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OFFLINE_OFFLINING:
|
case OFFLINE_OFFLINING:
|
||||||
|
@ -1108,7 +1054,7 @@ int journal_file_append_object(
|
||||||
|
|
||||||
int r;
|
int r;
|
||||||
uint64_t p;
|
uint64_t p;
|
||||||
Object *o;
|
Object *tail, *o;
|
||||||
void *t;
|
void *t;
|
||||||
|
|
||||||
assert(f);
|
assert(f);
|
||||||
|
@ -1120,9 +1066,26 @@ int journal_file_append_object(
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = journal_file_tail_end(f, &p);
|
p = le64toh(f->header->tail_object_offset);
|
||||||
if (r < 0)
|
if (p == 0)
|
||||||
return r;
|
p = le64toh(f->header->header_size);
|
||||||
|
else {
|
||||||
|
uint64_t sz;
|
||||||
|
|
||||||
|
r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &tail);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
sz = le64toh(READ_NOW(tail->object.size));
|
||||||
|
if (sz > UINT64_MAX - sizeof(uint64_t) + 1)
|
||||||
|
return -EBADMSG;
|
||||||
|
|
||||||
|
sz = ALIGN64(sz);
|
||||||
|
if (p > UINT64_MAX - sz)
|
||||||
|
return -EBADMSG;
|
||||||
|
|
||||||
|
p += sz;
|
||||||
|
}
|
||||||
|
|
||||||
r = journal_file_allocate(f, p, size);
|
r = journal_file_allocate(f, p, size);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
Loading…
Reference in a new issue