diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2017-04-12 15:26:07 -0400 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2017-05-03 16:21:40 -0400 |
commit | fe0be23e68200573de027de9b8cc2b27e7fce35e (patch) | |
tree | a40dfe8284fd34d5cadca3bfee63fad922655946 /fs/xfs/xfs_reflink.c | |
parent | e20c8a517f259cb4d258e10b0cd5d4b30d4167a0 (diff) |
xfs: reserve enough blocks to handle btree splits when remapping
In xfs_reflink_end_cow, we erroneously reserve only enough blocks to
handle adding 1 extent. This is problematic if we fragment free space,
have to do CoW, and then have to perform multiple bmap btree expansions.
Furthermore, the BUI recovery routine doesn't reserve /any/ blocks to
handle btree splits, so log recovery fails after our first error causes
the filesystem to go down.
Therefore, refactor the transaction block reservation macros until we
have a macro that works for our deferred (re)mapping activities, and fix
both problems by using that macro.
With 1k blocks we can hit this fairly often in g/187 if the scratch fs
is big enough.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/xfs_reflink.c')
-rw-r--r-- | fs/xfs/xfs_reflink.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index c0f3754caca2..ffe6fe7a7eb5 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c | |||
@@ -705,8 +705,22 @@ xfs_reflink_end_cow( | |||
705 | offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); | 705 | offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); |
706 | end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count); | 706 | end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count); |
707 | 707 | ||
708 | /* Start a rolling transaction to switch the mappings */ | 708 | /* |
709 | resblks = XFS_EXTENTADD_SPACE_RES(ip->i_mount, XFS_DATA_FORK); | 709 | * Start a rolling transaction to switch the mappings. We're |
710 | * unlikely ever to have to remap 16T worth of single-block | ||
711 | * extents, so just cap the worst case extent count to 2^32-1. | ||
712 | * Stick a warning in just in case, and avoid 64-bit division. | ||
713 | */ | ||
714 | BUILD_BUG_ON(MAX_RW_COUNT > UINT_MAX); | ||
715 | if (end_fsb - offset_fsb > UINT_MAX) { | ||
716 | error = -EFSCORRUPTED; | ||
717 | xfs_force_shutdown(ip->i_mount, SHUTDOWN_CORRUPT_INCORE); | ||
718 | ASSERT(0); | ||
719 | goto out; | ||
720 | } | ||
721 | resblks = XFS_NEXTENTADD_SPACE_RES(ip->i_mount, | ||
722 | (unsigned int)(end_fsb - offset_fsb), | ||
723 | XFS_DATA_FORK); | ||
710 | error = xfs_trans_alloc(ip->i_mount, &M_RES(ip->i_mount)->tr_write, | 724 | error = xfs_trans_alloc(ip->i_mount, &M_RES(ip->i_mount)->tr_write, |
711 | resblks, 0, 0, &tp); | 725 | resblks, 0, 0, &tp); |
712 | if (error) | 726 | if (error) |