Skip to content

Commit

Permalink
xfs: Check for extent overflow when writing to unwritten extent
Browse files Browse the repository at this point in the history
A write to a sub-interval of an existing unwritten extent causes
the original extent to be split into 3 extents
i.e. | Unwritten | Real | Unwritten |
Hence extent count can increase 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 3a19bb1 commit c442f30
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 @@ -70,6 +70,15 @@ struct xfs_ifork {
#define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \
(XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks))

/*
* A write to a sub-interval of an existing unwritten extent causes the original
* extent to be split into 3 extents
* i.e. | Unwritten | Real | Unwritten |
* Hence extent count can increase by 2.
*/
#define XFS_IEXT_WRITE_UNWRITTEN_CNT (2)


/*
* Fork handling.
*/
Expand Down
5 changes: 5 additions & 0 deletions fs/xfs/xfs_iomap.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ xfs_iomap_write_unwritten(
if (error)
goto error_on_bmapi_transaction;

error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
XFS_IEXT_WRITE_UNWRITTEN_CNT);
if (error)
goto error_on_bmapi_transaction;

/*
* Modify the unwritten extent state of the buffer.
*/
Expand Down

0 comments on commit c442f30

Please sign in to comment.