xfs: ask the dentry cache if it knows the parent of a directory
authorDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:54:54 +0000 (14:54 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:58:56 +0000 (14:58 -0700)
commit34c9382c128270d0f4c8b36783b30f3c8085b2dd
tree01f022310753b59b33c65ef21d8f11d2f57b491b
parentcc22edab9ea7f3ebcb61d41a417d4397e9b7b128
xfs: ask the dentry cache if it knows the parent of a directory

It's possible that the dentry cache can tell us the parent of a
directory.  Therefore, when repairing directory dot dot entries, query
the dcache as a last resort before scanning the entire filesystem.

A reviewer asks:

"How high is the chance that we actually have a valid dcache entry for a
file in a corrupted directory?"

There's a decent chance of this actually working.  Say you have a
1000-block directory foo, and block 980 gets corrupted.  Let's further
suppose that block 0 has a correct entry for ".." and "bar".  If someone
accesses /mnt/foo/bar, that will cause the dcache to create a dentry
from /mnt to /mnt/foo whose d_parent points back to /mnt.  If you then
want to rebuild the directory, XFS can obtain the parent from the dcache
without needing to wander into parent pointers or scan the filesystem to
find /mnt's connection to foo.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/scrub/dir_repair.c
fs/xfs/scrub/findparent.c
fs/xfs/scrub/findparent.h
fs/xfs/scrub/parent_repair.c
fs/xfs/scrub/trace.h