xfs: detect and correct directory tree problems [v13.4 6/9]

Historically, checking the tree-ness of the directory tree structure has
 not been complete.  Cycles of subdirectories break the tree properties,
 as do subdirectories with multiple parents.  It's easy enough for DFS to
 detect problems as long as one of the participants is reachable from the
 root, but this technique cannot find unconnected cycles.
 
 Directory parent pointers change that, because we can discover all of
 these problems from a simple walk from a subdirectory towards the root.
 For each child we start with, if the walk terminates without reaching
 the root, we know the path is disconnected and ought to be attached to
 the lost and found.  If we find ourselves, we know this is a cycle and
 can delete an incoming edge.  If we find multiple paths to the root, we
 know to delete an incoming edge.
 
 Even better, once we've finished walking paths, we've identified the
 good ones and know which other path(s) to remove.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZih1NwAKCRBKO3ySh0YR
 pg8TAQD/usg8IEtpiHxiewnJPWrxnM5X3e4fmuHRz41pvCntnwD+Oa28Oa9Fmogf
 Y5AwmdLpy3qugvnHdxhQx4nGKiz8FAA=
 =wJgH
 -----END PGP SIGNATURE-----

Merge tag 'scrub-directory-tree-6.10_2024-04-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.10-mergeC

xfs: detect and correct directory tree problems

Historically, checking the tree-ness of the directory tree structure has
not been complete.  Cycles of subdirectories break the tree properties,
as do subdirectories with multiple parents.  It's easy enough for DFS to
detect problems as long as one of the participants is reachable from the
root, but this technique cannot find unconnected cycles.

Directory parent pointers change that, because we can discover all of
these problems from a simple walk from a subdirectory towards the root.
For each child we start with, if the walk terminates without reaching
the root, we know the path is disconnected and ought to be attached to
the lost and found.  If we find ourselves, we know this is a cycle and
can delete an incoming edge.  If we find multiple paths to the root, we
know to delete an incoming edge.

Even better, once we've finished walking paths, we've identified the
good ones and know which other path(s) to remove.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'scrub-directory-tree-6.10_2024-04-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: fix corruptions in the directory tree
  xfs: report directory tree corruption in the health information
  xfs: invalidate dirloop scrub path data when concurrent updates happen
  xfs: teach online scrub to find directory tree structure problems
This commit is contained in:
Chandan Babu R 2024-04-24 12:17:51 +05:30
commit f7cea94646
21 changed files with 2337 additions and 4 deletions