]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: simplify xfs_verify_rgbext
authorChristoph Hellwig <hch@lst.de>
Tue, 1 Oct 2024 07:00:30 +0000 (09:00 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 2 Oct 2024 07:04:25 +0000 (09:04 +0200)
Fold xfs_verify_rgbno into xfs_verify_rgbext so that the end only needs
to be calculated once, and so that the rtsb check only needs to be done
on the start.  Also use the proper helper to look for overflows.

Note: xfs_verify_rgbext should probably move into the rtrmap series
when rebased, as nothing in the rtgroups series uses it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_rtgroup.h

index 3d8e398c2b9de4a0ec61f305ac85a823ab950c9e..9020298029e62e6e253c7a1fdbb6fc15804cd186 100644 (file)
@@ -119,34 +119,38 @@ xfs_rtgroup_next(
        return xfs_rtgroup_next_range(mp, rtg, 0, mp->m_sb.sb_rgcount - 1);
 }
 
+/*
+ * Check that [@rgbno,@len] is a valid extent range in @rtg.
+ *
+ * Must only be used for RTG-enabled file systems.
+ */
 static inline bool
-xfs_verify_rgbno(
+xfs_verify_rgbext(
        struct xfs_rtgroup      *rtg,
-       xfs_rgblock_t           rgbno)
+       xfs_rgblock_t           rgbno,
+       xfs_rgblock_t           len)
 {
        struct xfs_mount        *mp = rtg_mount(rtg);
+       xfs_rgblock_t           rg_end = rtg->rtg_extents * mp->m_sb.sb_rextsize;
+       xfs_rgblock_t           end;
 
-       if (rgbno >= rtg->rtg_extents * mp->m_sb.sb_rextsize)
+       if (rgbno >= rg_end)
                return false;
-       if (xfs_has_rtsb(mp) && rtg_rgno(rtg) == 0 &&
-           rgbno < mp->m_sb.sb_rextsize)
+       if (check_add_overflow(rgbno, len - 1, &end))
                return false;
-       return true;
-}
-
-static inline bool
-xfs_verify_rgbext(
-       struct xfs_rtgroup      *rtg,
-       xfs_rgblock_t           rgbno,
-       xfs_rgblock_t           len)
-{
-       if (rgbno + len <= rgbno)
+       if (end >= rg_end)
                return false;
 
-       if (!xfs_verify_rgbno(rtg, rgbno))
-               return false;
+       /*
+        * Check that the extent does not overlap the superblock if there is
+        * one in this RTG.
+        */
+       if (xfs_has_rtsb(mp) && rtg_rgno(rtg) == 0) {
+               if (rgbno < mp->m_sb.sb_rextsize)
+                       return false;
+       }
 
-       return xfs_verify_rgbno(rtg, rgbno + len - 1);
+       return true;
 }
 
 static inline xfs_rtblock_t