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

xfs: make xfs_btree_magic more generic

Right now the xfs_btree_magic() define takes only a cursor;
change this to take crc and btnum args to make it more generically
useful, and move to a function.

This will allow xfs_btree_init_block_int callers which don't
have a cursor to make use of the xfs_magics array, which will
happen in the next patch.
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 f88ae46b
...@@ -50,8 +50,18 @@ static const __uint32_t xfs_magics[2][XFS_BTNUM_MAX] = { ...@@ -50,8 +50,18 @@ static const __uint32_t xfs_magics[2][XFS_BTNUM_MAX] = {
XFS_BMAP_CRC_MAGIC, XFS_IBT_CRC_MAGIC, XFS_FIBT_CRC_MAGIC, XFS_BMAP_CRC_MAGIC, XFS_IBT_CRC_MAGIC, XFS_FIBT_CRC_MAGIC,
XFS_REFC_CRC_MAGIC } XFS_REFC_CRC_MAGIC }
}; };
#define xfs_btree_magic(cur) \
xfs_magics[!!((cur)->bc_flags & XFS_BTREE_CRC_BLOCKS)][cur->bc_btnum] __uint32_t
xfs_btree_magic(
int crc,
xfs_btnum_t btnum)
{
__uint32_t magic = xfs_magics[crc][btnum];
/* Ensure we asked for crc for crc-only magics. */
ASSERT(magic != 0);
return magic;
}
STATIC int /* error (0 or EFSCORRUPTED) */ STATIC int /* error (0 or EFSCORRUPTED) */
xfs_btree_check_lblock( xfs_btree_check_lblock(
...@@ -62,10 +72,13 @@ xfs_btree_check_lblock( ...@@ -62,10 +72,13 @@ xfs_btree_check_lblock(
{ {
int lblock_ok = 1; /* block passes checks */ int lblock_ok = 1; /* block passes checks */
struct xfs_mount *mp; /* file system mount point */ struct xfs_mount *mp; /* file system mount point */
xfs_btnum_t btnum = cur->bc_btnum;
int crc;
mp = cur->bc_mp; mp = cur->bc_mp;
crc = xfs_sb_version_hascrc(&mp->m_sb);
if (xfs_sb_version_hascrc(&mp->m_sb)) { if (crc) {
lblock_ok = lblock_ok && lblock_ok = lblock_ok &&
uuid_equal(&block->bb_u.l.bb_uuid, uuid_equal(&block->bb_u.l.bb_uuid,
&mp->m_sb.sb_meta_uuid) && &mp->m_sb.sb_meta_uuid) &&
...@@ -74,7 +87,7 @@ xfs_btree_check_lblock( ...@@ -74,7 +87,7 @@ xfs_btree_check_lblock(
} }
lblock_ok = lblock_ok && lblock_ok = lblock_ok &&
be32_to_cpu(block->bb_magic) == xfs_btree_magic(cur) && be32_to_cpu(block->bb_magic) == xfs_btree_magic(crc, btnum) &&
be16_to_cpu(block->bb_level) == level && be16_to_cpu(block->bb_level) == level &&
be16_to_cpu(block->bb_numrecs) <= be16_to_cpu(block->bb_numrecs) <=
cur->bc_ops->get_maxrecs(cur, level) && cur->bc_ops->get_maxrecs(cur, level) &&
...@@ -110,13 +123,16 @@ xfs_btree_check_sblock( ...@@ -110,13 +123,16 @@ xfs_btree_check_sblock(
struct xfs_agf *agf; /* ag. freespace structure */ struct xfs_agf *agf; /* ag. freespace structure */
xfs_agblock_t agflen; /* native ag. freespace length */ xfs_agblock_t agflen; /* native ag. freespace length */
int sblock_ok = 1; /* block passes checks */ int sblock_ok = 1; /* block passes checks */
xfs_btnum_t btnum = cur->bc_btnum;
int crc;
mp = cur->bc_mp; mp = cur->bc_mp;
crc = xfs_sb_version_hascrc(&mp->m_sb);
agbp = cur->bc_private.a.agbp; agbp = cur->bc_private.a.agbp;
agf = XFS_BUF_TO_AGF(agbp); agf = XFS_BUF_TO_AGF(agbp);
agflen = be32_to_cpu(agf->agf_length); agflen = be32_to_cpu(agf->agf_length);
if (xfs_sb_version_hascrc(&mp->m_sb)) { if (crc) {
sblock_ok = sblock_ok && sblock_ok = sblock_ok &&
uuid_equal(&block->bb_u.s.bb_uuid, uuid_equal(&block->bb_u.s.bb_uuid,
&mp->m_sb.sb_meta_uuid) && &mp->m_sb.sb_meta_uuid) &&
...@@ -125,7 +141,7 @@ xfs_btree_check_sblock( ...@@ -125,7 +141,7 @@ xfs_btree_check_sblock(
} }
sblock_ok = sblock_ok && sblock_ok = sblock_ok &&
be32_to_cpu(block->bb_magic) == xfs_btree_magic(cur) && be32_to_cpu(block->bb_magic) == xfs_btree_magic(crc, btnum) &&
be16_to_cpu(block->bb_level) == level && be16_to_cpu(block->bb_level) == level &&
be16_to_cpu(block->bb_numrecs) <= be16_to_cpu(block->bb_numrecs) <=
cur->bc_ops->get_maxrecs(cur, level) && cur->bc_ops->get_maxrecs(cur, level) &&
...@@ -1143,6 +1159,8 @@ xfs_btree_init_block_cur( ...@@ -1143,6 +1159,8 @@ 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
...@@ -1156,7 +1174,7 @@ xfs_btree_init_block_cur( ...@@ -1156,7 +1174,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(cur), level, numrecs, xfs_btree_magic(crc, btnum), level, numrecs,
owner, cur->bc_flags); owner, cur->bc_flags);
} }
......
...@@ -76,6 +76,8 @@ union xfs_btree_rec { ...@@ -76,6 +76,8 @@ union xfs_btree_rec {
#define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi) #define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi)
#define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi) #define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi)
__uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum);
/* /*
* For logging record fields. * For logging record fields.
*/ */
......
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