Skip to content

Commit

Permalink
xfs: Check for extent overflow when moving extent from cow to data fork
Browse files Browse the repository at this point in the history
Moving an extent to data fork can cause a sub-interval of an existing
extent to be unmapped. This will increase extent count by 1. Mapping in
the new extent can increase the extent count by 1 again i.e.
 | Old extent | New extent | Old extent |
Hence number of extents increases by 2.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
  • Loading branch information
Chandan Babu R authored and Darrick J. Wong committed Jan 23, 2021
1 parent c442f30 commit 5f1d5bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fs/xfs/libxfs/xfs_inode_fork.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ struct xfs_ifork {
#define XFS_IEXT_WRITE_UNWRITTEN_CNT (2)


/*
* Moving an extent to data fork can cause a sub-interval of an existing extent
* to be unmapped. This will increase extent count by 1. Mapping in the new
* extent can increase the extent count by 1 again i.e.
* | Old extent | New extent | Old extent |
* Hence number of extents increases by 2.
*/
#define XFS_IEXT_REFLINK_END_COW_CNT (2)

/*
* Fork handling.
*/
Expand Down
5 changes: 5 additions & 0 deletions fs/xfs/xfs_reflink.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,11 @@ xfs_reflink_end_cow_extent(
xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip, 0);

error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
XFS_IEXT_REFLINK_END_COW_CNT);
if (error)
goto out_cancel;

/*
* 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
Expand Down

0 comments on commit 5f1d5bb

Please sign in to comment.