summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-10-25 17:15:51 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-10-26 18:32:25 -0700
commit63e82146ad0e062258892ed36afe1e4afb0c01c3 (patch)
treef0d371d67f2cdcc40015eb51caa40b3989e7ff7d
parent3c543bb2bd33146991a10cb070c449f006c88e45 (diff)
xfs: parent repair should try the dcache first
If we need to find a directory's parent, try the dcache first. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/scrub/dir_repair.c7
-rw-r--r--fs/xfs/scrub/parent.h1
-rw-r--r--fs/xfs/scrub/parent_repair.c31
3 files changed, 38 insertions, 1 deletions
diff --git a/fs/xfs/scrub/dir_repair.c b/fs/xfs/scrub/dir_repair.c
index 641d0153f3a2..839d6030f8b4 100644
--- a/fs/xfs/scrub/dir_repair.c
+++ b/fs/xfs/scrub/dir_repair.c
@@ -1102,12 +1102,17 @@ xrep_dir_validate_parent(
/*
* If the directory salvage scan found no parent or found an obviously
- * incorrect parent, jump to the filesystem scan.
+ * incorrect parent, try asking the dcache for the parent.
+ *
+ * If the dcache doesn't know about a parent or the parent seems
+ * obviously incorrect, jump to the filesystem scan.
*
* Otherwise, if the alleged parent seems plausible, scan the directory
* to make sure it really points to us.
*/
if (!xrep_parent_acceptable(sc, rd->parent_ino))
+ rd->parent_ino = xrep_parent_check_dcache(sc->ip);
+ if (!xrep_parent_acceptable(sc, rd->parent_ino))
goto scan;
/*
diff --git a/fs/xfs/scrub/parent.h b/fs/xfs/scrub/parent.h
index 6c79f7f99e9e..62db392b19a5 100644
--- a/fs/xfs/scrub/parent.h
+++ b/fs/xfs/scrub/parent.h
@@ -14,5 +14,6 @@ typedef int (*xrep_parents_iter_fn)(struct xfs_inode *dp, struct xfs_name *name,
int xrep_scan_for_parents(struct xfs_scrub *sc, xfs_ino_t target_ino,
xrep_parents_iter_fn fn, void *data);
bool xrep_parent_acceptable(struct xfs_scrub *sc, xfs_ino_t ino);
+xfs_ino_t xrep_parent_check_dcache(struct xfs_inode *dp);
#endif /* __XFS_SCRUB_PARENT_H__ */
diff --git a/fs/xfs/scrub/parent_repair.c b/fs/xfs/scrub/parent_repair.c
index 9dc48d496af6..aa196acb5600 100644
--- a/fs/xfs/scrub/parent_repair.c
+++ b/fs/xfs/scrub/parent_repair.c
@@ -172,6 +172,37 @@ out_rele:
return error;
}
+/* Does the dcache have a parent for this directory? */
+xfs_ino_t
+xrep_parent_check_dcache(
+ struct xfs_inode *dp)
+{
+ struct inode *pip = NULL;
+ struct dentry *dentry, *parent;
+ xfs_ino_t ret = NULLFSINO;
+
+ ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
+
+ dentry = d_find_alias(VFS_I(dp));
+ if (!dentry)
+ goto out;
+
+ parent = dget_parent(dentry);
+ if (!parent)
+ goto out_dput;
+
+ pip = igrab(d_inode(parent));
+ dput(parent);
+
+ ret = pip->i_ino;
+ xfs_irele(XFS_I(pip));
+
+out_dput:
+ dput(dentry);
+out:
+ return ret;
+}
+
/* Is this an acceptable parent for the inode we're scrubbing? */
bool
xrep_parent_acceptable(