Skip to content

Commit 18695ad

Browse files
committed
xfs: refactor realtime volume extent validation
Refactor all the open-coded validation of realtime device extents into a single helper. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent 67457eb commit 18695ad

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6226,20 +6226,13 @@ xfs_bmap_validate_extent(
62266226
struct xfs_bmbt_irec *irec)
62276227
{
62286228
struct xfs_mount *mp = ip->i_mount;
6229-
xfs_fsblock_t endfsb;
6230-
bool isrt;
62316229

6232-
if (irec->br_startblock + irec->br_blockcount <= irec->br_startblock)
6233-
return __this_address;
62346230
if (irec->br_startoff + irec->br_blockcount <= irec->br_startoff)
62356231
return __this_address;
62366232

6237-
isrt = XFS_IS_REALTIME_INODE(ip);
6238-
endfsb = irec->br_startblock + irec->br_blockcount - 1;
6239-
if (isrt && whichfork == XFS_DATA_FORK) {
6240-
if (!xfs_verify_rtbno(mp, irec->br_startblock))
6241-
return __this_address;
6242-
if (!xfs_verify_rtbno(mp, endfsb))
6233+
if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) {
6234+
if (!xfs_verify_rtext(mp, irec->br_startblock,
6235+
irec->br_blockcount))
62436236
return __this_address;
62446237
} else {
62456238
if (!xfs_verify_fsbext(mp, irec->br_startblock,

fs/xfs/libxfs/xfs_types.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ xfs_verify_rtbno(
198198
return rtbno < mp->m_sb.sb_rblocks;
199199
}
200200

201+
/* Verify that a realtime device extent is fully contained inside the volume. */
202+
bool
203+
xfs_verify_rtext(
204+
struct xfs_mount *mp,
205+
xfs_rtblock_t rtbno,
206+
xfs_rtblock_t len)
207+
{
208+
if (rtbno + len <= rtbno)
209+
return false;
210+
211+
if (!xfs_verify_rtbno(mp, rtbno))
212+
return false;
213+
214+
return xfs_verify_rtbno(mp, rtbno + len - 1);
215+
}
216+
201217
/* Calculate the range of valid icount values. */
202218
void
203219
xfs_icount_range(

fs/xfs/libxfs/xfs_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
197197
bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
198198
bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
199199
bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
200+
bool xfs_verify_rtext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
201+
xfs_rtblock_t len);
200202
bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
201203
bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
202204
void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,

fs/xfs/scrub/bmap.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ xchk_bmap_iextent(
319319
struct xfs_bmbt_irec *irec)
320320
{
321321
struct xfs_mount *mp = info->sc->mp;
322-
xfs_filblks_t end;
323322
int error = 0;
324323

325324
/*
@@ -349,13 +348,8 @@ xchk_bmap_iextent(
349348
if (irec->br_blockcount > MAXEXTLEN)
350349
xchk_fblock_set_corrupt(info->sc, info->whichfork,
351350
irec->br_startoff);
352-
if (irec->br_startblock + irec->br_blockcount <= irec->br_startblock)
353-
xchk_fblock_set_corrupt(info->sc, info->whichfork,
354-
irec->br_startoff);
355-
end = irec->br_startblock + irec->br_blockcount - 1;
356351
if (info->is_rt &&
357-
(!xfs_verify_rtbno(mp, irec->br_startblock) ||
358-
!xfs_verify_rtbno(mp, end)))
352+
!xfs_verify_rtext(mp, irec->br_startblock, irec->br_blockcount))
359353
xchk_fblock_set_corrupt(info->sc, info->whichfork,
360354
irec->br_startoff);
361355
if (!info->is_rt &&

fs/xfs/scrub/rtbitmap.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ xchk_rtbitmap_rec(
5252
startblock = rec->ar_startext * tp->t_mountp->m_sb.sb_rextsize;
5353
blockcount = rec->ar_extcount * tp->t_mountp->m_sb.sb_rextsize;
5454

55-
if (startblock + blockcount <= startblock ||
56-
!xfs_verify_rtbno(sc->mp, startblock) ||
57-
!xfs_verify_rtbno(sc->mp, startblock + blockcount - 1))
55+
if (!xfs_verify_rtext(sc->mp, startblock, blockcount))
5856
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
5957
return 0;
6058
}

0 commit comments

Comments
 (0)