Skip to content

Commit

Permalink
xfs: replace xfs_sb_version checks with feature flag checks
Browse files Browse the repository at this point in the history
Convert the xfs_sb_version_hasfoo() to checks against
mp->m_features. Checks of the superblock itself during disk
operations (e.g. in the read/write verifiers and the to/from disk
formatters) are not converted - they operate purely on the
superblock state. Everything else should use the mount features.

Large parts of this conversion were done with sed with commands like
this:

for f in `git grep -l xfs_sb_version_has fs/xfs/*.c`; do
	sed -i -e 's/xfs_sb_version_has\(.*\)(&\(.*\)->m_sb)/xfs_has_\1(\2)/' $f
done

With manual cleanups for things like "xfs_has_extflgbit" and other
little inconsistencies in naming.

The result is ia lot less typing to check features and an XFS binary
size reduced by a bit over 3kB:

$ size -t fs/xfs/built-in.a
	text	   data	    bss	    dec	    hex	filenam
before	1130866  311352     484 1442702  16038e (TOTALS)
after	1127727  311352     484 1439563  15f74b (TOTALS)

Signed-off-by: Dave Chinner <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Signed-off-by: Darrick J. Wong <[email protected]>
  • Loading branch information
Dave Chinner authored and Darrick J. Wong committed Aug 19, 2021
1 parent a1d86e8 commit 38c26bf
Show file tree
Hide file tree
Showing 75 changed files with 267 additions and 267 deletions.
20 changes: 10 additions & 10 deletions fs/xfs/libxfs/xfs_ag.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ xfs_rmaproot_init(
rrec->rm_offset = 0;

/* account for refc btree root */
if (xfs_sb_version_hasreflink(&mp->m_sb)) {
if (xfs_has_reflink(mp)) {
rrec = XFS_RMAP_REC_ADDR(block, 5);
rrec->rm_startblock = cpu_to_be32(xfs_refc_block(mp));
rrec->rm_blockcount = cpu_to_be32(1);
Expand Down Expand Up @@ -528,7 +528,7 @@ xfs_agfblock_init(
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);
if (xfs_sb_version_hasrmapbt(&mp->m_sb)) {
if (xfs_has_rmapbt(mp)) {
agf->agf_roots[XFS_BTNUM_RMAPi] =
cpu_to_be32(XFS_RMAP_BLOCK(mp));
agf->agf_levels[XFS_BTNUM_RMAPi] = cpu_to_be32(1);
Expand All @@ -541,9 +541,9 @@ xfs_agfblock_init(
tmpsize = id->agsize - mp->m_ag_prealloc_blocks;
agf->agf_freeblks = cpu_to_be32(tmpsize);
agf->agf_longest = cpu_to_be32(tmpsize);
if (xfs_sb_version_hascrc(&mp->m_sb))
if (xfs_has_crc(mp))
uuid_copy(&agf->agf_uuid, &mp->m_sb.sb_meta_uuid);
if (xfs_sb_version_hasreflink(&mp->m_sb)) {
if (xfs_has_reflink(mp)) {
agf->agf_refcount_root = cpu_to_be32(
xfs_refc_block(mp));
agf->agf_refcount_level = cpu_to_be32(1);
Expand All @@ -569,7 +569,7 @@ xfs_agflblock_init(
__be32 *agfl_bno;
int bucket;

if (xfs_sb_version_hascrc(&mp->m_sb)) {
if (xfs_has_crc(mp)) {
agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
agfl->agfl_seqno = cpu_to_be32(id->agno);
uuid_copy(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid);
Expand Down Expand Up @@ -599,9 +599,9 @@ xfs_agiblock_init(
agi->agi_freecount = 0;
agi->agi_newino = cpu_to_be32(NULLAGINO);
agi->agi_dirino = cpu_to_be32(NULLAGINO);
if (xfs_sb_version_hascrc(&mp->m_sb))
if (xfs_has_crc(mp))
uuid_copy(&agi->agi_uuid, &mp->m_sb.sb_meta_uuid);
if (xfs_sb_version_hasfinobt(&mp->m_sb)) {
if (xfs_has_finobt(mp)) {
agi->agi_free_root = cpu_to_be32(XFS_FIBT_BLOCK(mp));
agi->agi_free_level = cpu_to_be32(1);
}
Expand Down Expand Up @@ -719,22 +719,22 @@ xfs_ag_init_headers(
.ops = &xfs_finobt_buf_ops,
.work = &xfs_btroot_init,
.type = XFS_BTNUM_FINO,
.need_init = xfs_sb_version_hasfinobt(&mp->m_sb)
.need_init = xfs_has_finobt(mp)
},
{ /* RMAP root block */
.daddr = XFS_AGB_TO_DADDR(mp, id->agno, XFS_RMAP_BLOCK(mp)),
.numblks = BTOBB(mp->m_sb.sb_blocksize),
.ops = &xfs_rmapbt_buf_ops,
.work = &xfs_rmaproot_init,
.need_init = xfs_sb_version_hasrmapbt(&mp->m_sb)
.need_init = xfs_has_rmapbt(mp)
},
{ /* REFC root block */
.daddr = XFS_AGB_TO_DADDR(mp, id->agno, xfs_refc_block(mp)),
.numblks = BTOBB(mp->m_sb.sb_blocksize),
.ops = &xfs_refcountbt_buf_ops,
.work = &xfs_btroot_init,
.type = XFS_BTNUM_REFC,
.need_init = xfs_sb_version_hasreflink(&mp->m_sb)
.need_init = xfs_has_reflink(mp)
},
{ /* NULL terminating block */
.daddr = XFS_BUF_DADDR_NULL,
Expand Down
34 changes: 17 additions & 17 deletions fs/xfs/libxfs/xfs_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ xfs_agfl_size(
{
unsigned int size = mp->m_sb.sb_sectsize;

if (xfs_sb_version_hascrc(&mp->m_sb))
if (xfs_has_crc(mp))
size -= sizeof(struct xfs_agfl);

return size / sizeof(xfs_agblock_t);
Expand All @@ -61,9 +61,9 @@ unsigned int
xfs_refc_block(
struct xfs_mount *mp)
{
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
if (xfs_has_rmapbt(mp))
return XFS_RMAP_BLOCK(mp) + 1;
if (xfs_sb_version_hasfinobt(&mp->m_sb))
if (xfs_has_finobt(mp))
return XFS_FIBT_BLOCK(mp) + 1;
return XFS_IBT_BLOCK(mp) + 1;
}
Expand All @@ -72,11 +72,11 @@ xfs_extlen_t
xfs_prealloc_blocks(
struct xfs_mount *mp)
{
if (xfs_sb_version_hasreflink(&mp->m_sb))
if (xfs_has_reflink(mp))
return xfs_refc_block(mp) + 1;
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
if (xfs_has_rmapbt(mp))
return XFS_RMAP_BLOCK(mp) + 1;
if (xfs_sb_version_hasfinobt(&mp->m_sb))
if (xfs_has_finobt(mp))
return XFS_FIBT_BLOCK(mp) + 1;
return XFS_IBT_BLOCK(mp) + 1;
}
Expand Down Expand Up @@ -126,11 +126,11 @@ xfs_alloc_ag_max_usable(
blocks = XFS_BB_TO_FSB(mp, XFS_FSS_TO_BB(mp, 4)); /* ag headers */
blocks += XFS_ALLOC_AGFL_RESERVE;
blocks += 3; /* AGF, AGI btree root blocks */
if (xfs_sb_version_hasfinobt(&mp->m_sb))
if (xfs_has_finobt(mp))
blocks++; /* finobt root block */
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
if (xfs_has_rmapbt(mp))
blocks++; /* rmap root block */
if (xfs_sb_version_hasreflink(&mp->m_sb))
if (xfs_has_reflink(mp))
blocks++; /* refcount root block */

return mp->m_sb.sb_agblocks - blocks;
Expand Down Expand Up @@ -598,7 +598,7 @@ xfs_agfl_verify(
* AGFL is what the AGF says is active. We can't get to the AGF, so we
* can't verify just those entries are valid.
*/
if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return NULL;

if (!xfs_verify_magic(bp, agfl->agfl_magicnum))
Expand Down Expand Up @@ -638,7 +638,7 @@ xfs_agfl_read_verify(
* AGFL is what the AGF says is active. We can't get to the AGF, so we
* can't verify just those entries are valid.
*/
if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return;

if (!xfs_buf_verify_cksum(bp, XFS_AGFL_CRC_OFF))
Expand All @@ -659,7 +659,7 @@ xfs_agfl_write_verify(
xfs_failaddr_t fa;

/* no verification of non-crc AGFLs */
if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return;

fa = xfs_agfl_verify(bp);
Expand Down Expand Up @@ -2373,7 +2373,7 @@ xfs_agfl_needs_reset(
int active;

/* no agfl header on v4 supers */
if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return false;

/*
Expand Down Expand Up @@ -2877,7 +2877,7 @@ xfs_agf_verify(
struct xfs_mount *mp = bp->b_mount;
struct xfs_agf *agf = bp->b_addr;

if (xfs_sb_version_hascrc(&mp->m_sb)) {
if (xfs_has_crc(mp)) {
if (!uuid_equal(&agf->agf_uuid, &mp->m_sb.sb_meta_uuid))
return __this_address;
if (!xfs_log_check_lsn(mp, be64_to_cpu(agf->agf_lsn)))
Expand Down Expand Up @@ -2907,7 +2907,7 @@ xfs_agf_verify(
be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) > mp->m_ag_maxlevels)
return __this_address;

if (xfs_sb_version_hasrmapbt(&mp->m_sb) &&
if (xfs_has_rmapbt(mp) &&
(be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) < 1 ||
be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) > mp->m_rmap_maxlevels))
return __this_address;
Expand Down Expand Up @@ -2950,7 +2950,7 @@ xfs_agf_read_verify(
struct xfs_mount *mp = bp->b_mount;
xfs_failaddr_t fa;

if (xfs_sb_version_hascrc(&mp->m_sb) &&
if (xfs_has_crc(mp) &&
!xfs_buf_verify_cksum(bp, XFS_AGF_CRC_OFF))
xfs_verifier_error(bp, -EFSBADCRC, __this_address);
else {
Expand All @@ -2975,7 +2975,7 @@ xfs_agf_write_verify(
return;
}

if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return;

if (bip)
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/libxfs/xfs_alloc_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ xfs_allocbt_init_common(
atomic_inc(&pag->pag_ref);
cur->bc_ag.pag = pag;

if (xfs_sb_version_hascrc(&mp->m_sb))
if (xfs_has_crc(mp))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;

return cur;
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/libxfs/xfs_alloc_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct xbtree_afakeroot;
* Btree block header size depends on a superblock flag.
*/
#define XFS_ALLOC_BLOCK_LEN(mp) \
(xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
(xfs_has_crc(((mp))) ? \
XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN)

/*
Expand Down
14 changes: 7 additions & 7 deletions fs/xfs/libxfs/xfs_attr_leaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ xfs_attr3_leaf_write_verify(
return;
}

if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return;

if (bip)
Expand All @@ -406,7 +406,7 @@ xfs_attr3_leaf_read_verify(
struct xfs_mount *mp = bp->b_mount;
xfs_failaddr_t fa;

if (xfs_sb_version_hascrc(&mp->m_sb) &&
if (xfs_has_crc(mp) &&
!xfs_buf_verify_cksum(bp, XFS_ATTR3_LEAF_CRC_OFF))
xfs_verifier_error(bp, -EFSBADCRC, __this_address);
else {
Expand Down Expand Up @@ -627,10 +627,10 @@ STATIC void
xfs_sbversion_add_attr2(xfs_mount_t *mp, xfs_trans_t *tp)
{
if ((mp->m_flags & XFS_MOUNT_ATTR2) &&
!(xfs_sb_version_hasattr2(&mp->m_sb))) {
!(xfs_has_attr2(mp))) {
spin_lock(&mp->m_sb_lock);
if (!xfs_sb_version_hasattr2(&mp->m_sb)) {
xfs_sb_version_addattr2(&mp->m_sb);
if (!xfs_has_attr2(mp)) {
xfs_add_attr2(mp);
spin_unlock(&mp->m_sb_lock);
xfs_log_sb(tp);
} else
Expand Down Expand Up @@ -1199,7 +1199,7 @@ xfs_attr3_leaf_to_node(
xfs_trans_buf_set_type(args->trans, bp2, XFS_BLFT_ATTR_LEAF_BUF);
bp2->b_ops = bp1->b_ops;
memcpy(bp2->b_addr, bp1->b_addr, args->geo->blksize);
if (xfs_sb_version_hascrc(&mp->m_sb)) {
if (xfs_has_crc(mp)) {
struct xfs_da3_blkinfo *hdr3 = bp2->b_addr;
hdr3->blkno = cpu_to_be64(bp2->b_bn);
}
Expand Down Expand Up @@ -1264,7 +1264,7 @@ xfs_attr3_leaf_create(
memset(&ichdr, 0, sizeof(ichdr));
ichdr.firstused = args->geo->blksize;

if (xfs_sb_version_hascrc(&mp->m_sb)) {
if (xfs_has_crc(mp)) {
struct xfs_da3_blkinfo *hdr3 = bp->b_addr;

ichdr.magic = XFS_ATTR3_LEAF_MAGIC;
Expand Down
10 changes: 5 additions & 5 deletions fs/xfs/libxfs/xfs_attr_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ xfs_attr3_rmt_blocks(
struct xfs_mount *mp,
int attrlen)
{
if (xfs_sb_version_hascrc(&mp->m_sb)) {
if (xfs_has_crc(mp)) {
int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
return (attrlen + buflen - 1) / buflen;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ __xfs_attr3_rmt_read_verify(
int blksize = mp->m_attr_geo->blksize;

/* no verification of non-crc buffers */
if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return 0;

ptr = bp->b_addr;
Expand Down Expand Up @@ -191,7 +191,7 @@ xfs_attr3_rmt_write_verify(
xfs_daddr_t bno;

/* no verification of non-crc buffers */
if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return;

ptr = bp->b_addr;
Expand Down Expand Up @@ -246,7 +246,7 @@ xfs_attr3_rmt_hdr_set(
{
struct xfs_attr3_rmt_hdr *rmt = ptr;

if (!xfs_sb_version_hascrc(&mp->m_sb))
if (!xfs_has_crc(mp))
return 0;

rmt->rm_magic = cpu_to_be32(XFS_ATTR3_RMT_MAGIC);
Expand Down Expand Up @@ -296,7 +296,7 @@ xfs_attr_rmtval_copyout(

byte_cnt = min(*valuelen, byte_cnt);

if (xfs_sb_version_hascrc(&mp->m_sb)) {
if (xfs_has_crc(mp)) {
if (xfs_attr3_rmt_hdr_ok(src, ino, *offset,
byte_cnt, bno)) {
xfs_alert(mp,
Expand Down
12 changes: 6 additions & 6 deletions fs/xfs/libxfs/xfs_bmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,17 +1115,17 @@ xfs_bmap_add_attrfork(
xfs_trans_log_inode(tp, ip, logflags);
if (error)
goto trans_cancel;
if (!xfs_sb_version_hasattr(&mp->m_sb) ||
(!xfs_sb_version_hasattr2(&mp->m_sb) && version == 2)) {
if (!xfs_has_attr(mp) ||
(!xfs_has_attr2(mp) && version == 2)) {
bool log_sb = false;

spin_lock(&mp->m_sb_lock);
if (!xfs_sb_version_hasattr(&mp->m_sb)) {
xfs_sb_version_addattr(&mp->m_sb);
if (!xfs_has_attr(mp)) {
xfs_add_attr(mp);
log_sb = true;
}
if (!xfs_sb_version_hasattr2(&mp->m_sb) && version == 2) {
xfs_sb_version_addattr2(&mp->m_sb);
if (!xfs_has_attr2(mp) && version == 2) {
xfs_add_attr2(mp);
log_sb = true;
}
spin_unlock(&mp->m_sb_lock);
Expand Down
4 changes: 2 additions & 2 deletions fs/xfs/libxfs/xfs_bmap_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ xfs_bmbt_to_bmdr(
xfs_bmbt_key_t *tkp;
__be64 *tpp;

if (xfs_sb_version_hascrc(&mp->m_sb)) {
if (xfs_has_crc(mp)) {
ASSERT(rblock->bb_magic == cpu_to_be32(XFS_BMAP_CRC_MAGIC));
ASSERT(uuid_equal(&rblock->bb_u.l.bb_uuid,
&mp->m_sb.sb_meta_uuid));
Expand Down Expand Up @@ -563,7 +563,7 @@ xfs_bmbt_init_cursor(

cur->bc_ops = &xfs_bmbt_ops;
cur->bc_flags = XFS_BTREE_LONG_PTRS | XFS_BTREE_ROOT_IN_INODE;
if (xfs_sb_version_hascrc(&mp->m_sb))
if (xfs_has_crc(mp))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;

cur->bc_ino.forksize = XFS_IFORK_SIZE(ip, whichfork);
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/libxfs/xfs_bmap_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct xfs_trans;
* Btree block header size depends on a superblock flag.
*/
#define XFS_BMBT_BLOCK_LEN(mp) \
(xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
(xfs_has_crc(((mp))) ? \
XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN)

#define XFS_BMBT_REC_ADDR(mp, block, index) \
Expand Down
Loading

0 comments on commit 38c26bf

Please sign in to comment.