xfs: fixup the metabtree reservation in xrep_reap_metadir_fsblocks
authorChristoph Hellwig <hch@lst.de>
Sat, 15 Feb 2025 06:43:02 +0000 (07:43 +0100)
committerChristoph Hellwig <hch@lst.de>
Mon, 3 Mar 2025 15:16:43 +0000 (08:16 -0700)
All callers of xrep_reap_metadir_fsblocks need to fix up the metabtree
reservation, otherwise they'd leave the reservations in an incoherent
state.  Move the call to xrep_reset_metafile_resv into
xrep_reap_metadir_fsblocks so it always is taken care of, and remove
now superfluous helper functions in the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
fs/xfs/scrub/reap.c
fs/xfs/scrub/rtrefcount_repair.c
fs/xfs/scrub/rtrmap_repair.c

index b32fb233cf847672e4798d2ae0c6ab160e244b31..8703897c0a9ccb958dd1dab9c76081c0ef908881 100644 (file)
@@ -935,10 +935,13 @@ xrep_reap_metadir_fsblocks(
        if (error)
                return error;
 
-       if (xreap_dirty(&rs))
-               return xrep_defer_finish(sc);
+       if (xreap_dirty(&rs)) {
+               error = xrep_defer_finish(sc);
+               if (error)
+                       return error;
+       }
 
-       return 0;
+       return xrep_reset_metafile_resv(sc);
 }
 
 /*
index 257cfb24beb428df29f1bdfeeab827bceb6bd842..983362447826dec2eebfc0cdb3fbd6bc8b136c7c 100644 (file)
@@ -697,32 +697,6 @@ err_cur:
        return error;
 }
 
-/*
- * Now that we've logged the roots of the new btrees, invalidate all of the
- * old blocks and free them.
- */
-STATIC int
-xrep_rtrefc_remove_old_tree(
-       struct xrep_rtrefc      *rr)
-{
-       int                     error;
-
-       /*
-        * Free all the extents that were allocated to the former rtrefcountbt
-        * and aren't cross-linked with something else.
-        */
-       error = xrep_reap_metadir_fsblocks(rr->sc,
-                       &rr->old_rtrefcountbt_blocks);
-       if (error)
-               return error;
-
-       /*
-        * Ensure the proper reservation for the rtrefcount inode so that we
-        * don't fail to expand the btree.
-        */
-       return xrep_reset_metafile_resv(rr->sc);
-}
-
 /* Rebuild the rt refcount btree. */
 int
 xrep_rtrefcountbt(
@@ -769,8 +743,12 @@ xrep_rtrefcountbt(
        if (error)
                goto out_bitmap;
 
-       /* Kill the old tree. */
-       error = xrep_rtrefc_remove_old_tree(rr);
+       /*
+        * Free all the extents that were allocated to the former rtrefcountbt
+        * and aren't cross-linked with something else.
+        */
+       error = xrep_reap_metadir_fsblocks(rr->sc,
+                       &rr->old_rtrefcountbt_blocks);
        if (error)
                goto out_bitmap;
 
index f2fdd7a9fc248342c3f66550a483707c92ef7c26..fc2592c53af56926a9adcc6929acf9ddd4ef2e32 100644 (file)
@@ -810,28 +810,6 @@ err_cur:
 
 /* Reaping the old btree. */
 
-/* Reap the old rtrmapbt blocks. */
-STATIC int
-xrep_rtrmap_remove_old_tree(
-       struct xrep_rtrmap      *rr)
-{
-       int                     error;
-
-       /*
-        * Free all the extents that were allocated to the former rtrmapbt and
-        * aren't cross-linked with something else.
-        */
-       error = xrep_reap_metadir_fsblocks(rr->sc, &rr->old_rtrmapbt_blocks);
-       if (error)
-               return error;
-
-       /*
-        * Ensure the proper reservation for the rtrmap inode so that we don't
-        * fail to expand the new btree.
-        */
-       return xrep_reset_metafile_resv(rr->sc);
-}
-
 static inline bool
 xrep_rtrmapbt_want_live_update(
        struct xchk_iscan               *iscan,
@@ -995,8 +973,11 @@ xrep_rtrmapbt(
        if (error)
                goto out_records;
 
-       /* Kill the old tree. */
-       error = xrep_rtrmap_remove_old_tree(rr);
+       /*
+        * Free all the extents that were allocated to the former rtrmapbt and
+        * aren't cross-linked with something else.
+        */
+       error = xrep_reap_metadir_fsblocks(rr->sc, &rr->old_rtrmapbt_blocks);
        if (error)
                goto out_records;