]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: clean up XFS_MIN_FREELIST macros
authorDave Chinner <dchinner@redhat.com>
Fri, 31 Jul 2015 01:11:56 +0000 (11:11 +1000)
committerDave Chinner <david@fromorbit.com>
Fri, 31 Jul 2015 01:11:56 +0000 (11:11 +1000)
We no longer calculate the minimum freelist size from the on-disk
AGF, so we don't need the macros used for this. That means the
nested macros can be cleaned up, and turn this into an actual
function so the logic is clear and concise. This will make it much
easier to add support for the rmap btree when the time comes.

This also gets rid of the XFS_AG_MAXLEVELS macro used by these
freelist macros as it is simply a wrapper around a single variable.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/xfs_alloc.c
libxfs/xfs_alloc.h
libxfs/xfs_bmap.c
libxfs/xfs_format.h
libxfs/xfs_trans_resv.h
libxfs/xfs_trans_space.h
mkfs/xfs_mkfs.c
repair/phase5.c
repair/xfs_repair.c

index 69a15ba14695cc9a4a7ce88cf378ccbb66b0c4fd..0d9b4c318cb46bc5ea0097c7fd96bc9a94f492e4 100644 (file)
@@ -1866,6 +1866,23 @@ xfs_alloc_longest_free_extent(
        return pag->pagf_flcount > 0 || pag->pagf_longest > 0;
 }
 
+unsigned int
+xfs_alloc_min_freelist(
+       struct xfs_mount        *mp,
+       struct xfs_perag        *pag)
+{
+       unsigned int            min_free;
+
+       /* space needed by-bno freespace btree */
+       min_free = min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_BNOi] + 1,
+                                      mp->m_ag_maxlevels);
+       /* space needed by-size freespace btree */
+       min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_CNTi] + 1,
+                                      mp->m_ag_maxlevels);
+
+       return min_free;
+}
+
 /*
  * Check if the operation we are fixing up the freelist for should go ahead or
  * not. If we are freeing blocks, we always allow it, otherwise the allocation
@@ -1940,7 +1957,7 @@ xfs_alloc_fix_freelist(
                goto out_agbp_relse;
        }
 
-       need = XFS_MIN_FREELIST_PAG(pag, mp);
+       need = xfs_alloc_min_freelist(mp, pag);
        if (!xfs_alloc_space_available(args, need, flags))
                goto out_agbp_relse;
 
@@ -1959,9 +1976,8 @@ xfs_alloc_fix_freelist(
                }
        }
 
-
        /* If there isn't enough total space or single-extent, reject it. */
-       need = XFS_MIN_FREELIST_PAG(pag, mp);
+       need = xfs_alloc_min_freelist(mp, pag);
        if (!xfs_alloc_space_available(args, need, flags))
                goto out_agbp_relse;
 
index c76b55c3de65dab2b4500a47d57aa34c986efd9b..071b28b814c110be0e2c63ca43df40d22eb8ccca 100644 (file)
@@ -132,6 +132,8 @@ typedef struct xfs_alloc_arg {
 
 xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_mount *mp,
                struct xfs_perag *pag, xfs_extlen_t need);
+unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
+               struct xfs_perag *pag);
 
 /*
  * Compute and fill in value of m_ag_maxlevels.
index 4638537d7cf6014391c7be875044fd5066e75b41..97822df5ebc9a7553d024f5db9eeb4613932981c 100644 (file)
@@ -3514,7 +3514,7 @@ xfs_bmap_longest_free_extent(
        }
 
        longest = xfs_alloc_longest_free_extent(mp, pag,
-                                               XFS_MIN_FREELIST_PAG(pag, mp));
+                                       xfs_alloc_min_freelist(mp, pag));
        if (*blen < longest)
                *blen = longest;
 
index 1699b8f0d248e17cc613a1512d35c65209aacd29..68d41753f35c54520a7778a53c04d5e6732e78af 100644 (file)
@@ -766,19 +766,6 @@ typedef struct xfs_agfl {
 
 #define XFS_AGFL_CRC_OFF       offsetof(struct xfs_agfl, agfl_crc)
 
-
-#define        XFS_AG_MAXLEVELS(mp)            ((mp)->m_ag_maxlevels)
-#define        XFS_MIN_FREELIST_RAW(bl,cl,mp)  \
-       (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
-#define        XFS_MIN_FREELIST(a,mp)          \
-       (XFS_MIN_FREELIST_RAW(          \
-               be32_to_cpu((a)->agf_levels[XFS_BTNUM_BNOi]), \
-               be32_to_cpu((a)->agf_levels[XFS_BTNUM_CNTi]), mp))
-#define        XFS_MIN_FREELIST_PAG(pag,mp)    \
-       (XFS_MIN_FREELIST_RAW(          \
-               (unsigned int)(pag)->pagf_levels[XFS_BTNUM_BNOi], \
-               (unsigned int)(pag)->pagf_levels[XFS_BTNUM_CNTi], mp))
-
 #define XFS_AGB_TO_FSB(mp,agno,agbno)  \
        (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
 #define        XFS_FSB_TO_AGNO(mp,fsbno)       \
index 2d5bdfce6d8fd2627fcc46603eb83faed12780e9..797815012c0e31fe711132b3c65aecd5591f7e38 100644 (file)
@@ -73,9 +73,9 @@ struct xfs_trans_resv {
  * 2 trees * (2 blocks/level * max depth - 1) * block size
  */
 #define        XFS_ALLOCFREE_LOG_RES(mp,nx) \
