Lines Matching refs:cur
68 struct xfs_btree_cur *cur, in xfs_btree_check_lblock_siblings() argument
82 if (!xfs_btree_check_lptr(cur, sibling, level + 1)) in xfs_btree_check_lblock_siblings()
95 struct xfs_btree_cur *cur, in xfs_btree_check_sblock_siblings() argument
109 if (!xfs_btree_check_sptr(cur, sibling, level + 1)) in xfs_btree_check_sblock_siblings()
124 struct xfs_btree_cur *cur, in __xfs_btree_check_lblock() argument
129 struct xfs_mount *mp = cur->bc_mp; in __xfs_btree_check_lblock()
130 xfs_btnum_t btnum = cur->bc_btnum; in __xfs_btree_check_lblock()
150 cur->bc_ops->get_maxrecs(cur, level)) in __xfs_btree_check_lblock()
156 fa = xfs_btree_check_lblock_siblings(mp, cur, level, fsb, in __xfs_btree_check_lblock()
159 fa = xfs_btree_check_lblock_siblings(mp, cur, level, fsb, in __xfs_btree_check_lblock()
167 struct xfs_btree_cur *cur, in xfs_btree_check_lblock() argument
172 struct xfs_mount *mp = cur->bc_mp; in xfs_btree_check_lblock()
175 fa = __xfs_btree_check_lblock(cur, block, level, bp); in xfs_btree_check_lblock()
191 struct xfs_btree_cur *cur, in __xfs_btree_check_sblock() argument
196 struct xfs_mount *mp = cur->bc_mp; in __xfs_btree_check_sblock()
197 struct xfs_perag *pag = cur->bc_ag.pag; in __xfs_btree_check_sblock()
198 xfs_btnum_t btnum = cur->bc_btnum; in __xfs_btree_check_sblock()
216 cur->bc_ops->get_maxrecs(cur, level)) in __xfs_btree_check_sblock()
222 fa = xfs_btree_check_sblock_siblings(pag, cur, level, agbno, in __xfs_btree_check_sblock()
225 fa = xfs_btree_check_sblock_siblings(pag, cur, level, agbno, in __xfs_btree_check_sblock()
233 struct xfs_btree_cur *cur, in xfs_btree_check_sblock() argument
238 struct xfs_mount *mp = cur->bc_mp; in xfs_btree_check_sblock()
241 fa = __xfs_btree_check_sblock(cur, block, level, bp); in xfs_btree_check_sblock()
256 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_check_block() argument
261 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_check_block()
262 return xfs_btree_check_lblock(cur, block, level, bp); in xfs_btree_check_block()
264 return xfs_btree_check_sblock(cur, block, level, bp); in xfs_btree_check_block()
270 struct xfs_btree_cur *cur, in xfs_btree_check_lptr() argument
276 return xfs_verify_fsbno(cur->bc_mp, fsbno); in xfs_btree_check_lptr()
282 struct xfs_btree_cur *cur, in xfs_btree_check_sptr() argument
288 return xfs_verify_agbno(cur->bc_ag.pag, agbno); in xfs_btree_check_sptr()
297 struct xfs_btree_cur *cur, in xfs_btree_check_ptr() argument
302 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_check_ptr()
303 if (xfs_btree_check_lptr(cur, be64_to_cpu((&ptr->l)[index]), in xfs_btree_check_ptr()
306 xfs_err(cur->bc_mp, in xfs_btree_check_ptr()
308 cur->bc_ino.ip->i_ino, in xfs_btree_check_ptr()
309 cur->bc_ino.whichfork, cur->bc_btnum, in xfs_btree_check_ptr()
312 if (xfs_btree_check_sptr(cur, be32_to_cpu((&ptr->s)[index]), in xfs_btree_check_ptr()
315 xfs_err(cur->bc_mp, in xfs_btree_check_ptr()
317 cur->bc_ag.pag->pag_agno, cur->bc_btnum, in xfs_btree_check_ptr()
408 struct xfs_btree_cur *cur, in xfs_btree_free_block() argument
413 error = cur->bc_ops->free_block(cur, bp); in xfs_btree_free_block()
415 xfs_trans_binval(cur->bc_tp, bp); in xfs_btree_free_block()
416 XFS_BTREE_STATS_INC(cur, free); in xfs_btree_free_block()
426 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_del_cursor() argument
438 for (i = 0; i < cur->bc_nlevels; i++) { in xfs_btree_del_cursor()
439 if (cur->bc_levels[i].bp) in xfs_btree_del_cursor()
440 xfs_trans_brelse(cur->bc_tp, cur->bc_levels[i].bp); in xfs_btree_del_cursor()
451 ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_ino.allocated == 0 || in xfs_btree_del_cursor()
452 xfs_is_shutdown(cur->bc_mp) || error != 0); in xfs_btree_del_cursor()
453 if (unlikely(cur->bc_flags & XFS_BTREE_STAGING)) in xfs_btree_del_cursor()
454 kmem_free(cur->bc_ops); in xfs_btree_del_cursor()
455 if (!(cur->bc_flags & XFS_BTREE_LONG_PTRS) && cur->bc_ag.pag) in xfs_btree_del_cursor()
456 xfs_perag_put(cur->bc_ag.pag); in xfs_btree_del_cursor()
457 kmem_cache_free(cur->bc_cache, cur); in xfs_btree_del_cursor()
466 struct xfs_btree_cur *cur, /* input cursor */ in xfs_btree_dup_cursor() argument
476 tp = cur->bc_tp; in xfs_btree_dup_cursor()
477 mp = cur->bc_mp; in xfs_btree_dup_cursor()
482 new = cur->bc_ops->dup_cursor(cur); in xfs_btree_dup_cursor()
487 new->bc_rec = cur->bc_rec; in xfs_btree_dup_cursor()
493 new->bc_levels[i].ptr = cur->bc_levels[i].ptr; in xfs_btree_dup_cursor()
494 new->bc_levels[i].ra = cur->bc_levels[i].ra; in xfs_btree_dup_cursor()
495 bp = cur->bc_levels[i].bp; in xfs_btree_dup_cursor()
500 cur->bc_ops->buf_ops); in xfs_btree_dup_cursor()
590 static inline size_t xfs_btree_block_len(struct xfs_btree_cur *cur) in xfs_btree_block_len() argument
592 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_block_len()
593 if (cur->bc_flags & XFS_BTREE_CRC_BLOCKS) in xfs_btree_block_len()
597 if (cur->bc_flags & XFS_BTREE_CRC_BLOCKS) in xfs_btree_block_len()
605 static inline size_t xfs_btree_ptr_len(struct xfs_btree_cur *cur) in xfs_btree_ptr_len() argument
607 return (cur->bc_flags & XFS_BTREE_LONG_PTRS) ? in xfs_btree_ptr_len()
616 struct xfs_btree_cur *cur, in xfs_btree_rec_offset() argument
619 return xfs_btree_block_len(cur) + in xfs_btree_rec_offset()
620 (n - 1) * cur->bc_ops->rec_len; in xfs_btree_rec_offset()
628 struct xfs_btree_cur *cur, in xfs_btree_key_offset() argument
631 return xfs_btree_block_len(cur) + in xfs_btree_key_offset()
632 (n - 1) * cur->bc_ops->key_len; in xfs_btree_key_offset()
640 struct xfs_btree_cur *cur, in xfs_btree_high_key_offset() argument
643 return xfs_btree_block_len(cur) + in xfs_btree_high_key_offset()
644 (n - 1) * cur->bc_ops->key_len + (cur->bc_ops->key_len / 2); in xfs_btree_high_key_offset()
652 struct xfs_btree_cur *cur, in xfs_btree_ptr_offset() argument
656 return xfs_btree_block_len(cur) + in xfs_btree_ptr_offset()
657 cur->bc_ops->get_maxrecs(cur, level) * cur->bc_ops->key_len + in xfs_btree_ptr_offset()
658 (n - 1) * xfs_btree_ptr_len(cur); in xfs_btree_ptr_offset()
666 struct xfs_btree_cur *cur, in xfs_btree_rec_addr() argument
671 ((char *)block + xfs_btree_rec_offset(cur, n)); in xfs_btree_rec_addr()
679 struct xfs_btree_cur *cur, in xfs_btree_key_addr() argument
684 ((char *)block + xfs_btree_key_offset(cur, n)); in xfs_btree_key_addr()
692 struct xfs_btree_cur *cur, in xfs_btree_high_key_addr() argument
697 ((char *)block + xfs_btree_high_key_offset(cur, n)); in xfs_btree_high_key_addr()
705 struct xfs_btree_cur *cur, in xfs_btree_ptr_addr() argument
714 ((char *)block + xfs_btree_ptr_offset(cur, n, level)); in xfs_btree_ptr_addr()
719 struct xfs_btree_cur *cur) in xfs_btree_ifork_ptr() argument
721 ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); in xfs_btree_ifork_ptr()
723 if (cur->bc_flags & XFS_BTREE_STAGING) in xfs_btree_ifork_ptr()
724 return cur->bc_ino.ifake->if_fork; in xfs_btree_ifork_ptr()
725 return xfs_ifork_ptr(cur->bc_ino.ip, cur->bc_ino.whichfork); in xfs_btree_ifork_ptr()
736 struct xfs_btree_cur *cur) in xfs_btree_get_iroot() argument
738 struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur); in xfs_btree_get_iroot()
749 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_get_block() argument
753 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_get_block()
754 (level == cur->bc_nlevels - 1)) { in xfs_btree_get_block()
756 return xfs_btree_get_iroot(cur); in xfs_btree_get_block()
759 *bpp = cur->bc_levels[level].bp; in xfs_btree_get_block()
769 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_firstrec() argument
778 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_firstrec()
779 if (xfs_btree_check_block(cur, block, level, bp)) in xfs_btree_firstrec()
789 cur->bc_levels[level].ptr = 1; in xfs_btree_firstrec()
799 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_lastrec() argument
808 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_lastrec()
809 if (xfs_btree_check_block(cur, block, level, bp)) in xfs_btree_lastrec()
819 cur->bc_levels[level].ptr = be16_to_cpu(block->bb_numrecs); in xfs_btree_lastrec()
931 struct xfs_btree_cur *cur, in xfs_btree_readahead_lblock() argument
940 xfs_btree_reada_bufl(cur->bc_mp, left, 1, in xfs_btree_readahead_lblock()
941 cur->bc_ops->buf_ops); in xfs_btree_readahead_lblock()
946 xfs_btree_reada_bufl(cur->bc_mp, right, 1, in xfs_btree_readahead_lblock()
947 cur->bc_ops->buf_ops); in xfs_btree_readahead_lblock()
956 struct xfs_btree_cur *cur, in xfs_btree_readahead_sblock() argument
966 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_ag.pag->pag_agno, in xfs_btree_readahead_sblock()
967 left, 1, cur->bc_ops->buf_ops); in xfs_btree_readahead_sblock()
972 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_ag.pag->pag_agno, in xfs_btree_readahead_sblock()
973 right, 1, cur->bc_ops->buf_ops); in xfs_btree_readahead_sblock()
986 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_readahead() argument
996 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_readahead()
997 (lev == cur->bc_nlevels - 1)) in xfs_btree_readahead()
1000 if ((cur->bc_levels[lev].ra | lr) == cur->bc_levels[lev].ra) in xfs_btree_readahead()
1003 cur->bc_levels[lev].ra |= lr; in xfs_btree_readahead()
1004 block = XFS_BUF_TO_BLOCK(cur->bc_levels[lev].bp); in xfs_btree_readahead()
1006 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_readahead()
1007 return xfs_btree_readahead_lblock(cur, lr, block); in xfs_btree_readahead()
1008 return xfs_btree_readahead_sblock(cur, lr, block); in xfs_btree_readahead()
1013 struct xfs_btree_cur *cur, in xfs_btree_ptr_to_daddr() argument
1021 error = xfs_btree_check_ptr(cur, ptr, 0, 1); in xfs_btree_ptr_to_daddr()
1025 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_ptr_to_daddr()
1027 *daddr = XFS_FSB_TO_DADDR(cur->bc_mp, fsbno); in xfs_btree_ptr_to_daddr()
1030 *daddr = XFS_AGB_TO_DADDR(cur->bc_mp, cur->bc_ag.pag->pag_agno, in xfs_btree_ptr_to_daddr()
1045 struct xfs_btree_cur *cur, in xfs_btree_readahead_ptr() argument
1051 if (xfs_btree_ptr_to_daddr(cur, ptr, &daddr)) in xfs_btree_readahead_ptr()
1053 xfs_buf_readahead(cur->bc_mp->m_ddev_targp, daddr, in xfs_btree_readahead_ptr()
1054 cur->bc_mp->m_bsize * count, cur->bc_ops->buf_ops); in xfs_btree_readahead_ptr()
1063 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_setbuf() argument
1069 if (cur->bc_levels[lev].bp) in xfs_btree_setbuf()
1070 xfs_trans_brelse(cur->bc_tp, cur->bc_levels[lev].bp); in xfs_btree_setbuf()
1071 cur->bc_levels[lev].bp = bp; in xfs_btree_setbuf()
1072 cur->bc_levels[lev].ra = 0; in xfs_btree_setbuf()
1075 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_setbuf()
1077 cur->bc_levels[lev].ra |= XFS_BTCUR_LEFTRA; in xfs_btree_setbuf()
1079 cur->bc_levels[lev].ra |= XFS_BTCUR_RIGHTRA; in xfs_btree_setbuf()
1082 cur->bc_levels[lev].ra |= XFS_BTCUR_LEFTRA; in xfs_btree_setbuf()
1084 cur->bc_levels[lev].ra |= XFS_BTCUR_RIGHTRA; in xfs_btree_setbuf()
1090 struct xfs_btree_cur *cur, in xfs_btree_ptr_is_null() argument
1093 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_ptr_is_null()
1101 struct xfs_btree_cur *cur, in xfs_btree_set_ptr_null() argument
1104 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_set_ptr_null()
1115 struct xfs_btree_cur *cur, in xfs_btree_get_sibling() argument
1122 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_get_sibling()
1137 struct xfs_btree_cur *cur, in xfs_btree_set_sibling() argument
1144 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_set_sibling()
1215 struct xfs_btree_cur *cur, in xfs_btree_init_block_cur() argument
1228 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_init_block_cur()
1229 owner = cur->bc_ino.ip->i_ino; in xfs_btree_init_block_cur()
1231 owner = cur->bc_ag.pag->pag_agno; in xfs_btree_init_block_cur()
1233 xfs_btree_init_block_int(cur->bc_mp, XFS_BUF_TO_BLOCK(bp), in xfs_btree_init_block_cur()
1234 xfs_buf_daddr(bp), cur->bc_btnum, level, in xfs_btree_init_block_cur()
1235 numrecs, owner, cur->bc_flags); in xfs_btree_init_block_cur()
1245 struct xfs_btree_cur *cur, in xfs_btree_is_lastrec() argument
1253 if (!(cur->bc_flags & XFS_BTREE_LASTREC_UPDATE)) in xfs_btree_is_lastrec()
1256 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB); in xfs_btree_is_lastrec()
1257 if (!xfs_btree_ptr_is_null(cur, &ptr)) in xfs_btree_is_lastrec()
1264 struct xfs_btree_cur *cur, in xfs_btree_buf_to_ptr() argument
1268 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_buf_to_ptr()
1269 ptr->l = cpu_to_be64(XFS_DADDR_TO_FSB(cur->bc_mp, in xfs_btree_buf_to_ptr()
1272 ptr->s = cpu_to_be32(xfs_daddr_to_agbno(cur->bc_mp, in xfs_btree_buf_to_ptr()
1279 struct xfs_btree_cur *cur, in xfs_btree_set_refs() argument
1282 switch (cur->bc_btnum) { in xfs_btree_set_refs()
1307 struct xfs_btree_cur *cur, in xfs_btree_get_buf_block() argument
1312 struct xfs_mount *mp = cur->bc_mp; in xfs_btree_get_buf_block()
1316 error = xfs_btree_ptr_to_daddr(cur, ptr, &d); in xfs_btree_get_buf_block()
1319 error = xfs_trans_get_buf(cur->bc_tp, mp->m_ddev_targp, d, mp->m_bsize, in xfs_btree_get_buf_block()
1324 (*bpp)->b_ops = cur->bc_ops->buf_ops; in xfs_btree_get_buf_block()
1335 struct xfs_btree_cur *cur, in xfs_btree_read_buf_block() argument
1341 struct xfs_mount *mp = cur->bc_mp; in xfs_btree_read_buf_block()
1348 error = xfs_btree_ptr_to_daddr(cur, ptr, &d); in xfs_btree_read_buf_block()
1351 error = xfs_trans_read_buf(mp, cur->bc_tp, mp->m_ddev_targp, d, in xfs_btree_read_buf_block()
1353 cur->bc_ops->buf_ops); in xfs_btree_read_buf_block()
1357 xfs_btree_set_refs(cur, *bpp); in xfs_btree_read_buf_block()
1367 struct xfs_btree_cur *cur, in xfs_btree_copy_keys() argument
1373 memcpy(dst_key, src_key, numkeys * cur->bc_ops->key_len); in xfs_btree_copy_keys()
1381 struct xfs_btree_cur *cur, in xfs_btree_copy_recs() argument
1387 memcpy(dst_rec, src_rec, numrecs * cur->bc_ops->rec_len); in xfs_btree_copy_recs()
1395 struct xfs_btree_cur *cur, in xfs_btree_copy_ptrs() argument
1401 memcpy(dst_ptr, src_ptr, numptrs * xfs_btree_ptr_len(cur)); in xfs_btree_copy_ptrs()
1409 struct xfs_btree_cur *cur, in xfs_btree_shift_keys() argument
1419 dst_key = (char *)key + (dir * cur->bc_ops->key_len); in xfs_btree_shift_keys()
1420 memmove(dst_key, key, numkeys * cur->bc_ops->key_len); in xfs_btree_shift_keys()
1428 struct xfs_btree_cur *cur, in xfs_btree_shift_recs() argument
1438 dst_rec = (char *)rec + (dir * cur->bc_ops->rec_len); in xfs_btree_shift_recs()
1439 memmove(dst_rec, rec, numrecs * cur->bc_ops->rec_len); in xfs_btree_shift_recs()
1447 struct xfs_btree_cur *cur, in xfs_btree_shift_ptrs() argument
1457 dst_ptr = (char *)ptr + (dir * xfs_btree_ptr_len(cur)); in xfs_btree_shift_ptrs()
1458 memmove(dst_ptr, ptr, numptrs * xfs_btree_ptr_len(cur)); in xfs_btree_shift_ptrs()
1466 struct xfs_btree_cur *cur, in xfs_btree_log_keys() argument
1473 xfs_trans_buf_set_type(cur->bc_tp, bp, XFS_BLFT_BTREE_BUF); in xfs_btree_log_keys()
1474 xfs_trans_log_buf(cur->bc_tp, bp, in xfs_btree_log_keys()
1475 xfs_btree_key_offset(cur, first), in xfs_btree_log_keys()
1476 xfs_btree_key_offset(cur, last + 1) - 1); in xfs_btree_log_keys()
1478 xfs_trans_log_inode(cur->bc_tp, cur->bc_ino.ip, in xfs_btree_log_keys()
1479 xfs_ilog_fbroot(cur->bc_ino.whichfork)); in xfs_btree_log_keys()
1488 struct xfs_btree_cur *cur, in xfs_btree_log_recs() argument
1494 xfs_trans_buf_set_type(cur->bc_tp, bp, XFS_BLFT_BTREE_BUF); in xfs_btree_log_recs()
1495 xfs_trans_log_buf(cur->bc_tp, bp, in xfs_btree_log_recs()
1496 xfs_btree_rec_offset(cur, first), in xfs_btree_log_recs()
1497 xfs_btree_rec_offset(cur, last + 1) - 1); in xfs_btree_log_recs()
1506 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_log_ptrs() argument
1516 xfs_trans_buf_set_type(cur->bc_tp, bp, XFS_BLFT_BTREE_BUF); in xfs_btree_log_ptrs()
1517 xfs_trans_log_buf(cur->bc_tp, bp, in xfs_btree_log_ptrs()
1518 xfs_btree_ptr_offset(cur, first, level), in xfs_btree_log_ptrs()
1519 xfs_btree_ptr_offset(cur, last + 1, level) - 1); in xfs_btree_log_ptrs()
1521 xfs_trans_log_inode(cur->bc_tp, cur->bc_ino.ip, in xfs_btree_log_ptrs()
1522 xfs_ilog_fbroot(cur->bc_ino.whichfork)); in xfs_btree_log_ptrs()
1532 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_log_block() argument
1569 if (cur->bc_flags & XFS_BTREE_CRC_BLOCKS) { in xfs_btree_log_block()
1584 (cur->bc_flags & XFS_BTREE_LONG_PTRS) ? in xfs_btree_log_block()
1587 xfs_trans_buf_set_type(cur->bc_tp, bp, XFS_BLFT_BTREE_BUF); in xfs_btree_log_block()
1588 xfs_trans_log_buf(cur->bc_tp, bp, first, last); in xfs_btree_log_block()
1590 xfs_trans_log_inode(cur->bc_tp, cur->bc_ino.ip, in xfs_btree_log_block()
1591 xfs_ilog_fbroot(cur->bc_ino.whichfork)); in xfs_btree_log_block()
1601 struct xfs_btree_cur *cur, in xfs_btree_increment() argument
1611 ASSERT(level < cur->bc_nlevels); in xfs_btree_increment()
1614 xfs_btree_readahead(cur, level, XFS_BTCUR_RIGHTRA); in xfs_btree_increment()
1617 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_increment()
1620 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_increment()
1626 if (++cur->bc_levels[level].ptr <= xfs_btree_get_numrecs(block)) in xfs_btree_increment()
1630 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB); in xfs_btree_increment()
1631 if (xfs_btree_ptr_is_null(cur, &ptr)) in xfs_btree_increment()
1634 XFS_BTREE_STATS_INC(cur, increment); in xfs_btree_increment()
1640 for (lev = level + 1; lev < cur->bc_nlevels; lev++) { in xfs_btree_increment()
1641 block = xfs_btree_get_block(cur, lev, &bp); in xfs_btree_increment()
1644 error = xfs_btree_check_block(cur, block, lev, bp); in xfs_btree_increment()
1649 if (++cur->bc_levels[lev].ptr <= xfs_btree_get_numrecs(block)) in xfs_btree_increment()
1653 xfs_btree_readahead(cur, lev, XFS_BTCUR_RIGHTRA); in xfs_btree_increment()
1660 if (lev == cur->bc_nlevels) { in xfs_btree_increment()
1661 if (cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) in xfs_btree_increment()
1667 ASSERT(lev < cur->bc_nlevels); in xfs_btree_increment()
1673 for (block = xfs_btree_get_block(cur, lev, &bp); lev > level; ) { in xfs_btree_increment()
1676 ptrp = xfs_btree_ptr_addr(cur, cur->bc_levels[lev].ptr, block); in xfs_btree_increment()
1678 error = xfs_btree_read_buf_block(cur, ptrp, 0, &block, &bp); in xfs_btree_increment()
1682 xfs_btree_setbuf(cur, lev, bp); in xfs_btree_increment()
1683 cur->bc_levels[lev].ptr = 1; in xfs_btree_increment()
1703 struct xfs_btree_cur *cur, in xfs_btree_decrement() argument
1713 ASSERT(level < cur->bc_nlevels); in xfs_btree_decrement()
1716 xfs_btree_readahead(cur, level, XFS_BTCUR_LEFTRA); in xfs_btree_decrement()
1719 if (--cur->bc_levels[level].ptr > 0) in xfs_btree_decrement()
1723 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_decrement()
1726 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_decrement()
1732 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_LEFTSIB); in xfs_btree_decrement()
1733 if (xfs_btree_ptr_is_null(cur, &ptr)) in xfs_btree_decrement()
1736 XFS_BTREE_STATS_INC(cur, decrement); in xfs_btree_decrement()
1742 for (lev = level + 1; lev < cur->bc_nlevels; lev++) { in xfs_btree_decrement()
1743 if (--cur->bc_levels[lev].ptr > 0) in xfs_btree_decrement()
1746 xfs_btree_readahead(cur, lev, XFS_BTCUR_LEFTRA); in xfs_btree_decrement()
1753 if (lev == cur->bc_nlevels) { in xfs_btree_decrement()
1754 if (cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) in xfs_btree_decrement()
1760 ASSERT(lev < cur->bc_nlevels); in xfs_btree_decrement()
1766 for (block = xfs_btree_get_block(cur, lev, &bp); lev > level; ) { in xfs_btree_decrement()
1769 ptrp = xfs_btree_ptr_addr(cur, cur->bc_levels[lev].ptr, block); in xfs_btree_decrement()
1771 error = xfs_btree_read_buf_block(cur, ptrp, 0, &block, &bp); in xfs_btree_decrement()
1774 xfs_btree_setbuf(cur, lev, bp); in xfs_btree_decrement()
1775 cur->bc_levels[lev].ptr = xfs_btree_get_numrecs(block); in xfs_btree_decrement()
1791 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_lookup_get_block() argument
1801 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_lookup_get_block()
1802 (level == cur->bc_nlevels - 1)) { in xfs_btree_lookup_get_block()
1803 *blkp = xfs_btree_get_iroot(cur); in xfs_btree_lookup_get_block()
1813 bp = cur->bc_levels[level].bp; in xfs_btree_lookup_get_block()
1814 error = xfs_btree_ptr_to_daddr(cur, pp, &daddr); in xfs_btree_lookup_get_block()
1822 error = xfs_btree_read_buf_block(cur, pp, 0, blkp, &bp); in xfs_btree_lookup_get_block()
1827 if (xfs_has_crc(cur->bc_mp) && in xfs_btree_lookup_get_block()
1828 !(cur->bc_ino.flags & XFS_BTCUR_BMBT_INVALID_OWNER) && in xfs_btree_lookup_get_block()
1829 (cur->bc_flags & XFS_BTREE_LONG_PTRS) && in xfs_btree_lookup_get_block()
1831 cur->bc_ino.ip->i_ino) in xfs_btree_lookup_get_block()
1842 xfs_btree_setbuf(cur, level, bp); in xfs_btree_lookup_get_block()
1848 xfs_trans_brelse(cur->bc_tp, bp); in xfs_btree_lookup_get_block()
1859 struct xfs_btree_cur *cur, in xfs_lookup_get_search_key() argument
1866 cur->bc_ops->init_key_from_rec(kp, in xfs_lookup_get_search_key()
1867 xfs_btree_rec_addr(cur, keyno, block)); in xfs_lookup_get_search_key()
1871 return xfs_btree_key_addr(cur, keyno, block); in xfs_lookup_get_search_key()
1880 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_lookup() argument
1892 XFS_BTREE_STATS_INC(cur, lookup); in xfs_btree_lookup()
1895 if (XFS_IS_CORRUPT(cur->bc_mp, cur->bc_nlevels == 0)) in xfs_btree_lookup()
1902 cur->bc_ops->init_ptr_from_cur(cur, &ptr); in xfs_btree_lookup()
1911 for (level = cur->bc_nlevels - 1, diff = 1; level >= 0; level--) { in xfs_btree_lookup()
1913 error = xfs_btree_lookup_get_block(cur, level, pp, &block); in xfs_btree_lookup()
1934 if (level != 0 || cur->bc_nlevels != 1) { in xfs_btree_lookup()
1937 cur->bc_mp, block, in xfs_btree_lookup()
1942 cur->bc_levels[0].ptr = dir != XFS_LOOKUP_LE; in xfs_btree_lookup()
1952 XFS_BTREE_STATS_INC(cur, compare); in xfs_btree_lookup()
1958 kp = xfs_lookup_get_search_key(cur, level, in xfs_btree_lookup()
1967 diff = cur->bc_ops->key_diff(cur, kp); in xfs_btree_lookup()
1988 pp = xfs_btree_ptr_addr(cur, keyno, block); in xfs_btree_lookup()
1990 error = xfs_btree_debug_check_ptr(cur, pp, 0, level); in xfs_btree_lookup()
1994 cur->bc_levels[level].ptr = keyno; in xfs_btree_lookup()
2005 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB); in xfs_btree_lookup()
2008 !xfs_btree_ptr_is_null(cur, &ptr)) { in xfs_btree_lookup()
2011 cur->bc_levels[0].ptr = keyno; in xfs_btree_lookup()
2012 error = xfs_btree_increment(cur, 0, &i); in xfs_btree_lookup()
2015 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) in xfs_btree_lookup()
2022 cur->bc_levels[0].ptr = keyno; in xfs_btree_lookup()
2040 struct xfs_btree_cur *cur, in xfs_btree_high_key_from_key() argument
2043 ASSERT(cur->bc_flags & XFS_BTREE_OVERLAPPING); in xfs_btree_high_key_from_key()
2045 (cur->bc_ops->key_len / 2)); in xfs_btree_high_key_from_key()
2051 struct xfs_btree_cur *cur, in xfs_btree_get_leaf_keys() argument
2061 rec = xfs_btree_rec_addr(cur, 1, block); in xfs_btree_get_leaf_keys()
2062 cur->bc_ops->init_key_from_rec(key, rec); in xfs_btree_get_leaf_keys()
2064 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in xfs_btree_get_leaf_keys()
2066 cur->bc_ops->init_high_key_from_rec(&max_hkey, rec); in xfs_btree_get_leaf_keys()
2068 rec = xfs_btree_rec_addr(cur, n, block); in xfs_btree_get_leaf_keys()
2069 cur->bc_ops->init_high_key_from_rec(&hkey, rec); in xfs_btree_get_leaf_keys()
2070 if (xfs_btree_keycmp_gt(cur, &hkey, &max_hkey)) in xfs_btree_get_leaf_keys()
2074 high = xfs_btree_high_key_from_key(cur, key); in xfs_btree_get_leaf_keys()
2075 memcpy(high, &max_hkey, cur->bc_ops->key_len / 2); in xfs_btree_get_leaf_keys()
2082 struct xfs_btree_cur *cur, in xfs_btree_get_node_keys() argument
2091 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in xfs_btree_get_node_keys()
2092 memcpy(key, xfs_btree_key_addr(cur, 1, block), in xfs_btree_get_node_keys()
2093 cur->bc_ops->key_len / 2); in xfs_btree_get_node_keys()
2095 max_hkey = xfs_btree_high_key_addr(cur, 1, block); in xfs_btree_get_node_keys()
2097 hkey = xfs_btree_high_key_addr(cur, n, block); in xfs_btree_get_node_keys()
2098 if (xfs_btree_keycmp_gt(cur, hkey, max_hkey)) in xfs_btree_get_node_keys()
2102 high = xfs_btree_high_key_from_key(cur, key); in xfs_btree_get_node_keys()
2103 memcpy(high, max_hkey, cur->bc_ops->key_len / 2); in xfs_btree_get_node_keys()
2105 memcpy(key, xfs_btree_key_addr(cur, 1, block), in xfs_btree_get_node_keys()
2106 cur->bc_ops->key_len); in xfs_btree_get_node_keys()
2113 struct xfs_btree_cur *cur, in xfs_btree_get_keys() argument
2118 xfs_btree_get_leaf_keys(cur, block, key); in xfs_btree_get_keys()
2120 xfs_btree_get_node_keys(cur, block, key); in xfs_btree_get_keys()
2132 struct xfs_btree_cur *cur, in xfs_btree_needs_key_update() argument
2135 return (cur->bc_flags & XFS_BTREE_OVERLAPPING) || ptr == 1; in xfs_btree_needs_key_update()
2145 struct xfs_btree_cur *cur, in __xfs_btree_updkeys() argument
2159 ASSERT(cur->bc_flags & XFS_BTREE_OVERLAPPING); in __xfs_btree_updkeys()
2162 if (level + 1 >= cur->bc_nlevels) in __xfs_btree_updkeys()
2165 trace_xfs_btree_updkeys(cur, level, bp0); in __xfs_btree_updkeys()
2168 hkey = xfs_btree_high_key_from_key(cur, lkey); in __xfs_btree_updkeys()
2169 xfs_btree_get_keys(cur, block, lkey); in __xfs_btree_updkeys()
2170 for (level++; level < cur->bc_nlevels; level++) { in __xfs_btree_updkeys()
2174 block = xfs_btree_get_block(cur, level, &bp); in __xfs_btree_updkeys()
2175 trace_xfs_btree_updkeys(cur, level, bp); in __xfs_btree_updkeys()
2177 error = xfs_btree_check_block(cur, block, level, bp); in __xfs_btree_updkeys()
2181 ptr = cur->bc_levels[level].ptr; in __xfs_btree_updkeys()
2182 nlkey = xfs_btree_key_addr(cur, ptr, block); in __xfs_btree_updkeys()
2183 nhkey = xfs_btree_high_key_addr(cur, ptr, block); in __xfs_btree_updkeys()
2185 xfs_btree_keycmp_eq(cur, nlkey, lkey) && in __xfs_btree_updkeys()
2186 xfs_btree_keycmp_eq(cur, nhkey, hkey)) in __xfs_btree_updkeys()
2188 xfs_btree_copy_keys(cur, nlkey, lkey, 1); in __xfs_btree_updkeys()
2189 xfs_btree_log_keys(cur, bp, ptr, ptr); in __xfs_btree_updkeys()
2190 if (level + 1 >= cur->bc_nlevels) in __xfs_btree_updkeys()
2192 xfs_btree_get_node_keys(cur, block, lkey); in __xfs_btree_updkeys()
2201 struct xfs_btree_cur *cur, in xfs_btree_updkeys_force() argument
2207 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_updkeys_force()
2208 return __xfs_btree_updkeys(cur, level, block, bp, true); in xfs_btree_updkeys_force()
2216 struct xfs_btree_cur *cur, in xfs_btree_update_keys() argument
2227 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_update_keys()
2228 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) in xfs_btree_update_keys()
2229 return __xfs_btree_updkeys(cur, level, block, bp, false); in xfs_btree_update_keys()
2237 xfs_btree_get_keys(cur, block, &key); in xfs_btree_update_keys()
2238 for (level++, ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) { in xfs_btree_update_keys()
2242 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_update_keys()
2244 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_update_keys()
2248 ptr = cur->bc_levels[level].ptr; in xfs_btree_update_keys()
2249 kp = xfs_btree_key_addr(cur, ptr, block); in xfs_btree_update_keys()
2250 xfs_btree_copy_keys(cur, kp, &key, 1); in xfs_btree_update_keys()
2251 xfs_btree_log_keys(cur, bp, ptr, ptr); in xfs_btree_update_keys()
2264 struct xfs_btree_cur *cur, in xfs_btree_update() argument
2274 block = xfs_btree_get_block(cur, 0, &bp); in xfs_btree_update()
2277 error = xfs_btree_check_block(cur, block, 0, bp); in xfs_btree_update()
2282 ptr = cur->bc_levels[0].ptr; in xfs_btree_update()
2283 rp = xfs_btree_rec_addr(cur, ptr, block); in xfs_btree_update()
2286 xfs_btree_copy_recs(cur, rp, rec, 1); in xfs_btree_update()
2287 xfs_btree_log_recs(cur, bp, ptr, ptr); in xfs_btree_update()
2293 if (xfs_btree_is_lastrec(cur, block, 0)) { in xfs_btree_update()
2294 cur->bc_ops->update_lastrec(cur, block, rec, in xfs_btree_update()
2299 if (xfs_btree_needs_key_update(cur, ptr)) { in xfs_btree_update()
2300 error = xfs_btree_update_keys(cur, 0); in xfs_btree_update()
2317 struct xfs_btree_cur *cur, in xfs_btree_lshift() argument
2335 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_lshift()
2336 level == cur->bc_nlevels - 1) in xfs_btree_lshift()
2340 right = xfs_btree_get_block(cur, level, &rbp); in xfs_btree_lshift()
2343 error = xfs_btree_check_block(cur, right, level, rbp); in xfs_btree_lshift()
2349 xfs_btree_get_sibling(cur, right, &lptr, XFS_BB_LEFTSIB); in xfs_btree_lshift()
2350 if (xfs_btree_ptr_is_null(cur, &lptr)) in xfs_btree_lshift()
2357 if (cur->bc_levels[level].ptr <= 1) in xfs_btree_lshift()
2361 error = xfs_btree_read_buf_block(cur, &lptr, 0, &left, &lbp); in xfs_btree_lshift()
2367 if (lrecs == cur->bc_ops->get_maxrecs(cur, level)) in xfs_btree_lshift()
2380 XFS_BTREE_STATS_INC(cur, lshift); in xfs_btree_lshift()
2381 XFS_BTREE_STATS_ADD(cur, moves, 1); in xfs_btree_lshift()
2392 lkp = xfs_btree_key_addr(cur, lrecs, left); in xfs_btree_lshift()
2393 rkp = xfs_btree_key_addr(cur, 1, right); in xfs_btree_lshift()
2395 lpp = xfs_btree_ptr_addr(cur, lrecs, left); in xfs_btree_lshift()
2396 rpp = xfs_btree_ptr_addr(cur, 1, right); in xfs_btree_lshift()
2398 error = xfs_btree_debug_check_ptr(cur, rpp, 0, level); in xfs_btree_lshift()
2402 xfs_btree_copy_keys(cur, lkp, rkp, 1); in xfs_btree_lshift()
2403 xfs_btree_copy_ptrs(cur, lpp, rpp, 1); in xfs_btree_lshift()
2405 xfs_btree_log_keys(cur, lbp, lrecs, lrecs); in xfs_btree_lshift()
2406 xfs_btree_log_ptrs(cur, lbp, lrecs, lrecs); in xfs_btree_lshift()
2408 ASSERT(cur->bc_ops->keys_inorder(cur, in xfs_btree_lshift()
2409 xfs_btree_key_addr(cur, lrecs - 1, left), lkp)); in xfs_btree_lshift()
2414 lrp = xfs_btree_rec_addr(cur, lrecs, left); in xfs_btree_lshift()
2415 rrp = xfs_btree_rec_addr(cur, 1, right); in xfs_btree_lshift()
2417 xfs_btree_copy_recs(cur, lrp, rrp, 1); in xfs_btree_lshift()
2418 xfs_btree_log_recs(cur, lbp, lrecs, lrecs); in xfs_btree_lshift()
2420 ASSERT(cur->bc_ops->recs_inorder(cur, in xfs_btree_lshift()
2421 xfs_btree_rec_addr(cur, lrecs - 1, left), lrp)); in xfs_btree_lshift()
2425 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS); in xfs_btree_lshift()
2428 xfs_btree_log_block(cur, rbp, XFS_BB_NUMRECS); in xfs_btree_lshift()
2433 XFS_BTREE_STATS_ADD(cur, moves, rrecs - 1); in xfs_btree_lshift()
2437 error = xfs_btree_debug_check_ptr(cur, rpp, i + 1, level); in xfs_btree_lshift()
2442 xfs_btree_shift_keys(cur, in xfs_btree_lshift()
2443 xfs_btree_key_addr(cur, 2, right), in xfs_btree_lshift()
2445 xfs_btree_shift_ptrs(cur, in xfs_btree_lshift()
2446 xfs_btree_ptr_addr(cur, 2, right), in xfs_btree_lshift()
2449 xfs_btree_log_keys(cur, rbp, 1, rrecs); in xfs_btree_lshift()
2450 xfs_btree_log_ptrs(cur, rbp, 1, rrecs); in xfs_btree_lshift()
2453 xfs_btree_shift_recs(cur, in xfs_btree_lshift()
2454 xfs_btree_rec_addr(cur, 2, right), in xfs_btree_lshift()
2456 xfs_btree_log_recs(cur, rbp, 1, rrecs); in xfs_btree_lshift()
2463 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in xfs_btree_lshift()
2464 error = xfs_btree_dup_cursor(cur, &tcur); in xfs_btree_lshift()
2486 error = xfs_btree_update_keys(cur, level); in xfs_btree_lshift()
2491 cur->bc_levels[level].ptr--; in xfs_btree_lshift()
2514 struct xfs_btree_cur *cur, in xfs_btree_rshift() argument
2530 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_rshift()
2531 (level == cur->bc_nlevels - 1)) in xfs_btree_rshift()
2535 left = xfs_btree_get_block(cur, level, &lbp); in xfs_btree_rshift()
2538 error = xfs_btree_check_block(cur, left, level, lbp); in xfs_btree_rshift()
2544 xfs_btree_get_sibling(cur, left, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_rshift()
2545 if (xfs_btree_ptr_is_null(cur, &rptr)) in xfs_btree_rshift()
2553 if (cur->bc_levels[level].ptr >= lrecs) in xfs_btree_rshift()
2557 error = xfs_btree_read_buf_block(cur, &rptr, 0, &right, &rbp); in xfs_btree_rshift()
2563 if (rrecs == cur->bc_ops->get_maxrecs(cur, level)) in xfs_btree_rshift()
2566 XFS_BTREE_STATS_INC(cur, rshift); in xfs_btree_rshift()
2567 XFS_BTREE_STATS_ADD(cur, moves, rrecs); in xfs_btree_rshift()
2579 lkp = xfs_btree_key_addr(cur, lrecs, left); in xfs_btree_rshift()
2580 lpp = xfs_btree_ptr_addr(cur, lrecs, left); in xfs_btree_rshift()
2581 rkp = xfs_btree_key_addr(cur, 1, right); in xfs_btree_rshift()
2582 rpp = xfs_btree_ptr_addr(cur, 1, right); in xfs_btree_rshift()
2585 error = xfs_btree_debug_check_ptr(cur, rpp, i, level); in xfs_btree_rshift()
2590 xfs_btree_shift_keys(cur, rkp, 1, rrecs); in xfs_btree_rshift()
2591 xfs_btree_shift_ptrs(cur, rpp, 1, rrecs); in xfs_btree_rshift()
2593 error = xfs_btree_debug_check_ptr(cur, lpp, 0, level); in xfs_btree_rshift()
2598 xfs_btree_copy_keys(cur, rkp, lkp, 1); in xfs_btree_rshift()
2599 xfs_btree_copy_ptrs(cur, rpp, lpp, 1); in xfs_btree_rshift()
2601 xfs_btree_log_keys(cur, rbp, 1, rrecs + 1); in xfs_btree_rshift()
2602 xfs_btree_log_ptrs(cur, rbp, 1, rrecs + 1); in xfs_btree_rshift()
2604 ASSERT(cur->bc_ops->keys_inorder(cur, rkp, in xfs_btree_rshift()
2605 xfs_btree_key_addr(cur, 2, right))); in xfs_btree_rshift()
2611 lrp = xfs_btree_rec_addr(cur, lrecs, left); in xfs_btree_rshift()
2612 rrp = xfs_btree_rec_addr(cur, 1, right); in xfs_btree_rshift()
2614 xfs_btree_shift_recs(cur, rrp, 1, rrecs); in xfs_btree_rshift()
2617 xfs_btree_copy_recs(cur, rrp, lrp, 1); in xfs_btree_rshift()
2618 xfs_btree_log_recs(cur, rbp, 1, rrecs + 1); in xfs_btree_rshift()
2625 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS); in xfs_btree_rshift()
2628 xfs_btree_log_block(cur, rbp, XFS_BB_NUMRECS); in xfs_btree_rshift()
2634 error = xfs_btree_dup_cursor(cur, &tcur); in xfs_btree_rshift()
2648 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in xfs_btree_rshift()
2649 error = xfs_btree_update_keys(cur, level); in xfs_btree_rshift()
2683 struct xfs_btree_cur *cur, in __xfs_btree_split() argument
2705 XFS_BTREE_STATS_INC(cur, split); in __xfs_btree_split()
2708 left = xfs_btree_get_block(cur, level, &lbp); in __xfs_btree_split()
2711 error = xfs_btree_check_block(cur, left, level, lbp); in __xfs_btree_split()
2716 xfs_btree_buf_to_ptr(cur, lbp, &lptr); in __xfs_btree_split()
2719 error = cur->bc_ops->alloc_block(cur, &lptr, &rptr, stat); in __xfs_btree_split()
2724 XFS_BTREE_STATS_INC(cur, alloc); in __xfs_btree_split()
2727 error = xfs_btree_get_buf_block(cur, &rptr, &right, &rbp); in __xfs_btree_split()
2732 xfs_btree_init_block_cur(cur, rbp, xfs_btree_get_level(left), 0); in __xfs_btree_split()
2741 if ((lrecs & 1) && cur->bc_levels[level].ptr <= rrecs + 1) in __xfs_btree_split()
2745 XFS_BTREE_STATS_ADD(cur, moves, rrecs); in __xfs_btree_split()
2764 lkp = xfs_btree_key_addr(cur, src_index, left); in __xfs_btree_split()
2765 lpp = xfs_btree_ptr_addr(cur, src_index, left); in __xfs_btree_split()
2766 rkp = xfs_btree_key_addr(cur, 1, right); in __xfs_btree_split()
2767 rpp = xfs_btree_ptr_addr(cur, 1, right); in __xfs_btree_split()
2770 error = xfs_btree_debug_check_ptr(cur, lpp, i, level); in __xfs_btree_split()
2776 xfs_btree_copy_keys(cur, rkp, lkp, rrecs); in __xfs_btree_split()
2777 xfs_btree_copy_ptrs(cur, rpp, lpp, rrecs); in __xfs_btree_split()
2779 xfs_btree_log_keys(cur, rbp, 1, rrecs); in __xfs_btree_split()
2780 xfs_btree_log_ptrs(cur, rbp, 1, rrecs); in __xfs_btree_split()
2783 xfs_btree_get_node_keys(cur, right, key); in __xfs_btree_split()
2789 lrp = xfs_btree_rec_addr(cur, src_index, left); in __xfs_btree_split()
2790 rrp = xfs_btree_rec_addr(cur, 1, right); in __xfs_btree_split()
2793 xfs_btree_copy_recs(cur, rrp, lrp, rrecs); in __xfs_btree_split()
2794 xfs_btree_log_recs(cur, rbp, 1, rrecs); in __xfs_btree_split()
2797 xfs_btree_get_leaf_keys(cur, right, key); in __xfs_btree_split()
2804 xfs_btree_get_sibling(cur, left, &rrptr, XFS_BB_RIGHTSIB); in __xfs_btree_split()
2805 xfs_btree_set_sibling(cur, right, &rrptr, XFS_BB_RIGHTSIB); in __xfs_btree_split()
2806 xfs_btree_set_sibling(cur, right, &lptr, XFS_BB_LEFTSIB); in __xfs_btree_split()
2807 xfs_btree_set_sibling(cur, left, &rptr, XFS_BB_RIGHTSIB); in __xfs_btree_split()
2809 xfs_btree_log_block(cur, rbp, XFS_BB_ALL_BITS); in __xfs_btree_split()
2810 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB); in __xfs_btree_split()
2816 if (!xfs_btree_ptr_is_null(cur, &rrptr)) { in __xfs_btree_split()
2817 error = xfs_btree_read_buf_block(cur, &rrptr, in __xfs_btree_split()
2821 xfs_btree_set_sibling(cur, rrblock, &rptr, XFS_BB_LEFTSIB); in __xfs_btree_split()
2822 xfs_btree_log_block(cur, rrbp, XFS_BB_LEFTSIB); in __xfs_btree_split()
2826 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in __xfs_btree_split()
2827 error = xfs_btree_update_keys(cur, level); in __xfs_btree_split()
2837 if (cur->bc_levels[level].ptr > lrecs + 1) { in __xfs_btree_split()
2838 xfs_btree_setbuf(cur, level, rbp); in __xfs_btree_split()
2839 cur->bc_levels[level].ptr -= lrecs; in __xfs_btree_split()
2845 if (level + 1 < cur->bc_nlevels) { in __xfs_btree_split()
2846 error = xfs_btree_dup_cursor(cur, curp); in __xfs_btree_split()
2864 struct xfs_btree_cur *cur; member
2898 xfs_trans_set_context(args->cur->bc_tp); in xfs_btree_split_worker()
2900 args->result = __xfs_btree_split(args->cur, args->level, args->ptrp, in xfs_btree_split_worker()
2903 xfs_trans_clear_context(args->cur->bc_tp); in xfs_btree_split_worker()
2934 struct xfs_btree_cur *cur, in xfs_btree_split() argument
2944 if (cur->bc_btnum != XFS_BTNUM_BMAP || in xfs_btree_split()
2945 cur->bc_tp->t_highest_agno == NULLAGNUMBER) in xfs_btree_split()
2946 return __xfs_btree_split(cur, level, ptrp, key, curp, stat); in xfs_btree_split()
2948 args.cur = cur; in xfs_btree_split()
2973 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_new_iroot() argument
2989 XFS_BTREE_STATS_INC(cur, newroot); in xfs_btree_new_iroot()
2991 ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); in xfs_btree_new_iroot()
2993 level = cur->bc_nlevels - 1; in xfs_btree_new_iroot()
2995 block = xfs_btree_get_iroot(cur); in xfs_btree_new_iroot()
2996 pp = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_new_iroot()
2999 error = cur->bc_ops->alloc_block(cur, pp, &nptr, stat); in xfs_btree_new_iroot()
3005 XFS_BTREE_STATS_INC(cur, alloc); in xfs_btree_new_iroot()
3008 error = xfs_btree_get_buf_block(cur, &nptr, &cblock, &cbp); in xfs_btree_new_iroot()
3016 memcpy(cblock, block, xfs_btree_block_len(cur)); in xfs_btree_new_iroot()
3017 if (cur->bc_flags & XFS_BTREE_CRC_BLOCKS) { in xfs_btree_new_iroot()
3019 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_new_iroot()
3027 cur->bc_nlevels++; in xfs_btree_new_iroot()
3028 ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); in xfs_btree_new_iroot()
3029 cur->bc_levels[level + 1].ptr = 1; in xfs_btree_new_iroot()
3031 kp = xfs_btree_key_addr(cur, 1, block); in xfs_btree_new_iroot()
3032 ckp = xfs_btree_key_addr(cur, 1, cblock); in xfs_btree_new_iroot()
3033 xfs_btree_copy_keys(cur, ckp, kp, xfs_btree_get_numrecs(cblock)); in xfs_btree_new_iroot()
3035 cpp = xfs_btree_ptr_addr(cur, 1, cblock); in xfs_btree_new_iroot()
3037 error = xfs_btree_debug_check_ptr(cur, pp, i, level); in xfs_btree_new_iroot()
3042 xfs_btree_copy_ptrs(cur, cpp, pp, xfs_btree_get_numrecs(cblock)); in xfs_btree_new_iroot()
3044 error = xfs_btree_debug_check_ptr(cur, &nptr, 0, level); in xfs_btree_new_iroot()
3048 xfs_btree_copy_ptrs(cur, pp, &nptr, 1); in xfs_btree_new_iroot()
3050 xfs_iroot_realloc(cur->bc_ino.ip, in xfs_btree_new_iroot()
3052 cur->bc_ino.whichfork); in xfs_btree_new_iroot()
3054 xfs_btree_setbuf(cur, level, cbp); in xfs_btree_new_iroot()
3060 xfs_btree_log_block(cur, cbp, XFS_BB_ALL_BITS); in xfs_btree_new_iroot()
3061 xfs_btree_log_keys(cur, cbp, 1, be16_to_cpu(cblock->bb_numrecs)); in xfs_btree_new_iroot()
3062 xfs_btree_log_ptrs(cur, cbp, 1, be16_to_cpu(cblock->bb_numrecs)); in xfs_btree_new_iroot()
3065 XFS_ILOG_CORE | xfs_ilog_fbroot(cur->bc_ino.whichfork); in xfs_btree_new_iroot()
3077 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_new_root() argument
3093 XFS_BTREE_STATS_INC(cur, newroot); in xfs_btree_new_root()
3096 cur->bc_ops->init_ptr_from_cur(cur, &rptr); in xfs_btree_new_root()
3099 error = cur->bc_ops->alloc_block(cur, &rptr, &lptr, stat); in xfs_btree_new_root()
3104 XFS_BTREE_STATS_INC(cur, alloc); in xfs_btree_new_root()
3107 error = xfs_btree_get_buf_block(cur, &lptr, &new, &nbp); in xfs_btree_new_root()
3112 cur->bc_ops->set_root(cur, &lptr, 1); in xfs_btree_new_root()
3120 block = xfs_btree_get_block(cur, cur->bc_nlevels - 1, &bp); in xfs_btree_new_root()
3123 error = xfs_btree_check_block(cur, block, cur->bc_nlevels - 1, bp); in xfs_btree_new_root()
3128 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_new_root()
3129 if (!xfs_btree_ptr_is_null(cur, &rptr)) { in xfs_btree_new_root()
3132 xfs_btree_buf_to_ptr(cur, lbp, &lptr); in xfs_btree_new_root()
3134 error = xfs_btree_read_buf_block(cur, &rptr, 0, &right, &rbp); in xfs_btree_new_root()
3142 xfs_btree_buf_to_ptr(cur, rbp, &rptr); in xfs_btree_new_root()
3144 xfs_btree_get_sibling(cur, right, &lptr, XFS_BB_LEFTSIB); in xfs_btree_new_root()
3145 error = xfs_btree_read_buf_block(cur, &lptr, 0, &left, &lbp); in xfs_btree_new_root()
3153 xfs_btree_init_block_cur(cur, nbp, cur->bc_nlevels, 2); in xfs_btree_new_root()
3154 xfs_btree_log_block(cur, nbp, XFS_BB_ALL_BITS); in xfs_btree_new_root()
3155 ASSERT(!xfs_btree_ptr_is_null(cur, &lptr) && in xfs_btree_new_root()
3156 !xfs_btree_ptr_is_null(cur, &rptr)); in xfs_btree_new_root()
3164 xfs_btree_get_node_keys(cur, left, in xfs_btree_new_root()
3165 xfs_btree_key_addr(cur, 1, new)); in xfs_btree_new_root()
3166 xfs_btree_get_node_keys(cur, right, in xfs_btree_new_root()
3167 xfs_btree_key_addr(cur, 2, new)); in xfs_btree_new_root()
3174 xfs_btree_get_leaf_keys(cur, left, in xfs_btree_new_root()
3175 xfs_btree_key_addr(cur, 1, new)); in xfs_btree_new_root()
3176 xfs_btree_get_leaf_keys(cur, right, in xfs_btree_new_root()
3177 xfs_btree_key_addr(cur, 2, new)); in xfs_btree_new_root()
3179 xfs_btree_log_keys(cur, nbp, 1, 2); in xfs_btree_new_root()
3182 xfs_btree_copy_ptrs(cur, in xfs_btree_new_root()
3183 xfs_btree_ptr_addr(cur, 1, new), &lptr, 1); in xfs_btree_new_root()
3184 xfs_btree_copy_ptrs(cur, in xfs_btree_new_root()
3185 xfs_btree_ptr_addr(cur, 2, new), &rptr, 1); in xfs_btree_new_root()
3186 xfs_btree_log_ptrs(cur, nbp, 1, 2); in xfs_btree_new_root()
3189 xfs_btree_setbuf(cur, cur->bc_nlevels, nbp); in xfs_btree_new_root()
3190 cur->bc_levels[cur->bc_nlevels].ptr = nptr; in xfs_btree_new_root()
3191 cur->bc_nlevels++; in xfs_btree_new_root()
3192 ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); in xfs_btree_new_root()
3204 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_make_block_unfull() argument
3216 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_make_block_unfull()
3217 level == cur->bc_nlevels - 1) { in xfs_btree_make_block_unfull()
3218 struct xfs_inode *ip = cur->bc_ino.ip; in xfs_btree_make_block_unfull()
3220 if (numrecs < cur->bc_ops->get_dmaxrecs(cur, level)) { in xfs_btree_make_block_unfull()
3222 xfs_iroot_realloc(ip, 1, cur->bc_ino.whichfork); in xfs_btree_make_block_unfull()
3228 error = xfs_btree_new_iroot(cur, &logflags, stat); in xfs_btree_make_block_unfull()
3232 xfs_trans_log_inode(cur->bc_tp, ip, logflags); in xfs_btree_make_block_unfull()
3239 error = xfs_btree_rshift(cur, level, stat); in xfs_btree_make_block_unfull()
3244 error = xfs_btree_lshift(cur, level, stat); in xfs_btree_make_block_unfull()
3249 *oindex = *index = cur->bc_levels[level].ptr; in xfs_btree_make_block_unfull()
3259 error = xfs_btree_split(cur, level, nptr, key, ncur, stat); in xfs_btree_make_block_unfull()
3264 *index = cur->bc_levels[level].ptr; in xfs_btree_make_block_unfull()
3274 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_insrec() argument
3302 if (!(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_insrec()
3303 (level >= cur->bc_nlevels)) { in xfs_btree_insrec()
3304 error = xfs_btree_new_root(cur, stat); in xfs_btree_insrec()
3305 xfs_btree_set_ptr_null(cur, ptrp); in xfs_btree_insrec()
3311 ptr = cur->bc_levels[level].ptr; in xfs_btree_insrec()
3319 XFS_BTREE_STATS_INC(cur, insrec); in xfs_btree_insrec()
3322 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_insrec()
3327 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_insrec()
3334 ASSERT(cur->bc_ops->recs_inorder(cur, rec, in xfs_btree_insrec()
3335 xfs_btree_rec_addr(cur, ptr, block))); in xfs_btree_insrec()
3337 ASSERT(cur->bc_ops->keys_inorder(cur, key, in xfs_btree_insrec()
3338 xfs_btree_key_addr(cur, ptr, block))); in xfs_btree_insrec()
3347 xfs_btree_set_ptr_null(cur, &nptr); in xfs_btree_insrec()
3348 if (numrecs == cur->bc_ops->get_maxrecs(cur, level)) { in xfs_btree_insrec()
3349 error = xfs_btree_make_block_unfull(cur, level, numrecs, in xfs_btree_insrec()
3359 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_insrec()
3363 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_insrec()
3372 XFS_BTREE_STATS_ADD(cur, moves, numrecs - ptr + 1); in xfs_btree_insrec()
3379 kp = xfs_btree_key_addr(cur, ptr, block); in xfs_btree_insrec()
3380 pp = xfs_btree_ptr_addr(cur, ptr, block); in xfs_btree_insrec()
3383 error = xfs_btree_debug_check_ptr(cur, pp, i, level); in xfs_btree_insrec()
3388 xfs_btree_shift_keys(cur, kp, 1, numrecs - ptr + 1); in xfs_btree_insrec()
3389 xfs_btree_shift_ptrs(cur, pp, 1, numrecs - ptr + 1); in xfs_btree_insrec()
3391 error = xfs_btree_debug_check_ptr(cur, ptrp, 0, level); in xfs_btree_insrec()
3396 xfs_btree_copy_keys(cur, kp, key, 1); in xfs_btree_insrec()
3397 xfs_btree_copy_ptrs(cur, pp, ptrp, 1); in xfs_btree_insrec()
3400 xfs_btree_log_ptrs(cur, bp, ptr, numrecs); in xfs_btree_insrec()
3401 xfs_btree_log_keys(cur, bp, ptr, numrecs); in xfs_btree_insrec()
3404 ASSERT(cur->bc_ops->keys_inorder(cur, kp, in xfs_btree_insrec()
3405 xfs_btree_key_addr(cur, ptr + 1, block))); in xfs_btree_insrec()
3412 rp = xfs_btree_rec_addr(cur, ptr, block); in xfs_btree_insrec()
3414 xfs_btree_shift_recs(cur, rp, 1, numrecs - ptr + 1); in xfs_btree_insrec()
3417 xfs_btree_copy_recs(cur, rp, rec, 1); in xfs_btree_insrec()
3419 xfs_btree_log_recs(cur, bp, ptr, numrecs); in xfs_btree_insrec()
3422 ASSERT(cur->bc_ops->recs_inorder(cur, rp, in xfs_btree_insrec()
3423 xfs_btree_rec_addr(cur, ptr + 1, block))); in xfs_btree_insrec()
3429 xfs_btree_log_block(cur, bp, XFS_BB_NUMRECS); in xfs_btree_insrec()
3440 xfs_btree_get_keys(cur, block, lkey); in xfs_btree_insrec()
3441 } else if (xfs_btree_needs_key_update(cur, optr)) { in xfs_btree_insrec()
3442 error = xfs_btree_update_keys(cur, level); in xfs_btree_insrec()
3451 if (xfs_btree_is_lastrec(cur, block, level)) { in xfs_btree_insrec()
3452 cur->bc_ops->update_lastrec(cur, block, rec, in xfs_btree_insrec()
3461 if (!xfs_btree_ptr_is_null(cur, &nptr)) { in xfs_btree_insrec()
3462 xfs_btree_copy_keys(cur, key, lkey, 1); in xfs_btree_insrec()
3484 struct xfs_btree_cur *cur, in xfs_btree_insert() argument
3499 pcur = cur; in xfs_btree_insert()
3502 xfs_btree_set_ptr_null(cur, &nptr); in xfs_btree_insert()
3505 cur->bc_ops->init_rec_from_cur(cur, &rec); in xfs_btree_insert()
3506 cur->bc_ops->init_key_from_rec(key, &rec); in xfs_btree_insert()
3521 if (pcur != cur) in xfs_btree_insert()
3526 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_insert()
3537 if (pcur != cur && in xfs_btree_insert()
3538 (ncur || xfs_btree_ptr_is_null(cur, &nptr))) { in xfs_btree_insert()
3540 if (cur->bc_ops->update_cursor) in xfs_btree_insert()
3541 cur->bc_ops->update_cursor(pcur, cur); in xfs_btree_insert()
3542 cur->bc_nlevels = pcur->bc_nlevels; in xfs_btree_insert()
3550 } while (!xfs_btree_ptr_is_null(cur, &nptr)); in xfs_btree_insert()
3568 struct xfs_btree_cur *cur) in xfs_btree_kill_iroot() argument
3570 int whichfork = cur->bc_ino.whichfork; in xfs_btree_kill_iroot()
3571 struct xfs_inode *ip = cur->bc_ino.ip; in xfs_btree_kill_iroot()
3589 ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); in xfs_btree_kill_iroot()
3590 ASSERT(cur->bc_nlevels > 1); in xfs_btree_kill_iroot()
3596 level = cur->bc_nlevels - 1; in xfs_btree_kill_iroot()
3603 block = xfs_btree_get_iroot(cur); in xfs_btree_kill_iroot()
3607 cblock = xfs_btree_get_block(cur, level - 1, &cbp); in xfs_btree_kill_iroot()
3615 if (numrecs > cur->bc_ops->get_dmaxrecs(cur, level)) in xfs_btree_kill_iroot()
3618 XFS_BTREE_STATS_INC(cur, killroot); in xfs_btree_kill_iroot()
3621 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_LEFTSIB); in xfs_btree_kill_iroot()
3622 ASSERT(xfs_btree_ptr_is_null(cur, &ptr)); in xfs_btree_kill_iroot()
3623 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB); in xfs_btree_kill_iroot()
3624 ASSERT(xfs_btree_ptr_is_null(cur, &ptr)); in xfs_btree_kill_iroot()
3627 index = numrecs - cur->bc_ops->get_maxrecs(cur, level); in xfs_btree_kill_iroot()
3629 xfs_iroot_realloc(cur->bc_ino.ip, index, in xfs_btree_kill_iroot()
3630 cur->bc_ino.whichfork); in xfs_btree_kill_iroot()
3637 kp = xfs_btree_key_addr(cur, 1, block); in xfs_btree_kill_iroot()
3638 ckp = xfs_btree_key_addr(cur, 1, cblock); in xfs_btree_kill_iroot()
3639 xfs_btree_copy_keys(cur, kp, ckp, numrecs); in xfs_btree_kill_iroot()
3641 pp = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_kill_iroot()
3642 cpp = xfs_btree_ptr_addr(cur, 1, cblock); in xfs_btree_kill_iroot()
3645 error = xfs_btree_debug_check_ptr(cur, cpp, i, level - 1); in xfs_btree_kill_iroot()
3650 xfs_btree_copy_ptrs(cur, pp, cpp, numrecs); in xfs_btree_kill_iroot()
3652 error = xfs_btree_free_block(cur, cbp); in xfs_btree_kill_iroot()
3656 cur->bc_levels[level - 1].bp = NULL; in xfs_btree_kill_iroot()
3658 xfs_trans_log_inode(cur->bc_tp, ip, in xfs_btree_kill_iroot()
3659 XFS_ILOG_CORE | xfs_ilog_fbroot(cur->bc_ino.whichfork)); in xfs_btree_kill_iroot()
3660 cur->bc_nlevels--; in xfs_btree_kill_iroot()
3670 struct xfs_btree_cur *cur, in xfs_btree_kill_root() argument
3677 XFS_BTREE_STATS_INC(cur, killroot); in xfs_btree_kill_root()
3683 cur->bc_ops->set_root(cur, newroot, -1); in xfs_btree_kill_root()
3685 error = xfs_btree_free_block(cur, bp); in xfs_btree_kill_root()
3689 cur->bc_levels[level].bp = NULL; in xfs_btree_kill_root()
3690 cur->bc_levels[level].ra = 0; in xfs_btree_kill_root()
3691 cur->bc_nlevels--; in xfs_btree_kill_root()
3698 struct xfs_btree_cur *cur, in xfs_btree_dec_cursor() argument
3706 error = xfs_btree_decrement(cur, level, &i); in xfs_btree_dec_cursor()
3723 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_delrec() argument
3749 ptr = cur->bc_levels[level].ptr; in xfs_btree_delrec()
3756 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_delrec()
3760 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_delrec()
3771 XFS_BTREE_STATS_INC(cur, delrec); in xfs_btree_delrec()
3772 XFS_BTREE_STATS_ADD(cur, moves, numrecs - ptr); in xfs_btree_delrec()
3780 lkp = xfs_btree_key_addr(cur, ptr + 1, block); in xfs_btree_delrec()
3781 lpp = xfs_btree_ptr_addr(cur, ptr + 1, block); in xfs_btree_delrec()
3784 error = xfs_btree_debug_check_ptr(cur, lpp, i, level); in xfs_btree_delrec()
3790 xfs_btree_shift_keys(cur, lkp, -1, numrecs - ptr); in xfs_btree_delrec()
3791 xfs_btree_shift_ptrs(cur, lpp, -1, numrecs - ptr); in xfs_btree_delrec()
3792 xfs_btree_log_keys(cur, bp, ptr, numrecs - 1); in xfs_btree_delrec()
3793 xfs_btree_log_ptrs(cur, bp, ptr, numrecs - 1); in xfs_btree_delrec()
3798 xfs_btree_shift_recs(cur, in xfs_btree_delrec()
3799 xfs_btree_rec_addr(cur, ptr + 1, block), in xfs_btree_delrec()
3801 xfs_btree_log_recs(cur, bp, ptr, numrecs - 1); in xfs_btree_delrec()
3809 xfs_btree_log_block(cur, bp, XFS_BB_NUMRECS); in xfs_btree_delrec()
3815 if (xfs_btree_is_lastrec(cur, block, level)) { in xfs_btree_delrec()
3816 cur->bc_ops->update_lastrec(cur, block, NULL, in xfs_btree_delrec()
3825 if (level == cur->bc_nlevels - 1) { in xfs_btree_delrec()
3826 if (cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) { in xfs_btree_delrec()
3827 xfs_iroot_realloc(cur->bc_ino.ip, -1, in xfs_btree_delrec()
3828 cur->bc_ino.whichfork); in xfs_btree_delrec()
3830 error = xfs_btree_kill_iroot(cur); in xfs_btree_delrec()
3834 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3852 pp = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_delrec()
3853 error = xfs_btree_kill_root(cur, bp, level, pp); in xfs_btree_delrec()
3857 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3869 if (xfs_btree_needs_key_update(cur, ptr)) { in xfs_btree_delrec()
3870 error = xfs_btree_update_keys(cur, level); in xfs_btree_delrec()
3879 if (numrecs >= cur->bc_ops->get_minrecs(cur, level)) { in xfs_btree_delrec()
3880 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3891 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
3892 xfs_btree_get_sibling(cur, block, &lptr, XFS_BB_LEFTSIB); in xfs_btree_delrec()
3894 if (cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) { in xfs_btree_delrec()
3900 if (xfs_btree_ptr_is_null(cur, &rptr) && in xfs_btree_delrec()
3901 xfs_btree_ptr_is_null(cur, &lptr) && in xfs_btree_delrec()
3902 level == cur->bc_nlevels - 2) { in xfs_btree_delrec()
3903 error = xfs_btree_kill_iroot(cur); in xfs_btree_delrec()
3905 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3912 ASSERT(!xfs_btree_ptr_is_null(cur, &rptr) || in xfs_btree_delrec()
3913 !xfs_btree_ptr_is_null(cur, &lptr)); in xfs_btree_delrec()
3919 error = xfs_btree_dup_cursor(cur, &tcur); in xfs_btree_delrec()
3927 if (!xfs_btree_ptr_is_null(cur, &rptr)) { in xfs_btree_delrec()
3933 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
3941 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
3947 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
3968 cur->bc_ops->get_minrecs(tcur, level)) { in xfs_btree_delrec()
3974 cur->bc_ops->get_minrecs(tcur, level)); in xfs_btree_delrec()
3979 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3992 if (!xfs_btree_ptr_is_null(cur, &lptr)) { in xfs_btree_delrec()
3994 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
4002 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
4013 if (!xfs_btree_ptr_is_null(cur, &lptr)) { in xfs_btree_delrec()
4019 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
4028 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
4036 error = xfs_btree_check_block(cur, left, level, lbp); in xfs_btree_delrec()
4049 cur->bc_ops->get_minrecs(tcur, level)) { in xfs_btree_delrec()
4055 cur->bc_ops->get_minrecs(tcur, level)); in xfs_btree_delrec()
4059 cur->bc_levels[0].ptr++; in xfs_btree_delrec()
4078 ASSERT(!xfs_btree_ptr_is_null(cur, &cptr)); in xfs_btree_delrec()
4080 if (!xfs_btree_ptr_is_null(cur, &lptr) && in xfs_btree_delrec()
4082 cur->bc_ops->get_maxrecs(cur, level)) { in xfs_btree_delrec()
4090 error = xfs_btree_read_buf_block(cur, &lptr, 0, &left, &lbp); in xfs_btree_delrec()
4097 } else if (!xfs_btree_ptr_is_null(cur, &rptr) && in xfs_btree_delrec()
4099 cur->bc_ops->get_maxrecs(cur, level)) { in xfs_btree_delrec()
4107 error = xfs_btree_read_buf_block(cur, &rptr, 0, &right, &rbp); in xfs_btree_delrec()
4116 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
4129 XFS_BTREE_STATS_ADD(cur, moves, rrecs); in xfs_btree_delrec()
4137 lkp = xfs_btree_key_addr(cur, lrecs + 1, left); in xfs_btree_delrec()
4138 lpp = xfs_btree_ptr_addr(cur, lrecs + 1, left); in xfs_btree_delrec()
4139 rkp = xfs_btree_key_addr(cur, 1, right); in xfs_btree_delrec()
4140 rpp = xfs_btree_ptr_addr(cur, 1, right); in xfs_btree_delrec()
4143 error = xfs_btree_debug_check_ptr(cur, rpp, i, level); in xfs_btree_delrec()
4148 xfs_btree_copy_keys(cur, lkp, rkp, rrecs); in xfs_btree_delrec()
4149 xfs_btree_copy_ptrs(cur, lpp, rpp, rrecs); in xfs_btree_delrec()
4151 xfs_btree_log_keys(cur, lbp, lrecs + 1, lrecs + rrecs); in xfs_btree_delrec()
4152 xfs_btree_log_ptrs(cur, lbp, lrecs + 1, lrecs + rrecs); in xfs_btree_delrec()
4158 lrp = xfs_btree_rec_addr(cur, lrecs + 1, left); in xfs_btree_delrec()
4159 rrp = xfs_btree_rec_addr(cur, 1, right); in xfs_btree_delrec()
4161 xfs_btree_copy_recs(cur, lrp, rrp, rrecs); in xfs_btree_delrec()
4162 xfs_btree_log_recs(cur, lbp, lrecs + 1, lrecs + rrecs); in xfs_btree_delrec()
4165 XFS_BTREE_STATS_INC(cur, join); in xfs_btree_delrec()
4172 xfs_btree_get_sibling(cur, right, &cptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4173 xfs_btree_set_sibling(cur, left, &cptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4174 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4177 xfs_btree_get_sibling(cur, left, &cptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4178 if (!xfs_btree_ptr_is_null(cur, &cptr)) { in xfs_btree_delrec()
4179 error = xfs_btree_read_buf_block(cur, &cptr, 0, &rrblock, &rrbp); in xfs_btree_delrec()
4182 xfs_btree_set_sibling(cur, rrblock, &lptr, XFS_BB_LEFTSIB); in xfs_btree_delrec()
4183 xfs_btree_log_block(cur, rrbp, XFS_BB_LEFTSIB); in xfs_btree_delrec()
4187 error = xfs_btree_free_block(cur, rbp); in xfs_btree_delrec()
4196 cur->bc_levels[level].bp = lbp; in xfs_btree_delrec()
4197 cur->bc_levels[level].ptr += lrecs; in xfs_btree_delrec()
4198 cur->bc_levels[level].ra = 0; in xfs_btree_delrec()
4204 else if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) || in xfs_btree_delrec()
4205 (level + 1 < cur->bc_nlevels)) { in xfs_btree_delrec()
4206 error = xfs_btree_increment(cur, level + 1, &i); in xfs_btree_delrec()
4218 cur->bc_levels[level].ptr--; in xfs_btree_delrec()
4247 struct xfs_btree_cur *cur, in xfs_btree_delete() argument
4262 error = xfs_btree_delrec(cur, level, &i); in xfs_btree_delete()
4273 if (joined && (cur->bc_flags & XFS_BTREE_OVERLAPPING)) { in xfs_btree_delete()
4274 error = xfs_btree_updkeys_force(cur, 0); in xfs_btree_delete()
4280 for (level = 1; level < cur->bc_nlevels; level++) { in xfs_btree_delete()
4281 if (cur->bc_levels[level].ptr == 0) { in xfs_btree_delete()
4282 error = xfs_btree_decrement(cur, level, &i); in xfs_btree_delete()
4301 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_get_rec() argument
4312 ptr = cur->bc_levels[0].ptr; in xfs_btree_get_rec()
4313 block = xfs_btree_get_block(cur, 0, &bp); in xfs_btree_get_rec()
4316 error = xfs_btree_check_block(cur, block, 0, bp); in xfs_btree_get_rec()
4332 *recp = xfs_btree_rec_addr(cur, ptr, block); in xfs_btree_get_rec()
4340 struct xfs_btree_cur *cur, in xfs_btree_visit_block() argument
4351 xfs_btree_readahead(cur, level, XFS_BTCUR_RIGHTRA); in xfs_btree_visit_block()
4352 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_visit_block()
4355 error = fn(cur, level, data); in xfs_btree_visit_block()
4360 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_visit_block()
4361 if (xfs_btree_ptr_is_null(cur, &rptr)) in xfs_btree_visit_block()
4370 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_visit_block()
4371 if (be64_to_cpu(rptr.l) == XFS_DADDR_TO_FSB(cur->bc_mp, in xfs_btree_visit_block()
4375 if (be32_to_cpu(rptr.s) == xfs_daddr_to_agbno(cur->bc_mp, in xfs_btree_visit_block()
4379 return xfs_btree_lookup_get_block(cur, level, &rptr, &block); in xfs_btree_visit_block()
4386 struct xfs_btree_cur *cur, in xfs_btree_visit_blocks() argument
4396 cur->bc_ops->init_ptr_from_cur(cur, &lptr); in xfs_btree_visit_blocks()
4399 for (level = cur->bc_nlevels - 1; level >= 0; level--) { in xfs_btree_visit_blocks()
4401 error = xfs_btree_lookup_get_block(cur, level, &lptr, &block); in xfs_btree_visit_blocks()
4409 ptr = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_visit_blocks()
4410 xfs_btree_readahead_ptr(cur, ptr, 1); in xfs_btree_visit_blocks()
4413 xfs_btree_copy_ptrs(cur, &lptr, ptr, 1); in xfs_btree_visit_blocks()
4423 error = xfs_btree_visit_block(cur, level, fn, data); in xfs_btree_visit_blocks()
4464 struct xfs_btree_cur *cur, in xfs_btree_block_change_owner() argument
4473 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_block_change_owner()
4474 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_block_change_owner()
4492 ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); in xfs_btree_block_change_owner()
4493 ASSERT(level == cur->bc_nlevels - 1); in xfs_btree_block_change_owner()
4497 if (cur->bc_tp) { in xfs_btree_block_change_owner()
4498 if (!xfs_trans_ordered_buf(cur->bc_tp, bp)) { in xfs_btree_block_change_owner()
4499 xfs_btree_log_block(cur, bp, XFS_BB_OWNER); in xfs_btree_block_change_owner()
4511 struct xfs_btree_cur *cur, in xfs_btree_change_owner() argument
4520 return xfs_btree_visit_blocks(cur, xfs_btree_block_change_owner, in xfs_btree_change_owner()
4710 struct xfs_btree_cur *cur, in xfs_btree_simple_query_range() argument
4722 ASSERT(cur->bc_ops->init_high_key_from_rec); in xfs_btree_simple_query_range()
4723 ASSERT(cur->bc_ops->diff_two_keys); in xfs_btree_simple_query_range()
4730 error = xfs_btree_lookup(cur, XFS_LOOKUP_LE, &stat); in xfs_btree_simple_query_range()
4736 error = xfs_btree_increment(cur, 0, &stat); in xfs_btree_simple_query_range()
4743 error = xfs_btree_get_rec(cur, &recp, &stat); in xfs_btree_simple_query_range()
4749 cur->bc_ops->init_high_key_from_rec(&rec_key, recp); in xfs_btree_simple_query_range()
4751 if (xfs_btree_keycmp_gt(cur, low_key, &rec_key)) in xfs_btree_simple_query_range()
4756 cur->bc_ops->init_key_from_rec(&rec_key, recp); in xfs_btree_simple_query_range()
4757 if (xfs_btree_keycmp_gt(cur, &rec_key, high_key)) in xfs_btree_simple_query_range()
4761 error = fn(cur, recp, priv); in xfs_btree_simple_query_range()
4767 error = xfs_btree_increment(cur, 0, &stat); in xfs_btree_simple_query_range()
4797 struct xfs_btree_cur *cur, in xfs_btree_overlapped_query_range() argument
4817 level = cur->bc_nlevels - 1; in xfs_btree_overlapped_query_range()
4818 cur->bc_ops->init_ptr_from_cur(cur, &ptr); in xfs_btree_overlapped_query_range()
4819 error = xfs_btree_lookup_get_block(cur, level, &ptr, &block); in xfs_btree_overlapped_query_range()
4822 xfs_btree_get_block(cur, level, &bp); in xfs_btree_overlapped_query_range()
4823 trace_xfs_btree_overlapped_query_range(cur, level, bp); in xfs_btree_overlapped_query_range()
4825 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_overlapped_query_range()
4829 cur->bc_levels[level].ptr = 1; in xfs_btree_overlapped_query_range()
4831 while (level < cur->bc_nlevels) { in xfs_btree_overlapped_query_range()
4832 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_overlapped_query_range()
4835 if (cur->bc_levels[level].ptr > in xfs_btree_overlapped_query_range()
4838 if (level < cur->bc_nlevels - 1) in xfs_btree_overlapped_query_range()
4839 cur->bc_levels[level + 1].ptr++; in xfs_btree_overlapped_query_range()
4846 recp = xfs_btree_rec_addr(cur, cur->bc_levels[0].ptr, in xfs_btree_overlapped_query_range()
4849 cur->bc_ops->init_high_key_from_rec(&rec_hkey, recp); in xfs_btree_overlapped_query_range()
4850 cur->bc_ops->init_key_from_rec(&rec_key, recp); in xfs_btree_overlapped_query_range()
4861 if (xfs_btree_keycmp_lt(cur, high_key, &rec_key)) in xfs_btree_overlapped_query_range()
4863 if (xfs_btree_keycmp_ge(cur, &rec_hkey, low_key)) { in xfs_btree_overlapped_query_range()
4864 error = fn(cur, recp, priv); in xfs_btree_overlapped_query_range()
4868 cur->bc_levels[level].ptr++; in xfs_btree_overlapped_query_range()
4873 lkp = xfs_btree_key_addr(cur, cur->bc_levels[level].ptr, block); in xfs_btree_overlapped_query_range()
4874 hkp = xfs_btree_high_key_addr(cur, cur->bc_levels[level].ptr, in xfs_btree_overlapped_query_range()
4876 pp = xfs_btree_ptr_addr(cur, cur->bc_levels[level].ptr, block); in xfs_btree_overlapped_query_range()
4887 if (xfs_btree_keycmp_lt(cur, high_key, lkp)) in xfs_btree_overlapped_query_range()
4889 if (xfs_btree_keycmp_ge(cur, hkp, low_key)) { in xfs_btree_overlapped_query_range()
4891 error = xfs_btree_lookup_get_block(cur, level, pp, in xfs_btree_overlapped_query_range()
4895 xfs_btree_get_block(cur, level, &bp); in xfs_btree_overlapped_query_range()
4896 trace_xfs_btree_overlapped_query_range(cur, level, bp); in xfs_btree_overlapped_query_range()
4898 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_overlapped_query_range()
4902 cur->bc_levels[level].ptr = 1; in xfs_btree_overlapped_query_range()
4905 cur->bc_levels[level].ptr++; in xfs_btree_overlapped_query_range()
4916 if (cur->bc_levels[0].bp == NULL) { in xfs_btree_overlapped_query_range()
4917 for (i = 0; i < cur->bc_nlevels; i++) { in xfs_btree_overlapped_query_range()
4918 if (cur->bc_levels[i].bp) { in xfs_btree_overlapped_query_range()
4919 xfs_trans_brelse(cur->bc_tp, in xfs_btree_overlapped_query_range()
4920 cur->bc_levels[i].bp); in xfs_btree_overlapped_query_range()
4921 cur->bc_levels[i].bp = NULL; in xfs_btree_overlapped_query_range()
4922 cur->bc_levels[i].ptr = 0; in xfs_btree_overlapped_query_range()
4923 cur->bc_levels[i].ra = 0; in xfs_btree_overlapped_query_range()
4933 struct xfs_btree_cur *cur, in xfs_btree_key_from_irec() argument
4939 cur->bc_rec = *irec; in xfs_btree_key_from_irec()
4940 cur->bc_ops->init_rec_from_cur(cur, &rec); in xfs_btree_key_from_irec()
4941 cur->bc_ops->init_key_from_rec(key, &rec); in xfs_btree_key_from_irec()
4952 struct xfs_btree_cur *cur, in xfs_btree_query_range() argument
4962 xfs_btree_key_from_irec(cur, &high_key, high_rec); in xfs_btree_query_range()
4963 xfs_btree_key_from_irec(cur, &low_key, low_rec); in xfs_btree_query_range()
4966 if (!xfs_btree_keycmp_le(cur, &low_key, &high_key)) in xfs_btree_query_range()
4969 if (!(cur->bc_flags & XFS_BTREE_OVERLAPPING)) in xfs_btree_query_range()
4970 return xfs_btree_simple_query_range(cur, &low_key, in xfs_btree_query_range()
4972 return xfs_btree_overlapped_query_range(cur, &low_key, &high_key, in xfs_btree_query_range()
4979 struct xfs_btree_cur *cur, in xfs_btree_query_all() argument
4986 memset(&cur->bc_rec, 0, sizeof(cur->bc_rec)); in xfs_btree_query_all()
4990 return xfs_btree_simple_query_range(cur, &low_key, &high_key, fn, priv); in xfs_btree_query_all()
4995 struct xfs_btree_cur *cur, in xfs_btree_count_blocks_helper() argument
5008 struct xfs_btree_cur *cur, in xfs_btree_count_blocks() argument
5012 return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper, in xfs_btree_count_blocks()
5019 struct xfs_btree_cur *cur, in xfs_btree_diff_two_ptrs() argument
5023 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_diff_two_ptrs()
5044 struct xfs_btree_cur *cur, in xfs_btree_has_records_helper() argument
5053 cur->bc_ops->init_key_from_rec(&rec_key, rec); in xfs_btree_has_records_helper()
5063 if (xfs_btree_masked_keycmp_lt(cur, &info->start_key, &rec_key, in xfs_btree_has_records_helper()
5074 key_contig = cur->bc_ops->keys_contiguous(cur, &info->high_key, in xfs_btree_has_records_helper()
5077 !(cur->bc_flags & XFS_BTREE_OVERLAPPING)) in xfs_btree_has_records_helper()
5087 cur->bc_ops->init_high_key_from_rec(&rec_high_key, rec); in xfs_btree_has_records_helper()
5088 if (xfs_btree_masked_keycmp_gt(cur, &rec_high_key, &info->high_key, in xfs_btree_has_records_helper()
5111 struct xfs_btree_cur *cur, in xfs_btree_has_records() argument
5124 if (!cur->bc_ops->keys_contiguous) { in xfs_btree_has_records()
5129 xfs_btree_key_from_irec(cur, &info.start_key, low); in xfs_btree_has_records()
5130 xfs_btree_key_from_irec(cur, &info.end_key, high); in xfs_btree_has_records()
5132 error = xfs_btree_query_range(cur, low, high, in xfs_btree_has_records()
5147 if (xfs_btree_masked_keycmp_ge(cur, &info.high_key, &info.end_key, in xfs_btree_has_records()
5159 struct xfs_btree_cur *cur) in xfs_btree_has_more_records() argument
5164 block = xfs_btree_get_block(cur, 0, &bp); in xfs_btree_has_more_records()
5167 if (cur->bc_levels[0].ptr < xfs_btree_get_numrecs(block)) in xfs_btree_has_more_records()
5171 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_has_more_records()