]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: convert XFS_AGFL_SIZE to a helper function
authorDave Chinner <dchinner@redhat.com>
Wed, 18 Apr 2018 19:46:06 +0000 (14:46 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 18 Apr 2018 19:46:06 +0000 (14:46 -0500)
Source kernel commit: a78ee256c325ecfaec13cafc41b315bd4e1dd518

The AGFL size calculation is about to get more complex, so lets turn
the macro into a function first and remove the macro.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
[darrick: forward port to newer kernel, simplify the helper]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
13 files changed:
db/agfl.c
db/check.c
db/freesp.c
db/metadump.c
libxfs/libxfs_api_defs.h
libxfs/xfs_alloc.c
libxfs/xfs_alloc.h
libxfs/xfs_format.h
mkfs/xfs_mkfs.c
repair/agheader.c
repair/phase5.c
repair/rmap.c
repair/scan.c

index 472873e0ab37b5fce37c639058732d5fa69475ee..ee0484196bb69eb5596d2aae7e75e66d354d4596 100644 (file)
--- a/db/agfl.c
+++ b/db/agfl.c
@@ -69,7 +69,7 @@ agfl_bno_size(
        void    *obj,
        int     startoff)
 {
-       return XFS_AGFL_SIZE(mp);
+       return libxfs_agfl_size(mp);
 }
 
 static void
index 2f8dee583e90cd5ba055e7b3162ddcac272ea18e..6a2c5fe07e87695940f913a49279e1fcc46c318e 100644 (file)
@@ -4053,8 +4053,8 @@ scan_freelist(
        i = be32_to_cpu(agf->agf_flfirst);
 
        /* verify agf values before proceeding */
-       if (be32_to_cpu(agf->agf_flfirst) >= XFS_AGFL_SIZE(mp) ||
-           be32_to_cpu(agf->agf_fllast) >= XFS_AGFL_SIZE(mp)) {
+       if (be32_to_cpu(agf->agf_flfirst) >= libxfs_agfl_size(mp) ||
+           be32_to_cpu(agf->agf_fllast) >= libxfs_agfl_size(mp)) {
                dbprintf(_("agf %d freelist blocks bad, skipping "
                          "freelist scan\n"), i);
                pop_cur();
@@ -4072,7 +4072,7 @@ scan_freelist(
                count++;
                if (i == be32_to_cpu(agf->agf_fllast))
                        break;
-               if (++i == XFS_AGFL_SIZE(mp))
+               if (++i == libxfs_agfl_size(mp))
                        i = 0;
        }
        if (count != be32_to_cpu(agf->agf_flcount)) {
index c3ca2f3ae20338261c774feed8520e21b8999a6e..6a3fcd3835002e179fe94afb59c863c61144cdfb 100644 (file)
@@ -254,8 +254,8 @@ scan_freelist(
                                                   : (__be32 *)agfl;
 
        /* verify agf values before proceeding */
-       if (be32_to_cpu(agf->agf_flfirst) >= XFS_AGFL_SIZE(mp) ||
-           be32_to_cpu(agf->agf_fllast) >= XFS_AGFL_SIZE(mp)) {
+       if (be32_to_cpu(agf->agf_flfirst) >= libxfs_agfl_size(mp) ||
+           be32_to_cpu(agf->agf_fllast) >= libxfs_agfl_size(mp)) {
                dbprintf(_("agf %d freelist blocks bad, skipping "
                          "freelist scan\n"), i);
                pop_cur();
@@ -267,7 +267,7 @@ scan_freelist(
                addtohist(seqno, bno, 1);
                if (i == be32_to_cpu(agf->agf_fllast))
                        break;
-               if (++i == XFS_AGFL_SIZE(mp))
+               if (++i == libxfs_agfl_size(mp))
                        i = 0;
        }
        pop_cur();
index d33f9014ff6781ad961787b66b59545bd18fc025..3fa65fe8f5475d043c2dd5918e17dab9f7c39c3d 100644 (file)
@@ -2611,7 +2611,7 @@ scan_ag(
                        i = be32_to_cpu(agf->agf_fllast);
 
                        for (;;) {
-                               if (++i == XFS_AGFL_SIZE(mp))
+                               if (++i == libxfs_agfl_size(mp))
                                        i = 0;
                                if (i == be32_to_cpu(agf->agf_flfirst))
                                        break;
index 78daca05bd725ef9dd37338f5753341b3370eae6..389f480f20a13c1d63e383c679c424850b3dd01e 100644 (file)
 #define xfs_refcount_lookup_le         libxfs_refcount_lookup_le
 #define xfs_refcount_get_rec           libxfs_refcount_get_rec
 #define xfs_rmap_lookup_le_range       libxfs_rmap_lookup_le_range
+#define xfs_agfl_size                  libxfs_agfl_size
 #define xfs_refc_block                 libxfs_refc_block
 #define xfs_rmap_compare               libxfs_rmap_compare
 #define xfs_dir_get_ops                        libxfs_dir_get_ops
index 86e3d3450c42e346c47589208b03f787ab7cc962..2bbd75ec9f49bc09459be21fbf78508e18d8964c 100644 (file)
@@ -49,6 +49,23 @@ STATIC int xfs_alloc_ag_vextent_size(xfs_alloc_arg_t *);
 STATIC int xfs_alloc_ag_vextent_small(xfs_alloc_arg_t *,
                xfs_btree_cur_t *, xfs_agblock_t *, xfs_extlen_t *, int *);
 
+/*
+ * Size of the AGFL.  For CRC-enabled filesystes we steal a couple of slots in
+ * the beginning of the block for a proper header with the location information
+ * and CRC.
+ */
+unsigned int
+xfs_agfl_size(
+       struct xfs_mount        *mp)
+{
+       unsigned int            size = mp->m_sb.sb_sectsize;
+
+       if (xfs_sb_version_hascrc(&mp->m_sb))
+               size -= sizeof(struct xfs_agfl);
+
+       return size / sizeof(xfs_agblock_t);
+}
+
 unsigned int
 xfs_refc_block(
        struct xfs_mount        *mp)
@@ -546,7 +563,7 @@ xfs_agfl_verify(
        if (bp->b_pag && be32_to_cpu(agfl->agfl_seqno) != bp->b_pag->pag_agno)
                return __this_address;
 
-       for (i = 0; i < XFS_AGFL_SIZE(mp); i++) {
+       for (i = 0; i < xfs_agfl_size(mp); i++) {
                if (be32_to_cpu(agfl->agfl_bno[i]) != NULLAGBLOCK &&
                    be32_to_cpu(agfl->agfl_bno[i]) >= mp->m_sb.sb_agblocks)
                        return __this_address;
@@ -2262,7 +2279,7 @@ xfs_alloc_get_freelist(
        bno = be32_to_cpu(agfl_bno[be32_to_cpu(agf->agf_flfirst)]);
        be32_add_cpu(&agf->agf_flfirst, 1);
        xfs_trans_brelse(tp, agflbp);
-       if (be32_to_cpu(agf->agf_flfirst) == XFS_AGFL_SIZE(mp))
+       if (be32_to_cpu(agf->agf_flfirst) == xfs_agfl_size(mp))
                agf->agf_flfirst = 0;
 
        pag = xfs_perag_get(mp, be32_to_cpu(agf->agf_seqno));
@@ -2373,7 +2390,7 @@ xfs_alloc_put_freelist(
                        be32_to_cpu(agf->agf_seqno), &agflbp)))
                return error;
        be32_add_cpu(&agf->agf_fllast, 1);
-       if (be32_to_cpu(agf->agf_fllast) == XFS_AGFL_SIZE(mp))
+       if (be32_to_cpu(agf->agf_fllast) == xfs_agfl_size(mp))
                agf->agf_fllast = 0;
 
        pag = xfs_perag_get(mp, be32_to_cpu(agf->agf_seqno));
@@ -2391,7 +2408,7 @@ xfs_alloc_put_freelist(
 
        xfs_alloc_log_agf(tp, agbp, logflags);
 
-       ASSERT(be32_to_cpu(agf->agf_flcount) <= XFS_AGFL_SIZE(mp));
+       ASSERT(be32_to_cpu(agf->agf_flcount) <= xfs_agfl_size(mp));
 
        agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agflbp);
        blockp = &agfl_bno[be32_to_cpu(agf->agf_fllast)];
@@ -2424,9 +2441,9 @@ xfs_agf_verify(
        if (!(agf->agf_magicnum == cpu_to_be32(XFS_AGF_MAGIC) &&
              XFS_AGF_GOOD_VERSION(be32_to_cpu(agf->agf_versionnum)) &&
              be32_to_cpu(agf->agf_freeblks) <= be32_to_cpu(agf->agf_length) &&
-             be32_to_cpu(agf->agf_flfirst) < XFS_AGFL_SIZE(mp) &&
-             be32_to_cpu(agf->agf_fllast) < XFS_AGFL_SIZE(mp) &&
-             be32_to_cpu(agf->agf_flcount) <= XFS_AGFL_SIZE(mp)))
+             be32_to_cpu(agf->agf_flfirst) < xfs_agfl_size(mp) &&
+             be32_to_cpu(agf->agf_fllast) < xfs_agfl_size(mp) &&
+             be32_to_cpu(agf->agf_flcount) <= xfs_agfl_size(mp)))
                return __this_address;
 
        if (be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) < 1 ||
index 65a0cafe06e4abcaff0d971aff5fbadc2e388945..a311a2414a6b892467548664fe71b381d1a29da3 100644 (file)
@@ -26,6 +26,8 @@ struct xfs_trans;
 
 extern struct workqueue_struct *xfs_alloc_wq;
 
+unsigned int xfs_agfl_size(struct xfs_mount *mp);
+
 /*
  * Freespace allocation types.  Argument to xfs_alloc_[v]extent.
  */
index 48548933fcdc18e8330ff86d7bcc080ea1fd289c..cc1055d024965080c64fcdbe5d774acf1815a1f7 100644 (file)
@@ -803,24 +803,13 @@ typedef struct xfs_agi {
                &(XFS_BUF_TO_AGFL(bp)->agfl_bno[0]) : \
                (__be32 *)(bp)->b_addr)
 
-/*
- * Size of the AGFL.  For CRC-enabled filesystes we steal a couple of
- * slots in the beginning of the block for a proper header with the
- * location information and CRC.
- */
-#define XFS_AGFL_SIZE(mp) \
-       (((mp)->m_sb.sb_sectsize - \
-        (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
-               sizeof(struct xfs_agfl) : 0)) / \
-         sizeof(xfs_agblock_t))
-
 typedef struct xfs_agfl {
        __be32          agfl_magicnum;
        __be32          agfl_seqno;
        uuid_t          agfl_uuid;
        __be64          agfl_lsn;
        __be32          agfl_crc;
-       __be32          agfl_bno[];     /* actually XFS_AGFL_SIZE(mp) */
+       __be32          agfl_bno[];     /* actually xfs_agfl_size(mp) */
 } __attribute__((packed)) xfs_agfl_t;
 
 #define XFS_AGFL_CRC_OFF       offsetof(struct xfs_agfl, agfl_crc)
index 78d0ce5da2ce173bb5d5fe95c185bd14509a16da..3804814b3b8a71034aebc0d8613f7239cda3ffb4 100644 (file)
@@ -3421,7 +3421,7 @@ initialise_ag_headers(
        }
 
        agf->agf_flfirst = 0;
-       agf->agf_fllast = cpu_to_be32(XFS_AGFL_SIZE(mp) - 1);
+       agf->agf_fllast = cpu_to_be32(libxfs_agfl_size(mp) - 1);
        agf->agf_flcount = 0;
        agblocks = (xfs_agblock_t)(agsize - libxfs_prealloc_blocks(mp));
        agf->agf_freeblks = cpu_to_be32(agblocks);
@@ -3453,7 +3453,7 @@ initialise_ag_headers(
                agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
                agfl->agfl_seqno = cpu_to_be32(agno);
                platform_uuid_copy(&agfl->agfl_uuid, &sbp->sb_uuid);
-               for (bucket = 0; bucket < XFS_AGFL_SIZE(mp); bucket++)
+               for (bucket = 0; bucket < libxfs_agfl_size(mp); bucket++)
                        agfl->agfl_bno[bucket] = cpu_to_be32(NULLAGBLOCK);
        }
 
index cce376f25c466ce4ae17a1e35de8f7bba36101bb..f0280b4acecf82dc9c8051f294871fef56e39342 100644 (file)
@@ -91,18 +91,18 @@ verify_set_agf(xfs_mount_t *mp, xfs_agf_t *agf, xfs_agnumber_t i)
         * check first/last AGF fields.  if need be, lose the free
         * space in the AGFL, we'll reclaim it later.
         */
-       if (be32_to_cpu(agf->agf_flfirst) >= XFS_AGFL_SIZE(mp))  {
-               do_warn(_("flfirst %d in agf %d too large (max = %zu)\n"),
+       if (be32_to_cpu(agf->agf_flfirst) >= libxfs_agfl_size(mp)) {
+               do_warn(_("flfirst %d in agf %d too large (max = %u)\n"),
                        be32_to_cpu(agf->agf_flfirst),
-                       i, XFS_AGFL_SIZE(mp) - 1);
+                       i, libxfs_agfl_size(mp) - 1);
                if (!no_modify)
                        agf->agf_flfirst = cpu_to_be32(0);
        }
 
-       if (be32_to_cpu(agf->agf_fllast) >= XFS_AGFL_SIZE(mp))  {
-               do_warn(_("fllast %d in agf %d too large (max = %zu)\n"),
+       if (be32_to_cpu(agf->agf_fllast) >= libxfs_agfl_size(mp)) {
+               do_warn(_("fllast %d in agf %d too large (max = %u)\n"),
                        be32_to_cpu(agf->agf_fllast),
-                       i, XFS_AGFL_SIZE(mp) - 1);
+                       i, libxfs_agfl_size(mp) - 1);
                if (!no_modify)
                        agf->agf_fllast = cpu_to_be32(0);
        }
index bb21ea7462ad992b7ed18227c717edc6c66b710f..8089846091f8b4860d2e509f8ac423e526d77bc1 100644 (file)
@@ -451,8 +451,8 @@ calculate_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
         * as they will be *after* accounting for the free space
         * we've used up will need fewer blocks to to represent
         * than we've allocated.  We can use the AGFL to hold
-        * XFS_AGFL_SIZE (sector/xfs_agfl_t) blocks but that's it.
-        * Thus we limit things to XFS_AGFL_SIZE/2 for each of the 2 btrees.
+        * xfs_agfl_size (sector/xfs_agfl_t) blocks but that's it.
+        * Thus we limit things to xfs_agfl_size/2 for each of the 2 btrees.
         * if the number of extra blocks is more than that,
         * we'll have to be called again.
         */
@@ -510,7 +510,7 @@ calculate_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
                        != btree_curs->level[0].num_blocks)  {
                /*
                 * yes -- recalculate the cursor.  If the number of
-                * excess (overallocated) blocks is < XFS_AGFL_SIZE/2, we're ok.
+                * excess (overallocated) blocks is < xfs_agfl_size/2, we're ok.
                 * we can put those into the AGFL.  we don't try
                 * and get things to converge exactly (reach a
                 * state with zero excess blocks) because there
@@ -2060,7 +2060,7 @@ build_agf_agfl(
                agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
                agfl->agfl_seqno = cpu_to_be32(agno);
                platform_uuid_copy(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid);
-               for (i = 0; i < XFS_AGFL_SIZE(mp); i++)
+               for (i = 0; i < libxfs_agfl_size(mp); i++)
                        agfl->agfl_bno[i] = cpu_to_be32(NULLAGBLOCK);
        }
        freelist = XFS_BUF_TO_AGFL_BNO(mp, agfl_buf);
@@ -2074,13 +2074,15 @@ build_agf_agfl(
                 * yes, now grab as many blocks as we can
                 */
                i = 0;
-               while (bno_bt->num_free_blocks > 0 && i < XFS_AGFL_SIZE(mp))  {
+               while (bno_bt->num_free_blocks > 0 && i < libxfs_agfl_size(mp))
+               {
                        freelist[i] = cpu_to_be32(
                                        get_next_blockaddr(agno, 0, bno_bt));
                        i++;
                }
 
-               while (bcnt_bt->num_free_blocks > 0 && i < XFS_AGFL_SIZE(mp))  {
+               while (bcnt_bt->num_free_blocks > 0 && i < libxfs_agfl_size(mp))
+               {
                        freelist[i] = cpu_to_be32(
                                        get_next_blockaddr(agno, 0, bcnt_bt));
                        i++;
@@ -2116,7 +2118,7 @@ _("Insufficient memory saving lost blocks.\n"));
 
        } else  {
                agf->agf_flfirst = 0;
-               agf->agf_fllast = cpu_to_be32(XFS_AGFL_SIZE(mp) - 1);
+               agf->agf_fllast = cpu_to_be32(libxfs_agfl_size(mp) - 1);
                agf->agf_flcount = 0;
        }
 
@@ -2311,8 +2313,8 @@ phase5_func(
                /*
                 * see if we can fit all the extra blocks into the AGFL
                 */
-               extra_blocks = (extra_blocks - XFS_AGFL_SIZE(mp) > 0)
-                               ? extra_blocks - XFS_AGFL_SIZE(mp)
+               extra_blocks = (extra_blocks - libxfs_agfl_size(mp) > 0)
+                               ? extra_blocks - libxfs_agfl_size(mp)
                                : 0;
 
                if (extra_blocks > 0)
index d51590b6a5bb5d99f04a3f0042ddda6ee25df5fc..4abf269074e39d8f510bcab8ec6d7af3ad5ee8a6 100644 (file)
@@ -497,7 +497,7 @@ rmap_store_ag_btree_rec(
         */
        agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agflbp);
        b = agfl_bno + ag_rmaps[agno].ar_flcount;
-       while (*b != NULLAGBLOCK && b - agfl_bno < XFS_AGFL_SIZE(mp)) {
+       while (*b != NULLAGBLOCK && b - agfl_bno < libxfs_agfl_size(mp)) {
                error = rmap_add_ag_rec(mp, agno, be32_to_cpu(*b), 1,
                                XFS_RMAP_OWN_AG);
                if (error)
index 0fc41f2be6dbc39850e5de7f9fc1285030420026..901f2d0b669a9b9c43d43b753a098067a07cdc3d 100644 (file)
@@ -2144,8 +2144,8 @@ scan_freelist(
 
        if (no_modify) {
                /* agf values not fixed in verify_set_agf, so recheck */
-               if (be32_to_cpu(agf->agf_flfirst) >= XFS_AGFL_SIZE(mp) ||
-                   be32_to_cpu(agf->agf_fllast) >= XFS_AGFL_SIZE(mp)) {
+               if (be32_to_cpu(agf->agf_flfirst) >= libxfs_agfl_size(mp) ||
+                   be32_to_cpu(agf->agf_fllast) >= libxfs_agfl_size(mp)) {
                        do_warn(_("agf %d freelist blocks bad, skipping "
                                  "freelist scan\n"), i);
                        return;
@@ -2163,7 +2163,7 @@ scan_freelist(
                count++;
                if (i == be32_to_cpu(agf->agf_fllast))
                        break;
-               if (++i == XFS_AGFL_SIZE(mp))
+               if (++i == libxfs_agfl_size(mp))
                        i = 0;
        }
        if (count != be32_to_cpu(agf->agf_flcount)) {