From: Daan De Meyer Date: Thu, 27 Jan 2022 14:44:35 +0000 (+0000) Subject: journal: Truncate file instead of punching hole in final object X-Git-Tag: v251-rc1~444^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F22262%2Fhead;p=thirdparty%2Fsystemd.git journal: Truncate file instead of punching hole in final object Instead of punching a hole in the final object if it's an entry array, let's just truncate the file instead. --- diff --git a/src/journal/journald-file.c b/src/journal/journald-file.c index 9337925ffde..4e095acc934 100644 --- a/src/journal/journald-file.c +++ b/src/journal/journald-file.c @@ -72,6 +72,19 @@ static int journald_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint if (sz < MINIMUM_HOLE_SIZE) return 0; + if (p == le64toh(f->header->tail_object_offset) && !f->seal) { + o.object.size = htole64(offset - p); + if (pwrite(f->fd, &o, sizeof(EntryArrayObject), p) < 0) + return log_debug_errno(errno, "Failed to modify entry array object size: %m"); + + f->header->arena_size = htole64(ALIGN64(offset) - le64toh(f->header->header_size)); + + if (ftruncate(f->fd, ALIGN64(offset)) < 0) + return log_debug_errno(errno, "Failed to truncate %s: %m", f->path); + + return 0; + } + if (fallocate(f->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, sz) < 0) return log_debug_errno(errno, "Failed to punch hole in entry array of %s: %m", f->path);