Commit e8882f69 authored by Darrick J. Wong's avatar Darrick J. Wong

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: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent 336642f7
...@@ -635,28 +635,28 @@ xchk_bmap_check_ag_rmaps( ...@@ -635,28 +635,28 @@ xchk_bmap_check_ag_rmaps(
return error; return error;
} }
/* Make sure each rmap has a corresponding bmbt entry. */ /*
STATIC int * Decide if we want to walk every rmap btree in the fs to make sure that each
xchk_bmap_check_rmaps( * rmap for this file fork has corresponding bmbt entries.
struct xfs_scrub *sc, */
int whichfork) static bool
xchk_bmap_want_check_rmaps(
struct xchk_bmap_info *info)
{ {
struct xfs_ifork *ifp = xfs_ifork_ptr(sc->ip, whichfork); struct xfs_scrub *sc = info->sc;
struct xfs_perag *pag; struct xfs_ifork *ifp;
xfs_agnumber_t agno;
bool zero_size; bool zero_size;
int error;
if (!xfs_has_rmapbt(sc->mp) || if (!xfs_has_rmapbt(sc->mp))
whichfork == XFS_COW_FORK || return false;
(sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) if (info->whichfork == XFS_COW_FORK)
return 0; return false;
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
return false;
/* Don't support realtime rmap checks yet. */ /* Don't support realtime rmap checks yet. */
if (XFS_IS_REALTIME_INODE(sc->ip) && whichfork == XFS_DATA_FORK) if (info->is_rt)
return 0; return false;
ASSERT(xfs_ifork_ptr(sc->ip, whichfork) != NULL);
/* /*
* Only do this for complex maps that are in btree format, or for * Only do this for complex maps that are in btree format, or for
...@@ -666,14 +666,28 @@ xchk_bmap_check_rmaps( ...@@ -666,14 +666,28 @@ xchk_bmap_check_rmaps(
* reattached. * reattached.
*/ */
if (whichfork == XFS_DATA_FORK) if (info->whichfork == XFS_DATA_FORK)
zero_size = i_size_read(VFS_I(sc->ip)) == 0; zero_size = i_size_read(VFS_I(sc->ip)) == 0;
else else
zero_size = false; zero_size = false;
ifp = xfs_ifork_ptr(sc->ip, info->whichfork);
if (ifp->if_format != XFS_DINODE_FMT_BTREE && if (ifp->if_format != XFS_DINODE_FMT_BTREE &&
(zero_size || ifp->if_nextents > 0)) (zero_size || ifp->if_nextents > 0))
return 0; return false;
return true;
}
/* Make sure each rmap has a corresponding bmbt entry. */
STATIC int
xchk_bmap_check_rmaps(
struct xfs_scrub *sc,
int whichfork)
{
struct xfs_perag *pag;
xfs_agnumber_t agno;
int error;
for_each_perag(sc->mp, agno, pag) { for_each_perag(sc->mp, agno, pag) {
error = xchk_bmap_check_ag_rmaps(sc, whichfork, pag); error = xchk_bmap_check_ag_rmaps(sc, whichfork, pag);
...@@ -915,9 +929,11 @@ xchk_bmap( ...@@ -915,9 +929,11 @@ xchk_bmap(
memcpy(&info.prev_rec, &irec, sizeof(struct xfs_bmbt_irec)); memcpy(&info.prev_rec, &irec, sizeof(struct xfs_bmbt_irec));
} }
error = xchk_bmap_check_rmaps(sc, whichfork); if (xchk_bmap_want_check_rmaps(&info)) {
if (!xchk_fblock_xref_process_error(sc, whichfork, 0, &error)) error = xchk_bmap_check_rmaps(sc, whichfork);
goto out; if (!xchk_fblock_xref_process_error(sc, whichfork, 0, &error))
goto out;
}
out: out:
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment