Commit ce5e42db authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Lachlan McIlroy

[XFS] add get_maxrecs btree operation

Factor xfs_btree_maxrecs into a per-btree operation.

The get_maxrecs method is based on a patch from Dave Chinner.

SGI-PV: 985583

SGI-Modid: xfs-linux-melb:xfs-kern:32188a
Signed-off-by: default avatarChristoph Hellwig <hch@infradead.org>
Signed-off-by: default avatarLachlan McIlroy <lachlan@sgi.com>
Signed-off-by: default avatarBill O'Donnell <billodo@sgi.com>
Signed-off-by: default avatarDavid Chinner <david@fromorbit.com>
parent 8c4ed633
...@@ -2219,6 +2219,14 @@ xfs_allocbt_dup_cursor( ...@@ -2219,6 +2219,14 @@ xfs_allocbt_dup_cursor(
cur->bc_btnum); cur->bc_btnum);
} }
STATIC int
xfs_allocbt_get_maxrecs(
struct xfs_btree_cur *cur,
int level)
{
return cur->bc_mp->m_alloc_mxr[level != 0];
}
#ifdef XFS_BTREE_TRACE #ifdef XFS_BTREE_TRACE
ktrace_t *xfs_allocbt_trace_buf; ktrace_t *xfs_allocbt_trace_buf;
...@@ -2287,6 +2295,7 @@ xfs_allocbt_trace_record( ...@@ -2287,6 +2295,7 @@ xfs_allocbt_trace_record(
static const struct xfs_btree_ops xfs_allocbt_ops = { static const struct xfs_btree_ops xfs_allocbt_ops = {
.dup_cursor = xfs_allocbt_dup_cursor, .dup_cursor = xfs_allocbt_dup_cursor,
.get_maxrecs = xfs_allocbt_get_maxrecs,
#ifdef XFS_BTREE_TRACE #ifdef XFS_BTREE_TRACE
.trace_enter = xfs_allocbt_trace_enter, .trace_enter = xfs_allocbt_trace_enter,
......
...@@ -2415,6 +2415,14 @@ xfs_bmbt_dup_cursor( ...@@ -2415,6 +2415,14 @@ xfs_bmbt_dup_cursor(
return new; return new;
} }
STATIC int
xfs_bmbt_get_maxrecs(
struct xfs_btree_cur *cur,
int level)
{
return XFS_BMAP_BLOCK_IMAXRECS(level, cur);
}
#ifdef XFS_BTREE_TRACE #ifdef XFS_BTREE_TRACE
ktrace_t *xfs_bmbt_trace_buf; ktrace_t *xfs_bmbt_trace_buf;
...@@ -2502,6 +2510,7 @@ xfs_bmbt_trace_record( ...@@ -2502,6 +2510,7 @@ xfs_bmbt_trace_record(
static const struct xfs_btree_ops xfs_bmbt_ops = { static const struct xfs_btree_ops xfs_bmbt_ops = {
.dup_cursor = xfs_bmbt_dup_cursor, .dup_cursor = xfs_bmbt_dup_cursor,
.get_maxrecs = xfs_bmbt_get_maxrecs,
#ifdef XFS_BTREE_TRACE #ifdef XFS_BTREE_TRACE
.trace_enter = xfs_bmbt_trace_enter, .trace_enter = xfs_bmbt_trace_enter,
......
...@@ -50,31 +50,6 @@ const __uint32_t xfs_magics[XFS_BTNUM_MAX] = { ...@@ -50,31 +50,6 @@ const __uint32_t xfs_magics[XFS_BTNUM_MAX] = {
XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC
}; };
/*
* Checking routine: return maxrecs for the block.
*/
STATIC int /* number of records fitting in block */
xfs_btree_maxrecs(
xfs_btree_cur_t *cur, /* btree cursor */
xfs_btree_block_t *block) /* generic btree block pointer */
{
switch (cur->bc_btnum) {
case XFS_BTNUM_BNO:
case XFS_BTNUM_CNT:
return (int)XFS_ALLOC_BLOCK_MAXRECS(
be16_to_cpu(block->bb_level), cur);
case XFS_BTNUM_BMAP:
return (int)XFS_BMAP_BLOCK_IMAXRECS(
be16_to_cpu(block->bb_level), cur);
case XFS_BTNUM_INO:
return (int)XFS_INOBT_BLOCK_MAXRECS(
be16_to_cpu(block->bb_level), cur);
default:
ASSERT(0);
return 0;
}
}
/* /*
* External routines. * External routines.
*/ */
...@@ -207,7 +182,7 @@ xfs_btree_check_lblock( ...@@ -207,7 +182,7 @@ xfs_btree_check_lblock(
be32_to_cpu(block->bb_magic) == xfs_magics[cur->bc_btnum] && be32_to_cpu(block->bb_magic) == xfs_magics[cur->bc_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) <=
xfs_btree_maxrecs(cur, (xfs_btree_block_t *)block) && cur->bc_ops->get_maxrecs(cur, level) &&
block->bb_leftsib && block->bb_leftsib &&
(be64_to_cpu(block->bb_leftsib) == NULLDFSBNO || (be64_to_cpu(block->bb_leftsib) == NULLDFSBNO ||
XFS_FSB_SANITY_CHECK(mp, be64_to_cpu(block->bb_leftsib))) && XFS_FSB_SANITY_CHECK(mp, be64_to_cpu(block->bb_leftsib))) &&
...@@ -245,7 +220,7 @@ xfs_btree_check_sblock( ...@@ -245,7 +220,7 @@ xfs_btree_check_sblock(
be32_to_cpu(block->bb_magic) == xfs_magics[cur->bc_btnum] && be32_to_cpu(block->bb_magic) == xfs_magics[cur->bc_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) <=
xfs_btree_maxrecs(cur, (xfs_btree_block_t *)block) && cur->bc_ops->get_maxrecs(cur, level) &&
(be32_to_cpu(block->bb_leftsib) == NULLAGBLOCK || (be32_to_cpu(block->bb_leftsib) == NULLAGBLOCK ||
be32_to_cpu(block->bb_leftsib) < agflen) && be32_to_cpu(block->bb_leftsib) < agflen) &&
block->bb_leftsib && block->bb_leftsib &&
......
...@@ -183,6 +183,9 @@ struct xfs_btree_ops { ...@@ -183,6 +183,9 @@ struct xfs_btree_ops {
/* cursor operations */ /* cursor operations */
struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *); struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *);
/* records in block/level */
int (*get_maxrecs)(struct xfs_btree_cur *cur, int level);
/* btree tracing */ /* btree tracing */
#ifdef XFS_BTREE_TRACE #ifdef XFS_BTREE_TRACE
void (*trace_enter)(struct xfs_btree_cur *, const char *, void (*trace_enter)(struct xfs_btree_cur *, const char *,
......
...@@ -2085,6 +2085,14 @@ xfs_inobt_dup_cursor( ...@@ -2085,6 +2085,14 @@ xfs_inobt_dup_cursor(
cur->bc_private.a.agbp, cur->bc_private.a.agno); cur->bc_private.a.agbp, cur->bc_private.a.agno);
} }
STATIC int
xfs_inobt_get_maxrecs(
struct xfs_btree_cur *cur,
int level)
{
return cur->bc_mp->m_inobt_mxr[level != 0];
}
#ifdef XFS_BTREE_TRACE #ifdef XFS_BTREE_TRACE
ktrace_t *xfs_inobt_trace_buf; ktrace_t *xfs_inobt_trace_buf;
...@@ -2153,6 +2161,7 @@ xfs_inobt_trace_record( ...@@ -2153,6 +2161,7 @@ xfs_inobt_trace_record(
static const struct xfs_btree_ops xfs_inobt_ops = { static const struct xfs_btree_ops xfs_inobt_ops = {
.dup_cursor = xfs_inobt_dup_cursor, .dup_cursor = xfs_inobt_dup_cursor,
.get_maxrecs = xfs_inobt_get_maxrecs,
#ifdef XFS_BTREE_TRACE #ifdef XFS_BTREE_TRACE
.trace_enter = xfs_inobt_trace_enter, .trace_enter = xfs_inobt_trace_enter,
......
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