fix xfs_copy betwen devices with mismatching sizes
This fixes copy between devices with different alignment requirements. xfs/601 trigges this when TEST_DIR is on a device that requires minimal alignment, but SCRATCH_DEV is on a device that requires more alignment.
PATCH 1/2 copy: log the error number when failing to write
Log the string form of the errno value to help debugging a failed write.
--- copy/xfs_copy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
copy/xfs_copy.c +2 -2
@@ -891,8 +891,8 @@ main(int argc, char **argv) off -=XFS_MAX_SECTORSIZE ; len =pwrite (target[i].fd, lb,XFS_MAX_SECTORSIZE , off);if (len <0 ) { -do_log (_ ("%s: failed to write last block\n" ), - progname); +do_log (_ ("%s: failed to write last block: %s\n" ), + progname,strerror (errno));do_log (_ ("\tIs target \"%s\" too small?\n" ), target[i].name);die_perror ();
Signature · 1 line
2.53.0
Re: [PATCH 1/2] copy: log the error number when failing to write
Quoted 3 lines · Christoph Hellwig
Log the string form of the errno value to help debugging a failed write.
Signed-off-by Christoph Hellwig <[email protected]>
Good idea!
--D
Quoted 23 lines
--- copy/xfs_copy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)copy/xfs_copy.c +2
-2@@ -891,8 +891,8 @@ main(int argc, char **argv) off -=XFS_MAX_SECTORSIZE ; len =pwrite (target[i].fd, lb,XFS_MAX_SECTORSIZE , off);if (len <0 ) { -do_log (_ ("%s: failed to write last block\n" ), - progname); +do_log (_ ("%s: failed to write last block: %s\n" ), + progname,strerror (errno));do_log (_ ("\tIs target \"%s\" too small?\n" ), target[i].name);die_perror ();Signature · 1 line
2.53.0
PATCH 2/2 copy: always align to at least page size
In reply to Christoph HellwigThe 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.
--- copy/xfs_copy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
copy/xfs_copy.c +2 -2
@@ -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 */ }
Signature · 1 line
2.53.0
Re: [PATCH 2/2] copy: always align to at least page size
Quoted 9 lines · Christoph Hellwig
The buffers used by
xfs_copyneed 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_blkdevice that requires 512-byte alignment.Signed-off-by Christoph Hellwig <[email protected]>
Mmmmmm, fun...
--D
Quoted 35 lines
--- copy/xfs_copy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)copy/xfs_copy.c +2
-2@@ -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 */ }Signature · 1 line
2.53.0