This source file includes following definitions.
- xfs_btree_get_numrecs
- xfs_btree_set_numrecs
- xfs_btree_get_level
1
2
3
4
5
6 #ifndef __XFS_BTREE_H__
7 #define __XFS_BTREE_H__
8
9 struct xfs_buf;
10 struct xfs_inode;
11 struct xfs_mount;
12 struct xfs_trans;
13
14 extern kmem_zone_t *xfs_btree_cur_zone;
15
16
17
18
19
20
21
22 union xfs_btree_ptr {
23 __be32 s;
24 __be64 l;
25 };
26
27
28
29
30
31
32 union xfs_btree_key {
33 struct xfs_bmbt_key bmbt;
34 xfs_bmdr_key_t bmbr;
35 xfs_alloc_key_t alloc;
36 struct xfs_inobt_key inobt;
37 struct xfs_rmap_key rmap;
38 struct xfs_rmap_key __rmap_bigkey[2];
39 struct xfs_refcount_key refc;
40 };
41
42 union xfs_btree_rec {
43 struct xfs_bmbt_rec bmbt;
44 xfs_bmdr_rec_t bmbr;
45 struct xfs_alloc_rec alloc;
46 struct xfs_inobt_rec inobt;
47 struct xfs_rmap_rec rmap;
48 struct xfs_refcount_rec refc;
49 };
50
51
52
53
54 #define XFS_LOOKUP_EQ ((xfs_lookup_t)XFS_LOOKUP_EQi)
55 #define XFS_LOOKUP_LE ((xfs_lookup_t)XFS_LOOKUP_LEi)
56 #define XFS_LOOKUP_GE ((xfs_lookup_t)XFS_LOOKUP_GEi)
57
58 #define XFS_BTNUM_BNO ((xfs_btnum_t)XFS_BTNUM_BNOi)
59 #define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi)
60 #define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi)
61 #define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi)
62 #define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi)
63 #define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi)
64 #define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi)
65
66 uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum);
67
68
69
70
71 #define XFS_BB_MAGIC (1 << 0)
72 #define XFS_BB_LEVEL (1 << 1)
73 #define XFS_BB_NUMRECS (1 << 2)
74 #define XFS_BB_LEFTSIB (1 << 3)
75 #define XFS_BB_RIGHTSIB (1 << 4)
76 #define XFS_BB_BLKNO (1 << 5)
77 #define XFS_BB_LSN (1 << 6)
78 #define XFS_BB_UUID (1 << 7)
79 #define XFS_BB_OWNER (1 << 8)
80 #define XFS_BB_NUM_BITS 5
81 #define XFS_BB_ALL_BITS ((1 << XFS_BB_NUM_BITS) - 1)
82 #define XFS_BB_NUM_BITS_CRC 9
83 #define XFS_BB_ALL_BITS_CRC ((1 << XFS_BB_NUM_BITS_CRC) - 1)
84
85
86
87
88 #define XFS_BTREE_STATS_INC(cur, stat) \
89 XFS_STATS_INC_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat)
90 #define XFS_BTREE_STATS_ADD(cur, stat, val) \
91 XFS_STATS_ADD_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat, val)
92
93 #define XFS_BTREE_MAXLEVELS 9
94
95 struct xfs_btree_ops {
96
97 size_t key_len;
98 size_t rec_len;
99
100
101 struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *);
102 void (*update_cursor)(struct xfs_btree_cur *src,
103 struct xfs_btree_cur *dst);
104
105
106 void (*set_root)(struct xfs_btree_cur *cur,
107 union xfs_btree_ptr *nptr, int level_change);
108
109
110 int (*alloc_block)(struct xfs_btree_cur *cur,
111 union xfs_btree_ptr *start_bno,
112 union xfs_btree_ptr *new_bno,
113 int *stat);
114 int (*free_block)(struct xfs_btree_cur *cur, struct xfs_buf *bp);
115
116
117 void (*update_lastrec)(struct xfs_btree_cur *cur,
118 struct xfs_btree_block *block,
119 union xfs_btree_rec *rec,
120 int ptr, int reason);
121
122
123 int (*get_minrecs)(struct xfs_btree_cur *cur, int level);
124 int (*get_maxrecs)(struct xfs_btree_cur *cur, int level);
125
126
127 int (*get_dmaxrecs)(struct xfs_btree_cur *cur, int level);
128
129
130 void (*init_key_from_rec)(union xfs_btree_key *key,
131 union xfs_btree_rec *rec);
132 void (*init_rec_from_cur)(struct xfs_btree_cur *cur,
133 union xfs_btree_rec *rec);
134 void (*init_ptr_from_cur)(struct xfs_btree_cur *cur,
135 union xfs_btree_ptr *ptr);
136 void (*init_high_key_from_rec)(union xfs_btree_key *key,
137 union xfs_btree_rec *rec);
138
139
140 int64_t (*key_diff)(struct xfs_btree_cur *cur,
141 union xfs_btree_key *key);
142
143
144
145
146
147 int64_t (*diff_two_keys)(struct xfs_btree_cur *cur,
148 union xfs_btree_key *key1,
149 union xfs_btree_key *key2);
150
151 const struct xfs_buf_ops *buf_ops;
152
153
154 int (*keys_inorder)(struct xfs_btree_cur *cur,
155 union xfs_btree_key *k1,
156 union xfs_btree_key *k2);
157
158
159 int (*recs_inorder)(struct xfs_btree_cur *cur,
160 union xfs_btree_rec *r1,
161 union xfs_btree_rec *r2);
162 };
163
164
165
166
167 #define LASTREC_UPDATE 0
168 #define LASTREC_INSREC 1
169 #define LASTREC_DELREC 2
170
171
172 union xfs_btree_irec {
173 struct xfs_alloc_rec_incore a;
174 struct xfs_bmbt_irec b;
175 struct xfs_inobt_rec_incore i;
176 struct xfs_rmap_irec r;
177 struct xfs_refcount_irec rc;
178 };
179
180
181 union xfs_btree_cur_private {
182 struct {
183 unsigned long nr_ops;
184 int shape_changes;
185 } refc;
186 };
187
188
189
190
191
192 typedef struct xfs_btree_cur
193 {
194 struct xfs_trans *bc_tp;
195 struct xfs_mount *bc_mp;
196 const struct xfs_btree_ops *bc_ops;
197 uint bc_flags;
198 union xfs_btree_irec bc_rec;
199 struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS];
200 int bc_ptrs[XFS_BTREE_MAXLEVELS];
201 uint8_t bc_ra[XFS_BTREE_MAXLEVELS];
202 #define XFS_BTCUR_LEFTRA 1
203 #define XFS_BTCUR_RIGHTRA 2
204 uint8_t bc_nlevels;
205 uint8_t bc_blocklog;
206 xfs_btnum_t bc_btnum;
207 int bc_statoff;
208 union {
209 struct {
210 struct xfs_buf *agbp;
211 xfs_agnumber_t agno;
212 union xfs_btree_cur_private priv;
213 } a;
214 struct {
215 struct xfs_inode *ip;
216 int allocated;
217 short forksize;
218 char whichfork;
219 char flags;
220 #define XFS_BTCUR_BPRV_WASDEL (1<<0)
221 #define XFS_BTCUR_BPRV_INVALID_OWNER (1<<1)
222 } b;
223 } bc_private;
224 } xfs_btree_cur_t;
225
226
227 #define XFS_BTREE_LONG_PTRS (1<<0)
228 #define XFS_BTREE_ROOT_IN_INODE (1<<1)
229 #define XFS_BTREE_LASTREC_UPDATE (1<<2)
230 #define XFS_BTREE_CRC_BLOCKS (1<<3)
231 #define XFS_BTREE_OVERLAPPING (1<<4)
232
233
234 #define XFS_BTREE_NOERROR 0
235 #define XFS_BTREE_ERROR 1
236
237
238
239
240 #define XFS_BUF_TO_BLOCK(bp) ((struct xfs_btree_block *)((bp)->b_addr))
241
242
243
244
245
246 xfs_failaddr_t __xfs_btree_check_lblock(struct xfs_btree_cur *cur,
247 struct xfs_btree_block *block, int level, struct xfs_buf *bp);
248 xfs_failaddr_t __xfs_btree_check_sblock(struct xfs_btree_cur *cur,
249 struct xfs_btree_block *block, int level, struct xfs_buf *bp);
250
251
252
253
254 int
255 xfs_btree_check_block(
256 struct xfs_btree_cur *cur,
257 struct xfs_btree_block *block,
258 int level,
259 struct xfs_buf *bp);
260
261
262
263
264 bool
265 xfs_btree_check_lptr(
266 struct xfs_btree_cur *cur,
267 xfs_fsblock_t fsbno,
268 int level);
269
270
271
272
273 bool
274 xfs_btree_check_sptr(
275 struct xfs_btree_cur *cur,
276 xfs_agblock_t agbno,
277 int level);
278
279
280
281
282 void
283 xfs_btree_del_cursor(
284 xfs_btree_cur_t *cur,
285 int error);
286
287
288
289
290
291 int
292 xfs_btree_dup_cursor(
293 xfs_btree_cur_t *cur,
294 xfs_btree_cur_t **ncur);
295
296
297
298
299
300 struct xfs_buf *
301 xfs_btree_get_bufl(
302 struct xfs_mount *mp,
303 struct xfs_trans *tp,
304 xfs_fsblock_t fsbno);
305
306
307
308
309
310 struct xfs_buf *
311 xfs_btree_get_bufs(
312 struct xfs_mount *mp,
313 struct xfs_trans *tp,
314 xfs_agnumber_t agno,
315 xfs_agblock_t agbno);
316
317
318
319
320 int
321 xfs_btree_islastblock(
322 xfs_btree_cur_t *cur,
323 int level);
324
325
326
327
328
329 void
330 xfs_btree_offsets(
331 int64_t fields,
332 const short *offsets,
333 int nbits,
334 int *first,
335 int *last);
336
337
338
339
340
341 int
342 xfs_btree_read_bufl(
343 struct xfs_mount *mp,
344 struct xfs_trans *tp,
345 xfs_fsblock_t fsbno,
346 struct xfs_buf **bpp,
347 int refval,
348 const struct xfs_buf_ops *ops);
349
350
351
352
353
354 void
355 xfs_btree_reada_bufl(
356 struct xfs_mount *mp,
357 xfs_fsblock_t fsbno,
358 xfs_extlen_t count,
359 const struct xfs_buf_ops *ops);
360
361
362
363
364
365 void
366 xfs_btree_reada_bufs(
367 struct xfs_mount *mp,
368 xfs_agnumber_t agno,
369 xfs_agblock_t agbno,
370 xfs_extlen_t count,
371 const struct xfs_buf_ops *ops);
372
373
374
375
376 void
377 xfs_btree_init_block(
378 struct xfs_mount *mp,
379 struct xfs_buf *bp,
380 xfs_btnum_t btnum,
381 __u16 level,
382 __u16 numrecs,
383 __u64 owner);
384
385 void
386 xfs_btree_init_block_int(
387 struct xfs_mount *mp,
388 struct xfs_btree_block *buf,
389 xfs_daddr_t blkno,
390 xfs_btnum_t btnum,
391 __u16 level,
392 __u16 numrecs,
393 __u64 owner,
394 unsigned int flags);
395
396
397
398
399 int xfs_btree_increment(struct xfs_btree_cur *, int, int *);
400 int xfs_btree_decrement(struct xfs_btree_cur *, int, int *);
401 int xfs_btree_lookup(struct xfs_btree_cur *, xfs_lookup_t, int *);
402 int xfs_btree_update(struct xfs_btree_cur *, union xfs_btree_rec *);
403 int xfs_btree_new_iroot(struct xfs_btree_cur *, int *, int *);
404 int xfs_btree_insert(struct xfs_btree_cur *, int *);
405 int xfs_btree_delete(struct xfs_btree_cur *, int *);
406 int xfs_btree_get_rec(struct xfs_btree_cur *, union xfs_btree_rec **, int *);
407 int xfs_btree_change_owner(struct xfs_btree_cur *cur, uint64_t new_owner,
408 struct list_head *buffer_list);
409
410
411
412
413 void xfs_btree_lblock_calc_crc(struct xfs_buf *);
414 bool xfs_btree_lblock_verify_crc(struct xfs_buf *);
415 void xfs_btree_sblock_calc_crc(struct xfs_buf *);
416 bool xfs_btree_sblock_verify_crc(struct xfs_buf *);
417
418
419
420
421 void xfs_btree_log_block(struct xfs_btree_cur *, struct xfs_buf *, int);
422 void xfs_btree_log_recs(struct xfs_btree_cur *, struct xfs_buf *, int, int);
423
424
425
426
427 static inline int xfs_btree_get_numrecs(struct xfs_btree_block *block)
428 {
429 return be16_to_cpu(block->bb_numrecs);
430 }
431
432 static inline void xfs_btree_set_numrecs(struct xfs_btree_block *block,
433 uint16_t numrecs)
434 {
435 block->bb_numrecs = cpu_to_be16(numrecs);
436 }
437
438 static inline int xfs_btree_get_level(struct xfs_btree_block *block)
439 {
440 return be16_to_cpu(block->bb_level);
441 }
442
443
444
445
446
447 #define XFS_EXTLEN_MIN(a,b) min_t(xfs_extlen_t, (a), (b))
448 #define XFS_EXTLEN_MAX(a,b) max_t(xfs_extlen_t, (a), (b))
449 #define XFS_AGBLOCK_MIN(a,b) min_t(xfs_agblock_t, (a), (b))
450 #define XFS_AGBLOCK_MAX(a,b) max_t(xfs_agblock_t, (a), (b))
451 #define XFS_FILEOFF_MIN(a,b) min_t(xfs_fileoff_t, (a), (b))
452 #define XFS_FILEOFF_MAX(a,b) max_t(xfs_fileoff_t, (a), (b))
453 #define XFS_FILBLKS_MIN(a,b) min_t(xfs_filblks_t, (a), (b))
454 #define XFS_FILBLKS_MAX(a,b) max_t(xfs_filblks_t, (a), (b))
455
456 xfs_failaddr_t xfs_btree_sblock_v5hdr_verify(struct xfs_buf *bp);
457 xfs_failaddr_t xfs_btree_sblock_verify(struct xfs_buf *bp,
458 unsigned int max_recs);
459 xfs_failaddr_t xfs_btree_lblock_v5hdr_verify(struct xfs_buf *bp,
460 uint64_t owner);
461 xfs_failaddr_t xfs_btree_lblock_verify(struct xfs_buf *bp,
462 unsigned int max_recs);
463
464 uint xfs_btree_compute_maxlevels(uint *limits, unsigned long len);
465 unsigned long long xfs_btree_calc_size(uint *limits, unsigned long long len);
466
467
468
469
470
471
472
473
474 typedef int (*xfs_btree_query_range_fn)(struct xfs_btree_cur *cur,
475 union xfs_btree_rec *rec, void *priv);
476
477 int xfs_btree_query_range(struct xfs_btree_cur *cur,
478 union xfs_btree_irec *low_rec, union xfs_btree_irec *high_rec,
479 xfs_btree_query_range_fn fn, void *priv);
480 int xfs_btree_query_all(struct xfs_btree_cur *cur, xfs_btree_query_range_fn fn,
481 void *priv);
482
483 typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
484 void *data);
485 int xfs_btree_visit_blocks(struct xfs_btree_cur *cur,
486 xfs_btree_visit_blocks_fn fn, void *data);
487
488 int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks);
489
490 union xfs_btree_rec *xfs_btree_rec_addr(struct xfs_btree_cur *cur, int n,
491 struct xfs_btree_block *block);
492 union xfs_btree_key *xfs_btree_key_addr(struct xfs_btree_cur *cur, int n,
493 struct xfs_btree_block *block);
494 union xfs_btree_key *xfs_btree_high_key_addr(struct xfs_btree_cur *cur, int n,
495 struct xfs_btree_block *block);
496 union xfs_btree_ptr *xfs_btree_ptr_addr(struct xfs_btree_cur *cur, int n,
497 struct xfs_btree_block *block);
498 int xfs_btree_lookup_get_block(struct xfs_btree_cur *cur, int level,
499 union xfs_btree_ptr *pp, struct xfs_btree_block **blkp);
500 struct xfs_btree_block *xfs_btree_get_block(struct xfs_btree_cur *cur,
501 int level, struct xfs_buf **bpp);
502 bool xfs_btree_ptr_is_null(struct xfs_btree_cur *cur, union xfs_btree_ptr *ptr);
503 int64_t xfs_btree_diff_two_ptrs(struct xfs_btree_cur *cur,
504 const union xfs_btree_ptr *a,
505 const union xfs_btree_ptr *b);
506 void xfs_btree_get_sibling(struct xfs_btree_cur *cur,
507 struct xfs_btree_block *block,
508 union xfs_btree_ptr *ptr, int lr);
509 void xfs_btree_get_keys(struct xfs_btree_cur *cur,
510 struct xfs_btree_block *block, union xfs_btree_key *key);
511 union xfs_btree_key *xfs_btree_high_key_from_key(struct xfs_btree_cur *cur,
512 union xfs_btree_key *key);
513 int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low,
514 union xfs_btree_irec *high, bool *exists);
515 bool xfs_btree_has_more_records(struct xfs_btree_cur *cur);
516
517 #endif