Skip to content

Commit e8882f6

Browse files
author
Darrick J. Wong
committed
xfs: split the xchk_bmap_check_rmaps into a predicate
This function has two parts: the second part scans every reverse mapping record for this file fork to make sure that there's a corresponding mapping in the fork, and the first part decides if we even want to do that. Split the first part into a separate predicate so that we can make more changes to it in the next patch. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent 336642f commit e8882f6

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

fs/xfs/scrub/bmap.c

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -635,28 +635,28 @@ xchk_bmap_check_ag_rmaps(
635635
return error;
636636
}
637637

638-
/* Make sure each rmap has a corresponding bmbt entry. */
639-
STATIC int
640-
xchk_bmap_check_rmaps(
641-
struct xfs_scrub *sc,
642-
int whichfork)
638+
/*
639+
* Decide if we want to walk every rmap btree in the fs to make sure that each
640+
* rmap for this file fork has corresponding bmbt entries.
641+
*/
642+
static bool
643+
xchk_bmap_want_check_rmaps(
644+
struct xchk_bmap_info *info)
643645
{
644-
struct xfs_ifork *ifp = xfs_ifork_ptr(sc->ip, whichfork);
645-
struct xfs_perag *pag;
646-
xfs_agnumber_t agno;
646+
struct xfs_scrub *sc = info->sc;
647+
struct xfs_ifork *ifp;
647648
bool zero_size;
648-
int error;
649649

650-
if (!xfs_has_rmapbt(sc->mp) ||
651-
whichfork == XFS_COW_FORK ||
652-
(sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
653-
return 0;
650+
if (!xfs_has_rmapbt(sc->mp))
651+
return false;
652+
if (info->whichfork == XFS_COW_FORK)
653+
return false;
654+
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
655+
return false;
654656

655657
/* Don't support realtime rmap checks yet. */
656-
if (XFS_IS_REALTIME_INODE(sc->ip) && whichfork == XFS_DATA_FORK)
657-
return 0;
658-
659-
ASSERT(xfs_ifork_ptr(sc->ip, whichfork) != NULL);
658+
if (info->is_rt)
659+
return false;
660660

661661
/*
662662
* Only do this for complex maps that are in btree format, or for
@@ -666,14 +666,28 @@ xchk_bmap_check_rmaps(
666666
* reattached.
667667
*/
668668

669-
if (whichfork == XFS_DATA_FORK)
669+
if (info->whichfork == XFS_DATA_FORK)
670670
zero_size = i_size_read(VFS_I(sc->ip)) == 0;
671671
else
672672
zero_size = false;
673673

674+
ifp = xfs_ifork_ptr(sc->ip, info->whichfork);
674675
if (ifp->if_format != XFS_DINODE_FMT_BTREE &&
675676
(zero_size || ifp->if_nextents > 0))
676-
return 0;
677+
return false;
678+
679+
return true;
680+
}
681+
682+
/* Make sure each rmap has a corresponding bmbt entry. */
683+
STATIC int
684+
xchk_bmap_check_rmaps(
685+
struct xfs_scrub *sc,
686+
int whichfork)
687+
{
688+
struct xfs_perag *pag;
689+
xfs_agnumber_t agno;
690+
int error;
677691

678692
for_each_perag(sc->mp, agno, pag) {
679693
error = xchk_bmap_check_ag_rmaps(sc, whichfork, pag);
@@ -915,9 +929,11 @@ xchk_bmap(
915929
memcpy(&info.prev_rec, &irec, sizeof(struct xfs_bmbt_irec));
916930
}
917931

918-
error = xchk_bmap_check_rmaps(sc, whichfork);
919-
if (!xchk_fblock_xref_process_error(sc, whichfork, 0, &error))
920-
goto out;
932+
if (xchk_bmap_want_check_rmaps(&info)) {
933+
error = xchk_bmap_check_rmaps(sc, whichfork);
934+
if (!xchk_fblock_xref_process_error(sc, whichfork, 0, &error))
935+
goto out;
936+
}
921937
out:
922938
return error;
923939
}

0 commit comments

Comments
 (0)