1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2020 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
6 #ifndef __XFS_BTREE_STAGING_H__
7 #define __XFS_BTREE_STAGING_H__
9 /* Fake root for an AG-rooted btree. */
10 struct xbtree_afakeroot {
11 /* AG block number of the new btree root. */
12 xfs_agblock_t af_root;
14 /* Height of the new btree. */
15 unsigned int af_levels;
17 /* Number of blocks used by the btree. */
18 unsigned int af_blocks;
21 /* Cursor interactions with fake roots for AG-rooted btrees. */
22 void xfs_btree_stage_afakeroot(struct xfs_btree_cur *cur,
23 struct xbtree_afakeroot *afake);
24 void xfs_btree_commit_afakeroot(struct xfs_btree_cur *cur, struct xfs_trans *tp,
25 struct xfs_buf *agbp, const struct xfs_btree_ops *ops);
27 /* Fake root for an inode-rooted btree. */
28 struct xbtree_ifakeroot {
29 /* Fake inode fork. */
30 struct xfs_ifork *if_fork;
32 /* Number of blocks used by the btree. */
35 /* Height of the new btree. */
36 unsigned int if_levels;
38 /* Number of bytes available for this fork in the inode. */
39 unsigned int if_fork_size;
42 unsigned int if_format;
44 /* Number of records. */
45 unsigned int if_extents;
48 /* Cursor interactions with fake roots for inode-rooted btrees. */
49 void xfs_btree_stage_ifakeroot(struct xfs_btree_cur *cur,
50 struct xbtree_ifakeroot *ifake,
51 struct xfs_btree_ops **new_ops);
52 void xfs_btree_commit_ifakeroot(struct xfs_btree_cur *cur, struct xfs_trans *tp,
53 int whichfork, const struct xfs_btree_ops *ops);
55 /* Bulk loading of staged btrees. */
56 typedef int (*xfs_btree_bload_get_record_fn)(struct xfs_btree_cur *cur, void *priv);
57 typedef int (*xfs_btree_bload_claim_block_fn)(struct xfs_btree_cur *cur,
58 union xfs_btree_ptr *ptr, void *priv);
59 typedef size_t (*xfs_btree_bload_iroot_size_fn)(struct xfs_btree_cur *cur,
60 unsigned int nr_this_level, void *priv);
62 struct xfs_btree_bload {
64 * This function will be called nr_records times to load records into
65 * the btree. The function does this by setting the cursor's bc_rec
66 * field in in-core format. Records must be returned in sort order.
68 xfs_btree_bload_get_record_fn get_record;
71 * This function will be called nr_blocks times to obtain a pointer
72 * to a new btree block on disk. Callers must preallocate all space
73 * for the new btree before calling xfs_btree_bload, and this function
74 * is what claims that reservation.
76 xfs_btree_bload_claim_block_fn claim_block;
79 * This function should return the size of the in-core btree root
80 * block. It is only necessary for XFS_BTREE_ROOT_IN_INODE btree
83 xfs_btree_bload_iroot_size_fn iroot_size;
86 * The caller should set this to the number of records that will be
87 * stored in the new btree.
92 * Number of free records to leave in each leaf block. If the caller
93 * sets this to -1, the slack value will be calculated to be halfway
94 * between maxrecs and minrecs. This typically leaves the block 75%
95 * full. Note that slack values are not enforced on inode root blocks.
100 * Number of free key/ptrs pairs to leave in each node block. This
101 * field has the same semantics as leaf_slack.
106 * The xfs_btree_bload_compute_geometry function will set this to the
107 * number of btree blocks needed to store nr_records records.
112 * The xfs_btree_bload_compute_geometry function will set this to the
113 * height of the new btree.
115 unsigned int btree_height;
118 int xfs_btree_bload_compute_geometry(struct xfs_btree_cur *cur,
119 struct xfs_btree_bload *bbl, uint64_t nr_records);
120 int xfs_btree_bload(struct xfs_btree_cur *cur, struct xfs_btree_bload *bbl,
123 #endif /* __XFS_BTREE_STAGING_H__ */