summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Disseldorp <ddiss@suse.de>2025-08-19 13:05:46 +1000
committerNathan Chancellor <nathan@kernel.org>2025-08-20 16:02:55 -0700
commit97169cd6d95b338f2dbf5d3154b7d2233fce7d8a (patch)
treefe4c7b350c929d4148dd5a07cb10674b2a210732
parentae18b94099b04264b32e33b057114024bc72c993 (diff)
gen_init_cpio: attempt copy_file_range for file data
The copy_file_range syscall can improve copy performance by cloning extents between cpio archive source and destination files. Existing read / write based copy logic is retained for fallback in case the copy_file_range syscall is unsupported or unavailable due to cross-filesystem EXDEV, etc. Clone or reflink, as opposed to copy, of source file extents into the output cpio archive may (e.g. on Btrfs and XFS) require alignment of the output to the filesystem block size. This could be achieved by inserting padding entries into the cpio archive manifest. Signed-off-by: David Disseldorp <ddiss@suse.de> Reviewed-by: Nicolas Schier <nsc@kernel.org> Link: https://lore.kernel.org/r/20250819032607.28727-4-ddiss@suse.de Signed-off-by: Nathan Chancellor <nathan@kernel.org>
-rw-r--r--usr/gen_init_cpio.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index ea4b9b5fed01..aa73afd3756c 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -354,6 +354,7 @@ static int cpio_mkfile(const char *name, const char *location,
int namesize;
unsigned int i;
uint32_t csum = 0;
+ ssize_t this_read;
mode |= S_IFREG;
@@ -429,9 +430,19 @@ static int cpio_mkfile(const char *name, const char *location,
push_pad(padlen(offset, 4)) < 0)
goto error;
+ if (size) {
+ this_read = copy_file_range(file, NULL, outfd, NULL, size, 0);
+ if (this_read > 0) {
+ if (this_read > size)
+ goto error;
+ offset += this_read;
+ size -= this_read;
+ }
+ /* short or failed copy falls back to read/write... */
+ }
+
while (size) {
unsigned char filebuf[65536];
- ssize_t this_read;
size_t this_size = MIN(size, sizeof(filebuf));
this_read = read(file, filebuf, this_size);