diff options
author | Chandan Babu R <chandanrlinux@gmail.com> | 2021-01-22 16:48:14 -0800 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2021-01-22 16:54:48 -0800 |
commit | c442f3086d5a108b7ff086c8ade1923a8f389db5 (patch) | |
tree | 25464ffb363d5d2d092acb124d61feb885c6c8c7 | |
parent | 3a19bb147c72d2e9b77137bf5130b9cfb50a5eef (diff) | |
download | linux-c442f3086d5a108b7ff086c8ade1923a8f389db5.tar.bz2 |
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 <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>
-rw-r--r-- | fs/xfs/libxfs/xfs_inode_fork.h | 9 | ||||
-rw-r--r-- | fs/xfs/xfs_iomap.c | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 8d89838e23f8..917e289ad962 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 32246d90b9cb..8f4b27cded20 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. */ |