Skip to content

Commit 128d0fd

Browse files
author
Chandan Babu R
committed
Merge tag 'scrub-nlinks-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC
xfs: online repair of file link counts Now that we've created the infrastructure to perform live scans of every file in the filesystem and the necessary hook infrastructure to observe live updates, use it to scan directories to compute the correct link counts for files in the filesystem, and reset those link counts. This patchset creates a tailored readdir implementation for scrub because the regular version has to cycle ILOCKs to copy information to userspace. We can't cycle the ILOCK during the nlink scan and we don't need all the other VFS support code (maintaining a readdir cursor and translating XFS structures to VFS structures and back) so it was easier to duplicate the code. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org> * tag 'scrub-nlinks-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: teach repair to fix file nlinks xfs: track directory entry updates during live nlinks fsck xfs: teach scrub to check file nlinks xfs: report health of inode link counts
2 parents aa03f52 + 6b631c6 commit 128d0fd

21 files changed

Lines changed: 1623 additions & 4 deletions

fs/xfs/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ xfs-y += $(addprefix scrub/, \
160160
ialloc.o \
161161
inode.o \
162162
iscan.o \
163+
nlinks.o \
163164
parent.o \
164165
readdir.o \
165166
refcount.o \
@@ -193,6 +194,7 @@ xfs-y += $(addprefix scrub/, \
193194
ialloc_repair.o \
194195
inode_repair.o \
195196
newbt.o \
197+
nlinks_repair.o \
196198
reap.o \
197199
refcount_repair.o \
198200
repair.o \

fs/xfs/libxfs/xfs_fs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ struct xfs_fsop_geom {
196196
#define XFS_FSOP_GEOM_SICK_RT_BITMAP (1 << 4) /* realtime bitmap */
197197
#define XFS_FSOP_GEOM_SICK_RT_SUMMARY (1 << 5) /* realtime summary */
198198
#define XFS_FSOP_GEOM_SICK_QUOTACHECK (1 << 6) /* quota counts */
199+
#define XFS_FSOP_GEOM_SICK_NLINKS (1 << 7) /* inode link counts */
199200

200201
/* Output for XFS_FS_COUNTS */
201202
typedef struct xfs_fsop_counts {
@@ -711,9 +712,10 @@ struct xfs_scrub_metadata {
711712
#define XFS_SCRUB_TYPE_PQUOTA 23 /* project quotas */
712713
#define XFS_SCRUB_TYPE_FSCOUNTERS 24 /* fs summary counters */
713714
#define XFS_SCRUB_TYPE_QUOTACHECK 25 /* quota counters */
715+
#define XFS_SCRUB_TYPE_NLINKS 26 /* inode link counts */
714716

715717
/* Number of scrub subcommands. */
716-
#define XFS_SCRUB_TYPE_NR 26
718+
#define XFS_SCRUB_TYPE_NR 27
717719

718720
/* i: Repair this metadata. */
719721
#define XFS_SCRUB_IFLAG_REPAIR (1u << 0)

fs/xfs/libxfs/xfs_health.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct xfs_fsop_geom;
4242
#define XFS_SICK_FS_GQUOTA (1 << 2) /* group quota */
4343
#define XFS_SICK_FS_PQUOTA (1 << 3) /* project quota */
4444
#define XFS_SICK_FS_QUOTACHECK (1 << 4) /* quota counts */
45+
#define XFS_SICK_FS_NLINKS (1 << 5) /* inode link counts */
4546

4647
/* Observable health issues for realtime volume metadata. */
4748
#define XFS_SICK_RT_BITMAP (1 << 0) /* realtime bitmap */
@@ -79,7 +80,8 @@ struct xfs_fsop_geom;
7980
XFS_SICK_FS_UQUOTA | \
8081
XFS_SICK_FS_GQUOTA | \
8182
XFS_SICK_FS_PQUOTA | \
82-
XFS_SICK_FS_QUOTACHECK)
83+
XFS_SICK_FS_QUOTACHECK | \
84+
XFS_SICK_FS_NLINKS)
8385

8486
#define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \
8587
XFS_SICK_RT_SUMMARY)

fs/xfs/scrub/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,9 @@ xchk_fsgates_enable(
13021302
if (scrub_fsgates & XCHK_FSGATES_QUOTA)
13031303
xfs_dqtrx_hook_enable();
13041304

1305+
if (scrub_fsgates & XCHK_FSGATES_DIRENTS)
1306+
xfs_dir_hook_enable();
1307+
13051308
sc->flags |= scrub_fsgates;
13061309
}
13071310

fs/xfs/scrub/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ xchk_setup_quotacheck(struct xfs_scrub *sc)
129129
}
130130
#endif
131131
int xchk_setup_fscounters(struct xfs_scrub *sc);
132+
int xchk_setup_nlinks(struct xfs_scrub *sc);
132133

133134
void xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa);
134135
int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno,

fs/xfs/scrub/health.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static const struct xchk_health_map type_to_health_flag[XFS_SCRUB_TYPE_NR] = {
106106
[XFS_SCRUB_TYPE_PQUOTA] = { XHG_FS, XFS_SICK_FS_PQUOTA },
107107
[XFS_SCRUB_TYPE_FSCOUNTERS] = { XHG_FS, XFS_SICK_FS_COUNTERS },
108108
[XFS_SCRUB_TYPE_QUOTACHECK] = { XHG_FS, XFS_SICK_FS_QUOTACHECK },
109+
[XFS_SCRUB_TYPE_NLINKS] = { XHG_FS, XFS_SICK_FS_NLINKS },
109110
};
110111

111112
/* Return the health status mask for this scrub type. */

0 commit comments

Comments
 (0)