summaryrefslogtreecommitdiff
path: root/fs/xfs/scrub/reap.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2022-08-04 15:35:28 -0700
committerDarrick J. Wong <djwong@kernel.org>2022-10-14 14:16:40 -0700
commit88b49300630e969f7ee35645bc11921d56dc5c0c (patch)
tree76d8c9a9a1d2fe2c9994da06b16f3fb5e0dd9845 /fs/xfs/scrub/reap.c
parent4de959d6b0a2ab75bb9bc5e3ac0bbb3f87a10797 (diff)
xfs: repair problems in CoW forksrepair-file-mappings_2022-10-14
Try to repair errors that we see in file CoW forks so that we don't do stupid things like remap garbage into a file. There's not a lot we can do with the COW fork -- the ondisk metadata record only that the COW staging extents are owned by the refcount btree, which effectively means that we can't reconstruct this incore structure from scratch. Actually, this is even worse -- we can't touch written extents, because those map space that are actively under writeback, and there's not much to do with delalloc reservations. Hence we can only detect crosslinked unwritten extents and fix them by punching out the problematic parts and replacing them with delalloc extents. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs/scrub/reap.c')
-rw-r--r--fs/xfs/scrub/reap.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/fs/xfs/scrub/reap.c b/fs/xfs/scrub/reap.c
index 696e38061095..44d7094db601 100644
--- a/fs/xfs/scrub/reap.c
+++ b/fs/xfs/scrub/reap.c
@@ -20,6 +20,7 @@
#include "xfs_ialloc_btree.h"
#include "xfs_rmap.h"
#include "xfs_rmap_btree.h"
+#include "xfs_refcount.h"
#include "xfs_refcount_btree.h"
#include "xfs_extent_busy.h"
#include "xfs_ag.h"
@@ -313,6 +314,14 @@ xreap_agextent(
trace_xreap_dispose_unmap_extent(sc->sa.pag, agbno, *aglenp);
rs->force_roll = true;
+ if (rs->oinfo == &XFS_RMAP_OINFO_COW) {
+ /*
+ * If we're unmapping CoW staging extents, remove the
+ * records from the refcountbt as well.
+ */
+ xfs_refcount_free_cow_extent(sc->tp, fsbno, *aglenp);
+ return 0;
+ }
return xfs_rmap_free(sc->tp, sc->sa.agf_bp, sc->sa.pag, agbno,
*aglenp, rs->oinfo);
}
@@ -331,6 +340,22 @@ xreap_agextent(
return 0;
}
+ /*
+ * If we're getting rid of CoW staging extents, use deferred work items
+ * to remove the refcountbt records (which removes the rmap records)
+ * and free the extent. We're not worried about the system going down
+ * here because log recovery walks the refcount btree to clean out the
+ * CoW staging extents.
+ */
+ if (rs->oinfo == &XFS_RMAP_OINFO_COW) {
+ ASSERT(rs->resv == XFS_AG_RESV_NONE);
+
+ rs->force_roll = true;
+ xfs_refcount_free_cow_extent(sc->tp, fsbno, *aglenp);
+ __xfs_free_extent_later(sc->tp, fsbno, *aglenp, NULL, true);
+ return 0;
+ }
+
switch (rs->resv) {
case XFS_AG_RESV_AGFL:
ASSERT(*aglenp == 1);