-       ((nx) * (2 * XFS_FSB_TO_B((mp), 2 * XFS_AG_MAXLEVELS(mp) - 1)))
+       ((nx) * (2 * XFS_FSB_TO_B((mp), 2 * (mp)->m_ag_maxlevels - 1)))
 #define        XFS_ALLOCFREE_LOG_COUNT(mp,nx) \
-       ((nx) * (2 * (2 * XFS_AG_MAXLEVELS(mp) - 1)))
+       ((nx) * (2 * (2 * (mp)->m_ag_maxlevels - 1)))
 
 /*
  * Per-directory log reservation for any directory change.
index bf9c4579334d500fea6c917d2a149ba05dead7fb..41e0428d8175a2ab7ea4be8d7f67ce932a7e3a3f 100644 (file)
@@ -67,7 +67,7 @@
 #define        XFS_DIOSTRAT_SPACE_RES(mp, v)   \
        (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v))
 #define        XFS_GROWFS_SPACE_RES(mp)        \
-       (2 * XFS_AG_MAXLEVELS(mp))
+       (2 * (mp)->m_ag_maxlevels)
 #define        XFS_GROWFSRT_SPACE_RES(mp,b)    \
        ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK))
 #define        XFS_LINK_SPACE_RES(mp,nl)       \
index 83f774982de91fc6123990956b653671276328e7..f3901beac36684413a929ce6ad8235b03b03216d 100644 (file)
@@ -2761,6 +2761,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
        for (agno = 0; agno < agcount; agno++) {
                struct xfs_agfl *agfl;
                int             bucket;
+               struct xfs_perag *pag = xfs_perag_get(mp, agno);
 
                /*
                 * Superblock.
@@ -2792,6 +2793,8 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
                agf->agf_roots[XFS_BTNUM_CNTi] = cpu_to_be32(XFS_CNT_BLOCK(mp));
                agf->agf_levels[XFS_BTNUM_BNOi] = cpu_to_be32(1);
                agf->agf_levels[XFS_BTNUM_CNTi] = cpu_to_be32(1);
+               pag->pagf_levels[XFS_BTNUM_BNOi] = 1;
+               pag->pagf_levels[XFS_BTNUM_CNTi] = 1;
                agf->agf_flfirst = 0;
                agf->agf_fllast = cpu_to_be32(XFS_AGFL_SIZE(mp) - 1);
                agf->agf_flcount = 0;
@@ -2806,8 +2809,8 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
                        agf->agf_longest = cpu_to_be32(agsize -
                                XFS_FSB_TO_AGBNO(mp, logstart) - logblocks);
                }
-               if (XFS_MIN_FREELIST(agf, mp) > worst_freelist)
-                       worst_freelist = XFS_MIN_FREELIST(agf, mp);
+               if (xfs_alloc_min_freelist(mp, pag) > worst_freelist)
+                       worst_freelist = xfs_alloc_min_freelist(mp, pag);
                libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 
                /*
@@ -2979,8 +2982,10 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
                /*
                 * Free INO btree root block
                 */
-               if (!finobt)
+               if (!finobt) {
+                       xfs_perag_put(pag);
                        continue;
+               }
 
                buf = libxfs_getbuf(mp->m_ddev_targp,
                                XFS_AGB_TO_DADDR(mp, agno, XFS_FIBT_BLOCK(mp)),
@@ -2995,6 +3000,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
                        xfs_btree_init_block(mp, buf, XFS_FIBT_MAGIC, 0, 0,
                                                agno, 0);
                libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+               xfs_perag_put(pag);
        }
 
        /*
index 7372734c1c151caa71561142fcd3d131094891c8..b5a53b192b3c0991a4623f4c42152210699ec630 100644 (file)
@@ -1510,7 +1510,8 @@ build_agf_agfl(xfs_mount_t        *mp,
                args.agno = agno;
                args.alignment = 1;
                args.pag = xfs_perag_get(mp,agno);
-               libxfs_trans_reserve(tp, &tres, XFS_MIN_FREELIST(agf, mp), 0);
+               libxfs_trans_reserve(tp, &tres,
+                                    xfs_alloc_min_freelist(mp, args.pag), 0);
                error = libxfs_alloc_fix_freelist(&args, 0);
                xfs_perag_put(args.pag);
                if (error) {
index 11a6069aca71af5f7a006023c7f26a35a1994152..9b0b99f38279a8d6ae56e3f23ffe9294537fdab7 100644 (file)
@@ -404,11 +404,16 @@ calc_mkfs(xfs_mount_t *mp)
         * and by size), the inode allocation btree root, the free inode
         * allocation btree root (if enabled) and some number of blocks to
         * prefill the agfl.
+        *
+        * Because the current shape of the btrees may differ from the current
+        * shape, we open code the mkfs freelist block count here. mkfs creates
+        * single level trees, so the calculation is pertty straight forward for
+        * the two trees that use the AGFL.
         */
        bnobt_root = howmany(4 * mp->m_sb.sb_sectsize, mp->m_sb.sb_blocksize);
        bcntbt_root = bnobt_root + 1;
        inobt_root = bnobt_root + 2;
-       fino_bno = inobt_root + XFS_MIN_FREELIST_RAW(1, 1, mp) + 1;
+       fino_bno = inobt_root + (2 * min(2, mp->m_ag_maxlevels)) + 1;
        if (xfs_sb_version_hasfinobt(&mp->m_sb))
                fino_bno++;