Re: [PATCH 5/5] xfs: ask the dentry cache if it knows the parent of a directory

Darrick J. Wong
2024-03-29T19:52:46Z

On Wed, Mar 27, 2024 at 04:16:31AM -0700, Christoph Hellwig wrote:
> On Tue, Mar 26, 2024 at 07:04:50PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > 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.
>
> The code looks fine, but how high is the chance that we actually have
> a valid dcache entry for a file in a corrupted directory?

Decent. Say you have a 1000-block directory foo, and block 980 gets
corrupted. Let's further suppose that block 0 has an entry for ".." and
"bar". If someone accesses /mnt/foo/bar, won't that 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, we 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.

--D