]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Truncate file instead of punching hole in final object 22262/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 27 Jan 2022 14:44:35 +0000 (14:44 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 27 Jan 2022 15:21:37 +0000 (15:21 +0000)
Instead of punching a hole in the final object if it's an entry array,
let's just truncate the file instead.

src/journal/journald-file.c

index 9337925ffdeba3c58d716c3fa25506b14302a22d..4e095acc934fe6923f85e4b0a6aa62047ac2c0d3 100644 (file)
@@ -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);