Skip to content

Commit b764ea2

Browse files
dchinnerdgchinner
authored andcommitted
Merge tag 'btree-hoist-scrub-checks-6.4_2023-04-11' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into guilt/xfs-for-next
xfs: hoist scrub record checks into libxfs [v24.5] There are a few things about btree records that scrub checked but the libxfs _get_rec functions didn't. Move these bits into libxfs so that everyone can benefit. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Dave Chinner <david@fromorbit.com>
2 parents 01822a7 + de1a9ce commit b764ea2

4 files changed

Lines changed: 31 additions & 28 deletions

File tree

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ xfs_inobt_check_irec(
103103
{
104104
uint64_t realfree;
105105

106+
/* Record has to be properly aligned within the AG. */
106107
if (!xfs_verify_agino(cur->bc_ag.pag, irec->ir_startino))
107108
return __this_address;
109+
if (!xfs_verify_agino(cur->bc_ag.pag,
110+
irec->ir_startino + XFS_INODES_PER_CHUNK - 1))
111+
return __this_address;
108112
if (irec->ir_count < XFS_INODES_PER_HOLEMASK_BIT ||
109113
irec->ir_count > XFS_INODES_PER_CHUNK)
110114
return __this_address;

fs/xfs/libxfs/xfs_rmap.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ xfs_rmap_check_irec(
212212
const struct xfs_rmap_irec *irec)
213213
{
214214
struct xfs_mount *mp = cur->bc_mp;
215+
bool is_inode;
216+
bool is_unwritten;
217+
bool is_bmbt;
218+
bool is_attr;
215219

216220
if (irec->rm_blockcount == 0)
217221
return __this_address;
@@ -232,6 +236,29 @@ xfs_rmap_check_irec(
232236
irec->rm_owner >= XFS_RMAP_OWN_MIN)))
233237
return __this_address;
234238

239+
/* Check flags. */
240+
is_inode = !XFS_RMAP_NON_INODE_OWNER(irec->rm_owner);
241+
is_bmbt = irec->rm_flags & XFS_RMAP_BMBT_BLOCK;
242+
is_attr = irec->rm_flags & XFS_RMAP_ATTR_FORK;
243+
is_unwritten = irec->rm_flags & XFS_RMAP_UNWRITTEN;
244+
245+
if (is_bmbt && irec->rm_offset != 0)
246+
return __this_address;
247+
248+
if (!is_inode && irec->rm_offset != 0)
249+
return __this_address;
250+
251+
if (is_unwritten && (is_bmbt || !is_inode || is_attr))
252+
return __this_address;
253+
254+
if (!is_inode && (is_bmbt || is_unwritten || is_attr))
255+
return __this_address;
256+
257+
/* Check for a valid fork offset, if applicable. */
258+
if (is_inode && !is_bmbt &&
259+
!xfs_verify_fileext(mp, irec->rm_offset, irec->rm_blockcount))
260+
return __this_address;
261+
235262
return NULL;
236263
}
237264

fs/xfs/scrub/ialloc.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ xchk_iallocbt_rec(
413413
const union xfs_btree_rec *rec)
414414
{
415415
struct xfs_mount *mp = bs->cur->bc_mp;
416-
struct xfs_perag *pag = bs->cur->bc_ag.pag;
417416
struct xchk_iallocbt *iabt = bs->private;
418417
struct xfs_inobt_rec_incore irec;
419418
uint64_t holes;
@@ -431,11 +430,6 @@ xchk_iallocbt_rec(
431430
}
432431

433432
agino = irec.ir_startino;
434-
/* Record has to be properly aligned within the AG. */
435-
if (!xfs_verify_agino(pag, agino + XFS_INODES_PER_CHUNK - 1)) {
436-
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
437-
goto out;
438-
}
439433

440434
xchk_iallocbt_rec_alignment(bs, &irec);
441435
if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)

fs/xfs/scrub/rmap.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,35 +94,13 @@ xchk_rmapbt_rec(
9494
const union xfs_btree_rec *rec)
9595
{
9696
struct xfs_rmap_irec irec;
97-
bool non_inode;
98-
bool is_unwritten;
99-
bool is_bmbt;
100-
bool is_attr;
10197

10298
if (xfs_rmap_btrec_to_irec(rec, &irec) != NULL ||
10399
xfs_rmap_check_irec(bs->cur, &irec) != NULL) {
104100
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
105101
return 0;
106102
}
107103

108-
/* Check flags. */
109-
non_inode = XFS_RMAP_NON_INODE_OWNER(irec.rm_owner);
110-
is_bmbt = irec.rm_flags & XFS_RMAP_BMBT_BLOCK;
111-
is_attr = irec.rm_flags & XFS_RMAP_ATTR_FORK;
112-
is_unwritten = irec.rm_flags & XFS_RMAP_UNWRITTEN;
113-
114-
if (is_bmbt && irec.rm_offset != 0)
115-
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
116-
117-
if (non_inode && irec.rm_offset != 0)
118-
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
119-
120-
if (is_unwritten && (is_bmbt || non_inode || is_attr))
121-
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
122-
123-
if (non_inode && (is_bmbt || is_unwritten || is_attr))
124-
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
125-
126104
xchk_rmapbt_xref(bs->sc, &irec);
127105
return 0;
128106
}

0 commit comments

Comments
 (0)