xfs: fix xfs_rtalloc_rec units
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 31 May 2018 16:12:10 +0000 (09:12 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Fri, 1 Jun 2018 16:00:16 +0000 (09:00 -0700)
All the realtime allocation functions deal with space on the rtdev in
units of realtime extents.  However, struct xfs_rtalloc_rec confusingly
uses the word 'block' in the name, even though they're really extents.

Fix the naming problem and fix all the unit handling problems in the two
existing users.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
fs/xfs/libxfs/xfs_rtbitmap.c
fs/xfs/scrub/rtbitmap.c
fs/xfs/xfs_fsmap.c
fs/xfs/xfs_rtalloc.h

index 1855182..369eeb7 100644 (file)
@@ -1036,17 +1036,17 @@ xfs_rtalloc_query_range(
        int                             is_free;
        int                             error = 0;
 
-       if (low_rec->ar_startblock > high_rec->ar_startblock)
+       if (low_rec->ar_startext > high_rec->ar_startext)
                return -EINVAL;
-       if (low_rec->ar_startblock >= mp->m_sb.sb_rextents ||
-           low_rec->ar_startblock == high_rec->ar_startblock)
+       if (low_rec->ar_startext >= mp->m_sb.sb_rextents ||
+           low_rec->ar_startext == high_rec->ar_startext)
                return 0;
-       if (high_rec->ar_startblock >= mp->m_sb.sb_rextents)
-               high_rec->ar_startblock = mp->m_sb.sb_rextents - 1;
+       if (high_rec->ar_startext >= mp->m_sb.sb_rextents)
+               high_rec->ar_startext = mp->m_sb.sb_rextents - 1;
 
        /* Iterate the bitmap, looking for discrepancies. */
-       rtstart = low_rec->ar_startblock;
-       rem = high_rec->ar_startblock - rtstart;
+       rtstart = low_rec->ar_startext;
+       rem = high_rec->ar_startext - rtstart;
        while (rem) {
                /* Is the first block free? */
                error = xfs_rtcheck_range(mp, tp, rtstart, 1, 1, &rtend,
@@ -1056,13 +1056,13 @@ xfs_rtalloc_query_range(
 
                /* How long does the extent go for? */
                error = xfs_rtfind_forw(mp, tp, rtstart,
-                               high_rec->ar_startblock - 1, &rtend);
+                               high_rec->ar_startext - 1, &rtend);
                if (error)
                        break;
 
                if (is_free) {
-                       rec.ar_startblock = rtstart;
-                       rec.ar_blockcount = rtend - rtstart + 1;
+                       rec.ar_startext = rtstart;
+                       rec.ar_extcount = rtend - rtstart + 1;
 
                        error = fn(tp, &rec, priv);
                        if (error)
@@ -1085,9 +1085,9 @@ xfs_rtalloc_query_all(
 {
        struct xfs_rtalloc_rec          keys[2];
 
-       keys[0].ar_startblock = 0;
-       keys[1].ar_startblock = tp->t_mountp->m_sb.sb_rextents - 1;
-       keys[0].ar_blockcount = keys[1].ar_blockcount = 0;
+       keys[0].ar_startext = 0;
+       keys[1].ar_startext = tp->t_mountp->m_sb.sb_rextents - 1;
+       keys[0].ar_extcount = keys[1].ar_extcount = 0;
 
        return xfs_rtalloc_query_range(tp, &keys[0], &keys[1], fn, priv);
 }
index 0fa3ef5..40f462a 100644 (file)
@@ -66,11 +66,15 @@ xfs_scrub_rtbitmap_rec(
        void                            *priv)
 {
        struct xfs_scrub_context        *sc = priv;
+       xfs_rtblock_t                   startblock;
+       xfs_rtblock_t                   blockcount;
 
-       if (rec->ar_startblock + rec->ar_blockcount <= rec->ar_startblock ||
-           !xfs_verify_rtbno(sc->mp, rec->ar_startblock) ||
-           !xfs_verify_rtbno(sc->mp, rec->ar_startblock +
-                       rec->ar_blockcount - 1))
+       startblock = rec->ar_startext * tp->t_mountp->m_sb.sb_rextsize;
+       blockcount = rec->ar_extcount * tp->t_mountp->m_sb.sb_rextsize;
+
+       if (startblock + blockcount <= startblock ||
+           !xfs_verify_rtbno(sc->mp, startblock) ||
+           !xfs_verify_rtbno(sc->mp, startblock + blockcount - 1))
                xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
        return 0;
 }
@@ -139,14 +143,23 @@ xfs_scrub_xref_is_used_rt_space(
        xfs_rtblock_t                   fsbno,
        xfs_extlen_t                    len)
 {
+       xfs_rtblock_t                   startext;
+       xfs_rtblock_t                   endext;
+       xfs_rtblock_t                   extcount;
        bool                            is_free;
        int                             error;
 
        if (xfs_scrub_skip_xref(sc->sm))
                return;
 
+       startext = fsbno;
+       endext = fsbno + len - 1;
+       do_div(startext, sc->mp->m_sb.sb_rextsize);
+       if (do_div(endext, sc->mp->m_sb.sb_rextsize))
+               endext++;
+       extcount = endext - startext;
        xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
-       error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, fsbno, len,
+       error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, extcount,
                        &is_free);
        if (!xfs_scrub_should_check_xref(sc, &error, NULL))
                goto out_unlock;
index 43cfc07..0299feb 100644 (file)
@@ -465,10 +465,9 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
        struct xfs_rmap_irec            irec;
        xfs_daddr_t                     rec_daddr;
 
-       rec_daddr = XFS_FSB_TO_BB(mp, rec->ar_startblock);
-
-       irec.rm_startblock = rec->ar_startblock;
-       irec.rm_blockcount = rec->ar_blockcount;
+       irec.rm_startblock = rec->ar_startext * mp->m_sb.sb_rextsize;
+       rec_daddr = XFS_FSB_TO_BB(mp, irec.rm_startblock);
+       irec.rm_blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize;
        irec.rm_owner = XFS_RMAP_OWN_NULL;      /* "free" */
        irec.rm_offset = 0;
        irec.rm_flags = 0;
@@ -534,8 +533,11 @@ xfs_getfsmap_rtdev_rtbitmap_query(
 
        xfs_ilock(tp->t_mountp->m_rbmip, XFS_ILOCK_SHARED);
 
-       alow.ar_startblock = info->low.rm_startblock;
-       ahigh.ar_startblock = info->high.rm_startblock;
+       alow.ar_startext = info->low.rm_startblock;
+       ahigh.ar_startext = info->high.rm_startblock;
+       do_div(alow.ar_startext, tp->t_mountp->m_sb.sb_rextsize);
+       if (do_div(ahigh.ar_startext, tp->t_mountp->m_sb.sb_rextsize))
+               ahigh.ar_startext++;
        error = xfs_rtalloc_query_range(tp, &alow, &ahigh,
                        xfs_getfsmap_rtdev_rtbitmap_helper, info);
        if (error)
index dfee3c9..52632ab 100644 (file)
 struct xfs_mount;
 struct xfs_trans;
 
+/*
+ * XXX: Most of the realtime allocation functions deal in units of realtime
+ * extents, not realtime blocks.  This looks funny when paired with the type
+ * name and screams for a larger cleanup.
+ */
 struct xfs_rtalloc_rec {
-       xfs_rtblock_t           ar_startblock;
-       xfs_rtblock_t           ar_blockcount;
+       xfs_rtblock_t           ar_startext;
+       xfs_rtblock_t           ar_extcount;
 };
 
 typedef int (*xfs_rtalloc_query_range_fn)(