summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-02-08 13:03:03 +0000
committerGitHub <noreply@github.com>2022-02-08 13:03:03 +0000
commit586e4850425090bb927100d0869f0e78781499f0 (patch)
tree09f7e7261e3cc3f3962dde8f6cebf7c443e53972 /src
parentfa16642f4a35c212fbbbf8deabb9c85499d56c2e (diff)
parentd94e8a50643c726503df9e37822b7c6877b25c86 (diff)
downloadsystemd-586e4850425090bb927100d0869f0e78781499f0.tar.gz
Merge pull request #22366 from poettering/journal-file-punch-fix
journald: some journal file hole punching fixes
Diffstat (limited to 'src')
-rw-r--r--src/journal/managed-journal-file.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/journal/managed-journal-file.c b/src/journal/managed-journal-file.c
index 5b5555315d..657cf5ebbf 100644
--- a/src/journal/managed-journal-file.c
+++ b/src/journal/managed-journal-file.c
@@ -5,6 +5,7 @@
#include "chattr-util.h"
#include "copy.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "journal-authenticate.h"
@@ -73,9 +74,15 @@ static int managed_journal_file_entry_array_punch_hole(JournalFile *f, uint64_t
return 0;
if (p == le64toh(f->header->tail_object_offset) && !f->seal) {
+ ssize_t n;
+
o.object.size = htole64(offset - p);
- if (pwrite(f->fd, &o, sizeof(EntryArrayObject), p) < 0)
+
+ n = pwrite(f->fd, &o, sizeof(EntryArrayObject), p);
+ if (n < 0)
return log_debug_errno(errno, "Failed to modify entry array object size: %m");
+ if ((size_t) n != sizeof(EntryArrayObject))
+ return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Short pwrite() while modifying entry array object size.");
f->header->arena_size = htole64(ALIGN64(offset) - le64toh(f->header->header_size));
@@ -85,8 +92,14 @@ static int managed_journal_file_entry_array_punch_hole(JournalFile *f, uint64_t
return 0;
}
- if (fallocate(f->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, sz) < 0)
+ if (fallocate(f->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, sz) < 0) {
+ if (ERRNO_IS_NOT_SUPPORTED(errno)) {
+ log_debug("Hole punching not supported by backing file system, skipping.");
+ return -EOPNOTSUPP; /* Make recognizable */
+ }
+
return log_debug_errno(errno, "Failed to punch hole in entry array of %s: %m", f->path);
+ }
return 0;
}
@@ -106,9 +119,10 @@ static int managed_journal_file_punch_holes(JournalFile *f) {
sz = le64toh(f->header->data_hash_table_size);
for (uint64_t i = p; i < p + sz && n > 0; i += n) {
- n = pread(f->fd, items, MIN(sizeof(items), p + sz - i), i);
+ size_t m = MIN(sizeof(items), p + sz - i);
+ n = pread(f->fd, items, m, i);
if (n < 0)
- return n;
+ return log_debug_errno(errno, "Failed to read hash table items: %m");
/* Let's ignore any partial hash items by rounding down to the nearest multiple of HashItem. */
n -= n % sizeof(HashItem);
@@ -128,8 +142,12 @@ static int managed_journal_file_punch_holes(JournalFile *f) {
if (le64toh(o.data.n_entries) == 0)
continue;
- (void) managed_journal_file_entry_array_punch_hole(
- f, le64toh(o.data.entry_array_offset), le64toh(o.data.n_entries) - 1);
+ r = managed_journal_file_entry_array_punch_hole(
+ f, le64toh(o.data.entry_array_offset), le64toh(o.data.n_entries) - 1);
+ if (r == -EOPNOTSUPP)
+ return -EOPNOTSUPP;
+
+ /* Ignore other errors */
}
}
}