Line data Source code
1 : /* SPDX-License-Identifier: GPL-2.0-or-later */
2 : /*
3 : * Copyright (C) 2018-2023 Oracle. All Rights Reserved.
4 : * Author: Darrick J. Wong <djwong@kernel.org>
5 : */
6 : #ifndef __XFS_RTRMAP_BTREE_H__
7 : #define __XFS_RTRMAP_BTREE_H__
8 :
9 : struct xfs_buf;
10 : struct xfs_btree_cur;
11 : struct xfs_mount;
12 : struct xbtree_ifakeroot;
13 : struct xfs_rtgroup;
14 : struct xfs_imeta_path;
15 :
16 : /* rmaps only exist on crc enabled filesystems */
17 : #define XFS_RTRMAP_BLOCK_LEN XFS_BTREE_LBLOCK_CRC_LEN
18 :
19 : struct xfs_btree_cur *xfs_rtrmapbt_init_cursor(struct xfs_mount *mp,
20 : struct xfs_trans *tp, struct xfs_rtgroup *rtg,
21 : struct xfs_inode *ip);
22 : struct xfs_btree_cur *xfs_rtrmapbt_stage_cursor(struct xfs_mount *mp,
23 : struct xfs_rtgroup *rtg, struct xfs_inode *ip,
24 : struct xbtree_ifakeroot *ifake);
25 : void xfs_rtrmapbt_commit_staged_btree(struct xfs_btree_cur *cur,
26 : struct xfs_trans *tp);
27 : unsigned int xfs_rtrmapbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
28 : bool leaf);
29 : void xfs_rtrmapbt_compute_maxlevels(struct xfs_mount *mp);
30 : unsigned int xfs_rtrmapbt_droot_maxrecs(unsigned int blocklen, bool leaf);
31 :
32 : /*
33 : * Addresses of records, keys, and pointers within an incore rtrmapbt block.
34 : *
35 : * (note that some of these may appear unused, but they are used in userspace)
36 : */
37 : static inline struct xfs_rmap_rec *
38 : xfs_rtrmap_rec_addr(
39 : struct xfs_btree_block *block,
40 : unsigned int index)
41 : {
42 690146 : return (struct xfs_rmap_rec *)
43 : ((char *)block + XFS_RTRMAP_BLOCK_LEN +
44 : (index - 1) * sizeof(struct xfs_rmap_rec));
45 : }
46 :
47 : static inline struct xfs_rmap_key *
48 : xfs_rtrmap_key_addr(
49 : struct xfs_btree_block *block,
50 : unsigned int index)
51 : {
52 56266 : return (struct xfs_rmap_key *)
53 : ((char *)block + XFS_RTRMAP_BLOCK_LEN +
54 : (index - 1) * 2 * sizeof(struct xfs_rmap_key));
55 : }
56 :
57 : static inline struct xfs_rmap_key *
58 : xfs_rtrmap_high_key_addr(
59 : struct xfs_btree_block *block,
60 : unsigned int index)
61 : {
62 : return (struct xfs_rmap_key *)
63 : ((char *)block + XFS_RTRMAP_BLOCK_LEN +
64 : sizeof(struct xfs_rmap_key) +
65 : (index - 1) * 2 * sizeof(struct xfs_rmap_key));
66 : }
67 :
68 : static inline xfs_rtrmap_ptr_t *
69 : xfs_rtrmap_ptr_addr(
70 : struct xfs_btree_block *block,
71 : unsigned int index,
72 : unsigned int maxrecs)
73 : {
74 65434 : return (xfs_rtrmap_ptr_t *)
75 : ((char *)block + XFS_RTRMAP_BLOCK_LEN +
76 65434 : maxrecs * 2 * sizeof(struct xfs_rmap_key) +
77 : (index - 1) * sizeof(xfs_rtrmap_ptr_t));
78 : }
79 :
80 : unsigned int xfs_rtrmapbt_maxlevels_ondisk(void);
81 :
82 : int __init xfs_rtrmapbt_init_cur_cache(void);
83 : void xfs_rtrmapbt_destroy_cur_cache(void);
84 :
85 : int xfs_rtrmapbt_create_path(struct xfs_mount *mp, xfs_rgnumber_t rgno,
86 : struct xfs_imeta_path **pathp);
87 :
88 : xfs_filblks_t xfs_rtrmapbt_calc_reserves(struct xfs_mount *mp);
89 :
90 : /* Addresses of key, pointers, and records within an ondisk rtrmapbt block. */
91 :
92 : static inline struct xfs_rmap_rec *
93 : xfs_rtrmap_droot_rec_addr(
94 : struct xfs_rtrmap_root *block,
95 : unsigned int index)
96 : {
97 113234 : return (struct xfs_rmap_rec *)
98 : ((char *)(block + 1) +
99 : (index - 1) * sizeof(struct xfs_rmap_rec));
100 : }
101 :
102 : static inline struct xfs_rmap_key *
103 : xfs_rtrmap_droot_key_addr(
104 : struct xfs_rtrmap_root *block,
105 : unsigned int index)
106 : {
107 49665 : return (struct xfs_rmap_key *)
108 : ((char *)(block + 1) +
109 : (index - 1) * 2 * sizeof(struct xfs_rmap_key));
110 : }
111 :
112 : static inline xfs_rtrmap_ptr_t *
113 : xfs_rtrmap_droot_ptr_addr(
114 : struct xfs_rtrmap_root *block,
115 : unsigned int index,
116 : unsigned int maxrecs)
117 : {
118 49665 : return (xfs_rtrmap_ptr_t *)
119 : ((char *)(block + 1) +
120 49665 : maxrecs * 2 * sizeof(struct xfs_rmap_key) +
121 : (index - 1) * sizeof(xfs_rtrmap_ptr_t));
122 : }
123 :
124 : /*
125 : * Address of pointers within the incore btree root.
126 : *
127 : * These are to be used when we know the size of the block and
128 : * we don't have a cursor.
129 : */
130 : static inline xfs_rtrmap_ptr_t *
131 : xfs_rtrmap_broot_ptr_addr(
132 : struct xfs_mount *mp,
133 : struct xfs_btree_block *bb,
134 : unsigned int index,
135 : unsigned int block_size)
136 : {
137 65434 : return xfs_rtrmap_ptr_addr(bb, index,
138 : xfs_rtrmapbt_maxrecs(mp, block_size, false));
139 : }
140 :
141 : /*
142 : * Compute the space required for the incore btree root containing the given
143 : * number of records.
144 : */
145 : static inline size_t
146 1338811 : xfs_rtrmap_broot_space_calc(
147 : struct xfs_mount *mp,
148 : unsigned int level,
149 : unsigned int nrecs)
150 : {
151 1544702 : size_t sz = XFS_RTRMAP_BLOCK_LEN;
152 :
153 1447291 : if (level > 0)
154 88631 : return sz + nrecs * (2 * sizeof(struct xfs_rmap_key) +
155 : sizeof(xfs_rtrmap_ptr_t));
156 1456071 : return sz + nrecs * sizeof(struct xfs_rmap_rec);
157 : }
158 :
159 : /*
160 : * Compute the space required for the incore btree root given the ondisk
161 : * btree root block.
162 : */
163 : static inline size_t
164 : xfs_rtrmap_broot_space(struct xfs_mount *mp, struct xfs_rtrmap_root *bb)
165 : {
166 97411 : return xfs_rtrmap_broot_space_calc(mp, be16_to_cpu(bb->bb_level),
167 97411 : be16_to_cpu(bb->bb_numrecs));
168 : }
169 :
170 : /* Compute the space required for the ondisk root block. */
171 : static inline size_t
172 : xfs_rtrmap_droot_space_calc(
173 : unsigned int level,
174 : unsigned int nrecs)
175 : {
176 1431952 : size_t sz = sizeof(struct xfs_rtrmap_root);
177 :
178 97411 : if (level > 0)
179 64073 : return sz + nrecs * (2 * sizeof(struct xfs_rmap_key) +
180 : sizeof(xfs_rtrmap_ptr_t));
181 1367879 : return sz + nrecs * sizeof(struct xfs_rmap_rec);
182 : }
183 :
184 : /*
185 : * Compute the space required for the ondisk root block given an incore root
186 : * block.
187 : */
188 : static inline size_t
189 : xfs_rtrmap_droot_space(struct xfs_btree_block *bb)
190 : {
191 1334541 : return xfs_rtrmap_droot_space_calc(be16_to_cpu(bb->bb_level),
192 1334541 : be16_to_cpu(bb->bb_numrecs));
193 : }
194 :
195 : int xfs_iformat_rtrmap(struct xfs_inode *ip, struct xfs_dinode *dip);
196 : void xfs_rtrmapbt_to_disk(struct xfs_mount *mp, struct xfs_btree_block *rblock,
197 : unsigned int rblocklen, struct xfs_rtrmap_root *dblock,
198 : unsigned int dblocklen);
199 : void xfs_iflush_rtrmap(struct xfs_inode *ip, struct xfs_dinode *dip);
200 :
201 : struct xfs_imeta_update;
202 :
203 : int xfs_rtrmapbt_create(struct xfs_imeta_update *upd, struct xfs_inode **ipp);
204 :
205 : unsigned long long xfs_rtrmapbt_calc_size(struct xfs_mount *mp,
206 : unsigned long long len);
207 :
208 : #ifdef CONFIG_XFS_BTREE_IN_XFILE
209 : struct xfbtree;
210 : struct xfs_btree_cur *xfs_rtrmapbt_mem_cursor(struct xfs_rtgroup *rtg,
211 : struct xfs_trans *tp, struct xfs_buf *mhead_bp,
212 : struct xfbtree *xfbtree);
213 : int xfs_rtrmapbt_mem_create(struct xfs_mount *mp, xfs_rgnumber_t rgno,
214 : struct xfs_buftarg *target, struct xfbtree **xfbtreep);
215 : #endif /* CONFIG_XFS_BTREE_IN_XFILE */
216 :
217 : #endif /* __XFS_RTRMAP_BTREE_H__ */
|