[PATCH 2/2] copy: always align to at least page size

Christoph Hellwig <[email protected]> Wed, 29 Jul 2026 14:58:57 +0200
Newsgroups org.kernel.vger.linux-xfs
Message-ID <[email protected]>
The buffers used by xfs_copy need to fit the alignment of both the source
and target.  As we can't rely on statx for more detailed information yet,
work around this by never going below the default page size alignment.

This fixes copy an image from an xfs file systems on a NVMe device that
only reqires dword alignment to a virtio_blk device that requires
512-byte alignment.

Signed-off-by: Christoph Hellwig <[email protected]>
---
 copy/xfs_copy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index ad18ceb1ac1b..5435c87dba38 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -673,6 +673,7 @@ main(int argc, char **argv)
 	if (S_ISREG(statbuf.st_mode))
 		source_is_file = 1;
 
+	wbuf_align = getpagesize();
 	if (source_is_file && platform_test_xfs_fd(source_fd))  {
 		if (fcntl(source_fd, F_SETFL, open_flags | O_DIRECT) < 0)  {
 			do_log(_("%s: Cannot set direct I/O flag on \"%s\".\n"),
@@ -685,13 +686,12 @@ main(int argc, char **argv)
 			die_perror();
 		}
 
-		wbuf_align = d.d_mem;
+		wbuf_align = max(wbuf_align, d.d_mem);
 		wbuf_size = min(d.d_maxiosz, 1 * 1024 * 1024);
 		wbuf_miniosize = d.d_miniosz;
 	} else  {
 		/* set arbitrary I/O params, miniosize at least 1 disk block */
 
-		wbuf_align = getpagesize();
 		wbuf_size = 1 * 1024 * 1024;
 		wbuf_miniosize = -1;	/* set after mounting source fs */
 	}
-- 
2.53.0