Lines Matching +full:max +full:- +full:cur

1 // SPDX-License-Identifier: GPL-2.0
30 * This is a per-ag tree used to track the owner(s) of a given extent. With
54 struct xfs_btree_cur *cur) in xfs_rmapbt_dup_cursor() argument
56 return xfs_rmapbt_init_cursor(cur->bc_mp, cur->bc_tp, in xfs_rmapbt_dup_cursor()
57 cur->bc_ag.agbp, cur->bc_ag.pag); in xfs_rmapbt_dup_cursor()
62 struct xfs_btree_cur *cur, in xfs_rmapbt_set_root() argument
66 struct xfs_buf *agbp = cur->bc_ag.agbp; in xfs_rmapbt_set_root()
67 struct xfs_agf *agf = agbp->b_addr; in xfs_rmapbt_set_root()
68 int btnum = cur->bc_btnum; in xfs_rmapbt_set_root()
70 ASSERT(ptr->s != 0); in xfs_rmapbt_set_root()
72 agf->agf_roots[btnum] = ptr->s; in xfs_rmapbt_set_root()
73 be32_add_cpu(&agf->agf_levels[btnum], inc); in xfs_rmapbt_set_root()
74 cur->bc_ag.pag->pagf_levels[btnum] += inc; in xfs_rmapbt_set_root()
76 xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_ROOTS | XFS_AGF_LEVELS); in xfs_rmapbt_set_root()
81 struct xfs_btree_cur *cur, in xfs_rmapbt_alloc_block() argument
86 struct xfs_buf *agbp = cur->bc_ag.agbp; in xfs_rmapbt_alloc_block()
87 struct xfs_agf *agf = agbp->b_addr; in xfs_rmapbt_alloc_block()
88 struct xfs_perag *pag = cur->bc_ag.pag; in xfs_rmapbt_alloc_block()
93 error = xfs_alloc_get_freelist(pag, cur->bc_tp, cur->bc_ag.agbp, in xfs_rmapbt_alloc_block()
98 trace_xfs_rmapbt_alloc_block(cur->bc_mp, pag->pag_agno, bno, 1); in xfs_rmapbt_alloc_block()
104 xfs_extent_busy_reuse(cur->bc_mp, pag, bno, 1, false); in xfs_rmapbt_alloc_block()
106 new->s = cpu_to_be32(bno); in xfs_rmapbt_alloc_block()
107 be32_add_cpu(&agf->agf_rmap_blocks, 1); in xfs_rmapbt_alloc_block()
108 xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_RMAP_BLOCKS); in xfs_rmapbt_alloc_block()
110 xfs_ag_resv_rmapbt_alloc(cur->bc_mp, pag->pag_agno); in xfs_rmapbt_alloc_block()
118 struct xfs_btree_cur *cur, in xfs_rmapbt_free_block() argument
121 struct xfs_buf *agbp = cur->bc_ag.agbp; in xfs_rmapbt_free_block()
122 struct xfs_agf *agf = agbp->b_addr; in xfs_rmapbt_free_block()
123 struct xfs_perag *pag = cur->bc_ag.pag; in xfs_rmapbt_free_block()
127 bno = xfs_daddr_to_agbno(cur->bc_mp, xfs_buf_daddr(bp)); in xfs_rmapbt_free_block()
128 trace_xfs_rmapbt_free_block(cur->bc_mp, pag->pag_agno, in xfs_rmapbt_free_block()
130 be32_add_cpu(&agf->agf_rmap_blocks, -1); in xfs_rmapbt_free_block()
131 xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_RMAP_BLOCKS); in xfs_rmapbt_free_block()
132 error = xfs_alloc_put_freelist(pag, cur->bc_tp, agbp, NULL, bno, 1); in xfs_rmapbt_free_block()
136 xfs_extent_busy_insert(cur->bc_tp, pag, bno, 1, in xfs_rmapbt_free_block()
145 struct xfs_btree_cur *cur, in xfs_rmapbt_get_minrecs() argument
148 return cur->bc_mp->m_rmap_mnr[level != 0]; in xfs_rmapbt_get_minrecs()
153 struct xfs_btree_cur *cur, in xfs_rmapbt_get_maxrecs() argument
156 return cur->bc_mp->m_rmap_mxr[level != 0]; in xfs_rmapbt_get_maxrecs()
164 key->rmap.rm_startblock = rec->rmap.rm_startblock; in xfs_rmapbt_init_key_from_rec()
165 key->rmap.rm_owner = rec->rmap.rm_owner; in xfs_rmapbt_init_key_from_rec()
166 key->rmap.rm_offset = rec->rmap.rm_offset; in xfs_rmapbt_init_key_from_rec()
172 * to that record. In practice this means that we add blockcount-1 to
174 * fork mapping, we add blockcount-1 to the offset too.
184 adj = be32_to_cpu(rec->rmap.rm_blockcount) - 1; in xfs_rmapbt_init_high_key_from_rec()
186 key->rmap.rm_startblock = rec->rmap.rm_startblock; in xfs_rmapbt_init_high_key_from_rec()
187 be32_add_cpu(&key->rmap.rm_startblock, adj); in xfs_rmapbt_init_high_key_from_rec()
188 key->rmap.rm_owner = rec->rmap.rm_owner; in xfs_rmapbt_init_high_key_from_rec()
189 key->rmap.rm_offset = rec->rmap.rm_offset; in xfs_rmapbt_init_high_key_from_rec()
190 if (XFS_RMAP_NON_INODE_OWNER(be64_to_cpu(rec->rmap.rm_owner)) || in xfs_rmapbt_init_high_key_from_rec()
191 XFS_RMAP_IS_BMBT_BLOCK(be64_to_cpu(rec->rmap.rm_offset))) in xfs_rmapbt_init_high_key_from_rec()
193 off = be64_to_cpu(key->rmap.rm_offset); in xfs_rmapbt_init_high_key_from_rec()
195 key->rmap.rm_offset = cpu_to_be64(off); in xfs_rmapbt_init_high_key_from_rec()
200 struct xfs_btree_cur *cur, in xfs_rmapbt_init_rec_from_cur() argument
203 rec->rmap.rm_startblock = cpu_to_be32(cur->bc_rec.r.rm_startblock); in xfs_rmapbt_init_rec_from_cur()
204 rec->rmap.rm_blockcount = cpu_to_be32(cur->bc_rec.r.rm_blockcount); in xfs_rmapbt_init_rec_from_cur()
205 rec->rmap.rm_owner = cpu_to_be64(cur->bc_rec.r.rm_owner); in xfs_rmapbt_init_rec_from_cur()
206 rec->rmap.rm_offset = cpu_to_be64( in xfs_rmapbt_init_rec_from_cur()
207 xfs_rmap_irec_offset_pack(&cur->bc_rec.r)); in xfs_rmapbt_init_rec_from_cur()
212 struct xfs_btree_cur *cur, in xfs_rmapbt_init_ptr_from_cur() argument
215 struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; in xfs_rmapbt_init_ptr_from_cur()
217 ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agf->agf_seqno)); in xfs_rmapbt_init_ptr_from_cur()
219 ptr->s = agf->agf_roots[cur->bc_btnum]; in xfs_rmapbt_init_ptr_from_cur()
224 struct xfs_btree_cur *cur, in xfs_rmapbt_key_diff() argument
227 struct xfs_rmap_irec *rec = &cur->bc_rec.r; in xfs_rmapbt_key_diff()
228 const struct xfs_rmap_key *kp = &key->rmap; in xfs_rmapbt_key_diff()
232 d = (int64_t)be32_to_cpu(kp->rm_startblock) - rec->rm_startblock; in xfs_rmapbt_key_diff()
236 x = be64_to_cpu(kp->rm_owner); in xfs_rmapbt_key_diff()
237 y = rec->rm_owner; in xfs_rmapbt_key_diff()
241 return -1; in xfs_rmapbt_key_diff()
243 x = XFS_RMAP_OFF(be64_to_cpu(kp->rm_offset)); in xfs_rmapbt_key_diff()
244 y = rec->rm_offset; in xfs_rmapbt_key_diff()
248 return -1; in xfs_rmapbt_key_diff()
254 struct xfs_btree_cur *cur, in xfs_rmapbt_diff_two_keys() argument
258 const struct xfs_rmap_key *kp1 = &k1->rmap; in xfs_rmapbt_diff_two_keys()
259 const struct xfs_rmap_key *kp2 = &k2->rmap; in xfs_rmapbt_diff_two_keys()
263 d = (int64_t)be32_to_cpu(kp1->rm_startblock) - in xfs_rmapbt_diff_two_keys()
264 be32_to_cpu(kp2->rm_startblock); in xfs_rmapbt_diff_two_keys()
268 x = be64_to_cpu(kp1->rm_owner); in xfs_rmapbt_diff_two_keys()
269 y = be64_to_cpu(kp2->rm_owner); in xfs_rmapbt_diff_two_keys()
273 return -1; in xfs_rmapbt_diff_two_keys()
275 x = XFS_RMAP_OFF(be64_to_cpu(kp1->rm_offset)); in xfs_rmapbt_diff_two_keys()
276 y = XFS_RMAP_OFF(be64_to_cpu(kp2->rm_offset)); in xfs_rmapbt_diff_two_keys()
280 return -1; in xfs_rmapbt_diff_two_keys()
288 struct xfs_mount *mp = bp->b_mount; in xfs_rmapbt_verify()
290 struct xfs_perag *pag = bp->b_pag; in xfs_rmapbt_verify()
306 if (!xfs_verify_magic(bp, block->bb_magic)) in xfs_rmapbt_verify()
315 level = be16_to_cpu(block->bb_level); in xfs_rmapbt_verify()
316 if (pag && pag->pagf_init) { in xfs_rmapbt_verify()
317 if (level >= pag->pagf_levels[XFS_BTNUM_RMAPi]) in xfs_rmapbt_verify()
319 } else if (level >= mp->m_rmap_maxlevels) in xfs_rmapbt_verify()
322 return xfs_btree_sblock_verify(bp, mp->m_rmap_mxr[level != 0]); in xfs_rmapbt_verify()
332 xfs_verifier_error(bp, -EFSBADCRC, __this_address); in xfs_rmapbt_read_verify()
336 xfs_verifier_error(bp, -EFSCORRUPTED, fa); in xfs_rmapbt_read_verify()
339 if (bp->b_error) in xfs_rmapbt_read_verify()
352 xfs_verifier_error(bp, -EFSCORRUPTED, fa); in xfs_rmapbt_write_verify()
369 struct xfs_btree_cur *cur, in xfs_rmapbt_keys_inorder() argument
378 x = be32_to_cpu(k1->rmap.rm_startblock); in xfs_rmapbt_keys_inorder()
379 y = be32_to_cpu(k2->rmap.rm_startblock); in xfs_rmapbt_keys_inorder()
384 a = be64_to_cpu(k1->rmap.rm_owner); in xfs_rmapbt_keys_inorder()
385 b = be64_to_cpu(k2->rmap.rm_owner); in xfs_rmapbt_keys_inorder()
390 a = XFS_RMAP_OFF(be64_to_cpu(k1->rmap.rm_offset)); in xfs_rmapbt_keys_inorder()
391 b = XFS_RMAP_OFF(be64_to_cpu(k2->rmap.rm_offset)); in xfs_rmapbt_keys_inorder()
399 struct xfs_btree_cur *cur, in xfs_rmapbt_recs_inorder() argument
408 x = be32_to_cpu(r1->rmap.rm_startblock); in xfs_rmapbt_recs_inorder()
409 y = be32_to_cpu(r2->rmap.rm_startblock); in xfs_rmapbt_recs_inorder()
414 a = be64_to_cpu(r1->rmap.rm_owner); in xfs_rmapbt_recs_inorder()
415 b = be64_to_cpu(r2->rmap.rm_owner); in xfs_rmapbt_recs_inorder()
420 a = XFS_RMAP_OFF(be64_to_cpu(r1->rmap.rm_offset)); in xfs_rmapbt_recs_inorder()
421 b = XFS_RMAP_OFF(be64_to_cpu(r2->rmap.rm_offset)); in xfs_rmapbt_recs_inorder()
454 struct xfs_btree_cur *cur; in xfs_rmapbt_init_common() local
457 cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_RMAP, in xfs_rmapbt_init_common()
458 mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); in xfs_rmapbt_init_common()
459 cur->bc_flags = XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING; in xfs_rmapbt_init_common()
460 cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); in xfs_rmapbt_init_common()
461 cur->bc_ops = &xfs_rmapbt_ops; in xfs_rmapbt_init_common()
464 atomic_inc(&pag->pag_ref); in xfs_rmapbt_init_common()
465 cur->bc_ag.pag = pag; in xfs_rmapbt_init_common()
467 return cur; in xfs_rmapbt_init_common()
478 struct xfs_agf *agf = agbp->b_addr; in xfs_rmapbt_init_cursor()
479 struct xfs_btree_cur *cur; in xfs_rmapbt_init_cursor() local
481 cur = xfs_rmapbt_init_common(mp, tp, pag); in xfs_rmapbt_init_cursor()
482 cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]); in xfs_rmapbt_init_cursor()
483 cur->bc_ag.agbp = agbp; in xfs_rmapbt_init_cursor()
484 return cur; in xfs_rmapbt_init_cursor()
494 struct xfs_btree_cur *cur; in xfs_rmapbt_stage_cursor() local
496 cur = xfs_rmapbt_init_common(mp, NULL, pag); in xfs_rmapbt_stage_cursor()
497 xfs_btree_stage_afakeroot(cur, afake); in xfs_rmapbt_stage_cursor()
498 return cur; in xfs_rmapbt_stage_cursor()
507 struct xfs_btree_cur *cur, in xfs_rmapbt_commit_staged_btree() argument
511 struct xfs_agf *agf = agbp->b_addr; in xfs_rmapbt_commit_staged_btree()
512 struct xbtree_afakeroot *afake = cur->bc_ag.afake; in xfs_rmapbt_commit_staged_btree()
514 ASSERT(cur->bc_flags & XFS_BTREE_STAGING); in xfs_rmapbt_commit_staged_btree()
516 agf->agf_roots[cur->bc_btnum] = cpu_to_be32(afake->af_root); in xfs_rmapbt_commit_staged_btree()
517 agf->agf_levels[cur->bc_btnum] = cpu_to_be32(afake->af_levels); in xfs_rmapbt_commit_staged_btree()
518 agf->agf_rmap_blocks = cpu_to_be32(afake->af_blocks); in xfs_rmapbt_commit_staged_btree()
521 xfs_btree_commit_afakeroot(cur, tp, agbp, &xfs_rmapbt_ops); in xfs_rmapbt_commit_staged_btree()
544 blocklen -= XFS_RMAP_BLOCK_LEN; in xfs_rmapbt_maxrecs()
548 /* Compute the max possible height for reverse mapping btrees. */
555 blocklen = XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN; in xfs_rmapbt_maxlevels_ondisk()
567 * we must compute the max height based on what the btree will look in xfs_rmapbt_maxlevels_ondisk()
580 mp->m_rmap_maxlevels = 0; in xfs_rmapbt_compute_maxlevels()
594 * max height based on what the btree will look like if it in xfs_rmapbt_compute_maxlevels()
598 mp->m_rmap_maxlevels = xfs_btree_space_to_height(mp->m_rmap_mnr, in xfs_rmapbt_compute_maxlevels()
599 mp->m_sb.sb_agblocks); in xfs_rmapbt_compute_maxlevels()
605 mp->m_rmap_maxlevels = xfs_btree_compute_maxlevels( in xfs_rmapbt_compute_maxlevels()
606 mp->m_rmap_mnr, mp->m_sb.sb_agblocks); in xfs_rmapbt_compute_maxlevels()
608 ASSERT(mp->m_rmap_maxlevels <= xfs_rmapbt_maxlevels_ondisk()); in xfs_rmapbt_compute_maxlevels()
617 return xfs_btree_calc_size(mp->m_rmap_mnr, len); in xfs_rmapbt_calc_size()
629 if (mp->m_rmap_mxr[0] == 0) in xfs_rmapbt_max_size()
659 agf = agbp->b_addr; in xfs_rmapbt_calc_reserves()
660 agblocks = be32_to_cpu(agf->agf_length); in xfs_rmapbt_calc_reserves()
661 tree_len = be32_to_cpu(agf->agf_rmap_blocks); in xfs_rmapbt_calc_reserves()
669 if (xfs_ag_contains_log(mp, pag->pag_agno)) in xfs_rmapbt_calc_reserves()
670 agblocks -= mp->m_sb.sb_logblocks; in xfs_rmapbt_calc_reserves()
673 *ask += max(agblocks / 100, xfs_rmapbt_max_size(mp, agblocks)); in xfs_rmapbt_calc_reserves()
687 return -ENOMEM; in xfs_rmapbt_init_cur_cache()