Skip to content

Commit e12199f

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: handle racy AIO in xfs_reflink_end_cow
If we got two AIO writes into a COW area the second one might not have any COW extents left to convert. Handle that case gracefully instead of triggering an assert or accessing beyond the bounds of the extent list. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 52bfcdd commit e12199f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/xfs/xfs_reflink.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,13 @@ xfs_reflink_end_cow(
736736
/* If there is a hole at end_fsb - 1 go to the previous extent */
737737
if (!xfs_iext_lookup_extent(ip, ifp, end_fsb - 1, &idx, &got) ||
738738
got.br_startoff > end_fsb) {
739-
ASSERT(idx > 0);
739+
/*
740+
* In case of racing, overlapping AIO writes no COW extents
741+
* might be left by the time I/O completes for the loser of
742+
* the race. In that case we are done.
743+
*/
744+
if (idx <= 0)
745+
goto out_cancel;
740746
xfs_iext_get_extent(ifp, --idx, &got);
741747
}
742748

@@ -809,6 +815,7 @@ xfs_reflink_end_cow(
809815

810816
out_defer:
811817
xfs_defer_cancel(&dfops);
818+
out_cancel:
812819
xfs_trans_cancel(tp);
813820
xfs_iunlock(ip, XFS_ILOCK_EXCL);
814821
out:

0 commit comments

Comments
 (0)