summaryrefslogtreecommitdiff
path: root/fs/xfs/scrub/btree.h
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-16 12:21:55 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-10-19 11:45:14 -0700
commiteae5db476f9db78b31d6665924539dd8e2d2f431 (patch)
tree055315da53845a0697ca6f018e6cbb21badd8ce7 /fs/xfs/scrub/btree.h
parentd47fef9342d0c322f69695a0eb2e2a643575b66d (diff)
xfs: dynamically allocate btree scrub context structure
Reorganize struct xchk_btree so that we can dynamically size the context structure to fit the type of btree cursor that we have. This will enable us to use memory more efficiently once we start adding very tall btree types. Right-size the lastkey array to match the number of *node* levels in the tree so that we stop wasting space. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
Diffstat (limited to 'fs/xfs/scrub/btree.h')
-rw-r--r--fs/xfs/scrub/btree.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/fs/xfs/scrub/btree.h b/fs/xfs/scrub/btree.h
index 7671108f9f85..da61a53a0b61 100644
--- a/fs/xfs/scrub/btree.h
+++ b/fs/xfs/scrub/btree.h
@@ -39,9 +39,22 @@ struct xchk_btree {
/* internal scrub state */
union xfs_btree_rec lastrec;
- union xfs_btree_key lastkey[XFS_BTREE_MAXLEVELS];
struct list_head to_check;
+
+ /* this element must come last! */
+ union xfs_btree_key lastkey[];
};
+
+/*
+ * Calculate the size of a xchk_btree structure. There are nlevels-1 slots for
+ * keys because we track leaf records separately in lastrec.
+ */
+static inline size_t
+xchk_btree_sizeof(unsigned int nlevels)
+{
+ return struct_size((struct xchk_btree *)NULL, lastkey, nlevels - 1);
+}
+
int xchk_btree(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
xchk_btree_rec_fn scrub_fn, const struct xfs_owner_info *oinfo,
void *private);