1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_trans_resv.h"
13 #include "xfs_mount.h"
14 #include "xfs_btree.h"
15 #include "xfs_btree_staging.h"
16 #include "xfs_ialloc.h"
17 #include "xfs_ialloc_btree.h"
18 #include "xfs_alloc.h"
19 #include "xfs_error.h"
20 #include "xfs_trace.h"
21 #include "xfs_trans.h"
25 static struct kmem_cache *xfs_inobt_cur_cache;
28 xfs_inobt_get_minrecs(
29 struct xfs_btree_cur *cur,
32 return M_IGEO(cur->bc_mp)->inobt_mnr[level != 0];
35 STATIC struct xfs_btree_cur *
37 struct xfs_btree_cur *cur)
39 return xfs_inobt_init_cursor(cur->bc_mp, cur->bc_tp,
40 cur->bc_ag.agbp, cur->bc_ag.pag, cur->bc_btnum);
45 struct xfs_btree_cur *cur,
46 const union xfs_btree_ptr *nptr,
47 int inc) /* level change */
49 struct xfs_buf *agbp = cur->bc_ag.agbp;
50 struct xfs_agi *agi = agbp->b_addr;
52 agi->agi_root = nptr->s;
53 be32_add_cpu(&agi->agi_level, inc);
54 xfs_ialloc_log_agi(cur->bc_tp, agbp, XFS_AGI_ROOT | XFS_AGI_LEVEL);
59 struct xfs_btree_cur *cur,
60 const union xfs_btree_ptr *nptr,
61 int inc) /* level change */
63 struct xfs_buf *agbp = cur->bc_ag.agbp;
64 struct xfs_agi *agi = agbp->b_addr;
66 agi->agi_free_root = nptr->s;
67 be32_add_cpu(&agi->agi_free_level, inc);
68 xfs_ialloc_log_agi(cur->bc_tp, agbp,
69 XFS_AGI_FREE_ROOT | XFS_AGI_FREE_LEVEL);
72 /* Update the inode btree block counter for this btree. */
74 xfs_inobt_mod_blockcount(
75 struct xfs_btree_cur *cur,
78 struct xfs_buf *agbp = cur->bc_ag.agbp;
79 struct xfs_agi *agi = agbp->b_addr;
81 if (!xfs_has_inobtcounts(cur->bc_mp))
84 if (cur->bc_btnum == XFS_BTNUM_FINO)
85 be32_add_cpu(&agi->agi_fblocks, howmuch);
86 else if (cur->bc_btnum == XFS_BTNUM_INO)
87 be32_add_cpu(&agi->agi_iblocks, howmuch);
88 xfs_ialloc_log_agi(cur->bc_tp, agbp, XFS_AGI_IBLOCKS);
92 __xfs_inobt_alloc_block(
93 struct xfs_btree_cur *cur,
94 const union xfs_btree_ptr *start,
95 union xfs_btree_ptr *new,
97 enum xfs_ag_resv_type resv)
99 xfs_alloc_arg_t args; /* block allocation args */
100 int error; /* error return value */
101 xfs_agblock_t sbno = be32_to_cpu(start->s);
103 memset(&args, 0, sizeof(args));
104 args.tp = cur->bc_tp;
105 args.mp = cur->bc_mp;
106 args.oinfo = XFS_RMAP_OINFO_INOBT;
107 args.fsbno = XFS_AGB_TO_FSB(args.mp, cur->bc_ag.pag->pag_agno, sbno);
111 args.type = XFS_ALLOCTYPE_NEAR_BNO;
114 error = xfs_alloc_vextent(&args);
118 if (args.fsbno == NULLFSBLOCK) {
122 ASSERT(args.len == 1);
124 new->s = cpu_to_be32(XFS_FSB_TO_AGBNO(args.mp, args.fsbno));
126 xfs_inobt_mod_blockcount(cur, 1);
131 xfs_inobt_alloc_block(
132 struct xfs_btree_cur *cur,
133 const union xfs_btree_ptr *start,
134 union xfs_btree_ptr *new,
137 return __xfs_inobt_alloc_block(cur, start, new, stat, XFS_AG_RESV_NONE);
141 xfs_finobt_alloc_block(
142 struct xfs_btree_cur *cur,
143 const union xfs_btree_ptr *start,
144 union xfs_btree_ptr *new,
147 if (cur->bc_mp->m_finobt_nores)
148 return xfs_inobt_alloc_block(cur, start, new, stat);
149 return __xfs_inobt_alloc_block(cur, start, new, stat,
150 XFS_AG_RESV_METADATA);
154 __xfs_inobt_free_block(
155 struct xfs_btree_cur *cur,
157 enum xfs_ag_resv_type resv)
159 xfs_inobt_mod_blockcount(cur, -1);
160 return xfs_free_extent(cur->bc_tp,
161 XFS_DADDR_TO_FSB(cur->bc_mp, xfs_buf_daddr(bp)), 1,
162 &XFS_RMAP_OINFO_INOBT, resv);
166 xfs_inobt_free_block(
167 struct xfs_btree_cur *cur,
170 return __xfs_inobt_free_block(cur, bp, XFS_AG_RESV_NONE);
174 xfs_finobt_free_block(
175 struct xfs_btree_cur *cur,
178 if (cur->bc_mp->m_finobt_nores)
179 return xfs_inobt_free_block(cur, bp);
180 return __xfs_inobt_free_block(cur, bp, XFS_AG_RESV_METADATA);
184 xfs_inobt_get_maxrecs(
185 struct xfs_btree_cur *cur,
188 return M_IGEO(cur->bc_mp)->inobt_mxr[level != 0];
192 xfs_inobt_init_key_from_rec(
193 union xfs_btree_key *key,
194 const union xfs_btree_rec *rec)
196 key->inobt.ir_startino = rec->inobt.ir_startino;
200 xfs_inobt_init_high_key_from_rec(
201 union xfs_btree_key *key,
202 const union xfs_btree_rec *rec)
206 x = be32_to_cpu(rec->inobt.ir_startino);
207 x += XFS_INODES_PER_CHUNK - 1;
208 key->inobt.ir_startino = cpu_to_be32(x);
212 xfs_inobt_init_rec_from_cur(
213 struct xfs_btree_cur *cur,
214 union xfs_btree_rec *rec)
216 rec->inobt.ir_startino = cpu_to_be32(cur->bc_rec.i.ir_startino);
217 if (xfs_has_sparseinodes(cur->bc_mp)) {
218 rec->inobt.ir_u.sp.ir_holemask =
219 cpu_to_be16(cur->bc_rec.i.ir_holemask);
220 rec->inobt.ir_u.sp.ir_count = cur->bc_rec.i.ir_count;
221 rec->inobt.ir_u.sp.ir_freecount = cur->bc_rec.i.ir_freecount;
223 /* ir_holemask/ir_count not supported on-disk */
224 rec->inobt.ir_u.f.ir_freecount =
225 cpu_to_be32(cur->bc_rec.i.ir_freecount);
227 rec->inobt.ir_free = cpu_to_be64(cur->bc_rec.i.ir_free);
231 * initial value of ptr for lookup
234 xfs_inobt_init_ptr_from_cur(
235 struct xfs_btree_cur *cur,
236 union xfs_btree_ptr *ptr)
238 struct xfs_agi *agi = cur->bc_ag.agbp->b_addr;
240 ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agi->agi_seqno));
242 ptr->s = agi->agi_root;
246 xfs_finobt_init_ptr_from_cur(
247 struct xfs_btree_cur *cur,
248 union xfs_btree_ptr *ptr)
250 struct xfs_agi *agi = cur->bc_ag.agbp->b_addr;
252 ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agi->agi_seqno));
253 ptr->s = agi->agi_free_root;
258 struct xfs_btree_cur *cur,
259 const union xfs_btree_key *key)
261 return (int64_t)be32_to_cpu(key->inobt.ir_startino) -
262 cur->bc_rec.i.ir_startino;
266 xfs_inobt_diff_two_keys(
267 struct xfs_btree_cur *cur,
268 const union xfs_btree_key *k1,
269 const union xfs_btree_key *k2)
271 return (int64_t)be32_to_cpu(k1->inobt.ir_startino) -
272 be32_to_cpu(k2->inobt.ir_startino);
275 static xfs_failaddr_t
279 struct xfs_mount *mp = bp->b_mount;
280 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
284 if (!xfs_verify_magic(bp, block->bb_magic))
285 return __this_address;
288 * During growfs operations, we can't verify the exact owner as the
289 * perag is not fully initialised and hence not attached to the buffer.
291 * Similarly, during log recovery we will have a perag structure
292 * attached, but the agi information will not yet have been initialised
293 * from the on disk AGI. We don't currently use any of this information,
294 * but beware of the landmine (i.e. need to check pag->pagi_init) if we
297 if (xfs_has_crc(mp)) {
298 fa = xfs_btree_sblock_v5hdr_verify(bp);
303 /* level verification */
304 level = be16_to_cpu(block->bb_level);
305 if (level >= M_IGEO(mp)->inobt_maxlevels)
306 return __this_address;
308 return xfs_btree_sblock_verify(bp,
309 M_IGEO(mp)->inobt_mxr[level != 0]);
313 xfs_inobt_read_verify(
318 if (!xfs_btree_sblock_verify_crc(bp))
319 xfs_verifier_error(bp, -EFSBADCRC, __this_address);
321 fa = xfs_inobt_verify(bp);
323 xfs_verifier_error(bp, -EFSCORRUPTED, fa);
327 trace_xfs_btree_corrupt(bp, _RET_IP_);
331 xfs_inobt_write_verify(
336 fa = xfs_inobt_verify(bp);
338 trace_xfs_btree_corrupt(bp, _RET_IP_);
339 xfs_verifier_error(bp, -EFSCORRUPTED, fa);
342 xfs_btree_sblock_calc_crc(bp);
346 const struct xfs_buf_ops xfs_inobt_buf_ops = {
348 .magic = { cpu_to_be32(XFS_IBT_MAGIC), cpu_to_be32(XFS_IBT_CRC_MAGIC) },
349 .verify_read = xfs_inobt_read_verify,
350 .verify_write = xfs_inobt_write_verify,
351 .verify_struct = xfs_inobt_verify,
354 const struct xfs_buf_ops xfs_finobt_buf_ops = {
355 .name = "xfs_finobt",
356 .magic = { cpu_to_be32(XFS_FIBT_MAGIC),
357 cpu_to_be32(XFS_FIBT_CRC_MAGIC) },
358 .verify_read = xfs_inobt_read_verify,
359 .verify_write = xfs_inobt_write_verify,
360 .verify_struct = xfs_inobt_verify,
364 xfs_inobt_keys_inorder(
365 struct xfs_btree_cur *cur,
366 const union xfs_btree_key *k1,
367 const union xfs_btree_key *k2)
369 return be32_to_cpu(k1->inobt.ir_startino) <
370 be32_to_cpu(k2->inobt.ir_startino);
374 xfs_inobt_recs_inorder(
375 struct xfs_btree_cur *cur,
376 const union xfs_btree_rec *r1,
377 const union xfs_btree_rec *r2)
379 return be32_to_cpu(r1->inobt.ir_startino) + XFS_INODES_PER_CHUNK <=
380 be32_to_cpu(r2->inobt.ir_startino);
383 static const struct xfs_btree_ops xfs_inobt_ops = {
384 .rec_len = sizeof(xfs_inobt_rec_t),
385 .key_len = sizeof(xfs_inobt_key_t),
387 .dup_cursor = xfs_inobt_dup_cursor,
388 .set_root = xfs_inobt_set_root,
389 .alloc_block = xfs_inobt_alloc_block,
390 .free_block = xfs_inobt_free_block,
391 .get_minrecs = xfs_inobt_get_minrecs,
392 .get_maxrecs = xfs_inobt_get_maxrecs,
393 .init_key_from_rec = xfs_inobt_init_key_from_rec,
394 .init_high_key_from_rec = xfs_inobt_init_high_key_from_rec,
395 .init_rec_from_cur = xfs_inobt_init_rec_from_cur,
396 .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur,
397 .key_diff = xfs_inobt_key_diff,
398 .buf_ops = &xfs_inobt_buf_ops,
399 .diff_two_keys = xfs_inobt_diff_two_keys,
400 .keys_inorder = xfs_inobt_keys_inorder,
401 .recs_inorder = xfs_inobt_recs_inorder,
404 static const struct xfs_btree_ops xfs_finobt_ops = {
405 .rec_len = sizeof(xfs_inobt_rec_t),
406 .key_len = sizeof(xfs_inobt_key_t),
408 .dup_cursor = xfs_inobt_dup_cursor,
409 .set_root = xfs_finobt_set_root,
410 .alloc_block = xfs_finobt_alloc_block,
411 .free_block = xfs_finobt_free_block,
412 .get_minrecs = xfs_inobt_get_minrecs,
413 .get_maxrecs = xfs_inobt_get_maxrecs,
414 .init_key_from_rec = xfs_inobt_init_key_from_rec,
415 .init_high_key_from_rec = xfs_inobt_init_high_key_from_rec,
416 .init_rec_from_cur = xfs_inobt_init_rec_from_cur,
417 .init_ptr_from_cur = xfs_finobt_init_ptr_from_cur,
418 .key_diff = xfs_inobt_key_diff,
419 .buf_ops = &xfs_finobt_buf_ops,
420 .diff_two_keys = xfs_inobt_diff_two_keys,
421 .keys_inorder = xfs_inobt_keys_inorder,
422 .recs_inorder = xfs_inobt_recs_inorder,
426 * Initialize a new inode btree cursor.
428 static struct xfs_btree_cur *
429 xfs_inobt_init_common(
430 struct xfs_mount *mp, /* file system mount point */
431 struct xfs_trans *tp, /* transaction pointer */
432 struct xfs_perag *pag,
433 xfs_btnum_t btnum) /* ialloc or free ino btree */
435 struct xfs_btree_cur *cur;
437 cur = xfs_btree_alloc_cursor(mp, tp, btnum,
438 M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
439 if (btnum == XFS_BTNUM_INO) {
440 cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2);
441 cur->bc_ops = &xfs_inobt_ops;
443 cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_fibt_2);
444 cur->bc_ops = &xfs_finobt_ops;
448 cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
450 /* take a reference for the cursor */
451 atomic_inc(&pag->pag_ref);
452 cur->bc_ag.pag = pag;
456 /* Create an inode btree cursor. */
457 struct xfs_btree_cur *
458 xfs_inobt_init_cursor(
459 struct xfs_mount *mp,
460 struct xfs_trans *tp,
461 struct xfs_buf *agbp,
462 struct xfs_perag *pag,
465 struct xfs_btree_cur *cur;
466 struct xfs_agi *agi = agbp->b_addr;
468 cur = xfs_inobt_init_common(mp, tp, pag, btnum);
469 if (btnum == XFS_BTNUM_INO)
470 cur->bc_nlevels = be32_to_cpu(agi->agi_level);
472 cur->bc_nlevels = be32_to_cpu(agi->agi_free_level);
473 cur->bc_ag.agbp = agbp;
477 /* Create an inode btree cursor with a fake root for staging. */
478 struct xfs_btree_cur *
479 xfs_inobt_stage_cursor(
480 struct xfs_mount *mp,
481 struct xbtree_afakeroot *afake,
482 struct xfs_perag *pag,
485 struct xfs_btree_cur *cur;
487 cur = xfs_inobt_init_common(mp, NULL, pag, btnum);
488 xfs_btree_stage_afakeroot(cur, afake);
493 * Install a new inobt btree root. Caller is responsible for invalidating
494 * and freeing the old btree blocks.
497 xfs_inobt_commit_staged_btree(
498 struct xfs_btree_cur *cur,
499 struct xfs_trans *tp,
500 struct xfs_buf *agbp)
502 struct xfs_agi *agi = agbp->b_addr;
503 struct xbtree_afakeroot *afake = cur->bc_ag.afake;
506 ASSERT(cur->bc_flags & XFS_BTREE_STAGING);
508 if (cur->bc_btnum == XFS_BTNUM_INO) {
509 fields = XFS_AGI_ROOT | XFS_AGI_LEVEL;
510 agi->agi_root = cpu_to_be32(afake->af_root);
511 agi->agi_level = cpu_to_be32(afake->af_levels);
512 if (xfs_has_inobtcounts(cur->bc_mp)) {
513 agi->agi_iblocks = cpu_to_be32(afake->af_blocks);
514 fields |= XFS_AGI_IBLOCKS;
516 xfs_ialloc_log_agi(tp, agbp, fields);
517 xfs_btree_commit_afakeroot(cur, tp, agbp, &xfs_inobt_ops);
519 fields = XFS_AGI_FREE_ROOT | XFS_AGI_FREE_LEVEL;
520 agi->agi_free_root = cpu_to_be32(afake->af_root);
521 agi->agi_free_level = cpu_to_be32(afake->af_levels);
522 if (xfs_has_inobtcounts(cur->bc_mp)) {
523 agi->agi_fblocks = cpu_to_be32(afake->af_blocks);
524 fields |= XFS_AGI_IBLOCKS;
526 xfs_ialloc_log_agi(tp, agbp, fields);
527 xfs_btree_commit_afakeroot(cur, tp, agbp, &xfs_finobt_ops);
531 /* Calculate number of records in an inode btree block. */
532 static inline unsigned int
533 xfs_inobt_block_maxrecs(
534 unsigned int blocklen,
538 return blocklen / sizeof(xfs_inobt_rec_t);
539 return blocklen / (sizeof(xfs_inobt_key_t) + sizeof(xfs_inobt_ptr_t));
543 * Calculate number of records in an inobt btree block.
547 struct xfs_mount *mp,
551 blocklen -= XFS_INOBT_BLOCK_LEN(mp);
552 return xfs_inobt_block_maxrecs(blocklen, leaf);
556 * Maximum number of inode btree records per AG. Pretend that we can fill an
557 * entire AG completely full of inodes except for the AG headers.
559 #define XFS_MAX_INODE_RECORDS \
560 ((XFS_MAX_AG_BYTES - (4 * BBSIZE)) / XFS_DINODE_MIN_SIZE) / \
563 /* Compute the max possible height for the inode btree. */
564 static inline unsigned int
565 xfs_inobt_maxlevels_ondisk(void)
567 unsigned int minrecs[2];
568 unsigned int blocklen;
570 blocklen = min(XFS_MIN_BLOCKSIZE - XFS_BTREE_SBLOCK_LEN,
571 XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN);
573 minrecs[0] = xfs_inobt_block_maxrecs(blocklen, true) / 2;
574 minrecs[1] = xfs_inobt_block_maxrecs(blocklen, false) / 2;
576 return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_INODE_RECORDS);
579 /* Compute the max possible height for the free inode btree. */
580 static inline unsigned int
581 xfs_finobt_maxlevels_ondisk(void)
583 unsigned int minrecs[2];
584 unsigned int blocklen;
586 blocklen = XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN;
588 minrecs[0] = xfs_inobt_block_maxrecs(blocklen, true) / 2;
589 minrecs[1] = xfs_inobt_block_maxrecs(blocklen, false) / 2;
591 return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_INODE_RECORDS);
594 /* Compute the max possible height for either inode btree. */
596 xfs_iallocbt_maxlevels_ondisk(void)
598 return max(xfs_inobt_maxlevels_ondisk(),
599 xfs_finobt_maxlevels_ondisk());
603 * Convert the inode record holemask to an inode allocation bitmap. The inode
604 * allocation bitmap is inode granularity and specifies whether an inode is
605 * physically allocated on disk (not whether the inode is considered allocated
606 * or free by the fs).
608 * A bit value of 1 means the inode is allocated, a value of 0 means it is free.
611 xfs_inobt_irec_to_allocmask(
612 struct xfs_inobt_rec_incore *rec)
620 * The holemask has 16-bits for a 64 inode record. Therefore each
621 * holemask bit represents multiple inodes. Create a mask of bits to set
622 * in the allocmask for each holemask bit.
624 inodespbit = (1 << XFS_INODES_PER_HOLEMASK_BIT) - 1;
627 * Allocated inodes are represented by 0 bits in holemask. Invert the 0
628 * bits to 1 and convert to a uint so we can use xfs_next_bit(). Mask
629 * anything beyond the 16 holemask bits since this casts to a larger
632 allocbitmap = ~rec->ir_holemask & ((1 << XFS_INOBT_HOLEMASK_BITS) - 1);
635 * allocbitmap is the inverted holemask so every set bit represents
636 * allocated inodes. To expand from 16-bit holemask granularity to
637 * 64-bit (e.g., bit-per-inode), set inodespbit bits in the target
638 * bitmap for every holemask bit.
640 nextbit = xfs_next_bit(&allocbitmap, 1, 0);
641 while (nextbit != -1) {
642 ASSERT(nextbit < (sizeof(rec->ir_holemask) * NBBY));
644 bitmap |= (inodespbit <<
645 (nextbit * XFS_INODES_PER_HOLEMASK_BIT));
647 nextbit = xfs_next_bit(&allocbitmap, 1, nextbit + 1);
653 #if defined(DEBUG) || defined(XFS_WARN)
655 * Verify that an in-core inode record has a valid inode count.
658 xfs_inobt_rec_check_count(
659 struct xfs_mount *mp,
660 struct xfs_inobt_rec_incore *rec)
667 wordsz = sizeof(allocbmap) / sizeof(unsigned int);
668 allocbmap = xfs_inobt_irec_to_allocmask(rec);
670 nextbit = xfs_next_bit((uint *) &allocbmap, wordsz, nextbit);
671 while (nextbit != -1) {
673 nextbit = xfs_next_bit((uint *) &allocbmap, wordsz,
677 if (inocount != rec->ir_count)
678 return -EFSCORRUPTED;
686 struct xfs_mount *mp,
689 xfs_agblock_t agblocks = xfs_ag_block_count(mp, agno);
691 /* Bail out if we're uninitialized, which can happen in mkfs. */
692 if (M_IGEO(mp)->inobt_mxr[0] == 0)
696 * The log is permanently allocated, so the space it occupies will
697 * never be available for the kinds of things that would require btree
698 * expansion. We therefore can pretend the space isn't there.
700 if (mp->m_sb.sb_logstart &&
701 XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart) == agno)
702 agblocks -= mp->m_sb.sb_logblocks;
704 return xfs_btree_calc_size(M_IGEO(mp)->inobt_mnr,
705 (uint64_t)agblocks * mp->m_sb.sb_inopblock /
706 XFS_INODES_PER_CHUNK);
709 /* Read AGI and create inobt cursor. */
712 struct xfs_mount *mp,
713 struct xfs_trans *tp,
714 struct xfs_perag *pag,
716 struct xfs_btree_cur **curpp,
717 struct xfs_buf **agi_bpp)
719 struct xfs_btree_cur *cur;
722 ASSERT(*agi_bpp == NULL);
723 ASSERT(*curpp == NULL);
725 error = xfs_ialloc_read_agi(pag, tp, agi_bpp);
729 cur = xfs_inobt_init_cursor(mp, tp, *agi_bpp, pag, which);
735 xfs_inobt_count_blocks(
736 struct xfs_mount *mp,
737 struct xfs_trans *tp,
738 struct xfs_perag *pag,
740 xfs_extlen_t *tree_blocks)
742 struct xfs_buf *agbp = NULL;
743 struct xfs_btree_cur *cur = NULL;
746 error = xfs_inobt_cur(mp, tp, pag, btnum, &cur, &agbp);
750 error = xfs_btree_count_blocks(cur, tree_blocks);
751 xfs_btree_del_cursor(cur, error);
752 xfs_trans_brelse(tp, agbp);
757 /* Read finobt block count from AGI header. */
759 xfs_finobt_read_blocks(
760 struct xfs_perag *pag,
761 struct xfs_trans *tp,
762 xfs_extlen_t *tree_blocks)
764 struct xfs_buf *agbp;
768 error = xfs_ialloc_read_agi(pag, tp, &agbp);
773 *tree_blocks = be32_to_cpu(agi->agi_fblocks);
774 xfs_trans_brelse(tp, agbp);
779 * Figure out how many blocks to reserve and how many are used by this btree.
782 xfs_finobt_calc_reserves(
783 struct xfs_mount *mp,
784 struct xfs_trans *tp,
785 struct xfs_perag *pag,
789 xfs_extlen_t tree_len = 0;
792 if (!xfs_has_finobt(mp))
795 if (xfs_has_inobtcounts(mp))
796 error = xfs_finobt_read_blocks(pag, tp, &tree_len);
798 error = xfs_inobt_count_blocks(mp, tp, pag, XFS_BTNUM_FINO,
803 *ask += xfs_inobt_max_size(mp, pag->pag_agno);
808 /* Calculate the inobt btree size for some records. */
810 xfs_iallocbt_calc_size(
811 struct xfs_mount *mp,
812 unsigned long long len)
814 return xfs_btree_calc_size(M_IGEO(mp)->inobt_mnr, len);
818 xfs_inobt_init_cur_cache(void)
820 xfs_inobt_cur_cache = kmem_cache_create("xfs_inobt_cur",
821 xfs_btree_cur_sizeof(xfs_inobt_maxlevels_ondisk()),
824 if (!xfs_inobt_cur_cache)
830 xfs_inobt_destroy_cur_cache(void)
832 kmem_cache_destroy(xfs_inobt_cur_cache);
833 xfs_inobt_cur_cache = NULL;