From: Chandan Babu R Date: Sat, 23 Jan 2021 00:48:14 +0000 (-0800) Subject: xfs: Check for extent overflow when writing to unwritten extent X-Git-Tag: accepted/tizen/unified/20230118.172025~7707^2~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c442f3086d5a108b7ff086c8ade1923a8f389db5;p=platform%2Fkernel%2Flinux-rpi.git xfs: Check for extent overflow when writing to unwritten extent 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 Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 8d89838..917e289 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -71,6 +71,15 @@ struct xfs_ifork { (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. */ diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 32246d90..8f4b27c 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -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. */