Skip to content

Commit 4b2f459

Browse files
dgchinnerChandan Babu R
authored andcommitted
xfs: fix SEEK_HOLE/DATA for regions with active COW extents
A data corruption problem was reported by CoreOS image builders when using reflink based disk image copies and then converting them to qcow2 images. The converted images failed the conversion verification step, and it was isolated down to the fact that qemu-img uses SEEK_HOLE/SEEK_DATA to find the data it is supposed to copy. The reproducer allowed me to isolate the issue down to a region of the file that had overlapping data and COW fork extents, and the problem was that the COW fork extent was being reported in it's entirity by xfs_seek_iomap_begin() and so skipping over the real data fork extents in that range. This was somewhat hidden by the fact that 'xfs_bmap -vvp' reported all the extents correctly, and reading the file completely (i.e. not using seek to skip holes) would map the file correctly and all the correct data extents are read. Hence the problem is isolated to just the xfs_seek_iomap_begin() implementation. Instrumentation with trace_printk made the problem obvious: we are passing the wrong length to xfs_trim_extent() in xfs_seek_iomap_begin(). We are passing the end_fsb, not the maximum length of the extent we want to trim the map too. Hence the COW extent map never gets trimmed to the start of the next data fork extent, and so the seek code treats the entire COW fork extent as unwritten and skips entirely over the data fork extents in that range. Link: coreos/coreos-assembler#3728 Fixes: 60271ab ("xfs: fix SEEK_DATA for speculative COW fork preallocation") Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent e5a2f47 commit 4b2f459

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

fs/xfs/xfs_iomap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ xfs_seek_iomap_begin(
13231323
if (cow_fsb != NULLFILEOFF && cow_fsb <= offset_fsb) {
13241324
if (data_fsb < cow_fsb + cmap.br_blockcount)
13251325
end_fsb = min(end_fsb, data_fsb);
1326-
xfs_trim_extent(&cmap, offset_fsb, end_fsb);
1326+
xfs_trim_extent(&cmap, offset_fsb, end_fsb - offset_fsb);
13271327
seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);
13281328
error = xfs_bmbt_to_iomap(ip, iomap, &cmap, flags,
13291329
IOMAP_F_SHARED, seq);
@@ -1348,7 +1348,7 @@ xfs_seek_iomap_begin(
13481348
imap.br_state = XFS_EXT_NORM;
13491349
done:
13501350
seq = xfs_iomap_inode_sequence(ip, 0);
1351-
xfs_trim_extent(&imap, offset_fsb, end_fsb);
1351+
xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
13521352
error = xfs_bmbt_to_iomap(ip, iomap, &imap, flags, 0, seq);
13531353
out_unlock:
13541354
xfs_iunlock(ip, lockmode);

0 commit comments

Comments
 (0)