Commit 67457eb0 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: refactor data device extent validation

Refactor all the open-coded validation of non-static data device extents
into a single helper.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
parent 4b80ac64
...@@ -6242,12 +6242,8 @@ xfs_bmap_validate_extent( ...@@ -6242,12 +6242,8 @@ xfs_bmap_validate_extent(
if (!xfs_verify_rtbno(mp, endfsb)) if (!xfs_verify_rtbno(mp, endfsb))
return __this_address; return __this_address;
} else { } else {
if (!xfs_verify_fsbno(mp, irec->br_startblock)) if (!xfs_verify_fsbext(mp, irec->br_startblock,
return __this_address; irec->br_blockcount))
if (!xfs_verify_fsbno(mp, endfsb))
return __this_address;
if (XFS_FSB_TO_AGNO(mp, irec->br_startblock) !=
XFS_FSB_TO_AGNO(mp, endfsb))
return __this_address; return __this_address;
} }
if (irec->br_state != XFS_EXT_NORM && whichfork != XFS_DATA_FORK) if (irec->br_state != XFS_EXT_NORM && whichfork != XFS_DATA_FORK)
......
...@@ -61,6 +61,29 @@ xfs_verify_fsbno( ...@@ -61,6 +61,29 @@ xfs_verify_fsbno(
return xfs_verify_agbno(mp, agno, XFS_FSB_TO_AGBNO(mp, fsbno)); return xfs_verify_agbno(mp, agno, XFS_FSB_TO_AGBNO(mp, fsbno));
} }
/*
* Verify that a data device extent is fully contained inside the filesystem,
* does not cross an AG boundary, and does not point at static metadata.
*/
bool
xfs_verify_fsbext(
struct xfs_mount *mp,
xfs_fsblock_t fsbno,
xfs_fsblock_t len)
{
if (fsbno + len <= fsbno)
return false;
if (!xfs_verify_fsbno(mp, fsbno))
return false;
if (!xfs_verify_fsbno(mp, fsbno + len - 1))
return false;
return XFS_FSB_TO_AGNO(mp, fsbno) ==
XFS_FSB_TO_AGNO(mp, fsbno + len - 1);
}
/* Calculate the first and last possible inode number in an AG. */ /* Calculate the first and last possible inode number in an AG. */
void void
xfs_agino_range( xfs_agino_range(
......
...@@ -184,6 +184,8 @@ xfs_agblock_t xfs_ag_block_count(struct xfs_mount *mp, xfs_agnumber_t agno); ...@@ -184,6 +184,8 @@ xfs_agblock_t xfs_ag_block_count(struct xfs_mount *mp, xfs_agnumber_t agno);
bool xfs_verify_agbno(struct xfs_mount *mp, xfs_agnumber_t agno, bool xfs_verify_agbno(struct xfs_mount *mp, xfs_agnumber_t agno,
xfs_agblock_t agbno); xfs_agblock_t agbno);
bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno); bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
bool xfs_verify_fsbext(struct xfs_mount *mp, xfs_fsblock_t fsbno,
xfs_fsblock_t len);
void xfs_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno, void xfs_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno,
xfs_agino_t *first, xfs_agino_t *last); xfs_agino_t *first, xfs_agino_t *last);
......
...@@ -359,10 +359,7 @@ xchk_bmap_iextent( ...@@ -359,10 +359,7 @@ xchk_bmap_iextent(
xchk_fblock_set_corrupt(info->sc, info->whichfork, xchk_fblock_set_corrupt(info->sc, info->whichfork,
irec->br_startoff); irec->br_startoff);
if (!info->is_rt && if (!info->is_rt &&
(!xfs_verify_fsbno(mp, irec->br_startblock) || !xfs_verify_fsbext(mp, irec->br_startblock, irec->br_blockcount))
!xfs_verify_fsbno(mp, end) ||
XFS_FSB_TO_AGNO(mp, irec->br_startblock) !=
XFS_FSB_TO_AGNO(mp, end)))
xchk_fblock_set_corrupt(info->sc, info->whichfork, xchk_fblock_set_corrupt(info->sc, info->whichfork,
irec->br_startoff); irec->br_startoff);
......
...@@ -448,16 +448,7 @@ xfs_bui_validate( ...@@ -448,16 +448,7 @@ xfs_bui_validate(
if (bmap->me_startoff + bmap->me_len <= bmap->me_startoff) if (bmap->me_startoff + bmap->me_len <= bmap->me_startoff)
return false; return false;
if (bmap->me_startblock + bmap->me_len <= bmap->me_startblock) return xfs_verify_fsbext(mp, bmap->me_startblock, bmap->me_len);
return false;
if (!xfs_verify_fsbno(mp, bmap->me_startblock))
return false;
if (!xfs_verify_fsbno(mp, bmap->me_startblock + bmap->me_len - 1))
return false;
return true;
} }
/* /*
......
...@@ -584,16 +584,7 @@ xfs_efi_validate_ext( ...@@ -584,16 +584,7 @@ xfs_efi_validate_ext(
struct xfs_mount *mp, struct xfs_mount *mp,
struct xfs_extent *extp) struct xfs_extent *extp)
{ {
if (extp->ext_start + extp->ext_len <= extp->ext_start) return xfs_verify_fsbext(mp, extp->ext_start, extp->ext_len);
return false;
if (!xfs_verify_fsbno(mp, extp->ext_start))
return false;
if (!xfs_verify_fsbno(mp, extp->ext_start + extp->ext_len - 1))
return false;
return true;
} }
/* /*
......
...@@ -439,16 +439,7 @@ xfs_cui_validate_phys( ...@@ -439,16 +439,7 @@ xfs_cui_validate_phys(
return false; return false;
} }
if (refc->pe_startblock + refc->pe_len <= refc->pe_startblock) return xfs_verify_fsbext(mp, refc->pe_startblock, refc->pe_len);
return false;
if (!xfs_verify_fsbno(mp, refc->pe_startblock))
return false;
if (!xfs_verify_fsbno(mp, refc->pe_startblock + refc->pe_len - 1))
return false;
return true;
} }
/* /*
......
...@@ -493,16 +493,7 @@ xfs_rui_validate_map( ...@@ -493,16 +493,7 @@ xfs_rui_validate_map(
if (rmap->me_startoff + rmap->me_len <= rmap->me_startoff) if (rmap->me_startoff + rmap->me_len <= rmap->me_startoff)
return false; return false;
if (rmap->me_startblock + rmap->me_len <= rmap->me_startblock) return xfs_verify_fsbext(mp, rmap->me_startblock, rmap->me_len);
return false;
if (!xfs_verify_fsbno(mp, rmap->me_startblock))
return false;
if (!xfs_verify_fsbno(mp, rmap->me_startblock + rmap->me_len - 1))
return false;
return true;
} }
/* /*
......
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