1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003,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_inode.h"
15 #include "xfs_trans.h"
16 #include "xfs_alloc.h"
17 #include "xfs_btree.h"
18 #include "xfs_btree_staging.h"
19 #include "xfs_bmap_btree.h"
21 #include "xfs_error.h"
22 #include "xfs_quota.h"
23 #include "xfs_trace.h"
27 static struct kmem_cache *xfs_bmbt_cur_cache;
30 * Convert on-disk form of btree root to in-memory form.
35 xfs_bmdr_block_t *dblock,
37 struct xfs_btree_block *rblock,
40 struct xfs_mount *mp = ip->i_mount;
47 xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL,
48 XFS_BTNUM_BMAP, 0, 0, ip->i_ino,
50 rblock->bb_level = dblock->bb_level;
51 ASSERT(be16_to_cpu(rblock->bb_level) > 0);
52 rblock->bb_numrecs = dblock->bb_numrecs;
53 dmxr = xfs_bmdr_maxrecs(dblocklen, 0);
54 fkp = XFS_BMDR_KEY_ADDR(dblock, 1);
55 tkp = XFS_BMBT_KEY_ADDR(mp, rblock, 1);
56 fpp = XFS_BMDR_PTR_ADDR(dblock, 1, dmxr);
57 tpp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, rblocklen);
58 dmxr = be16_to_cpu(dblock->bb_numrecs);
59 memcpy(tkp, fkp, sizeof(*fkp) * dmxr);
60 memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
64 xfs_bmbt_disk_get_all(
65 const struct xfs_bmbt_rec *rec,
66 struct xfs_bmbt_irec *irec)
68 uint64_t l0 = get_unaligned_be64(&rec->l0);
69 uint64_t l1 = get_unaligned_be64(&rec->l1);
71 irec->br_startoff = (l0 & xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
72 irec->br_startblock = ((l0 & xfs_mask64lo(9)) << 43) | (l1 >> 21);
73 irec->br_blockcount = l1 & xfs_mask64lo(21);
74 if (l0 >> (64 - BMBT_EXNTFLAG_BITLEN))
75 irec->br_state = XFS_EXT_UNWRITTEN;
77 irec->br_state = XFS_EXT_NORM;
81 * Extract the blockcount field from an on disk bmap extent record.
84 xfs_bmbt_disk_get_blockcount(
85 const struct xfs_bmbt_rec *r)
87 return (xfs_filblks_t)(be64_to_cpu(r->l1) & xfs_mask64lo(21));
91 * Extract the startoff field from a disk format bmap extent record.
94 xfs_bmbt_disk_get_startoff(
95 const struct xfs_bmbt_rec *r)
97 return ((xfs_fileoff_t)be64_to_cpu(r->l0) &
98 xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
102 * Set all the fields in a bmap extent record from the uncompressed form.
105 xfs_bmbt_disk_set_all(
106 struct xfs_bmbt_rec *r,
107 struct xfs_bmbt_irec *s)
109 int extent_flag = (s->br_state != XFS_EXT_NORM);
111 ASSERT(s->br_state == XFS_EXT_NORM || s->br_state == XFS_EXT_UNWRITTEN);
112 ASSERT(!(s->br_startoff & xfs_mask64hi(64-BMBT_STARTOFF_BITLEN)));
113 ASSERT(!(s->br_blockcount & xfs_mask64hi(64-BMBT_BLOCKCOUNT_BITLEN)));
114 ASSERT(!(s->br_startblock & xfs_mask64hi(64-BMBT_STARTBLOCK_BITLEN)));
117 ((xfs_bmbt_rec_base_t)extent_flag << 63) |
118 ((xfs_bmbt_rec_base_t)s->br_startoff << 9) |
119 ((xfs_bmbt_rec_base_t)s->br_startblock >> 43), &r->l0);
121 ((xfs_bmbt_rec_base_t)s->br_startblock << 21) |
122 ((xfs_bmbt_rec_base_t)s->br_blockcount &
123 (xfs_bmbt_rec_base_t)xfs_mask64lo(21)), &r->l1);
127 * Convert in-memory form of btree root to on-disk form.
131 struct xfs_mount *mp,
132 struct xfs_btree_block *rblock,
134 xfs_bmdr_block_t *dblock,
143 if (xfs_has_crc(mp)) {
144 ASSERT(rblock->bb_magic == cpu_to_be32(XFS_BMAP_CRC_MAGIC));
145 ASSERT(uuid_equal(&rblock->bb_u.l.bb_uuid,
146 &mp->m_sb.sb_meta_uuid));
147 ASSERT(rblock->bb_u.l.bb_blkno ==
148 cpu_to_be64(XFS_BUF_DADDR_NULL));
150 ASSERT(rblock->bb_magic == cpu_to_be32(XFS_BMAP_MAGIC));
151 ASSERT(rblock->bb_u.l.bb_leftsib == cpu_to_be64(NULLFSBLOCK));
152 ASSERT(rblock->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK));
153 ASSERT(rblock->bb_level != 0);
154 dblock->bb_level = rblock->bb_level;
155 dblock->bb_numrecs = rblock->bb_numrecs;
156 dmxr = xfs_bmdr_maxrecs(dblocklen, 0);
157 fkp = XFS_BMBT_KEY_ADDR(mp, rblock, 1);
158 tkp = XFS_BMDR_KEY_ADDR(dblock, 1);
159 fpp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, rblocklen);
160 tpp = XFS_BMDR_PTR_ADDR(dblock, 1, dmxr);
161 dmxr = be16_to_cpu(dblock->bb_numrecs);
162 memcpy(tkp, fkp, sizeof(*fkp) * dmxr);
163 memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
166 STATIC struct xfs_btree_cur *
168 struct xfs_btree_cur *cur)
170 struct xfs_btree_cur *new;
172 new = xfs_bmbt_init_cursor(cur->bc_mp, cur->bc_tp,
173 cur->bc_ino.ip, cur->bc_ino.whichfork);
176 * Copy the firstblock, dfops, and flags values,
177 * since init cursor doesn't get them.
179 new->bc_ino.flags = cur->bc_ino.flags;
185 xfs_bmbt_update_cursor(
186 struct xfs_btree_cur *src,
187 struct xfs_btree_cur *dst)
189 ASSERT((dst->bc_tp->t_highest_agno != NULLAGNUMBER) ||
190 (dst->bc_ino.ip->i_diflags & XFS_DIFLAG_REALTIME));
192 dst->bc_ino.allocated += src->bc_ino.allocated;
193 dst->bc_tp->t_highest_agno = src->bc_tp->t_highest_agno;
195 src->bc_ino.allocated = 0;
199 xfs_bmbt_alloc_block(
200 struct xfs_btree_cur *cur,
201 const union xfs_btree_ptr *start,
202 union xfs_btree_ptr *new,
205 struct xfs_alloc_arg args;
208 memset(&args, 0, sizeof(args));
209 args.tp = cur->bc_tp;
210 args.mp = cur->bc_mp;
211 xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_ino.ip->i_ino,
212 cur->bc_ino.whichfork);
213 args.minlen = args.maxlen = args.prod = 1;
214 args.wasdel = cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL;
215 if (!args.wasdel && args.tp->t_blk_res == 0)
219 * If we are coming here from something like unwritten extent
220 * conversion, there has been no data extent allocation already done, so
221 * we have to ensure that we attempt to locate the entire set of bmbt
222 * allocations in the same AG, as xfs_bmapi_write() would have reserved.
224 if (cur->bc_tp->t_highest_agno == NULLAGNUMBER)
225 args.minleft = xfs_bmapi_minleft(cur->bc_tp, cur->bc_ino.ip,
226 cur->bc_ino.whichfork);
228 error = xfs_alloc_vextent_start_ag(&args, be64_to_cpu(start->l));
232 if (args.fsbno == NULLFSBLOCK && args.minleft) {
234 * Could not find an AG with enough free space to satisfy
235 * a full btree split. Try again and if
236 * successful activate the lowspace algorithm.
239 error = xfs_alloc_vextent_start_ag(&args, 0);
242 cur->bc_tp->t_flags |= XFS_TRANS_LOWMODE;
244 if (WARN_ON_ONCE(args.fsbno == NULLFSBLOCK)) {
249 ASSERT(args.len == 1);
250 cur->bc_ino.allocated++;
251 cur->bc_ino.ip->i_nblocks++;
252 xfs_trans_log_inode(args.tp, cur->bc_ino.ip, XFS_ILOG_CORE);
253 xfs_trans_mod_dquot_byino(args.tp, cur->bc_ino.ip,
254 XFS_TRANS_DQ_BCOUNT, 1L);
256 new->l = cpu_to_be64(args.fsbno);
264 struct xfs_btree_cur *cur,
267 struct xfs_mount *mp = cur->bc_mp;
268 struct xfs_inode *ip = cur->bc_ino.ip;
269 struct xfs_trans *tp = cur->bc_tp;
270 xfs_fsblock_t fsbno = XFS_DADDR_TO_FSB(mp, xfs_buf_daddr(bp));
271 struct xfs_owner_info oinfo;
274 xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_ino.whichfork);
275 error = xfs_free_extent_later(cur->bc_tp, fsbno, 1, &oinfo,
276 XFS_AG_RESV_NONE, false);
281 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
282 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L);
287 xfs_bmbt_get_minrecs(
288 struct xfs_btree_cur *cur,
291 if (level == cur->bc_nlevels - 1) {
292 struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur);
294 return xfs_bmbt_maxrecs(cur->bc_mp,
295 ifp->if_broot_bytes, level == 0) / 2;
298 return cur->bc_mp->m_bmap_dmnr[level != 0];
302 xfs_bmbt_get_maxrecs(
303 struct xfs_btree_cur *cur,
306 if (level == cur->bc_nlevels - 1) {
307 struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur);
309 return xfs_bmbt_maxrecs(cur->bc_mp,
310 ifp->if_broot_bytes, level == 0);
313 return cur->bc_mp->m_bmap_dmxr[level != 0];
318 * Get the maximum records we could store in the on-disk format.
320 * For non-root nodes this is equivalent to xfs_bmbt_get_maxrecs, but
321 * for the root node this checks the available space in the dinode fork
322 * so that we can resize the in-memory buffer to match it. After a
323 * resize to the maximum size this function returns the same value
324 * as xfs_bmbt_get_maxrecs for the root node, too.
327 xfs_bmbt_get_dmaxrecs(
328 struct xfs_btree_cur *cur,
331 if (level != cur->bc_nlevels - 1)
332 return cur->bc_mp->m_bmap_dmxr[level != 0];
333 return xfs_bmdr_maxrecs(cur->bc_ino.forksize, level == 0);
337 xfs_bmbt_init_key_from_rec(
338 union xfs_btree_key *key,
339 const union xfs_btree_rec *rec)
341 key->bmbt.br_startoff =
342 cpu_to_be64(xfs_bmbt_disk_get_startoff(&rec->bmbt));
346 xfs_bmbt_init_high_key_from_rec(
347 union xfs_btree_key *key,
348 const union xfs_btree_rec *rec)
350 key->bmbt.br_startoff = cpu_to_be64(
351 xfs_bmbt_disk_get_startoff(&rec->bmbt) +
352 xfs_bmbt_disk_get_blockcount(&rec->bmbt) - 1);
356 xfs_bmbt_init_rec_from_cur(
357 struct xfs_btree_cur *cur,
358 union xfs_btree_rec *rec)
360 xfs_bmbt_disk_set_all(&rec->bmbt, &cur->bc_rec.b);
364 xfs_bmbt_init_ptr_from_cur(
365 struct xfs_btree_cur *cur,
366 union xfs_btree_ptr *ptr)
373 struct xfs_btree_cur *cur,
374 const union xfs_btree_key *key)
376 return (int64_t)be64_to_cpu(key->bmbt.br_startoff) -
377 cur->bc_rec.b.br_startoff;
381 xfs_bmbt_diff_two_keys(
382 struct xfs_btree_cur *cur,
383 const union xfs_btree_key *k1,
384 const union xfs_btree_key *k2,
385 const union xfs_btree_key *mask)
387 uint64_t a = be64_to_cpu(k1->bmbt.br_startoff);
388 uint64_t b = be64_to_cpu(k2->bmbt.br_startoff);
390 ASSERT(!mask || mask->bmbt.br_startoff);
393 * Note: This routine previously casted a and b to int64 and subtracted
394 * them to generate a result. This lead to problems if b was the
395 * "maximum" key value (all ones) being signed incorrectly, hence this
396 * somewhat less efficient version.
405 static xfs_failaddr_t
409 struct xfs_mount *mp = bp->b_mount;
410 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
414 if (!xfs_verify_magic(bp, block->bb_magic))
415 return __this_address;
417 if (xfs_has_crc(mp)) {
419 * XXX: need a better way of verifying the owner here. Right now
420 * just make sure there has been one set.
422 fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN);
428 * numrecs and level verification.
430 * We don't know what fork we belong to, so just verify that the level
431 * is less than the maximum of the two. Later checks will be more
434 level = be16_to_cpu(block->bb_level);
435 if (level > max(mp->m_bm_maxlevels[0], mp->m_bm_maxlevels[1]))
436 return __this_address;
438 return xfs_btree_lblock_verify(bp, mp->m_bmap_dmxr[level != 0]);
442 xfs_bmbt_read_verify(
447 if (!xfs_btree_lblock_verify_crc(bp))
448 xfs_verifier_error(bp, -EFSBADCRC, __this_address);
450 fa = xfs_bmbt_verify(bp);
452 xfs_verifier_error(bp, -EFSCORRUPTED, fa);
456 trace_xfs_btree_corrupt(bp, _RET_IP_);
460 xfs_bmbt_write_verify(
465 fa = xfs_bmbt_verify(bp);
467 trace_xfs_btree_corrupt(bp, _RET_IP_);
468 xfs_verifier_error(bp, -EFSCORRUPTED, fa);
471 xfs_btree_lblock_calc_crc(bp);
474 const struct xfs_buf_ops xfs_bmbt_buf_ops = {
476 .magic = { cpu_to_be32(XFS_BMAP_MAGIC),
477 cpu_to_be32(XFS_BMAP_CRC_MAGIC) },
478 .verify_read = xfs_bmbt_read_verify,
479 .verify_write = xfs_bmbt_write_verify,
480 .verify_struct = xfs_bmbt_verify,
485 xfs_bmbt_keys_inorder(
486 struct xfs_btree_cur *cur,
487 const union xfs_btree_key *k1,
488 const union xfs_btree_key *k2)
490 return be64_to_cpu(k1->bmbt.br_startoff) <
491 be64_to_cpu(k2->bmbt.br_startoff);
495 xfs_bmbt_recs_inorder(
496 struct xfs_btree_cur *cur,
497 const union xfs_btree_rec *r1,
498 const union xfs_btree_rec *r2)
500 return xfs_bmbt_disk_get_startoff(&r1->bmbt) +
501 xfs_bmbt_disk_get_blockcount(&r1->bmbt) <=
502 xfs_bmbt_disk_get_startoff(&r2->bmbt);
505 STATIC enum xbtree_key_contig
506 xfs_bmbt_keys_contiguous(
507 struct xfs_btree_cur *cur,
508 const union xfs_btree_key *key1,
509 const union xfs_btree_key *key2,
510 const union xfs_btree_key *mask)
512 ASSERT(!mask || mask->bmbt.br_startoff);
514 return xbtree_key_contig(be64_to_cpu(key1->bmbt.br_startoff),
515 be64_to_cpu(key2->bmbt.br_startoff));
518 static const struct xfs_btree_ops xfs_bmbt_ops = {
519 .rec_len = sizeof(xfs_bmbt_rec_t),
520 .key_len = sizeof(xfs_bmbt_key_t),
522 .dup_cursor = xfs_bmbt_dup_cursor,
523 .update_cursor = xfs_bmbt_update_cursor,
524 .alloc_block = xfs_bmbt_alloc_block,
525 .free_block = xfs_bmbt_free_block,
526 .get_maxrecs = xfs_bmbt_get_maxrecs,
527 .get_minrecs = xfs_bmbt_get_minrecs,
528 .get_dmaxrecs = xfs_bmbt_get_dmaxrecs,
529 .init_key_from_rec = xfs_bmbt_init_key_from_rec,
530 .init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec,
531 .init_rec_from_cur = xfs_bmbt_init_rec_from_cur,
532 .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
533 .key_diff = xfs_bmbt_key_diff,
534 .diff_two_keys = xfs_bmbt_diff_two_keys,
535 .buf_ops = &xfs_bmbt_buf_ops,
536 .keys_inorder = xfs_bmbt_keys_inorder,
537 .recs_inorder = xfs_bmbt_recs_inorder,
538 .keys_contiguous = xfs_bmbt_keys_contiguous,
541 static struct xfs_btree_cur *
542 xfs_bmbt_init_common(
543 struct xfs_mount *mp,
544 struct xfs_trans *tp,
545 struct xfs_inode *ip,
548 struct xfs_btree_cur *cur;
550 ASSERT(whichfork != XFS_COW_FORK);
552 cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP,
553 mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache);
554 cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2);
556 cur->bc_ops = &xfs_bmbt_ops;
557 cur->bc_flags = XFS_BTREE_LONG_PTRS | XFS_BTREE_ROOT_IN_INODE;
559 cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
562 cur->bc_ino.allocated = 0;
563 cur->bc_ino.flags = 0;
569 * Allocate a new bmap btree cursor.
571 struct xfs_btree_cur *
572 xfs_bmbt_init_cursor(
573 struct xfs_mount *mp,
574 struct xfs_trans *tp,
575 struct xfs_inode *ip,
578 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork);
579 struct xfs_btree_cur *cur;
581 cur = xfs_bmbt_init_common(mp, tp, ip, whichfork);
583 cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1;
584 cur->bc_ino.forksize = xfs_inode_fork_size(ip, whichfork);
585 cur->bc_ino.whichfork = whichfork;
590 /* Calculate number of records in a block mapping btree block. */
591 static inline unsigned int
592 xfs_bmbt_block_maxrecs(
593 unsigned int blocklen,
597 return blocklen / sizeof(xfs_bmbt_rec_t);
598 return blocklen / (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t));
602 * Allocate a new bmap btree cursor for reloading an inode block mapping data
603 * structure. Note that callers can use the staged cursor to reload extents
604 * format inode forks if they rebuild the iext tree and commit the staged
605 * cursor immediately.
607 struct xfs_btree_cur *
608 xfs_bmbt_stage_cursor(
609 struct xfs_mount *mp,
610 struct xfs_inode *ip,
611 struct xbtree_ifakeroot *ifake)
613 struct xfs_btree_cur *cur;
614 struct xfs_btree_ops *ops;
616 /* data fork always has larger maxheight */
617 cur = xfs_bmbt_init_common(mp, NULL, ip, XFS_DATA_FORK);
618 cur->bc_nlevels = ifake->if_levels;
619 cur->bc_ino.forksize = ifake->if_fork_size;
621 /* Don't let anyone think we're attached to the real fork yet. */
622 cur->bc_ino.whichfork = -1;
623 xfs_btree_stage_ifakeroot(cur, ifake, &ops);
624 ops->update_cursor = NULL;
629 * Swap in the new inode fork root. Once we pass this point the newly rebuilt
630 * mappings are in place and we have to kill off any old btree blocks.
633 xfs_bmbt_commit_staged_btree(
634 struct xfs_btree_cur *cur,
635 struct xfs_trans *tp,
638 struct xbtree_ifakeroot *ifake = cur->bc_ino.ifake;
639 struct xfs_ifork *ifp;
640 static const short brootflag[2] = {XFS_ILOG_DBROOT, XFS_ILOG_ABROOT};
641 static const short extflag[2] = {XFS_ILOG_DEXT, XFS_ILOG_AEXT};
642 int flags = XFS_ILOG_CORE;
644 ASSERT(cur->bc_flags & XFS_BTREE_STAGING);
645 ASSERT(whichfork != XFS_COW_FORK);
648 * Free any resources hanging off the real fork, then shallow-copy the
649 * staging fork's contents into the real fork to transfer everything
652 ifp = xfs_ifork_ptr(cur->bc_ino.ip, whichfork);
653 xfs_idestroy_fork(ifp);
654 memcpy(ifp, ifake->if_fork, sizeof(struct xfs_ifork));
656 switch (ifp->if_format) {
657 case XFS_DINODE_FMT_EXTENTS:
658 flags |= extflag[whichfork];
660 case XFS_DINODE_FMT_BTREE:
661 flags |= brootflag[whichfork];
667 xfs_trans_log_inode(tp, cur->bc_ino.ip, flags);
668 xfs_btree_commit_ifakeroot(cur, tp, whichfork, &xfs_bmbt_ops);
672 * Calculate number of records in a bmap btree block.
676 struct xfs_mount *mp,
680 blocklen -= XFS_BMBT_BLOCK_LEN(mp);
681 return xfs_bmbt_block_maxrecs(blocklen, leaf);
685 * Calculate the maximum possible height of the btree that the on-disk format
686 * supports. This is used for sizing structures large enough to support every
687 * possible configuration of a filesystem that might get mounted.
690 xfs_bmbt_maxlevels_ondisk(void)
692 unsigned int minrecs[2];
693 unsigned int blocklen;
695 blocklen = min(XFS_MIN_BLOCKSIZE - XFS_BTREE_SBLOCK_LEN,
696 XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN);
698 minrecs[0] = xfs_bmbt_block_maxrecs(blocklen, true) / 2;
699 minrecs[1] = xfs_bmbt_block_maxrecs(blocklen, false) / 2;
701 /* One extra level for the inode root. */
702 return xfs_btree_compute_maxlevels(minrecs,
703 XFS_MAX_EXTCNT_DATA_FORK_LARGE) + 1;
707 * Calculate number of records in a bmap btree inode root.
714 blocklen -= sizeof(xfs_bmdr_block_t);
717 return blocklen / sizeof(xfs_bmdr_rec_t);
718 return blocklen / (sizeof(xfs_bmdr_key_t) + sizeof(xfs_bmdr_ptr_t));
722 * Change the owner of a btree format fork fo the inode passed in. Change it to
723 * the owner of that is passed in so that we can change owners before or after
724 * we switch forks between inodes. The operation that the caller is doing will
725 * determine whether is needs to change owner before or after the switch.
727 * For demand paged transactional modification, the fork switch should be done
728 * after reading in all the blocks, modifying them and pinning them in the
729 * transaction. For modification when the buffers are already pinned in memory,
730 * the fork switch can be done before changing the owner as we won't need to
731 * validate the owner until the btree buffers are unpinned and writes can occur
734 * For recovery based ownership change, there is no transactional context and
735 * so a buffer list must be supplied so that we can record the buffers that we
736 * modified for the caller to issue IO on.
739 xfs_bmbt_change_owner(
740 struct xfs_trans *tp,
741 struct xfs_inode *ip,
744 struct list_head *buffer_list)
746 struct xfs_btree_cur *cur;
749 ASSERT(tp || buffer_list);
750 ASSERT(!(tp && buffer_list));
751 ASSERT(xfs_ifork_ptr(ip, whichfork)->if_format == XFS_DINODE_FMT_BTREE);
753 cur = xfs_bmbt_init_cursor(ip->i_mount, tp, ip, whichfork);
754 cur->bc_ino.flags |= XFS_BTCUR_BMBT_INVALID_OWNER;
756 error = xfs_btree_change_owner(cur, new_owner, buffer_list);
757 xfs_btree_del_cursor(cur, error);
761 /* Calculate the bmap btree size for some records. */
764 struct xfs_mount *mp,
765 unsigned long long len)
767 return xfs_btree_calc_size(mp->m_bmap_dmnr, len);
771 xfs_bmbt_init_cur_cache(void)
773 xfs_bmbt_cur_cache = kmem_cache_create("xfs_bmbt_cur",
774 xfs_btree_cur_sizeof(xfs_bmbt_maxlevels_ondisk()),
777 if (!xfs_bmbt_cur_cache)
783 xfs_bmbt_destroy_cur_cache(void)
785 kmem_cache_destroy(xfs_bmbt_cur_cache);
786 xfs_bmbt_cur_cache = NULL;