From b9aac0891c3fc8e16ca5e3c8d3ecece75eca814c Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Tue, 21 Apr 2020 15:08:43 -0700 Subject: xfs: clean up the metadata validation in xfs_swap_extent_rmap Bail out if there's something not right with either file's fork mappings. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_bmap_util.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index cc23a3e23e2d..2774939e176d 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1342,8 +1342,16 @@ xfs_swap_extent_rmap( &nimaps, 0); if (error) goto out; - ASSERT(nimaps == 1); - ASSERT(tirec.br_startblock != DELAYSTARTBLOCK); + if (nimaps != 1 || tirec.br_startblock == DELAYSTARTBLOCK) { + /* + * We should never get no mapping or a delalloc extent + * since the donor file should have been flushed by the + * caller. + */ + ASSERT(0); + error = -EINVAL; + goto out; + } trace_xfs_swap_extent_rmap_remap(tip, &tirec); ilen = tirec.br_blockcount; @@ -1360,8 +1368,17 @@ xfs_swap_extent_rmap( &nimaps, 0); if (error) goto out; - ASSERT(nimaps == 1); - ASSERT(tirec.br_startoff == irec.br_startoff); + if (nimaps != 1 || + tirec.br_startoff != irec.br_startoff) { + /* + * We should never get no mapping or a mapping + * for another offset, but bail out if that + * ever does. + */ + ASSERT(0); + error = -EFSCORRUPTED; + goto out; + } trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); /* Trim the extent. */ @@ -1400,11 +1417,9 @@ xfs_swap_extent_rmap( offset_fsb += ilen; } - tip->i_d.di_flags2 = tip_flags2; - return 0; - out: - trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); + if (error) + trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); tip->i_d.di_flags2 = tip_flags2; return error; } -- cgit v1.2.3