Commit 1b4998dc authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Greg Kroah-Hartman
Browse files

xfs: handle racy AIO in xfs_reflink_end_cow



commit e12199f8 upstream.

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 002295a6
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -767,7 +767,13 @@ xfs_reflink_end_cow(

	/* If there is a hole at end_fsb - 1 go to the previous extent */
	if (eof || got.br_startoff > end_fsb) {
		ASSERT(idx > 0);
		/*
		 * In case of racing, overlapping AIO writes no COW extents
		 * might be left by the time I/O completes for the loser of
		 * the race.  In that case we are done.
		 */
		if (idx <= 0)
			goto out_cancel;
		xfs_bmbt_get_all(xfs_iext_get_ext(ifp, --idx), &got);
	}

@@ -841,6 +847,7 @@ next_extent:

out_defer:
	xfs_defer_cancel(&dfops);
out_cancel:
	xfs_trans_cancel(tp);
	xfs_iunlock(ip, XFS_ILOCK_EXCL);
out: