]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor realtime volume extent validation
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 7 Jan 2021 20:59:17 +0000 (15:59 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 7 Jan 2021 20:59:17 +0000 (15:59 -0500)
Source kernel commit: 18695ad4251462b33787b7e375dbda57c1969c8f

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_bmap.c
libxfs/xfs_types.c
libxfs/xfs_types.h

index 92361f30f5f5490791929ed887a58e9a095590c3..96fadc8f5c1d31753d6a79ce49d47483f1753520 100644 (file)
@@ -6219,20 +6219,13 @@ xfs_bmap_validate_extent(
        struct xfs_bmbt_irec    *irec)
 {
        struct xfs_mount        *mp = ip->i_mount;
-       xfs_fsblock_t           endfsb;
-       bool                    isrt;
 
-       if (irec->br_startblock + irec->br_blockcount <= irec->br_startblock)
-               return __this_address;
        if (irec->br_startoff + irec->br_blockcount <= irec->br_startoff)
                return __this_address;
 
-       isrt = XFS_IS_REALTIME_INODE(ip);
-       endfsb = irec->br_startblock + irec->br_blockcount - 1;
-       if (isrt && whichfork == XFS_DATA_FORK) {
-               if (!xfs_verify_rtbno(mp, irec->br_startblock))
-                       return __this_address;
-               if (!xfs_verify_rtbno(mp, endfsb))
+       if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) {
+               if (!xfs_verify_rtext(mp, irec->br_startblock,
+                                         irec->br_blockcount))
                        return __this_address;
        } else {
                if (!xfs_verify_fsbext(mp, irec->br_startblock,
index 3e6921e0137a0f75389059174c287cce835c6322..9d25de6bdfab73233ed7bdeac14130900c0028e3 100644 (file)
@@ -198,6 +198,22 @@ xfs_verify_rtbno(
        return rtbno < mp->m_sb.sb_rblocks;
 }
 
+/* Verify that a realtime device extent is fully contained inside the volume. */
+bool
+xfs_verify_rtext(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtbno,
+       xfs_rtblock_t           len)
+{
+       if (rtbno + len <= rtbno)
+               return false;
+
+       if (!xfs_verify_rtbno(mp, rtbno))
+               return false;
+
+       return xfs_verify_rtbno(mp, rtbno + len - 1);
+}
+
 /* Calculate the range of valid icount values. */
 void
 xfs_icount_range(
index 7feaaac25b3d76ee95c3c40463c4b99d08cb994b..18e83ce465681513c0f92bb6ac9aef82ed0fa620 100644 (file)
@@ -197,6 +197,8 @@ bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
 bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
 bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
+bool xfs_verify_rtext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
+               xfs_rtblock_t len);
 bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
 bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
 void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,