From: Lennart Poettering Date: Wed, 2 Feb 2022 14:21:27 +0000 (+0100) Subject: journal: when copying journal file to undo NOCOW flag, go via fd X-Git-Tag: v251-rc1~365 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5d04cec867365a4b5d76e327df4ef8b7ad1e89c2;p=thirdparty%2Fsystemd.git journal: when copying journal file to undo NOCOW flag, go via fd We have the journal file open already, hence reference it via the fd insted of the file name. After all, some other tool might have renamed/deleted it already. Let's not actually reuse the fd though, since we want a separate file offset for the copying, hence just make it simply and reopen via /proc/self/fd/. Follow-up for d71ece3f0b85c7a3decc50143b68ac07fc5831ae --- diff --git a/src/journal/managed-journal-file.c b/src/journal/managed-journal-file.c index 8880329fa5e..5b5555315dc 100644 --- a/src/journal/managed-journal-file.c +++ b/src/journal/managed-journal-file.c @@ -192,7 +192,7 @@ static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) { log_debug_errno(r, "Failed to re-enable copy-on-write for %s: %m, rewriting file", f->file->path); - r = copy_file_atomic(f->file->path, f->file->path, f->file->mode, 0, FS_NOCOW_FL, COPY_REPLACE | COPY_FSYNC | COPY_HOLES); + r = copy_file_atomic(FORMAT_PROC_FD_PATH(f->file->fd), f->file->path, f->file->mode, 0, FS_NOCOW_FL, COPY_REPLACE | COPY_FSYNC | COPY_HOLES); if (r < 0) { log_debug_errno(r, "Failed to rewrite %s: %m", f->file->path); continue;