summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-01-05 17:45:47 -0800
committerDarrick J. Wong <djwong@kernel.org>2021-03-25 17:08:40 -0700
commit4ae16170f49736b2b51eb8915d8439d2641c3517 (patch)
tree6fe2206a240897755e5efff838f3f35728adaa84
parentf0371716d9337225ba11b4e9b7a888dc55ff754d (diff)
xfs: encode the max btree height in the cursor
Encode the maximum btree height in the cursor, since we're soon going to allow smaller cursors for AG btrees and larger cursors for file btrees. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c2
-rw-r--r--fs/xfs/libxfs/xfs_btree.c7
-rw-r--r--fs/xfs/libxfs/xfs_btree.h3
-rw-r--r--fs/xfs/libxfs/xfs_btree_staging.c10
4 files changed, 12 insertions, 10 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index c870825646c3..230c7604dbb8 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -237,7 +237,7 @@ xfs_bmap_get_bp(
if (!cur)
return NULL;
- for (i = 0; i < XFS_BTREE_MAXLEVELS; i++) {
+ for (i = 0; i < cur->bc_maxlevels; i++) {
if (!cur->bc_levels[i].bp)
break;
if (XFS_BUF_ADDR(cur->bc_levels[i].bp) == bno)
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
index b6b2cd52de99..536f2a9bdc73 100644
--- a/fs/xfs/libxfs/xfs_btree.c
+++ b/fs/xfs/libxfs/xfs_btree.c
@@ -2941,7 +2941,7 @@ xfs_btree_promote_leaf_iroot(
/* Zap the old root and change the tree height. */
xfs_iroot_free(cur->bc_ino.ip, cur->bc_ino.whichfork);
cur->bc_nlevels++;
- ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS);
+ ASSERT(cur->bc_nlevels <= cur->bc_maxlevels);
cur->bc_levels[1].ptr = 1;
/*
@@ -2997,7 +2997,7 @@ xfs_btree_promote_node_iroot(
*/
be16_add_cpu(&block->bb_level, 1);
cur->bc_nlevels++;
- ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS);
+ ASSERT(cur->bc_nlevels <= cur->bc_maxlevels);
cur->bc_levels[level + 1].ptr = 1;
/*
@@ -3233,7 +3233,7 @@ xfs_btree_new_root(
xfs_btree_setbuf(cur, cur->bc_nlevels, nbp);
cur->bc_levels[cur->bc_nlevels].ptr = nptr;
cur->bc_nlevels++;
- ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS);
+ ASSERT(cur->bc_nlevels <= cur->bc_maxlevels);
*stat = 1;
return 0;
error0:
@@ -5243,6 +5243,7 @@ xfs_btree_alloc_cursor(
cur->bc_mp = mp;
cur->bc_btnum = btnum;
cur->bc_blocklog = mp->m_sb.sb_blocklog;
+ cur->bc_maxlevels = XFS_BTREE_MAXLEVELS;
return cur;
}
diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h
index 439e130e9a42..dc154a071ad8 100644
--- a/fs/xfs/libxfs/xfs_btree.h
+++ b/fs/xfs/libxfs/xfs_btree.h
@@ -237,9 +237,10 @@ struct xfs_btree_cur
struct xfs_mount *bc_mp; /* file system mount struct */
const struct xfs_btree_ops *bc_ops;
uint bc_flags; /* btree features - below */
- union xfs_btree_irec bc_rec; /* current insert/search record value */
+ uint8_t bc_maxlevels; /* maximum levels for this btree type */
uint8_t bc_nlevels; /* number of levels in the tree */
uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */
+ union xfs_btree_irec bc_rec; /* current insert/search record value */
xfs_btnum_t bc_btnum; /* identifies which btree type */
int bc_statoff; /* offset of btre stats array */
union {
diff --git a/fs/xfs/libxfs/xfs_btree_staging.c b/fs/xfs/libxfs/xfs_btree_staging.c
index 1b7cc63bfe15..e335944da8ad 100644
--- a/fs/xfs/libxfs/xfs_btree_staging.c
+++ b/fs/xfs/libxfs/xfs_btree_staging.c
@@ -665,12 +665,12 @@ xfs_btree_bload_compute_geometry(
* checking levels 0 and 1 here, so set bc_nlevels such that the btree
* code doesn't interpret either as the root level.
*/
- cur->bc_nlevels = XFS_BTREE_MAXLEVELS - 1;
+ cur->bc_nlevels = cur->bc_maxlevels - 1;
xfs_btree_bload_ensure_slack(cur, &bbl->leaf_slack, 0);
xfs_btree_bload_ensure_slack(cur, &bbl->node_slack, 1);
bbl->nr_records = nr_this_level = nr_records;
- for (cur->bc_nlevels = 1; cur->bc_nlevels <= XFS_BTREE_MAXLEVELS;) {
+ for (cur->bc_nlevels = 1; cur->bc_nlevels <= cur->bc_maxlevels;) {
uint64_t level_blocks;
uint64_t dontcare64;
unsigned int level = cur->bc_nlevels - 1;
@@ -713,7 +713,7 @@ xfs_btree_bload_compute_geometry(
* block-based btree level.
*/
cur->bc_nlevels++;
- ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS);
+ ASSERT(cur->bc_nlevels <= cur->bc_maxlevels);
xfs_btree_bload_level_geometry(cur, bbl, level,
nr_this_level, &avg_per_block,
&level_blocks, &dontcare64);
@@ -729,14 +729,14 @@ xfs_btree_bload_compute_geometry(
/* Otherwise, we need another level of btree. */
cur->bc_nlevels++;
- ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS);
+ ASSERT(cur->bc_nlevels <= cur->bc_maxlevels);
}
nr_blocks += level_blocks;
nr_this_level = level_blocks;
}
- if (cur->bc_nlevels > XFS_BTREE_MAXLEVELS)
+ if (cur->bc_nlevels > cur->bc_maxlevels)
return -EOVERFLOW;
bbl->btree_height = cur->bc_nlevels;