]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-file-util: use COPY_VERIFY_LINKED
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 15 Feb 2024 13:46:06 +0000 (22:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 15 Feb 2024 18:48:18 +0000 (03:48 +0900)
As the main thread may call journal_directory_vacuum() ->
unlinkat_deallocate() while another thread is copying the file.

Fixes #24150 and #31222.

src/shared/journal-file-util.c

index b9c44442c314f4d75df26fd852adea530502396e..8df165d2f144f9db833768b2bf68c71b137e3f46 100644 (file)
@@ -210,11 +210,15 @@ static void journal_file_set_offline_internal(JournalFile *f) {
 
                                 log_debug_errno(r, "Failed to re-enable copy-on-write for %s: %m, rewriting file", f->path);
 
+                                /* Here, setting COPY_VERIFY_LINKED flag is crucial. Otherwise, a broken
+                                 * journal file may be created, if journal_directory_vacuum() ->
+                                 * unlinkat_deallocate() is called in the main thread while this thread is
+                                 * copying the file. See issue #24150 and #31222. */
                                 r = copy_file_atomic_at_full(
                                                 f->fd, NULL, AT_FDCWD, f->path, f->mode,
                                                 0,
                                                 FS_NOCOW_FL,
-                                                COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS,
+                                                COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS | COPY_VERIFY_LINKED,
                                                 NULL, NULL);
                                 if (r < 0) {
                                         log_debug_errno(r, "Failed to rewrite %s: %m", f->path);