Skip to content

Commit

Permalink
Merge tag 'btree-hoist-scrub-checks-6.4_2023-04-11' of git://git.kern…
Browse files Browse the repository at this point in the history
…el.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 <[email protected]>
Signed-off-by: Dave Chinner <[email protected]>
  • Loading branch information
dchinner authored and Dave Chinner committed Apr 13, 2023
2 parents 01822a7 + de1a9ce commit b764ea2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
4 changes: 4 additions & 0 deletions fs/xfs/libxfs/xfs_ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ xfs_inobt_check_irec(
{
uint64_t realfree;

/* Record has to be properly aligned within the AG. */
if (!xfs_verify_agino(cur->bc_ag.pag, irec->ir_startino))
return __this_address;
if (!xfs_verify_agino(cur->bc_ag.pag,
irec->ir_startino + XFS_INODES_PER_CHUNK - 1))
return __this_address;
if (irec->ir_count < XFS_INODES_PER_HOLEMASK_BIT ||
irec->ir_count > XFS_INODES_PER_CHUNK)
return __this_address;
Expand Down
27 changes: 27 additions & 0 deletions fs/xfs/libxfs/xfs_rmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ xfs_rmap_check_irec(
const struct xfs_rmap_irec *irec)
{
struct xfs_mount *mp = cur->bc_mp;
bool is_inode;
bool is_unwritten;
bool is_bmbt;
bool is_attr;

if (irec->rm_blockcount == 0)
return __this_address;
Expand All @@ -232,6 +236,29 @@ xfs_rmap_check_irec(
irec->rm_owner >= XFS_RMAP_OWN_MIN)))
return __this_address;

/* Check flags. */
is_inode = !XFS_RMAP_NON_INODE_OWNER(irec->rm_owner);
is_bmbt = irec->rm_flags & XFS_RMAP_BMBT_BLOCK;
is_attr = irec->rm_flags & XFS_RMAP_ATTR_FORK;
is_unwritten = irec->rm_flags & XFS_RMAP_UNWRITTEN;

if (is_bmbt && irec->rm_offset != 0)
return __this_address;

if (!is_inode && irec->rm_offset != 0)
return __this_address;

if (is_unwritten && (is_bmbt || !is_inode || is_attr))
return __this_address;

if (!is_inode && (is_bmbt || is_unwritten || is_attr))
return __this_address;

/* Check for a valid fork offset, if applicable. */
if (is_inode && !is_bmbt &&
!xfs_verify_fileext(mp, irec->rm_offset, irec->rm_blockcount))
return __this_address;

return NULL;
}

Expand Down
6 changes: 0 additions & 6 deletions fs/xfs/scrub/ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ xchk_iallocbt_rec(
const union xfs_btree_rec *rec)
{
struct xfs_mount *mp = bs->cur->bc_mp;
struct xfs_perag *pag = bs->cur->bc_ag.pag;
struct xchk_iallocbt *iabt = bs->private;
struct xfs_inobt_rec_incore irec;
uint64_t holes;
Expand All @@ -431,11 +430,6 @@ xchk_iallocbt_rec(
}

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

xchk_iallocbt_rec_alignment(bs, &irec);
if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
Expand Down
22 changes: 0 additions & 22 deletions fs/xfs/scrub/rmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,13 @@ xchk_rmapbt_rec(
const union xfs_btree_rec *rec)
{
struct xfs_rmap_irec irec;
bool non_inode;
bool is_unwritten;
bool is_bmbt;
bool is_attr;

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

/* Check flags. */
non_inode = XFS_RMAP_NON_INODE_OWNER(irec.rm_owner);
is_bmbt = irec.rm_flags & XFS_RMAP_BMBT_BLOCK;
is_attr = irec.rm_flags & XFS_RMAP_ATTR_FORK;
is_unwritten = irec.rm_flags & XFS_RMAP_UNWRITTEN;

if (is_bmbt && irec.rm_offset != 0)
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);

if (non_inode && irec.rm_offset != 0)
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);

if (is_unwritten && (is_bmbt || non_inode || is_attr))
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);

if (non_inode && (is_bmbt || is_unwritten || is_attr))
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);

xchk_rmapbt_xref(bs->sc, &irec);
return 0;
}
Expand Down

0 comments on commit b764ea2

Please sign in to comment.