summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 11:15:51 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-09-17 18:55:10 -0700
commit93f2d33988b397f3e77d3e3f42a5ba73c00bb2f2 (patch)
tree41ce10779ddebe1828b63c519ef490b77d16ad12
parentb5a2d05768f1c52dd92553e17a2bfbf9d166d3eb (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 3ff4ca794095..cd97288f6abc 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -240,7 +240,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_daddr(cur->bc_levels[i].bp) == bno)
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
index 659c7849eec0..5754495e8aa4 100644
--- a/fs/xfs/libxfs/xfs_btree.c
+++ b/fs/xfs/libxfs/xfs_btree.c
@@ -2944,7 +2944,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;
/*
@@ -3000,7 +3000,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;
/*
@@ -3237,7 +3237,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:
@@ -5251,6 +5251,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 8813b5b4c798..86d4a225aca1 100644
--- a/fs/xfs/libxfs/xfs_btree.h
+++ b/fs/xfs/libxfs/xfs_btree.h
@@ -238,9 +238,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 */
diff --git a/fs/xfs/libxfs/xfs_btree_staging.c b/fs/xfs/libxfs/xfs_btree_staging.c
index 6d9c89d8c918..03e23ce17314 100644
--- a/fs/xfs/libxfs/xfs_btree_staging.c
+++ b/fs/xfs/libxfs/xfs_btree_staging.c
@@ -664,12 +664,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;
@@ -712,7 +712,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);
@@ -728,14 +728,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;