summaryrefslogtreecommitdiff
path: root/fs/xfs/scrub/nlinks.h
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 11:25:16 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-10-22 16:41:14 -0700
commitaa7bbb4df5d4f26f134b67f7a4218a2c7a116d50 (patch)
treed81b793c3bf5840db2a0bb7b52f051b354a453f7 /fs/xfs/scrub/nlinks.h
parenta96548dece0c260f61a0007e7f45ae968802b8c6 (diff)
xfs: teach scrub to check file nlinks
Copy-pasta the online quotacheck code to check inode link counts too. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs/scrub/nlinks.h')
-rw-r--r--fs/xfs/scrub/nlinks.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/fs/xfs/scrub/nlinks.h b/fs/xfs/scrub/nlinks.h
new file mode 100644
index 000000000000..0ece2ab5dd38
--- /dev/null
+++ b/fs/xfs/scrub/nlinks.h
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 Oracle. All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef __XFS_SCRUB_NLINKS_H__
+#define __XFS_SCRUB_NLINKS_H__
+
+/* Live link count control structure. */
+struct xchk_nlink_ctrs {
+ struct xfs_scrub *sc;
+
+ /* Shadow link count data and its mutex. */
+ struct xfarray *nlinks;
+ struct mutex lock;
+
+ /*
+ * The collection step uses a separate iscan context from the compare
+ * step because the collection iscan coordinates live updates to the
+ * observation data while this scanner is running. The compare iscan
+ * is secondary and can be reinitialized as needed.
+ */
+ struct xchk_iscan collect_iscan;
+ struct xchk_iscan compare_iscan;
+
+ /*
+ * Hook into bumplink/droplink so that we can receive live updates
+ * from other writer threads.
+ */
+ struct notifier_block nlink_delta_hook;
+};
+
+struct xchk_nlink {
+ /* Links from a parent directory to this inode. */
+ xfs_nlink_t parent;
+
+ /* Links from children of this inode (e.g. dot and dotdot). */
+ xfs_nlink_t child;
+
+ /* Record state flags */
+ unsigned int flags;
+};
+
+/* This data item was seen by the check-time compare function. */
+#define XCHK_NLINK_COMPARE_SCANNED (1U << 0)
+
+/* Compute total link count, using large enough variables to detect overflow. */
+static inline uint64_t
+xchk_nlink_total(const struct xchk_nlink *live)
+{
+ uint64_t ret = live->parent;
+
+ return ret + live->child;
+}
+
+#endif /* __XFS_SCRUB_NLINKS_H__ */