xfs: fix online repair block reaping [v26.1]

These patches fix a few problems that I noticed in the code that deals
 with old btree blocks after a successful repair.
 
 First, I observed that it is possible for repair to incorrectly
 invalidate and delete old btree blocks if they were crosslinked.  The
 solution here is to consult the reverse mappings for each block in the
 extent -- singly owned blocks are invalidated and freed, whereas for
 crosslinked blocks, we merely drop the incorrect reverse mapping.
 
 A largeish change in this patchset is moving the reaping code to a
 separate file, because the code are mostly interrelated static
 functions.  For now this also drops the ability to reap file blocks,
 which will return when we add the bmbt repair functions.
 
 Second, we convert the reap function to use EFIs so that we can commit
 to freeing as many blocks in as few transactions as we dare.  We would
 like to free as many old blocks as we can in the same transaction that
 commits the new structure to the ondisk filesystem to minimize the
 number of blocks that leak if the system crashes before the repair fully
 completes.
 
 The third change made in this series is to avoid tripping buffer cache
 assertions if we're merely scanning the buffer cache for buffers to
 invalidate, and find a non-stale buffer of the wrong length.  This is
 primarily cosmetic, but makes my life easier.
 
 The fourth change restructures the reaping code to try to process as many
 blocks in one go as possible, to reduce logging traffic.
 
 The last change switches the reaping mechanism to use per-AG bitmaps
 defined in a previous patchset.  This should reduce type confusion when
 reading the source code.
 
 This has been running on the djcloud for years with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZNT+WAAKCRBKO3ySh0YR
 pt1nAQDn4pjj8ugmH3mcbwE6pqOde52xvApWD6HM2gz7CJa17gEAyGNQu2tw8I15
 MJ15sGUq6LaNWBF5kZjLt3qpWykoLgk=
 =sVzo
 -----END PGP SIGNATURE-----

Merge tag 'repair-reap-fixes-6.6_2023-08-10' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.6-mergeA

xfs: fix online repair block reaping

These patches fix a few problems that I noticed in the code that deals
with old btree blocks after a successful repair.

First, I observed that it is possible for repair to incorrectly
invalidate and delete old btree blocks if they were crosslinked.  The
solution here is to consult the reverse mappings for each block in the
extent -- singly owned blocks are invalidated and freed, whereas for
crosslinked blocks, we merely drop the incorrect reverse mapping.

A largeish change in this patchset is moving the reaping code to a
separate file, because the code are mostly interrelated static
functions.  For now this also drops the ability to reap file blocks,
which will return when we add the bmbt repair functions.

Second, we convert the reap function to use EFIs so that we can commit
to freeing as many blocks in as few transactions as we dare.  We would
like to free as many old blocks as we can in the same transaction that
commits the new structure to the ondisk filesystem to minimize the
number of blocks that leak if the system crashes before the repair fully
completes.

The third change made in this series is to avoid tripping buffer cache
assertions if we're merely scanning the buffer cache for buffers to
invalidate, and find a non-stale buffer of the wrong length.  This is
primarily cosmetic, but makes my life easier.

The fourth change restructures the reaping code to try to process as many
blocks in one go as possible, to reduce logging traffic.

The last change switches the reaping mechanism to use per-AG bitmaps
defined in a previous patchset.  This should reduce type confusion when
reading the source code.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>

* tag 'repair-reap-fixes-6.6_2023-08-10' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: use per-AG bitmaps to reap unused AG metadata blocks during repair
  xfs: reap large AG metadata extents when possible
  xfs: allow scanning ranges of the buffer cache for live buffers
  xfs: rearrange xrep_reap_block to make future code flow easier
  xfs: use deferred frees to reap old btree blocks
  xfs: only allow reaping of per-AG blocks in xrep_reap_extents
  xfs: only invalidate blocks if we're going to free them
  xfs: move the post-repair block reaping code to a separate file
  xfs: cull repair code that will never get used
This commit is contained in:
Chandan Babu R 2023-08-18 12:45:06 +05:30
commit 81fbc5f930
11 changed files with 673 additions and 479 deletions