Skip to content

Commit 4d7fc77

Browse files
committed
journal-file-util: use COPY_VERIFY_LINKED
As the main thread may call journal_directory_vacuum() -> unlinkat_deallocate() while another thread is copying the file. Fixes systemd#24150 and systemd#31222.
1 parent 62749bb commit 4d7fc77

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/shared/journal-file-util.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,15 @@ static void journal_file_set_offline_internal(JournalFile *f) {
210210

211211
log_debug_errno(r, "Failed to re-enable copy-on-write for %s: %m, rewriting file", f->path);
212212

213+
/* Here, setting COPY_VERIFY_LINKED flag is crucial. Otherwise, a broken
214+
* journal file may be created, if journal_directory_vacuum() ->
215+
* unlinkat_deallocate() is called in the main thread while this thread is
216+
* copying the file. See issue #24150 and #31222. */
213217
r = copy_file_atomic_at_full(
214218
f->fd, NULL, AT_FDCWD, f->path, f->mode,
215219
0,
216220
FS_NOCOW_FL,
217-
COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS,
221+
COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS | COPY_VERIFY_LINKED,
218222
NULL, NULL);
219223
if (r < 0) {
220224
log_debug_errno(r, "Failed to rewrite %s: %m", f->path);

0 commit comments

Comments
 (0)