1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
6 #include "libxfs_priv.h"
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_trace.h"
20 #include "xfs_trans.h"
24 static struct kmem_cache
*xfs_inobt_cur_cache
;
27 xfs_inobt_get_minrecs(
28 struct xfs_btree_cur
*cur
,
31 return M_IGEO(cur
->bc_mp
)->inobt_mnr
[level
!= 0];
34 STATIC
struct xfs_btree_cur
*
36 struct xfs_btree_cur
*cur
)
38 return xfs_inobt_init_cursor(cur
->bc_mp
, cur
->bc_tp
,
39 cur
->bc_ag
.agbp
, cur
->bc_ag
.pag
, cur
->bc_btnum
);
44 struct xfs_btree_cur
*cur
,
45 const union xfs_btree_ptr
*nptr
,
46 int inc
) /* level change */
48 struct xfs_buf
*agbp
= cur
->bc_ag
.agbp
;
49 struct xfs_agi
*agi
= agbp
->b_addr
;
51 agi
->agi_root
= nptr
->s
;
52 be32_add_cpu(&agi
->agi_level
, inc
);
53 xfs_ialloc_log_agi(cur
->bc_tp
, agbp
, XFS_AGI_ROOT
| XFS_AGI_LEVEL
);
58 struct xfs_btree_cur
*cur
,
59 const union xfs_btree_ptr
*nptr
,
60 int inc
) /* level change */
62 struct xfs_buf
*agbp
= cur
->bc_ag
.agbp
;
63 struct xfs_agi
*agi
= agbp
->b_addr
;
65 agi
->agi_free_root
= nptr
->s
;
66 be32_add_cpu(&agi
->agi_free_level
, inc
);
67 xfs_ialloc_log_agi(cur
->bc_tp
, agbp
,
68 XFS_AGI_FREE_ROOT
| XFS_AGI_FREE_LEVEL
);
71 /* Update the inode btree block counter for this btree. */
73 xfs_inobt_mod_blockcount(
74 struct xfs_btree_cur
*cur
,
77 struct xfs_buf
*agbp
= cur
->bc_ag
.agbp
;
78 struct xfs_agi
*agi
= agbp
->b_addr
;
80 if (!xfs_has_inobtcounts(cur
->bc_mp
))
83 if (cur
->bc_btnum
== XFS_BTNUM_FINO
)
84 be32_add_cpu(&agi
->agi_fblocks
, howmuch
);
85 else if (cur
->bc_btnum
== XFS_BTNUM_INO
)
86 be32_add_cpu(&agi
->agi_iblocks
, howmuch
);
87 xfs_ialloc_log_agi(cur
->bc_tp
, agbp
, XFS_AGI_IBLOCKS
);
91 __xfs_inobt_alloc_block(
92 struct xfs_btree_cur
*cur
,
93 const union xfs_btree_ptr
*start
,
94 union xfs_btree_ptr
*new,
96 enum xfs_ag_resv_type resv
)
98 xfs_alloc_arg_t args
; /* block allocation args */
99 int error
; /* error return value */
100 xfs_agblock_t sbno
= be32_to_cpu(start
->s
);
102 memset(&args
, 0, sizeof(args
));
103 args
.tp
= cur
->bc_tp
;
104 args
.mp
= cur
->bc_mp
;
105 args
.oinfo
= XFS_RMAP_OINFO_INOBT
;
106 args
.fsbno
= XFS_AGB_TO_FSB(args
.mp
, cur
->bc_ag
.pag
->pag_agno
, sbno
);
110 args
.type
= XFS_ALLOCTYPE_NEAR_BNO
;
113 error
= xfs_alloc_vextent(&args
);
117 if (args
.fsbno
== NULLFSBLOCK
) {
121 ASSERT(args
.len
== 1);
123 new->s
= cpu_to_be32(XFS_FSB_TO_AGBNO(args
.mp
, args
.fsbno
));
125 xfs_inobt_mod_blockcount(cur
, 1);
130 xfs_inobt_alloc_block(
131 struct xfs_btree_cur
*cur
,
132 const union xfs_btree_ptr
*start
,
133 union xfs_btree_ptr
*new,
136 return __xfs_inobt_alloc_block(cur
, start
, new, stat
, XFS_AG_RESV_NONE
);
140 xfs_finobt_alloc_block(
141 struct xfs_btree_cur
*cur
,
142 const union xfs_btree_ptr
*start
,
143 union xfs_btree_ptr
*new,
146 if (cur
->bc_mp
->m_finobt_nores
)
147 return xfs_inobt_alloc_block(cur
, start
, new, stat
);
148 return __xfs_inobt_alloc_block(cur
, start
, new, stat
,
149 XFS_AG_RESV_METADATA
);
153 __xfs_inobt_free_block(
154 struct xfs_btree_cur
*cur
,
156 enum xfs_ag_resv_type resv
)
158 xfs_inobt_mod_blockcount(cur
, -1);
159 return xfs_free_extent(cur
->bc_tp
,
160 XFS_DADDR_TO_FSB(cur
->bc_mp
, xfs_buf_daddr(bp
)), 1,
161 &XFS_RMAP_OINFO_INOBT
, resv
);
165 xfs_inobt_free_block(
166 struct xfs_btree_cur
*cur
,
169 return __xfs_inobt_free_block(cur
, bp
, XFS_AG_RESV_NONE
);
173 xfs_finobt_free_block(
174 struct xfs_btree_cur
*cur
,
177 if (cur
->bc_mp
->m_finobt_nores
)
178 return xfs_inobt_free_block(cur
, bp
);
179 return __xfs_inobt_free_block(cur
, bp
, XFS_AG_RESV_METADATA
);
183 xfs_inobt_get_maxrecs(
184 struct xfs_btree_cur
*cur
,
187 return M_IGEO(cur
->bc_mp
)->inobt_mxr
[level
!= 0];
191 xfs_inobt_init_key_from_rec(
192 union xfs_btree_key
*key
,
193 const union xfs_btree_rec
*rec
)
195 key
->inobt
.ir_startino
= rec
->inobt
.ir_startino
;
199 xfs_inobt_init_high_key_from_rec(
200 union xfs_btree_key
*key
,
201 const union xfs_btree_rec
*rec
)
205 x
= be32_to_cpu(rec
->inobt
.ir_startino
);
206 x
+= XFS_INODES_PER_CHUNK
- 1;
207 key
->inobt
.ir_startino
= cpu_to_be32(x
);
211 xfs_inobt_init_rec_from_cur(
212 struct xfs_btree_cur
*cur
,
213 union xfs_btree_rec
*rec
)
215 rec
->inobt
.ir_startino
= cpu_to_be32(cur
->bc_rec
.i
.ir_startino
);
216 if (xfs_has_sparseinodes(cur
->bc_mp
)) {
217 rec
->inobt
.ir_u
.sp
.ir_holemask
=
218 cpu_to_be16(cur
->bc_rec
.i
.ir_holemask
);
219 rec
->inobt
.ir_u
.sp
.ir_count
= cur
->bc_rec
.i
.ir_count
;
220 rec
->inobt
.ir_u
.sp
.ir_freecount
= cur
->bc_rec
.i
.ir_freecount
;
222 /* ir_holemask/ir_count not supported on-disk */
223 rec
->inobt
.ir_u
.f
.ir_freecount
=
224 cpu_to_be32(cur
->bc_rec
.i
.ir_freecount
);
226 rec
->inobt
.ir_free
= cpu_to_be64(cur
->bc_rec
.i
.ir_free
);
230 * initial value of ptr for lookup
233 xfs_inobt_init_ptr_from_cur(
234 struct xfs_btree_cur
*cur
,
235 union xfs_btree_ptr
*ptr
)
237 struct xfs_agi
*agi
= cur
->bc_ag
.agbp
->b_addr
;
239 ASSERT(cur
->bc_ag
.pag
->pag_agno
== be32_to_cpu(agi
->agi_seqno
));
241 ptr
->s
= agi
->agi_root
;
245 xfs_finobt_init_ptr_from_cur(
246 struct xfs_btree_cur
*cur
,
247 union xfs_btree_ptr
*ptr
)
249 struct xfs_agi
*agi
= cur
->bc_ag
.agbp
->b_addr
;
251 ASSERT(cur
->bc_ag
.pag
->pag_agno
== be32_to_cpu(agi
->agi_seqno
));
252 ptr
->s
= agi
->agi_free_root
;
257 struct xfs_btree_cur
*cur
,
258 const union xfs_btree_key
*key
)
260 return (int64_t)be32_to_cpu(key
->inobt
.ir_startino
) -
261 cur
->bc_rec
.i
.ir_startino
;
265 xfs_inobt_diff_two_keys(
266 struct xfs_btree_cur
*cur
,
267 const union xfs_btree_key
*k1
,
268 const union xfs_btree_key
*k2
)
270 return (int64_t)be32_to_cpu(k1
->inobt
.ir_startino
) -
271 be32_to_cpu(k2
->inobt
.ir_startino
);
274 static xfs_failaddr_t
278 struct xfs_mount
*mp
= bp
->b_mount
;
279 struct xfs_btree_block
*block
= XFS_BUF_TO_BLOCK(bp
);
283 if (!xfs_verify_magic(bp
, block
->bb_magic
))
284 return __this_address
;
287 * During growfs operations, we can't verify the exact owner as the
288 * perag is not fully initialised and hence not attached to the buffer.
290 * Similarly, during log recovery we will have a perag structure
291 * attached, but the agi information will not yet have been initialised
292 * from the on disk AGI. We don't currently use any of this information,
293 * but beware of the landmine (i.e. need to check pag->pagi_init) if we
296 if (xfs_has_crc(mp
)) {
297 fa
= xfs_btree_sblock_v5hdr_verify(bp
);
302 /* level verification */
303 level
= be16_to_cpu(block
->bb_level
);
304 if (level
>= M_IGEO(mp
)->inobt_maxlevels
)
305 return __this_address
;
307 return xfs_btree_sblock_verify(bp
,
308 M_IGEO(mp
)->inobt_mxr
[level
!= 0]);
312 xfs_inobt_read_verify(
317 if (!xfs_btree_sblock_verify_crc(bp
))
318 xfs_verifier_error(bp
, -EFSBADCRC
, __this_address
);
320 fa
= xfs_inobt_verify(bp
);
322 xfs_verifier_error(bp
, -EFSCORRUPTED
, fa
);
326 trace_xfs_btree_corrupt(bp
, _RET_IP_
);
330 xfs_inobt_write_verify(
335 fa
= xfs_inobt_verify(bp
);
337 trace_xfs_btree_corrupt(bp
, _RET_IP_
);
338 xfs_verifier_error(bp
, -EFSCORRUPTED
, fa
);
341 xfs_btree_sblock_calc_crc(bp
);
345 const struct xfs_buf_ops xfs_inobt_buf_ops
= {
347 .magic
= { cpu_to_be32(XFS_IBT_MAGIC
), cpu_to_be32(XFS_IBT_CRC_MAGIC
) },
348 .verify_read
= xfs_inobt_read_verify
,
349 .verify_write
= xfs_inobt_write_verify
,
350 .verify_struct
= xfs_inobt_verify
,
353 const struct xfs_buf_ops xfs_finobt_buf_ops
= {
354 .name
= "xfs_finobt",
355 .magic
= { cpu_to_be32(XFS_FIBT_MAGIC
),
356 cpu_to_be32(XFS_FIBT_CRC_MAGIC
) },
357 .verify_read
= xfs_inobt_read_verify
,
358 .verify_write
= xfs_inobt_write_verify
,
359 .verify_struct
= xfs_inobt_verify
,
363 xfs_inobt_keys_inorder(
364 struct xfs_btree_cur
*cur
,
365 const union xfs_btree_key
*k1
,
366 const union xfs_btree_key
*k2
)
368 return be32_to_cpu(k1
->inobt
.ir_startino
) <
369 be32_to_cpu(k2
->inobt
.ir_startino
);
373 xfs_inobt_recs_inorder(
374 struct xfs_btree_cur
*cur
,
375 const union xfs_btree_rec
*r1
,
376 const union xfs_btree_rec
*r2
)
378 return be32_to_cpu(r1
->inobt
.ir_startino
) + XFS_INODES_PER_CHUNK
<=
379 be32_to_cpu(r2
->inobt
.ir_startino
);
382 static const struct xfs_btree_ops xfs_inobt_ops
= {
383 .rec_len
= sizeof(xfs_inobt_rec_t
),
384 .key_len
= sizeof(xfs_inobt_key_t
),
386 .dup_cursor
= xfs_inobt_dup_cursor
,
387 .set_root
= xfs_inobt_set_root
,
388 .alloc_block
= xfs_inobt_alloc_block
,
389 .free_block
= xfs_inobt_free_block
,
390 .get_minrecs
= xfs_inobt_get_minrecs
,
391 .get_maxrecs
= xfs_inobt_get_maxrecs
,
392 .init_key_from_rec
= xfs_inobt_init_key_from_rec
,
393 .init_high_key_from_rec
= xfs_inobt_init_high_key_from_rec
,
394 .init_rec_from_cur
= xfs_inobt_init_rec_from_cur
,
395 .init_ptr_from_cur
= xfs_inobt_init_ptr_from_cur
,
396 .key_diff
= xfs_inobt_key_diff
,
397 .buf_ops
= &xfs_inobt_buf_ops
,
398 .diff_two_keys
= xfs_inobt_diff_two_keys
,
399 .keys_inorder
= xfs_inobt_keys_inorder
,
400 .recs_inorder
= xfs_inobt_recs_inorder
,
403 static const struct xfs_btree_ops xfs_finobt_ops
= {
404 .rec_len
= sizeof(xfs_inobt_rec_t
),
405 .key_len
= sizeof(xfs_inobt_key_t
),
407 .dup_cursor
= xfs_inobt_dup_cursor
,
408 .set_root
= xfs_finobt_set_root
,
409 .alloc_block
= xfs_finobt_alloc_block
,
410 .free_block
= xfs_finobt_free_block
,
411 .get_minrecs
= xfs_inobt_get_minrecs
,
412 .get_maxrecs
= xfs_inobt_get_maxrecs
,
413 .init_key_from_rec
= xfs_inobt_init_key_from_rec
,
414 .init_high_key_from_rec
= xfs_inobt_init_high_key_from_rec
,
415 .init_rec_from_cur
= xfs_inobt_init_rec_from_cur
,
416 .init_ptr_from_cur
= xfs_finobt_init_ptr_from_cur
,
417 .key_diff
= xfs_inobt_key_diff
,
418 .buf_ops
= &xfs_finobt_buf_ops
,
419 .diff_two_keys
= xfs_inobt_diff_two_keys
,
420 .keys_inorder
= xfs_inobt_keys_inorder
,
421 .recs_inorder
= xfs_inobt_recs_inorder
,
425 * Initialize a new inode btree cursor.
427 static struct xfs_btree_cur
*
428 xfs_inobt_init_common(
429 struct xfs_mount
*mp
, /* file system mount point */
430 struct xfs_trans
*tp
, /* transaction pointer */
431 struct xfs_perag
*pag
,
432 xfs_btnum_t btnum
) /* ialloc or free ino btree */
434 struct xfs_btree_cur
*cur
;
436 cur
= xfs_btree_alloc_cursor(mp
, tp
, btnum
,
437 M_IGEO(mp
)->inobt_maxlevels
, xfs_inobt_cur_cache
);
438 if (btnum
== XFS_BTNUM_INO
) {
439 cur
->bc_statoff
= XFS_STATS_CALC_INDEX(xs_ibt_2
);
440 cur
->bc_ops
= &xfs_inobt_ops
;
442 cur
->bc_statoff
= XFS_STATS_CALC_INDEX(xs_fibt_2
);
443 cur
->bc_ops
= &xfs_finobt_ops
;
447 cur
->bc_flags
|= XFS_BTREE_CRC_BLOCKS
;
449 /* take a reference for the cursor */
450 atomic_inc(&pag
->pag_ref
);
451 cur
->bc_ag
.pag
= pag
;
455 /* Create an inode btree cursor. */
456 struct xfs_btree_cur
*
457 xfs_inobt_init_cursor(
458 struct xfs_mount
*mp
,
459 struct xfs_trans
*tp
,
460 struct xfs_buf
*agbp
,
461 struct xfs_perag
*pag
,
464 struct xfs_btree_cur
*cur
;
465 struct xfs_agi
*agi
= agbp
->b_addr
;
467 cur
= xfs_inobt_init_common(mp
, tp
, pag
, btnum
);
468 if (btnum
== XFS_BTNUM_INO
)
469 cur
->bc_nlevels
= be32_to_cpu(agi
->agi_level
);
471 cur
->bc_nlevels
= be32_to_cpu(agi
->agi_free_level
);
472 cur
->bc_ag
.agbp
= agbp
;
476 /* Create an inode btree cursor with a fake root for staging. */
477 struct xfs_btree_cur
*
478 xfs_inobt_stage_cursor(
479 struct xfs_mount
*mp
,
480 struct xbtree_afakeroot
*afake
,
481 struct xfs_perag
*pag
,
484 struct xfs_btree_cur
*cur
;
486 cur
= xfs_inobt_init_common(mp
, NULL
, pag
, btnum
);
487 xfs_btree_stage_afakeroot(cur
, afake
);
492 * Install a new inobt btree root. Caller is responsible for invalidating
493 * and freeing the old btree blocks.
496 xfs_inobt_commit_staged_btree(
497 struct xfs_btree_cur
*cur
,
498 struct xfs_trans
*tp
,
499 struct xfs_buf
*agbp
)
501 struct xfs_agi
*agi
= agbp
->b_addr
;
502 struct xbtree_afakeroot
*afake
= cur
->bc_ag
.afake
;
505 ASSERT(cur
->bc_flags
& XFS_BTREE_STAGING
);
507 if (cur
->bc_btnum
== XFS_BTNUM_INO
) {
508 fields
= XFS_AGI_ROOT
| XFS_AGI_LEVEL
;
509 agi
->agi_root
= cpu_to_be32(afake
->af_root
);
510 agi
->agi_level
= cpu_to_be32(afake
->af_levels
);
511 if (xfs_has_inobtcounts(cur
->bc_mp
)) {
512 agi
->agi_iblocks
= cpu_to_be32(afake
->af_blocks
);
513 fields
|= XFS_AGI_IBLOCKS
;
515 xfs_ialloc_log_agi(tp
, agbp
, fields
);
516 xfs_btree_commit_afakeroot(cur
, tp
, agbp
, &xfs_inobt_ops
);
518 fields
= XFS_AGI_FREE_ROOT
| XFS_AGI_FREE_LEVEL
;
519 agi
->agi_free_root
= cpu_to_be32(afake
->af_root
);
520 agi
->agi_free_level
= cpu_to_be32(afake
->af_levels
);
521 if (xfs_has_inobtcounts(cur
->bc_mp
)) {
522 agi
->agi_fblocks
= cpu_to_be32(afake
->af_blocks
);
523 fields
|= XFS_AGI_IBLOCKS
;
525 xfs_ialloc_log_agi(tp
, agbp
, fields
);
526 xfs_btree_commit_afakeroot(cur
, tp
, agbp
, &xfs_finobt_ops
);
530 /* Calculate number of records in an inode btree block. */
531 static inline unsigned int
532 xfs_inobt_block_maxrecs(
533 unsigned int blocklen
,
537 return blocklen
/ sizeof(xfs_inobt_rec_t
);
538 return blocklen
/ (sizeof(xfs_inobt_key_t
) + sizeof(xfs_inobt_ptr_t
));
542 * Calculate number of records in an inobt btree block.
546 struct xfs_mount
*mp
,
550 blocklen
-= XFS_INOBT_BLOCK_LEN(mp
);
551 return xfs_inobt_block_maxrecs(blocklen
, leaf
);
555 * Maximum number of inode btree records per AG. Pretend that we can fill an
556 * entire AG completely full of inodes except for the AG headers.
558 #define XFS_MAX_INODE_RECORDS \
559 ((XFS_MAX_AG_BYTES - (4 * BBSIZE)) / XFS_DINODE_MIN_SIZE) / \
562 /* Compute the max possible height for the inode btree. */
563 static inline unsigned int
564 xfs_inobt_maxlevels_ondisk(void)
566 unsigned int minrecs
[2];
567 unsigned int blocklen
;
569 blocklen
= min(XFS_MIN_BLOCKSIZE
- XFS_BTREE_SBLOCK_LEN
,
570 XFS_MIN_CRC_BLOCKSIZE
- XFS_BTREE_SBLOCK_CRC_LEN
);
572 minrecs
[0] = xfs_inobt_block_maxrecs(blocklen
, true) / 2;
573 minrecs
[1] = xfs_inobt_block_maxrecs(blocklen
, false) / 2;
575 return xfs_btree_compute_maxlevels(minrecs
, XFS_MAX_INODE_RECORDS
);
578 /* Compute the max possible height for the free inode btree. */
579 static inline unsigned int
580 xfs_finobt_maxlevels_ondisk(void)
582 unsigned int minrecs
[2];
583 unsigned int blocklen
;
585 blocklen
= XFS_MIN_CRC_BLOCKSIZE
- XFS_BTREE_SBLOCK_CRC_LEN
;
587 minrecs
[0] = xfs_inobt_block_maxrecs(blocklen
, true) / 2;
588 minrecs
[1] = xfs_inobt_block_maxrecs(blocklen
, false) / 2;
590 return xfs_btree_compute_maxlevels(minrecs
, XFS_MAX_INODE_RECORDS
);
593 /* Compute the max possible height for either inode btree. */
595 xfs_iallocbt_maxlevels_ondisk(void)
597 return max(xfs_inobt_maxlevels_ondisk(),
598 xfs_finobt_maxlevels_ondisk());
602 * Convert the inode record holemask to an inode allocation bitmap. The inode
603 * allocation bitmap is inode granularity and specifies whether an inode is
604 * physically allocated on disk (not whether the inode is considered allocated
605 * or free by the fs).
607 * A bit value of 1 means the inode is allocated, a value of 0 means it is free.
610 xfs_inobt_irec_to_allocmask(
611 struct xfs_inobt_rec_incore
*rec
)
619 * The holemask has 16-bits for a 64 inode record. Therefore each
620 * holemask bit represents multiple inodes. Create a mask of bits to set
621 * in the allocmask for each holemask bit.
623 inodespbit
= (1 << XFS_INODES_PER_HOLEMASK_BIT
) - 1;
626 * Allocated inodes are represented by 0 bits in holemask. Invert the 0
627 * bits to 1 and convert to a uint so we can use xfs_next_bit(). Mask
628 * anything beyond the 16 holemask bits since this casts to a larger
631 allocbitmap
= ~rec
->ir_holemask
& ((1 << XFS_INOBT_HOLEMASK_BITS
) - 1);
634 * allocbitmap is the inverted holemask so every set bit represents
635 * allocated inodes. To expand from 16-bit holemask granularity to
636 * 64-bit (e.g., bit-per-inode), set inodespbit bits in the target
637 * bitmap for every holemask bit.
639 nextbit
= xfs_next_bit(&allocbitmap
, 1, 0);
640 while (nextbit
!= -1) {
641 ASSERT(nextbit
< (sizeof(rec
->ir_holemask
) * NBBY
));
643 bitmap
|= (inodespbit
<<
644 (nextbit
* XFS_INODES_PER_HOLEMASK_BIT
));
646 nextbit
= xfs_next_bit(&allocbitmap
, 1, nextbit
+ 1);
652 #if defined(DEBUG) || defined(XFS_WARN)
654 * Verify that an in-core inode record has a valid inode count.
657 xfs_inobt_rec_check_count(
658 struct xfs_mount
*mp
,
659 struct xfs_inobt_rec_incore
*rec
)
666 wordsz
= sizeof(allocbmap
) / sizeof(unsigned int);
667 allocbmap
= xfs_inobt_irec_to_allocmask(rec
);
669 nextbit
= xfs_next_bit((uint
*) &allocbmap
, wordsz
, nextbit
);
670 while (nextbit
!= -1) {
672 nextbit
= xfs_next_bit((uint
*) &allocbmap
, wordsz
,
676 if (inocount
!= rec
->ir_count
)
677 return -EFSCORRUPTED
;
685 struct xfs_mount
*mp
,
688 xfs_agblock_t agblocks
= xfs_ag_block_count(mp
, agno
);
690 /* Bail out if we're uninitialized, which can happen in mkfs. */
691 if (M_IGEO(mp
)->inobt_mxr
[0] == 0)
695 * The log is permanently allocated, so the space it occupies will
696 * never be available for the kinds of things that would require btree
697 * expansion. We therefore can pretend the space isn't there.
699 if (mp
->m_sb
.sb_logstart
&&
700 XFS_FSB_TO_AGNO(mp
, mp
->m_sb
.sb_logstart
) == agno
)
701 agblocks
-= mp
->m_sb
.sb_logblocks
;
703 return xfs_btree_calc_size(M_IGEO(mp
)->inobt_mnr
,
704 (uint64_t)agblocks
* mp
->m_sb
.sb_inopblock
/
705 XFS_INODES_PER_CHUNK
);
708 /* Read AGI and create inobt cursor. */
711 struct xfs_mount
*mp
,
712 struct xfs_trans
*tp
,
713 struct xfs_perag
*pag
,
715 struct xfs_btree_cur
**curpp
,
716 struct xfs_buf
**agi_bpp
)
718 struct xfs_btree_cur
*cur
;
721 ASSERT(*agi_bpp
== NULL
);
722 ASSERT(*curpp
== NULL
);
724 error
= xfs_ialloc_read_agi(mp
, tp
, pag
->pag_agno
, agi_bpp
);
728 cur
= xfs_inobt_init_cursor(mp
, tp
, *agi_bpp
, pag
, which
);
734 xfs_inobt_count_blocks(
735 struct xfs_mount
*mp
,
736 struct xfs_trans
*tp
,
737 struct xfs_perag
*pag
,
739 xfs_extlen_t
*tree_blocks
)
741 struct xfs_buf
*agbp
= NULL
;
742 struct xfs_btree_cur
*cur
= NULL
;
745 error
= xfs_inobt_cur(mp
, tp
, pag
, btnum
, &cur
, &agbp
);
749 error
= xfs_btree_count_blocks(cur
, tree_blocks
);
750 xfs_btree_del_cursor(cur
, error
);
751 xfs_trans_brelse(tp
, agbp
);
756 /* Read finobt block count from AGI header. */
758 xfs_finobt_read_blocks(
759 struct xfs_mount
*mp
,
760 struct xfs_trans
*tp
,
761 struct xfs_perag
*pag
,
762 xfs_extlen_t
*tree_blocks
)
764 struct xfs_buf
*agbp
;
768 error
= xfs_ialloc_read_agi(mp
, tp
, pag
->pag_agno
, &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(mp
, tp
, pag
, &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
;