Commit b6f41e44 authored by Eric Sandeen's avatar Eric Sandeen Committed by Darrick J. Wong

xfs: remove boilerplate around xfs_btree_init_block

Now that xfs_btree_init_block_int is able to determine crc
status from the passed-in mp, we can determine the proper
magic as well if we are given a btree number, rather than
an explicit magic value.

Change xfs_btree_init_block[_int] callers to pass in the
btree number, and let xfs_btree_init_block_int use the
xfs_magics array via the xfs_btree_magic macro to determine
which magic value is needed.  This makes all of the
if (crc) / else stanzas identical, and the if/else can be
removed, leading to a single, common init_block call.
Signed-off-by: default avatarEric Sandeen <sandeen@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent af7d20fd
...@@ -740,15 +740,9 @@ xfs_bmap_extents_to_btree( ...@@ -740,15 +740,9 @@ xfs_bmap_extents_to_btree(
* Fill in the root. * Fill in the root.
*/ */
block = ifp->if_broot; block = ifp->if_broot;
if (xfs_sb_version_hascrc(&mp->m_sb)) xfs_btree_init_block_int(mp, block, XFS_BUF_DADDR_NULL,
xfs_btree_init_block_int(mp, block, XFS_BUF_DADDR_NULL, XFS_BTNUM_BMAP, 1, 1, ip->i_ino,
XFS_BMAP_CRC_MAGIC, 1, 1, ip->i_ino,
XFS_BTREE_LONG_PTRS); XFS_BTREE_LONG_PTRS);
else
xfs_btree_init_block_int(mp, block, XFS_BUF_DADDR_NULL,
XFS_BMAP_MAGIC, 1, 1, ip->i_ino,
XFS_BTREE_LONG_PTRS);
/* /*
* Need a cursor. Can't allocate until bb_level is filled in. * Need a cursor. Can't allocate until bb_level is filled in.
*/ */
...@@ -817,13 +811,8 @@ xfs_bmap_extents_to_btree( ...@@ -817,13 +811,8 @@ xfs_bmap_extents_to_btree(
*/ */
abp->b_ops = &xfs_bmbt_buf_ops; abp->b_ops = &xfs_bmbt_buf_ops;
ablock = XFS_BUF_TO_BLOCK(abp); ablock = XFS_BUF_TO_BLOCK(abp);
if (xfs_sb_version_hascrc(&mp->m_sb)) xfs_btree_init_block_int(mp, ablock, abp->b_bn,
xfs_btree_init_block_int(mp, ablock, abp->b_bn, XFS_BTNUM_BMAP, 0, 0, ip->i_ino,
XFS_BMAP_CRC_MAGIC, 0, 0, ip->i_ino,
XFS_BTREE_LONG_PTRS);
else
xfs_btree_init_block_int(mp, ablock, abp->b_bn,
XFS_BMAP_MAGIC, 0, 0, ip->i_ino,
XFS_BTREE_LONG_PTRS); XFS_BTREE_LONG_PTRS);
arp = XFS_BMBT_REC_ADDR(mp, ablock, 1); arp = XFS_BMBT_REC_ADDR(mp, ablock, 1);
......
...@@ -71,15 +71,9 @@ xfs_bmdr_to_bmbt( ...@@ -71,15 +71,9 @@ xfs_bmdr_to_bmbt(
xfs_bmbt_key_t *tkp; xfs_bmbt_key_t *tkp;
__be64 *tpp; __be64 *tpp;
if (xfs_sb_version_hascrc(&mp->m_sb)) xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL,
xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL, XFS_BTNUM_BMAP, 0, 0, ip->i_ino,
XFS_BMAP_CRC_MAGIC, 0, 0, ip->i_ino,
XFS_BTREE_LONG_PTRS);
else
xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL,
XFS_BMAP_MAGIC, 0, 0, ip->i_ino,
XFS_BTREE_LONG_PTRS); XFS_BTREE_LONG_PTRS);
rblock->bb_level = dblock->bb_level; rblock->bb_level = dblock->bb_level;
ASSERT(be16_to_cpu(rblock->bb_level) > 0); ASSERT(be16_to_cpu(rblock->bb_level) > 0);
rblock->bb_numrecs = dblock->bb_numrecs; rblock->bb_numrecs = dblock->bb_numrecs;
......
...@@ -1100,13 +1100,14 @@ xfs_btree_init_block_int( ...@@ -1100,13 +1100,14 @@ xfs_btree_init_block_int(
struct xfs_mount *mp, struct xfs_mount *mp,
struct xfs_btree_block *buf, struct xfs_btree_block *buf,
xfs_daddr_t blkno, xfs_daddr_t blkno,
__u32 magic, xfs_btnum_t btnum,
__u16 level, __u16 level,
__u16 numrecs, __u16 numrecs,
__u64 owner, __u64 owner,
unsigned int flags) unsigned int flags)
{ {
int crc = xfs_sb_version_hascrc(&mp->m_sb); int crc = xfs_sb_version_hascrc(&mp->m_sb);
__u32 magic = xfs_btree_magic(crc, btnum);
buf->bb_magic = cpu_to_be32(magic); buf->bb_magic = cpu_to_be32(magic);
buf->bb_level = cpu_to_be16(level); buf->bb_level = cpu_to_be16(level);
...@@ -1141,14 +1142,14 @@ void ...@@ -1141,14 +1142,14 @@ void
xfs_btree_init_block( xfs_btree_init_block(
struct xfs_mount *mp, struct xfs_mount *mp,
struct xfs_buf *bp, struct xfs_buf *bp,
__u32 magic, xfs_btnum_t btnum,
__u16 level, __u16 level,
__u16 numrecs, __u16 numrecs,
__u64 owner, __u64 owner,
unsigned int flags) unsigned int flags)
{ {
xfs_btree_init_block_int(mp, XFS_BUF_TO_BLOCK(bp), bp->b_bn, xfs_btree_init_block_int(mp, XFS_BUF_TO_BLOCK(bp), bp->b_bn,
magic, level, numrecs, owner, flags); btnum, level, numrecs, owner, flags);
} }
STATIC void STATIC void
...@@ -1159,8 +1160,6 @@ xfs_btree_init_block_cur( ...@@ -1159,8 +1160,6 @@ xfs_btree_init_block_cur(
int numrecs) int numrecs)
{ {
__u64 owner; __u64 owner;
int crc = xfs_sb_version_hascrc(&cur->bc_mp->m_sb);
xfs_btnum_t btnum = cur->bc_btnum;
/* /*
* we can pull the owner from the cursor right now as the different * we can pull the owner from the cursor right now as the different
...@@ -1174,7 +1173,7 @@ xfs_btree_init_block_cur( ...@@ -1174,7 +1173,7 @@ xfs_btree_init_block_cur(
owner = cur->bc_private.a.agno; owner = cur->bc_private.a.agno;
xfs_btree_init_block_int(cur->bc_mp, XFS_BUF_TO_BLOCK(bp), bp->b_bn, xfs_btree_init_block_int(cur->bc_mp, XFS_BUF_TO_BLOCK(bp), bp->b_bn,
xfs_btree_magic(crc, btnum), level, numrecs, cur->bc_btnum, level, numrecs,
owner, cur->bc_flags); owner, cur->bc_flags);
} }
......
...@@ -380,7 +380,7 @@ void ...@@ -380,7 +380,7 @@ void
xfs_btree_init_block( xfs_btree_init_block(
struct xfs_mount *mp, struct xfs_mount *mp,
struct xfs_buf *bp, struct xfs_buf *bp,
__u32 magic, xfs_btnum_t btnum,
__u16 level, __u16 level,
__u16 numrecs, __u16 numrecs,
__u64 owner, __u64 owner,
...@@ -391,7 +391,7 @@ xfs_btree_init_block_int( ...@@ -391,7 +391,7 @@ xfs_btree_init_block_int(
struct xfs_mount *mp, struct xfs_mount *mp,
struct xfs_btree_block *buf, struct xfs_btree_block *buf,
xfs_daddr_t blkno, xfs_daddr_t blkno,
__u32 magic, xfs_btnum_t btnum,
__u16 level, __u16 level,
__u16 numrecs, __u16 numrecs,
__u64 owner, __u64 owner,
......
...@@ -352,12 +352,7 @@ xfs_growfs_data_private( ...@@ -352,12 +352,7 @@ xfs_growfs_data_private(
goto error0; goto error0;
} }
if (xfs_sb_version_hascrc(&mp->m_sb)) xfs_btree_init_block(mp, bp, XFS_BTNUM_BNO, 0, 1, agno, 0);
xfs_btree_init_block(mp, bp, XFS_ABTB_CRC_MAGIC, 0, 1,
agno, 0);
else
xfs_btree_init_block(mp, bp, XFS_ABTB_MAGIC, 0, 1,
agno, 0);
arec = XFS_ALLOC_REC_ADDR(mp, XFS_BUF_TO_BLOCK(bp), 1); arec = XFS_ALLOC_REC_ADDR(mp, XFS_BUF_TO_BLOCK(bp), 1);
arec->ar_startblock = cpu_to_be32(mp->m_ag_prealloc_blocks); arec->ar_startblock = cpu_to_be32(mp->m_ag_prealloc_blocks);
...@@ -381,12 +376,7 @@ xfs_growfs_data_private( ...@@ -381,12 +376,7 @@ xfs_growfs_data_private(
goto error0; goto error0;
} }
if (xfs_sb_version_hascrc(&mp->m_sb)) xfs_btree_init_block(mp, bp, XFS_BTNUM_CNT, 0, 1, agno, 0);
xfs_btree_init_block(mp, bp, XFS_ABTC_CRC_MAGIC, 0, 1,
agno, 0);
else
xfs_btree_init_block(mp, bp, XFS_ABTC_MAGIC, 0, 1,
agno, 0);
arec = XFS_ALLOC_REC_ADDR(mp, XFS_BUF_TO_BLOCK(bp), 1); arec = XFS_ALLOC_REC_ADDR(mp, XFS_BUF_TO_BLOCK(bp), 1);
arec->ar_startblock = cpu_to_be32(mp->m_ag_prealloc_blocks); arec->ar_startblock = cpu_to_be32(mp->m_ag_prealloc_blocks);
...@@ -413,7 +403,7 @@ xfs_growfs_data_private( ...@@ -413,7 +403,7 @@ xfs_growfs_data_private(
goto error0; goto error0;
} }
xfs_btree_init_block(mp, bp, XFS_RMAP_CRC_MAGIC, 0, 0, xfs_btree_init_block(mp, bp, XFS_BTNUM_RMAP, 0, 0,
agno, 0); agno, 0);
block = XFS_BUF_TO_BLOCK(bp); block = XFS_BUF_TO_BLOCK(bp);
...@@ -488,12 +478,7 @@ xfs_growfs_data_private( ...@@ -488,12 +478,7 @@ xfs_growfs_data_private(
goto error0; goto error0;
} }
if (xfs_sb_version_hascrc(&mp->m_sb)) xfs_btree_init_block(mp, bp, XFS_BTNUM_INO , 0, 0, agno, 0);
xfs_btree_init_block(mp, bp, XFS_IBT_CRC_MAGIC, 0, 0,
agno, 0);
else
xfs_btree_init_block(mp, bp, XFS_IBT_MAGIC, 0, 0,
agno, 0);
error = xfs_bwrite(bp); error = xfs_bwrite(bp);
xfs_buf_relse(bp); xfs_buf_relse(bp);
...@@ -513,12 +498,8 @@ xfs_growfs_data_private( ...@@ -513,12 +498,8 @@ xfs_growfs_data_private(
goto error0; goto error0;
} }
if (xfs_sb_version_hascrc(&mp->m_sb)) xfs_btree_init_block(mp, bp, XFS_BTNUM_FINO,
xfs_btree_init_block(mp, bp, XFS_FIBT_CRC_MAGIC,
0, 0, agno, 0); 0, 0, agno, 0);
else
xfs_btree_init_block(mp, bp, XFS_FIBT_MAGIC, 0,
0, agno, 0);
error = xfs_bwrite(bp); error = xfs_bwrite(bp);
xfs_buf_relse(bp); xfs_buf_relse(bp);
...@@ -539,7 +520,7 @@ xfs_growfs_data_private( ...@@ -539,7 +520,7 @@ xfs_growfs_data_private(
goto error0; goto error0;
} }
xfs_btree_init_block(mp, bp, XFS_REFC_CRC_MAGIC, xfs_btree_init_block(mp, bp, XFS_BTNUM_REFC,
0, 0, agno, 0); 0, 0, agno, 0);
error = xfs_bwrite(bp); error = xfs_bwrite(bp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment