summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-04-21 15:08:43 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-05-06 17:58:36 -0700
commitb9aac0891c3fc8e16ca5e3c8d3ecece75eca814c (patch)
tree6293972066f055823ebd03213a03dc33b2b34246
parentfd5aedb204492a160e431dcfc1eff319de34916e (diff)
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 <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/xfs_bmap_util.c31
1 files 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;
}