summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2022-07-14 11:06:57 -0700
committerDarrick J. Wong <djwong@kernel.org>2022-10-14 14:16:55 -0700
commitfda03069f8f633b69603624b89ba6a9a2ceb77a4 (patch)
tree15d3aa645625bcecd87d3385378146e694f5c166
parent7ae15be4ced5d9da0732370b067945448a9923b1 (diff)
xfs: ask the dentry cache if it knows the parent of a directoryrepair-dirs_2022-10-14
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. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/scrub/dir_repair.c27
-rw-r--r--fs/xfs/scrub/parent.h1
-rw-r--r--fs/xfs/scrub/parent_repair.c44
-rw-r--r--fs/xfs/scrub/trace.h1
4 files changed, 73 insertions, 0 deletions
diff --git a/fs/xfs/scrub/dir_repair.c b/fs/xfs/scrub/dir_repair.c
index e7d52c77456b..825f291b9402 100644
--- a/fs/xfs/scrub/dir_repair.c
+++ b/fs/xfs/scrub/dir_repair.c
@@ -1040,6 +1040,29 @@ xrep_dir_lookup_parent(
return parent_ino;
}
+/*
+ * Look up '..' in the dentry cache and confirm that it's really the parent.
+ * Returns NULLFSINO if the dcache misses or if the hit is implausible.
+ */
+static inline xfs_ino_t
+xrep_dir_dcache_parent(
+ struct xrep_dir *rd)
+{
+ struct xfs_scrub *sc = rd->sc;
+ xfs_ino_t parent_ino;
+ int error;
+
+ parent_ino = xrep_parent_from_dcache(sc);
+ if (parent_ino == NULLFSINO)
+ return parent_ino;
+
+ error = xrep_parent_confirm(sc, &parent_ino);
+ if (error)
+ return NULLFSINO;
+
+ return parent_ino;
+}
+
/* Try to find the parent of the directory being repaired. */
STATIC int
xrep_dir_find_parent(
@@ -1051,6 +1074,10 @@ xrep_dir_find_parent(
if (rd->parent_ino != NULLFSINO)
return 0;
+ rd->parent_ino = xrep_dir_dcache_parent(rd);
+ if (rd->parent_ino != NULLFSINO)
+ return 0;
+
rd->parent_ino = xrep_dir_lookup_parent(rd);
if (rd->parent_ino != NULLFSINO)
return 0;
diff --git a/fs/xfs/scrub/parent.h b/fs/xfs/scrub/parent.h
index e1979f5bb001..c20673d8f093 100644
--- a/fs/xfs/scrub/parent.h
+++ b/fs/xfs/scrub/parent.h
@@ -10,6 +10,7 @@ int xchk_parent_lock_two_dirs(struct xfs_scrub *sc, struct xfs_inode *dp);
int xrep_parent_confirm(struct xfs_scrub *sc, xfs_ino_t *parent_ino);
int xrep_parent_scan(struct xfs_scrub *sc, xfs_ino_t *parent_ino);
+xfs_ino_t xrep_parent_from_dcache(struct xfs_scrub *sc);
xfs_ino_t xrep_parent_self_reference(struct xfs_scrub *sc);
diff --git a/fs/xfs/scrub/parent_repair.c b/fs/xfs/scrub/parent_repair.c
index 1d01d00a1501..99fd0363da43 100644
--- a/fs/xfs/scrub/parent_repair.c
+++ b/fs/xfs/scrub/parent_repair.c
@@ -255,6 +255,44 @@ out_rele:
return error;
}
+/* Check the dentry cache to see if knows of a parent for the scrub target. */
+xfs_ino_t
+xrep_parent_from_dcache(
+ struct xfs_scrub *sc)
+{
+ struct inode *pip = NULL;
+ struct dentry *dentry, *parent;
+ xfs_ino_t ret = NULLFSINO;
+
+ dentry = d_find_alias(VFS_I(sc->ip));
+ if (!dentry)
+ goto out;
+
+ parent = dget_parent(dentry);
+ if (!parent)
+ goto out_dput;
+
+ if (parent->d_sb != sc->ip->i_mount->m_super) {
+ dput(parent);
+ goto out_dput;
+ }
+
+ pip = igrab(d_inode(parent));
+ dput(parent);
+
+ if (S_ISDIR(pip->i_mode)) {
+ trace_xrep_findparent_from_dcache(sc->ip, XFS_I(pip)->i_ino);
+ ret = XFS_I(pip)->i_ino;
+ }
+
+ xchk_irele(sc, XFS_I(pip));
+
+out_dput:
+ dput(dentry);
+out:
+ return ret;
+}
+
/*
* Scan the entire filesystem looking for a parent inode for the inode being
* scrubbed. @sc->ip must not be the root of a directory tree.
@@ -384,6 +422,12 @@ xrep_parent(
if (parent_ino != NULLFSINO)
goto reset_parent;
+ /* Does the VFS dcache have an answer for us? */
+ parent_ino = xrep_parent_from_dcache(sc);
+ error = xrep_parent_confirm(sc, &parent_ino);
+ if (!error && parent_ino != NULLFSINO)
+ goto reset_parent;
+
/* Scan the entire filesystem for a parent. */
error = xrep_parent_scan(sc, &parent_ino);
if (error)
diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h
index 3ce859a23119..09d984c42368 100644
--- a/fs/xfs/scrub/trace.h
+++ b/fs/xfs/scrub/trace.h
@@ -2505,6 +2505,7 @@ DEFINE_EVENT(xrep_parent_salvage_class, name, \
TP_ARGS(dp, ino))
DEFINE_XREP_PARENT_SALVAGE_CLASS(xrep_dir_salvaged_parent);
DEFINE_XREP_PARENT_SALVAGE_CLASS(xrep_findparent_dirent);
+DEFINE_XREP_PARENT_SALVAGE_CLASS(xrep_findparent_from_dcache);
#endif /* IS_ENABLED(CONFIG_XFS_ONLINE_REPAIR) */