From: Dave Chinner Date: Wed, 18 Apr 2018 19:46:06 +0000 (-0500) Subject: xfs: convert XFS_AGFL_SIZE to a helper function X-Git-Tag: v4.17.0-rc1~44^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b81655087300d11e7c9d930bba05656f7c458006;p=thirdparty%2Fxfsprogs-dev.git xfs: convert XFS_AGFL_SIZE to a helper function 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 [darrick: forward port to newer kernel, simplify the helper] Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Eric Sandeen --- diff --git a/db/agfl.c b/db/agfl.c index 472873e0a..ee0484196 100644 --- 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 diff --git a/db/check.c b/db/check.c index 2f8dee583..6a2c5fe07 100644 --- a/db/check.c +++ b/db/check.c @@ -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)) { diff --git a/db/freesp.c b/db/freesp.c index c3ca2f3ae..6a3fcd383 100644 --- a/db/freesp.c +++ b/db/freesp.c @@ -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(); diff --git a/db/metadump.c b/db/metadump.c index d33f9014f..3fa65fe8f 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -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; diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 78daca05b..389f480f2 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -148,6 +148,7 @@ #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 diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 86e3d3450..2bbd75ec9 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -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 || diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index 65a0cafe0..a311a2414 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -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. */ diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 48548933f..cc1055d02 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -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) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 78d0ce5da..3804814b3 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -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); } diff --git a/repair/agheader.c b/repair/agheader.c index cce376f25..f0280b4ac 100644 --- a/repair/agheader.c +++ b/repair/agheader.c @@ -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); } diff --git a/repair/phase5.c b/repair/phase5.c index bb21ea746..808984609 100644 --- a/repair/phase5.c +++ b/repair/phase5.c @@ -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) diff --git a/repair/rmap.c b/repair/rmap.c index d51590b6a..4abf26907 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -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) diff --git a/repair/scan.c b/repair/scan.c index 0fc41f2be..901f2d0b6 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -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)) {