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 (cur->bc_ops->diff_two_keys(cur, &hkey, &max_hkey) in xfs_btree_get_leaf_keys()
2075 high = xfs_btree_high_key_from_key(cur, key); in xfs_btree_get_leaf_keys()
2076 memcpy(high, &max_hkey, cur->bc_ops->key_len / 2); in xfs_btree_get_leaf_keys()
2083 struct xfs_btree_cur *cur, in xfs_btree_get_node_keys() argument
2092 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in xfs_btree_get_node_keys()
2093 memcpy(key, xfs_btree_key_addr(cur, 1, block), in xfs_btree_get_node_keys()
2094 cur->bc_ops->key_len / 2); in xfs_btree_get_node_keys()
2096 max_hkey = xfs_btree_high_key_addr(cur, 1, block); in xfs_btree_get_node_keys()
2098 hkey = xfs_btree_high_key_addr(cur, n, block); in xfs_btree_get_node_keys()
2099 if (cur->bc_ops->diff_two_keys(cur, hkey, max_hkey) > 0) in xfs_btree_get_node_keys()
2103 high = xfs_btree_high_key_from_key(cur, key); in xfs_btree_get_node_keys()
2104 memcpy(high, max_hkey, cur->bc_ops->key_len / 2); in xfs_btree_get_node_keys()
2106 memcpy(key, xfs_btree_key_addr(cur, 1, block), in xfs_btree_get_node_keys()
2107 cur->bc_ops->key_len); in xfs_btree_get_node_keys()
2114 struct xfs_btree_cur *cur, in xfs_btree_get_keys() argument
2119 xfs_btree_get_leaf_keys(cur, block, key); in xfs_btree_get_keys()
2121 xfs_btree_get_node_keys(cur, block, key); in xfs_btree_get_keys()
2133 struct xfs_btree_cur *cur, in xfs_btree_needs_key_update() argument
2136 return (cur->bc_flags & XFS_BTREE_OVERLAPPING) || ptr == 1; in xfs_btree_needs_key_update()
2146 struct xfs_btree_cur *cur, in __xfs_btree_updkeys() argument
2160 ASSERT(cur->bc_flags & XFS_BTREE_OVERLAPPING); in __xfs_btree_updkeys()
2163 if (level + 1 >= cur->bc_nlevels) in __xfs_btree_updkeys()
2166 trace_xfs_btree_updkeys(cur, level, bp0); in __xfs_btree_updkeys()
2169 hkey = xfs_btree_high_key_from_key(cur, lkey); in __xfs_btree_updkeys()
2170 xfs_btree_get_keys(cur, block, lkey); in __xfs_btree_updkeys()
2171 for (level++; level < cur->bc_nlevels; level++) { in __xfs_btree_updkeys()
2175 block = xfs_btree_get_block(cur, level, &bp); in __xfs_btree_updkeys()
2176 trace_xfs_btree_updkeys(cur, level, bp); in __xfs_btree_updkeys()
2178 error = xfs_btree_check_block(cur, block, level, bp); in __xfs_btree_updkeys()
2182 ptr = cur->bc_levels[level].ptr; in __xfs_btree_updkeys()
2183 nlkey = xfs_btree_key_addr(cur, ptr, block); in __xfs_btree_updkeys()
2184 nhkey = xfs_btree_high_key_addr(cur, ptr, block); in __xfs_btree_updkeys()
2186 !(cur->bc_ops->diff_two_keys(cur, nlkey, lkey) != 0 || in __xfs_btree_updkeys()
2187 cur->bc_ops->diff_two_keys(cur, nhkey, hkey) != 0)) in __xfs_btree_updkeys()
2189 xfs_btree_copy_keys(cur, nlkey, lkey, 1); in __xfs_btree_updkeys()
2190 xfs_btree_log_keys(cur, bp, ptr, ptr); in __xfs_btree_updkeys()
2191 if (level + 1 >= cur->bc_nlevels) in __xfs_btree_updkeys()
2193 xfs_btree_get_node_keys(cur, block, lkey); in __xfs_btree_updkeys()
2202 struct xfs_btree_cur *cur, in xfs_btree_updkeys_force() argument
2208 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_updkeys_force()
2209 return __xfs_btree_updkeys(cur, level, block, bp, true); in xfs_btree_updkeys_force()
2217 struct xfs_btree_cur *cur, in xfs_btree_update_keys() argument
2228 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_update_keys()
2229 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) in xfs_btree_update_keys()
2230 return __xfs_btree_updkeys(cur, level, block, bp, false); in xfs_btree_update_keys()
2238 xfs_btree_get_keys(cur, block, &key); in xfs_btree_update_keys()
2239 for (level++, ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) { in xfs_btree_update_keys()
2243 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_update_keys()
2245 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_update_keys()
2249 ptr = cur->bc_levels[level].ptr; in xfs_btree_update_keys()
2250 kp = xfs_btree_key_addr(cur, ptr, block); in xfs_btree_update_keys()
2251 xfs_btree_copy_keys(cur, kp, &key, 1); in xfs_btree_update_keys()
2252 xfs_btree_log_keys(cur, bp, ptr, ptr); in xfs_btree_update_keys()
2265 struct xfs_btree_cur *cur, in xfs_btree_update() argument
2275 block = xfs_btree_get_block(cur, 0, &bp); in xfs_btree_update()
2278 error = xfs_btree_check_block(cur, block, 0, bp); in xfs_btree_update()
2283 ptr = cur->bc_levels[0].ptr; in xfs_btree_update()
2284 rp = xfs_btree_rec_addr(cur, ptr, block); in xfs_btree_update()
2287 xfs_btree_copy_recs(cur, rp, rec, 1); in xfs_btree_update()
2288 xfs_btree_log_recs(cur, bp, ptr, ptr); in xfs_btree_update()
2294 if (xfs_btree_is_lastrec(cur, block, 0)) { in xfs_btree_update()
2295 cur->bc_ops->update_lastrec(cur, block, rec, in xfs_btree_update()
2300 if (xfs_btree_needs_key_update(cur, ptr)) { in xfs_btree_update()
2301 error = xfs_btree_update_keys(cur, 0); in xfs_btree_update()
2318 struct xfs_btree_cur *cur, in xfs_btree_lshift() argument
2336 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_lshift()
2337 level == cur->bc_nlevels - 1) in xfs_btree_lshift()
2341 right = xfs_btree_get_block(cur, level, &rbp); in xfs_btree_lshift()
2344 error = xfs_btree_check_block(cur, right, level, rbp); in xfs_btree_lshift()
2350 xfs_btree_get_sibling(cur, right, &lptr, XFS_BB_LEFTSIB); in xfs_btree_lshift()
2351 if (xfs_btree_ptr_is_null(cur, &lptr)) in xfs_btree_lshift()
2358 if (cur->bc_levels[level].ptr <= 1) in xfs_btree_lshift()
2362 error = xfs_btree_read_buf_block(cur, &lptr, 0, &left, &lbp); in xfs_btree_lshift()
2368 if (lrecs == cur->bc_ops->get_maxrecs(cur, level)) in xfs_btree_lshift()
2381 XFS_BTREE_STATS_INC(cur, lshift); in xfs_btree_lshift()
2382 XFS_BTREE_STATS_ADD(cur, moves, 1); in xfs_btree_lshift()
2393 lkp = xfs_btree_key_addr(cur, lrecs, left); in xfs_btree_lshift()
2394 rkp = xfs_btree_key_addr(cur, 1, right); in xfs_btree_lshift()
2396 lpp = xfs_btree_ptr_addr(cur, lrecs, left); in xfs_btree_lshift()
2397 rpp = xfs_btree_ptr_addr(cur, 1, right); in xfs_btree_lshift()
2399 error = xfs_btree_debug_check_ptr(cur, rpp, 0, level); in xfs_btree_lshift()
2403 xfs_btree_copy_keys(cur, lkp, rkp, 1); in xfs_btree_lshift()
2404 xfs_btree_copy_ptrs(cur, lpp, rpp, 1); in xfs_btree_lshift()
2406 xfs_btree_log_keys(cur, lbp, lrecs, lrecs); in xfs_btree_lshift()
2407 xfs_btree_log_ptrs(cur, lbp, lrecs, lrecs); in xfs_btree_lshift()
2409 ASSERT(cur->bc_ops->keys_inorder(cur, in xfs_btree_lshift()
2410 xfs_btree_key_addr(cur, lrecs - 1, left), lkp)); in xfs_btree_lshift()
2415 lrp = xfs_btree_rec_addr(cur, lrecs, left); in xfs_btree_lshift()
2416 rrp = xfs_btree_rec_addr(cur, 1, right); in xfs_btree_lshift()
2418 xfs_btree_copy_recs(cur, lrp, rrp, 1); in xfs_btree_lshift()
2419 xfs_btree_log_recs(cur, lbp, lrecs, lrecs); in xfs_btree_lshift()
2421 ASSERT(cur->bc_ops->recs_inorder(cur, in xfs_btree_lshift()
2422 xfs_btree_rec_addr(cur, lrecs - 1, left), lrp)); in xfs_btree_lshift()
2426 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS); in xfs_btree_lshift()
2429 xfs_btree_log_block(cur, rbp, XFS_BB_NUMRECS); in xfs_btree_lshift()
2434 XFS_BTREE_STATS_ADD(cur, moves, rrecs - 1); in xfs_btree_lshift()
2438 error = xfs_btree_debug_check_ptr(cur, rpp, i + 1, level); in xfs_btree_lshift()
2443 xfs_btree_shift_keys(cur, in xfs_btree_lshift()
2444 xfs_btree_key_addr(cur, 2, right), in xfs_btree_lshift()
2446 xfs_btree_shift_ptrs(cur, in xfs_btree_lshift()
2447 xfs_btree_ptr_addr(cur, 2, right), in xfs_btree_lshift()
2450 xfs_btree_log_keys(cur, rbp, 1, rrecs); in xfs_btree_lshift()
2451 xfs_btree_log_ptrs(cur, rbp, 1, rrecs); in xfs_btree_lshift()
2454 xfs_btree_shift_recs(cur, in xfs_btree_lshift()
2455 xfs_btree_rec_addr(cur, 2, right), in xfs_btree_lshift()
2457 xfs_btree_log_recs(cur, rbp, 1, rrecs); in xfs_btree_lshift()
2464 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in xfs_btree_lshift()
2465 error = xfs_btree_dup_cursor(cur, &tcur); in xfs_btree_lshift()
2487 error = xfs_btree_update_keys(cur, level); in xfs_btree_lshift()
2492 cur->bc_levels[level].ptr--; in xfs_btree_lshift()
2515 struct xfs_btree_cur *cur, in xfs_btree_rshift() argument
2531 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_rshift()
2532 (level == cur->bc_nlevels - 1)) in xfs_btree_rshift()
2536 left = xfs_btree_get_block(cur, level, &lbp); in xfs_btree_rshift()
2539 error = xfs_btree_check_block(cur, left, level, lbp); in xfs_btree_rshift()
2545 xfs_btree_get_sibling(cur, left, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_rshift()
2546 if (xfs_btree_ptr_is_null(cur, &rptr)) in xfs_btree_rshift()
2554 if (cur->bc_levels[level].ptr >= lrecs) in xfs_btree_rshift()
2558 error = xfs_btree_read_buf_block(cur, &rptr, 0, &right, &rbp); in xfs_btree_rshift()
2564 if (rrecs == cur->bc_ops->get_maxrecs(cur, level)) in xfs_btree_rshift()
2567 XFS_BTREE_STATS_INC(cur, rshift); in xfs_btree_rshift()
2568 XFS_BTREE_STATS_ADD(cur, moves, rrecs); in xfs_btree_rshift()
2580 lkp = xfs_btree_key_addr(cur, lrecs, left); in xfs_btree_rshift()
2581 lpp = xfs_btree_ptr_addr(cur, lrecs, left); in xfs_btree_rshift()
2582 rkp = xfs_btree_key_addr(cur, 1, right); in xfs_btree_rshift()
2583 rpp = xfs_btree_ptr_addr(cur, 1, right); in xfs_btree_rshift()
2586 error = xfs_btree_debug_check_ptr(cur, rpp, i, level); in xfs_btree_rshift()
2591 xfs_btree_shift_keys(cur, rkp, 1, rrecs); in xfs_btree_rshift()
2592 xfs_btree_shift_ptrs(cur, rpp, 1, rrecs); in xfs_btree_rshift()
2594 error = xfs_btree_debug_check_ptr(cur, lpp, 0, level); in xfs_btree_rshift()
2599 xfs_btree_copy_keys(cur, rkp, lkp, 1); in xfs_btree_rshift()
2600 xfs_btree_copy_ptrs(cur, rpp, lpp, 1); in xfs_btree_rshift()
2602 xfs_btree_log_keys(cur, rbp, 1, rrecs + 1); in xfs_btree_rshift()
2603 xfs_btree_log_ptrs(cur, rbp, 1, rrecs + 1); in xfs_btree_rshift()
2605 ASSERT(cur->bc_ops->keys_inorder(cur, rkp, in xfs_btree_rshift()
2606 xfs_btree_key_addr(cur, 2, right))); in xfs_btree_rshift()
2612 lrp = xfs_btree_rec_addr(cur, lrecs, left); in xfs_btree_rshift()
2613 rrp = xfs_btree_rec_addr(cur, 1, right); in xfs_btree_rshift()
2615 xfs_btree_shift_recs(cur, rrp, 1, rrecs); in xfs_btree_rshift()
2618 xfs_btree_copy_recs(cur, rrp, lrp, 1); in xfs_btree_rshift()
2619 xfs_btree_log_recs(cur, rbp, 1, rrecs + 1); in xfs_btree_rshift()
2626 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS); in xfs_btree_rshift()
2629 xfs_btree_log_block(cur, rbp, XFS_BB_NUMRECS); in xfs_btree_rshift()
2635 error = xfs_btree_dup_cursor(cur, &tcur); in xfs_btree_rshift()
2649 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in xfs_btree_rshift()
2650 error = xfs_btree_update_keys(cur, level); in xfs_btree_rshift()
2684 struct xfs_btree_cur *cur, in __xfs_btree_split() argument
2706 XFS_BTREE_STATS_INC(cur, split); in __xfs_btree_split()
2709 left = xfs_btree_get_block(cur, level, &lbp); in __xfs_btree_split()
2712 error = xfs_btree_check_block(cur, left, level, lbp); in __xfs_btree_split()
2717 xfs_btree_buf_to_ptr(cur, lbp, &lptr); in __xfs_btree_split()
2720 error = cur->bc_ops->alloc_block(cur, &lptr, &rptr, stat); in __xfs_btree_split()
2725 XFS_BTREE_STATS_INC(cur, alloc); in __xfs_btree_split()
2728 error = xfs_btree_get_buf_block(cur, &rptr, &right, &rbp); in __xfs_btree_split()
2733 xfs_btree_init_block_cur(cur, rbp, xfs_btree_get_level(left), 0); in __xfs_btree_split()
2742 if ((lrecs & 1) && cur->bc_levels[level].ptr <= rrecs + 1) in __xfs_btree_split()
2746 XFS_BTREE_STATS_ADD(cur, moves, rrecs); in __xfs_btree_split()
2765 lkp = xfs_btree_key_addr(cur, src_index, left); in __xfs_btree_split()
2766 lpp = xfs_btree_ptr_addr(cur, src_index, left); in __xfs_btree_split()
2767 rkp = xfs_btree_key_addr(cur, 1, right); in __xfs_btree_split()
2768 rpp = xfs_btree_ptr_addr(cur, 1, right); in __xfs_btree_split()
2771 error = xfs_btree_debug_check_ptr(cur, lpp, i, level); in __xfs_btree_split()
2777 xfs_btree_copy_keys(cur, rkp, lkp, rrecs); in __xfs_btree_split()
2778 xfs_btree_copy_ptrs(cur, rpp, lpp, rrecs); in __xfs_btree_split()
2780 xfs_btree_log_keys(cur, rbp, 1, rrecs); in __xfs_btree_split()
2781 xfs_btree_log_ptrs(cur, rbp, 1, rrecs); in __xfs_btree_split()
2784 xfs_btree_get_node_keys(cur, right, key); in __xfs_btree_split()
2790 lrp = xfs_btree_rec_addr(cur, src_index, left); in __xfs_btree_split()
2791 rrp = xfs_btree_rec_addr(cur, 1, right); in __xfs_btree_split()
2794 xfs_btree_copy_recs(cur, rrp, lrp, rrecs); in __xfs_btree_split()
2795 xfs_btree_log_recs(cur, rbp, 1, rrecs); in __xfs_btree_split()
2798 xfs_btree_get_leaf_keys(cur, right, key); in __xfs_btree_split()
2805 xfs_btree_get_sibling(cur, left, &rrptr, XFS_BB_RIGHTSIB); in __xfs_btree_split()
2806 xfs_btree_set_sibling(cur, right, &rrptr, XFS_BB_RIGHTSIB); in __xfs_btree_split()
2807 xfs_btree_set_sibling(cur, right, &lptr, XFS_BB_LEFTSIB); in __xfs_btree_split()
2808 xfs_btree_set_sibling(cur, left, &rptr, XFS_BB_RIGHTSIB); in __xfs_btree_split()
2810 xfs_btree_log_block(cur, rbp, XFS_BB_ALL_BITS); in __xfs_btree_split()
2811 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB); in __xfs_btree_split()
2817 if (!xfs_btree_ptr_is_null(cur, &rrptr)) { in __xfs_btree_split()
2818 error = xfs_btree_read_buf_block(cur, &rrptr, in __xfs_btree_split()
2822 xfs_btree_set_sibling(cur, rrblock, &rptr, XFS_BB_LEFTSIB); in __xfs_btree_split()
2823 xfs_btree_log_block(cur, rrbp, XFS_BB_LEFTSIB); in __xfs_btree_split()
2827 if (cur->bc_flags & XFS_BTREE_OVERLAPPING) { in __xfs_btree_split()
2828 error = xfs_btree_update_keys(cur, level); in __xfs_btree_split()
2838 if (cur->bc_levels[level].ptr > lrecs + 1) { in __xfs_btree_split()
2839 xfs_btree_setbuf(cur, level, rbp); in __xfs_btree_split()
2840 cur->bc_levels[level].ptr -= lrecs; in __xfs_btree_split()
2846 if (level + 1 < cur->bc_nlevels) { in __xfs_btree_split()
2847 error = xfs_btree_dup_cursor(cur, curp); in __xfs_btree_split()
2865 struct xfs_btree_cur *cur; member
2899 xfs_trans_set_context(args->cur->bc_tp); in xfs_btree_split_worker()
2901 args->result = __xfs_btree_split(args->cur, args->level, args->ptrp, in xfs_btree_split_worker()
2904 xfs_trans_clear_context(args->cur->bc_tp); in xfs_btree_split_worker()
2922 struct xfs_btree_cur *cur, in xfs_btree_split() argument
2932 if (cur->bc_btnum != XFS_BTNUM_BMAP) in xfs_btree_split()
2933 return __xfs_btree_split(cur, level, ptrp, key, curp, stat); in xfs_btree_split()
2935 args.cur = cur; in xfs_btree_split()
2960 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_new_iroot() argument
2976 XFS_BTREE_STATS_INC(cur, newroot); in xfs_btree_new_iroot()
2978 ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); in xfs_btree_new_iroot()
2980 level = cur->bc_nlevels - 1; in xfs_btree_new_iroot()
2982 block = xfs_btree_get_iroot(cur); in xfs_btree_new_iroot()
2983 pp = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_new_iroot()
2986 error = cur->bc_ops->alloc_block(cur, pp, &nptr, stat); in xfs_btree_new_iroot()
2992 XFS_BTREE_STATS_INC(cur, alloc); in xfs_btree_new_iroot()
2995 error = xfs_btree_get_buf_block(cur, &nptr, &cblock, &cbp); in xfs_btree_new_iroot()
3003 memcpy(cblock, block, xfs_btree_block_len(cur)); in xfs_btree_new_iroot()
3004 if (cur->bc_flags & XFS_BTREE_CRC_BLOCKS) { in xfs_btree_new_iroot()
3006 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_new_iroot()
3014 cur->bc_nlevels++; in xfs_btree_new_iroot()
3015 ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); in xfs_btree_new_iroot()
3016 cur->bc_levels[level + 1].ptr = 1; in xfs_btree_new_iroot()
3018 kp = xfs_btree_key_addr(cur, 1, block); in xfs_btree_new_iroot()
3019 ckp = xfs_btree_key_addr(cur, 1, cblock); in xfs_btree_new_iroot()
3020 xfs_btree_copy_keys(cur, ckp, kp, xfs_btree_get_numrecs(cblock)); in xfs_btree_new_iroot()
3022 cpp = xfs_btree_ptr_addr(cur, 1, cblock); in xfs_btree_new_iroot()
3024 error = xfs_btree_debug_check_ptr(cur, pp, i, level); in xfs_btree_new_iroot()
3029 xfs_btree_copy_ptrs(cur, cpp, pp, xfs_btree_get_numrecs(cblock)); in xfs_btree_new_iroot()
3031 error = xfs_btree_debug_check_ptr(cur, &nptr, 0, level); in xfs_btree_new_iroot()
3035 xfs_btree_copy_ptrs(cur, pp, &nptr, 1); in xfs_btree_new_iroot()
3037 xfs_iroot_realloc(cur->bc_ino.ip, in xfs_btree_new_iroot()
3039 cur->bc_ino.whichfork); in xfs_btree_new_iroot()
3041 xfs_btree_setbuf(cur, level, cbp); in xfs_btree_new_iroot()
3047 xfs_btree_log_block(cur, cbp, XFS_BB_ALL_BITS); in xfs_btree_new_iroot()
3048 xfs_btree_log_keys(cur, cbp, 1, be16_to_cpu(cblock->bb_numrecs)); in xfs_btree_new_iroot()
3049 xfs_btree_log_ptrs(cur, cbp, 1, be16_to_cpu(cblock->bb_numrecs)); in xfs_btree_new_iroot()
3052 XFS_ILOG_CORE | xfs_ilog_fbroot(cur->bc_ino.whichfork); in xfs_btree_new_iroot()
3064 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_new_root() argument
3080 XFS_BTREE_STATS_INC(cur, newroot); in xfs_btree_new_root()
3083 cur->bc_ops->init_ptr_from_cur(cur, &rptr); in xfs_btree_new_root()
3086 error = cur->bc_ops->alloc_block(cur, &rptr, &lptr, stat); in xfs_btree_new_root()
3091 XFS_BTREE_STATS_INC(cur, alloc); in xfs_btree_new_root()
3094 error = xfs_btree_get_buf_block(cur, &lptr, &new, &nbp); in xfs_btree_new_root()
3099 cur->bc_ops->set_root(cur, &lptr, 1); in xfs_btree_new_root()
3107 block = xfs_btree_get_block(cur, cur->bc_nlevels - 1, &bp); in xfs_btree_new_root()
3110 error = xfs_btree_check_block(cur, block, cur->bc_nlevels - 1, bp); in xfs_btree_new_root()
3115 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_new_root()
3116 if (!xfs_btree_ptr_is_null(cur, &rptr)) { in xfs_btree_new_root()
3119 xfs_btree_buf_to_ptr(cur, lbp, &lptr); in xfs_btree_new_root()
3121 error = xfs_btree_read_buf_block(cur, &rptr, 0, &right, &rbp); in xfs_btree_new_root()
3129 xfs_btree_buf_to_ptr(cur, rbp, &rptr); in xfs_btree_new_root()
3131 xfs_btree_get_sibling(cur, right, &lptr, XFS_BB_LEFTSIB); in xfs_btree_new_root()
3132 error = xfs_btree_read_buf_block(cur, &lptr, 0, &left, &lbp); in xfs_btree_new_root()
3140 xfs_btree_init_block_cur(cur, nbp, cur->bc_nlevels, 2); in xfs_btree_new_root()
3141 xfs_btree_log_block(cur, nbp, XFS_BB_ALL_BITS); in xfs_btree_new_root()
3142 ASSERT(!xfs_btree_ptr_is_null(cur, &lptr) && in xfs_btree_new_root()
3143 !xfs_btree_ptr_is_null(cur, &rptr)); in xfs_btree_new_root()
3151 xfs_btree_get_node_keys(cur, left, in xfs_btree_new_root()
3152 xfs_btree_key_addr(cur, 1, new)); in xfs_btree_new_root()
3153 xfs_btree_get_node_keys(cur, right, in xfs_btree_new_root()
3154 xfs_btree_key_addr(cur, 2, new)); in xfs_btree_new_root()
3161 xfs_btree_get_leaf_keys(cur, left, in xfs_btree_new_root()
3162 xfs_btree_key_addr(cur, 1, new)); in xfs_btree_new_root()
3163 xfs_btree_get_leaf_keys(cur, right, in xfs_btree_new_root()
3164 xfs_btree_key_addr(cur, 2, new)); in xfs_btree_new_root()
3166 xfs_btree_log_keys(cur, nbp, 1, 2); in xfs_btree_new_root()
3169 xfs_btree_copy_ptrs(cur, in xfs_btree_new_root()
3170 xfs_btree_ptr_addr(cur, 1, new), &lptr, 1); in xfs_btree_new_root()
3171 xfs_btree_copy_ptrs(cur, in xfs_btree_new_root()
3172 xfs_btree_ptr_addr(cur, 2, new), &rptr, 1); in xfs_btree_new_root()
3173 xfs_btree_log_ptrs(cur, nbp, 1, 2); in xfs_btree_new_root()
3176 xfs_btree_setbuf(cur, cur->bc_nlevels, nbp); in xfs_btree_new_root()
3177 cur->bc_levels[cur->bc_nlevels].ptr = nptr; in xfs_btree_new_root()
3178 cur->bc_nlevels++; in xfs_btree_new_root()
3179 ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); in xfs_btree_new_root()
3191 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_make_block_unfull() argument
3203 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_make_block_unfull()
3204 level == cur->bc_nlevels - 1) { in xfs_btree_make_block_unfull()
3205 struct xfs_inode *ip = cur->bc_ino.ip; in xfs_btree_make_block_unfull()
3207 if (numrecs < cur->bc_ops->get_dmaxrecs(cur, level)) { in xfs_btree_make_block_unfull()
3209 xfs_iroot_realloc(ip, 1, cur->bc_ino.whichfork); in xfs_btree_make_block_unfull()
3215 error = xfs_btree_new_iroot(cur, &logflags, stat); in xfs_btree_make_block_unfull()
3219 xfs_trans_log_inode(cur->bc_tp, ip, logflags); in xfs_btree_make_block_unfull()
3226 error = xfs_btree_rshift(cur, level, stat); in xfs_btree_make_block_unfull()
3231 error = xfs_btree_lshift(cur, level, stat); in xfs_btree_make_block_unfull()
3236 *oindex = *index = cur->bc_levels[level].ptr; in xfs_btree_make_block_unfull()
3246 error = xfs_btree_split(cur, level, nptr, key, ncur, stat); in xfs_btree_make_block_unfull()
3251 *index = cur->bc_levels[level].ptr; in xfs_btree_make_block_unfull()
3261 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_insrec() argument
3289 if (!(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && in xfs_btree_insrec()
3290 (level >= cur->bc_nlevels)) { in xfs_btree_insrec()
3291 error = xfs_btree_new_root(cur, stat); in xfs_btree_insrec()
3292 xfs_btree_set_ptr_null(cur, ptrp); in xfs_btree_insrec()
3298 ptr = cur->bc_levels[level].ptr; in xfs_btree_insrec()
3306 XFS_BTREE_STATS_INC(cur, insrec); in xfs_btree_insrec()
3309 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_insrec()
3314 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_insrec()
3321 ASSERT(cur->bc_ops->recs_inorder(cur, rec, in xfs_btree_insrec()
3322 xfs_btree_rec_addr(cur, ptr, block))); in xfs_btree_insrec()
3324 ASSERT(cur->bc_ops->keys_inorder(cur, key, in xfs_btree_insrec()
3325 xfs_btree_key_addr(cur, ptr, block))); in xfs_btree_insrec()
3334 xfs_btree_set_ptr_null(cur, &nptr); in xfs_btree_insrec()
3335 if (numrecs == cur->bc_ops->get_maxrecs(cur, level)) { in xfs_btree_insrec()
3336 error = xfs_btree_make_block_unfull(cur, level, numrecs, in xfs_btree_insrec()
3346 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_insrec()
3350 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_insrec()
3359 XFS_BTREE_STATS_ADD(cur, moves, numrecs - ptr + 1); in xfs_btree_insrec()
3366 kp = xfs_btree_key_addr(cur, ptr, block); in xfs_btree_insrec()
3367 pp = xfs_btree_ptr_addr(cur, ptr, block); in xfs_btree_insrec()
3370 error = xfs_btree_debug_check_ptr(cur, pp, i, level); in xfs_btree_insrec()
3375 xfs_btree_shift_keys(cur, kp, 1, numrecs - ptr + 1); in xfs_btree_insrec()
3376 xfs_btree_shift_ptrs(cur, pp, 1, numrecs - ptr + 1); in xfs_btree_insrec()
3378 error = xfs_btree_debug_check_ptr(cur, ptrp, 0, level); in xfs_btree_insrec()
3383 xfs_btree_copy_keys(cur, kp, key, 1); in xfs_btree_insrec()
3384 xfs_btree_copy_ptrs(cur, pp, ptrp, 1); in xfs_btree_insrec()
3387 xfs_btree_log_ptrs(cur, bp, ptr, numrecs); in xfs_btree_insrec()
3388 xfs_btree_log_keys(cur, bp, ptr, numrecs); in xfs_btree_insrec()
3391 ASSERT(cur->bc_ops->keys_inorder(cur, kp, in xfs_btree_insrec()
3392 xfs_btree_key_addr(cur, ptr + 1, block))); in xfs_btree_insrec()
3399 rp = xfs_btree_rec_addr(cur, ptr, block); in xfs_btree_insrec()
3401 xfs_btree_shift_recs(cur, rp, 1, numrecs - ptr + 1); in xfs_btree_insrec()
3404 xfs_btree_copy_recs(cur, rp, rec, 1); in xfs_btree_insrec()
3406 xfs_btree_log_recs(cur, bp, ptr, numrecs); in xfs_btree_insrec()
3409 ASSERT(cur->bc_ops->recs_inorder(cur, rp, in xfs_btree_insrec()
3410 xfs_btree_rec_addr(cur, ptr + 1, block))); in xfs_btree_insrec()
3416 xfs_btree_log_block(cur, bp, XFS_BB_NUMRECS); in xfs_btree_insrec()
3427 xfs_btree_get_keys(cur, block, lkey); in xfs_btree_insrec()
3428 } else if (xfs_btree_needs_key_update(cur, optr)) { in xfs_btree_insrec()
3429 error = xfs_btree_update_keys(cur, level); in xfs_btree_insrec()
3438 if (xfs_btree_is_lastrec(cur, block, level)) { in xfs_btree_insrec()
3439 cur->bc_ops->update_lastrec(cur, block, rec, in xfs_btree_insrec()
3448 if (!xfs_btree_ptr_is_null(cur, &nptr)) { in xfs_btree_insrec()
3449 xfs_btree_copy_keys(cur, key, lkey, 1); in xfs_btree_insrec()
3471 struct xfs_btree_cur *cur, in xfs_btree_insert() argument
3486 pcur = cur; in xfs_btree_insert()
3489 xfs_btree_set_ptr_null(cur, &nptr); in xfs_btree_insert()
3492 cur->bc_ops->init_rec_from_cur(cur, &rec); in xfs_btree_insert()
3493 cur->bc_ops->init_key_from_rec(key, &rec); in xfs_btree_insert()
3508 if (pcur != cur) in xfs_btree_insert()
3513 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_insert()
3524 if (pcur != cur && in xfs_btree_insert()
3525 (ncur || xfs_btree_ptr_is_null(cur, &nptr))) { in xfs_btree_insert()
3527 if (cur->bc_ops->update_cursor) in xfs_btree_insert()
3528 cur->bc_ops->update_cursor(pcur, cur); in xfs_btree_insert()
3529 cur->bc_nlevels = pcur->bc_nlevels; in xfs_btree_insert()
3537 } while (!xfs_btree_ptr_is_null(cur, &nptr)); in xfs_btree_insert()
3555 struct xfs_btree_cur *cur) in xfs_btree_kill_iroot() argument
3557 int whichfork = cur->bc_ino.whichfork; in xfs_btree_kill_iroot()
3558 struct xfs_inode *ip = cur->bc_ino.ip; in xfs_btree_kill_iroot()
3576 ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); in xfs_btree_kill_iroot()
3577 ASSERT(cur->bc_nlevels > 1); in xfs_btree_kill_iroot()
3583 level = cur->bc_nlevels - 1; in xfs_btree_kill_iroot()
3590 block = xfs_btree_get_iroot(cur); in xfs_btree_kill_iroot()
3594 cblock = xfs_btree_get_block(cur, level - 1, &cbp); in xfs_btree_kill_iroot()
3602 if (numrecs > cur->bc_ops->get_dmaxrecs(cur, level)) in xfs_btree_kill_iroot()
3605 XFS_BTREE_STATS_INC(cur, killroot); in xfs_btree_kill_iroot()
3608 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_LEFTSIB); in xfs_btree_kill_iroot()
3609 ASSERT(xfs_btree_ptr_is_null(cur, &ptr)); in xfs_btree_kill_iroot()
3610 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB); in xfs_btree_kill_iroot()
3611 ASSERT(xfs_btree_ptr_is_null(cur, &ptr)); in xfs_btree_kill_iroot()
3614 index = numrecs - cur->bc_ops->get_maxrecs(cur, level); in xfs_btree_kill_iroot()
3616 xfs_iroot_realloc(cur->bc_ino.ip, index, in xfs_btree_kill_iroot()
3617 cur->bc_ino.whichfork); in xfs_btree_kill_iroot()
3624 kp = xfs_btree_key_addr(cur, 1, block); in xfs_btree_kill_iroot()
3625 ckp = xfs_btree_key_addr(cur, 1, cblock); in xfs_btree_kill_iroot()
3626 xfs_btree_copy_keys(cur, kp, ckp, numrecs); in xfs_btree_kill_iroot()
3628 pp = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_kill_iroot()
3629 cpp = xfs_btree_ptr_addr(cur, 1, cblock); in xfs_btree_kill_iroot()
3632 error = xfs_btree_debug_check_ptr(cur, cpp, i, level - 1); in xfs_btree_kill_iroot()
3637 xfs_btree_copy_ptrs(cur, pp, cpp, numrecs); in xfs_btree_kill_iroot()
3639 error = xfs_btree_free_block(cur, cbp); in xfs_btree_kill_iroot()
3643 cur->bc_levels[level - 1].bp = NULL; in xfs_btree_kill_iroot()
3645 xfs_trans_log_inode(cur->bc_tp, ip, in xfs_btree_kill_iroot()
3646 XFS_ILOG_CORE | xfs_ilog_fbroot(cur->bc_ino.whichfork)); in xfs_btree_kill_iroot()
3647 cur->bc_nlevels--; in xfs_btree_kill_iroot()
3657 struct xfs_btree_cur *cur, in xfs_btree_kill_root() argument
3664 XFS_BTREE_STATS_INC(cur, killroot); in xfs_btree_kill_root()
3670 cur->bc_ops->set_root(cur, newroot, -1); in xfs_btree_kill_root()
3672 error = xfs_btree_free_block(cur, bp); in xfs_btree_kill_root()
3676 cur->bc_levels[level].bp = NULL; in xfs_btree_kill_root()
3677 cur->bc_levels[level].ra = 0; in xfs_btree_kill_root()
3678 cur->bc_nlevels--; in xfs_btree_kill_root()
3685 struct xfs_btree_cur *cur, in xfs_btree_dec_cursor() argument
3693 error = xfs_btree_decrement(cur, level, &i); in xfs_btree_dec_cursor()
3710 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_delrec() argument
3736 ptr = cur->bc_levels[level].ptr; in xfs_btree_delrec()
3743 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_delrec()
3747 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_delrec()
3758 XFS_BTREE_STATS_INC(cur, delrec); in xfs_btree_delrec()
3759 XFS_BTREE_STATS_ADD(cur, moves, numrecs - ptr); in xfs_btree_delrec()
3767 lkp = xfs_btree_key_addr(cur, ptr + 1, block); in xfs_btree_delrec()
3768 lpp = xfs_btree_ptr_addr(cur, ptr + 1, block); in xfs_btree_delrec()
3771 error = xfs_btree_debug_check_ptr(cur, lpp, i, level); in xfs_btree_delrec()
3777 xfs_btree_shift_keys(cur, lkp, -1, numrecs - ptr); in xfs_btree_delrec()
3778 xfs_btree_shift_ptrs(cur, lpp, -1, numrecs - ptr); in xfs_btree_delrec()
3779 xfs_btree_log_keys(cur, bp, ptr, numrecs - 1); in xfs_btree_delrec()
3780 xfs_btree_log_ptrs(cur, bp, ptr, numrecs - 1); in xfs_btree_delrec()
3785 xfs_btree_shift_recs(cur, in xfs_btree_delrec()
3786 xfs_btree_rec_addr(cur, ptr + 1, block), in xfs_btree_delrec()
3788 xfs_btree_log_recs(cur, bp, ptr, numrecs - 1); in xfs_btree_delrec()
3796 xfs_btree_log_block(cur, bp, XFS_BB_NUMRECS); in xfs_btree_delrec()
3802 if (xfs_btree_is_lastrec(cur, block, level)) { in xfs_btree_delrec()
3803 cur->bc_ops->update_lastrec(cur, block, NULL, in xfs_btree_delrec()
3812 if (level == cur->bc_nlevels - 1) { in xfs_btree_delrec()
3813 if (cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) { in xfs_btree_delrec()
3814 xfs_iroot_realloc(cur->bc_ino.ip, -1, in xfs_btree_delrec()
3815 cur->bc_ino.whichfork); in xfs_btree_delrec()
3817 error = xfs_btree_kill_iroot(cur); in xfs_btree_delrec()
3821 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3839 pp = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_delrec()
3840 error = xfs_btree_kill_root(cur, bp, level, pp); in xfs_btree_delrec()
3844 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3856 if (xfs_btree_needs_key_update(cur, ptr)) { in xfs_btree_delrec()
3857 error = xfs_btree_update_keys(cur, level); in xfs_btree_delrec()
3866 if (numrecs >= cur->bc_ops->get_minrecs(cur, level)) { in xfs_btree_delrec()
3867 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3878 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
3879 xfs_btree_get_sibling(cur, block, &lptr, XFS_BB_LEFTSIB); in xfs_btree_delrec()
3881 if (cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) { in xfs_btree_delrec()
3887 if (xfs_btree_ptr_is_null(cur, &rptr) && in xfs_btree_delrec()
3888 xfs_btree_ptr_is_null(cur, &lptr) && in xfs_btree_delrec()
3889 level == cur->bc_nlevels - 2) { in xfs_btree_delrec()
3890 error = xfs_btree_kill_iroot(cur); in xfs_btree_delrec()
3892 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3899 ASSERT(!xfs_btree_ptr_is_null(cur, &rptr) || in xfs_btree_delrec()
3900 !xfs_btree_ptr_is_null(cur, &lptr)); in xfs_btree_delrec()
3906 error = xfs_btree_dup_cursor(cur, &tcur); in xfs_btree_delrec()
3914 if (!xfs_btree_ptr_is_null(cur, &rptr)) { in xfs_btree_delrec()
3920 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
3928 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
3934 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
3955 cur->bc_ops->get_minrecs(tcur, level)) { in xfs_btree_delrec()
3961 cur->bc_ops->get_minrecs(tcur, level)); in xfs_btree_delrec()
3966 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
3979 if (!xfs_btree_ptr_is_null(cur, &lptr)) { in xfs_btree_delrec()
3981 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
3989 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
4000 if (!xfs_btree_ptr_is_null(cur, &lptr)) { in xfs_btree_delrec()
4006 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
4015 if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) { in xfs_btree_delrec()
4023 error = xfs_btree_check_block(cur, left, level, lbp); in xfs_btree_delrec()
4036 cur->bc_ops->get_minrecs(tcur, level)) { in xfs_btree_delrec()
4042 cur->bc_ops->get_minrecs(tcur, level)); in xfs_btree_delrec()
4046 cur->bc_levels[0].ptr++; in xfs_btree_delrec()
4065 ASSERT(!xfs_btree_ptr_is_null(cur, &cptr)); in xfs_btree_delrec()
4067 if (!xfs_btree_ptr_is_null(cur, &lptr) && in xfs_btree_delrec()
4069 cur->bc_ops->get_maxrecs(cur, level)) { in xfs_btree_delrec()
4077 error = xfs_btree_read_buf_block(cur, &lptr, 0, &left, &lbp); in xfs_btree_delrec()
4084 } else if (!xfs_btree_ptr_is_null(cur, &rptr) && in xfs_btree_delrec()
4086 cur->bc_ops->get_maxrecs(cur, level)) { in xfs_btree_delrec()
4094 error = xfs_btree_read_buf_block(cur, &rptr, 0, &right, &rbp); in xfs_btree_delrec()
4103 error = xfs_btree_dec_cursor(cur, level, stat); in xfs_btree_delrec()
4116 XFS_BTREE_STATS_ADD(cur, moves, rrecs); in xfs_btree_delrec()
4124 lkp = xfs_btree_key_addr(cur, lrecs + 1, left); in xfs_btree_delrec()
4125 lpp = xfs_btree_ptr_addr(cur, lrecs + 1, left); in xfs_btree_delrec()
4126 rkp = xfs_btree_key_addr(cur, 1, right); in xfs_btree_delrec()
4127 rpp = xfs_btree_ptr_addr(cur, 1, right); in xfs_btree_delrec()
4130 error = xfs_btree_debug_check_ptr(cur, rpp, i, level); in xfs_btree_delrec()
4135 xfs_btree_copy_keys(cur, lkp, rkp, rrecs); in xfs_btree_delrec()
4136 xfs_btree_copy_ptrs(cur, lpp, rpp, rrecs); in xfs_btree_delrec()
4138 xfs_btree_log_keys(cur, lbp, lrecs + 1, lrecs + rrecs); in xfs_btree_delrec()
4139 xfs_btree_log_ptrs(cur, lbp, lrecs + 1, lrecs + rrecs); in xfs_btree_delrec()
4145 lrp = xfs_btree_rec_addr(cur, lrecs + 1, left); in xfs_btree_delrec()
4146 rrp = xfs_btree_rec_addr(cur, 1, right); in xfs_btree_delrec()
4148 xfs_btree_copy_recs(cur, lrp, rrp, rrecs); in xfs_btree_delrec()
4149 xfs_btree_log_recs(cur, lbp, lrecs + 1, lrecs + rrecs); in xfs_btree_delrec()
4152 XFS_BTREE_STATS_INC(cur, join); in xfs_btree_delrec()
4159 xfs_btree_get_sibling(cur, right, &cptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4160 xfs_btree_set_sibling(cur, left, &cptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4161 xfs_btree_log_block(cur, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4164 xfs_btree_get_sibling(cur, left, &cptr, XFS_BB_RIGHTSIB); in xfs_btree_delrec()
4165 if (!xfs_btree_ptr_is_null(cur, &cptr)) { in xfs_btree_delrec()
4166 error = xfs_btree_read_buf_block(cur, &cptr, 0, &rrblock, &rrbp); in xfs_btree_delrec()
4169 xfs_btree_set_sibling(cur, rrblock, &lptr, XFS_BB_LEFTSIB); in xfs_btree_delrec()
4170 xfs_btree_log_block(cur, rrbp, XFS_BB_LEFTSIB); in xfs_btree_delrec()
4174 error = xfs_btree_free_block(cur, rbp); in xfs_btree_delrec()
4183 cur->bc_levels[level].bp = lbp; in xfs_btree_delrec()
4184 cur->bc_levels[level].ptr += lrecs; in xfs_btree_delrec()
4185 cur->bc_levels[level].ra = 0; in xfs_btree_delrec()
4191 else if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) || in xfs_btree_delrec()
4192 (level + 1 < cur->bc_nlevels)) { in xfs_btree_delrec()
4193 error = xfs_btree_increment(cur, level + 1, &i); in xfs_btree_delrec()
4205 cur->bc_levels[level].ptr--; in xfs_btree_delrec()
4234 struct xfs_btree_cur *cur, in xfs_btree_delete() argument
4249 error = xfs_btree_delrec(cur, level, &i); in xfs_btree_delete()
4260 if (joined && (cur->bc_flags & XFS_BTREE_OVERLAPPING)) { in xfs_btree_delete()
4261 error = xfs_btree_updkeys_force(cur, 0); in xfs_btree_delete()
4267 for (level = 1; level < cur->bc_nlevels; level++) { in xfs_btree_delete()
4268 if (cur->bc_levels[level].ptr == 0) { in xfs_btree_delete()
4269 error = xfs_btree_decrement(cur, level, &i); in xfs_btree_delete()
4288 struct xfs_btree_cur *cur, /* btree cursor */ in xfs_btree_get_rec() argument
4299 ptr = cur->bc_levels[0].ptr; in xfs_btree_get_rec()
4300 block = xfs_btree_get_block(cur, 0, &bp); in xfs_btree_get_rec()
4303 error = xfs_btree_check_block(cur, block, 0, bp); in xfs_btree_get_rec()
4319 *recp = xfs_btree_rec_addr(cur, ptr, block); in xfs_btree_get_rec()
4327 struct xfs_btree_cur *cur, in xfs_btree_visit_block() argument
4338 xfs_btree_readahead(cur, level, XFS_BTCUR_RIGHTRA); in xfs_btree_visit_block()
4339 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_visit_block()
4342 error = fn(cur, level, data); in xfs_btree_visit_block()
4347 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB); in xfs_btree_visit_block()
4348 if (xfs_btree_ptr_is_null(cur, &rptr)) in xfs_btree_visit_block()
4357 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_visit_block()
4358 if (be64_to_cpu(rptr.l) == XFS_DADDR_TO_FSB(cur->bc_mp, in xfs_btree_visit_block()
4362 if (be32_to_cpu(rptr.s) == xfs_daddr_to_agbno(cur->bc_mp, in xfs_btree_visit_block()
4366 return xfs_btree_lookup_get_block(cur, level, &rptr, &block); in xfs_btree_visit_block()
4373 struct xfs_btree_cur *cur, in xfs_btree_visit_blocks() argument
4383 cur->bc_ops->init_ptr_from_cur(cur, &lptr); in xfs_btree_visit_blocks()
4386 for (level = cur->bc_nlevels - 1; level >= 0; level--) { in xfs_btree_visit_blocks()
4388 error = xfs_btree_lookup_get_block(cur, level, &lptr, &block); in xfs_btree_visit_blocks()
4396 ptr = xfs_btree_ptr_addr(cur, 1, block); in xfs_btree_visit_blocks()
4397 xfs_btree_readahead_ptr(cur, ptr, 1); in xfs_btree_visit_blocks()
4400 xfs_btree_copy_ptrs(cur, &lptr, ptr, 1); in xfs_btree_visit_blocks()
4410 error = xfs_btree_visit_block(cur, level, fn, data); in xfs_btree_visit_blocks()
4451 struct xfs_btree_cur *cur, in xfs_btree_block_change_owner() argument
4460 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_block_change_owner()
4461 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { in xfs_btree_block_change_owner()
4479 ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); in xfs_btree_block_change_owner()
4480 ASSERT(level == cur->bc_nlevels - 1); in xfs_btree_block_change_owner()
4484 if (cur->bc_tp) { in xfs_btree_block_change_owner()
4485 if (!xfs_trans_ordered_buf(cur->bc_tp, bp)) { in xfs_btree_block_change_owner()
4486 xfs_btree_log_block(cur, bp, XFS_BB_OWNER); in xfs_btree_block_change_owner()
4498 struct xfs_btree_cur *cur, in xfs_btree_change_owner() argument
4507 return xfs_btree_visit_blocks(cur, xfs_btree_block_change_owner, in xfs_btree_change_owner()
4692 struct xfs_btree_cur *cur, in xfs_btree_simple_query_range() argument
4705 ASSERT(cur->bc_ops->init_high_key_from_rec); in xfs_btree_simple_query_range()
4706 ASSERT(cur->bc_ops->diff_two_keys); in xfs_btree_simple_query_range()
4713 error = xfs_btree_lookup(cur, XFS_LOOKUP_LE, &stat); in xfs_btree_simple_query_range()
4719 error = xfs_btree_increment(cur, 0, &stat); in xfs_btree_simple_query_range()
4726 error = xfs_btree_get_rec(cur, &recp, &stat); in xfs_btree_simple_query_range()
4732 cur->bc_ops->init_high_key_from_rec(&rec_key, recp); in xfs_btree_simple_query_range()
4734 diff = cur->bc_ops->diff_two_keys(cur, low_key, in xfs_btree_simple_query_range()
4741 cur->bc_ops->init_key_from_rec(&rec_key, recp); in xfs_btree_simple_query_range()
4742 diff = cur->bc_ops->diff_two_keys(cur, &rec_key, high_key); in xfs_btree_simple_query_range()
4747 error = fn(cur, recp, priv); in xfs_btree_simple_query_range()
4753 error = xfs_btree_increment(cur, 0, &stat); in xfs_btree_simple_query_range()
4783 struct xfs_btree_cur *cur, in xfs_btree_overlapped_query_range() argument
4805 level = cur->bc_nlevels - 1; in xfs_btree_overlapped_query_range()
4806 cur->bc_ops->init_ptr_from_cur(cur, &ptr); in xfs_btree_overlapped_query_range()
4807 error = xfs_btree_lookup_get_block(cur, level, &ptr, &block); in xfs_btree_overlapped_query_range()
4810 xfs_btree_get_block(cur, level, &bp); in xfs_btree_overlapped_query_range()
4811 trace_xfs_btree_overlapped_query_range(cur, level, bp); in xfs_btree_overlapped_query_range()
4813 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_overlapped_query_range()
4817 cur->bc_levels[level].ptr = 1; in xfs_btree_overlapped_query_range()
4819 while (level < cur->bc_nlevels) { in xfs_btree_overlapped_query_range()
4820 block = xfs_btree_get_block(cur, level, &bp); in xfs_btree_overlapped_query_range()
4823 if (cur->bc_levels[level].ptr > in xfs_btree_overlapped_query_range()
4826 if (level < cur->bc_nlevels - 1) in xfs_btree_overlapped_query_range()
4827 cur->bc_levels[level + 1].ptr++; in xfs_btree_overlapped_query_range()
4834 recp = xfs_btree_rec_addr(cur, cur->bc_levels[0].ptr, in xfs_btree_overlapped_query_range()
4837 cur->bc_ops->init_high_key_from_rec(&rec_hkey, recp); in xfs_btree_overlapped_query_range()
4838 ldiff = cur->bc_ops->diff_two_keys(cur, &rec_hkey, in xfs_btree_overlapped_query_range()
4841 cur->bc_ops->init_key_from_rec(&rec_key, recp); in xfs_btree_overlapped_query_range()
4842 hdiff = cur->bc_ops->diff_two_keys(cur, high_key, in xfs_btree_overlapped_query_range()
4851 error = fn(cur, recp, priv); in xfs_btree_overlapped_query_range()
4858 cur->bc_levels[level].ptr++; in xfs_btree_overlapped_query_range()
4863 lkp = xfs_btree_key_addr(cur, cur->bc_levels[level].ptr, block); in xfs_btree_overlapped_query_range()
4864 hkp = xfs_btree_high_key_addr(cur, cur->bc_levels[level].ptr, in xfs_btree_overlapped_query_range()
4866 pp = xfs_btree_ptr_addr(cur, cur->bc_levels[level].ptr, block); in xfs_btree_overlapped_query_range()
4868 ldiff = cur->bc_ops->diff_two_keys(cur, hkp, low_key); in xfs_btree_overlapped_query_range()
4869 hdiff = cur->bc_ops->diff_two_keys(cur, high_key, lkp); in xfs_btree_overlapped_query_range()
4878 error = xfs_btree_lookup_get_block(cur, level, pp, in xfs_btree_overlapped_query_range()
4882 xfs_btree_get_block(cur, level, &bp); in xfs_btree_overlapped_query_range()
4883 trace_xfs_btree_overlapped_query_range(cur, level, bp); in xfs_btree_overlapped_query_range()
4885 error = xfs_btree_check_block(cur, block, level, bp); in xfs_btree_overlapped_query_range()
4889 cur->bc_levels[level].ptr = 1; in xfs_btree_overlapped_query_range()
4895 cur->bc_levels[level].ptr++; in xfs_btree_overlapped_query_range()
4906 if (cur->bc_levels[0].bp == NULL) { in xfs_btree_overlapped_query_range()
4907 for (i = 0; i < cur->bc_nlevels; i++) { in xfs_btree_overlapped_query_range()
4908 if (cur->bc_levels[i].bp) { in xfs_btree_overlapped_query_range()
4909 xfs_trans_brelse(cur->bc_tp, in xfs_btree_overlapped_query_range()
4910 cur->bc_levels[i].bp); in xfs_btree_overlapped_query_range()
4911 cur->bc_levels[i].bp = NULL; in xfs_btree_overlapped_query_range()
4912 cur->bc_levels[i].ptr = 0; in xfs_btree_overlapped_query_range()
4913 cur->bc_levels[i].ra = 0; in xfs_btree_overlapped_query_range()
4929 struct xfs_btree_cur *cur, in xfs_btree_query_range() argument
4940 cur->bc_rec = *high_rec; in xfs_btree_query_range()
4941 cur->bc_ops->init_rec_from_cur(cur, &rec); in xfs_btree_query_range()
4942 cur->bc_ops->init_key_from_rec(&high_key, &rec); in xfs_btree_query_range()
4944 cur->bc_rec = *low_rec; in xfs_btree_query_range()
4945 cur->bc_ops->init_rec_from_cur(cur, &rec); in xfs_btree_query_range()
4946 cur->bc_ops->init_key_from_rec(&low_key, &rec); in xfs_btree_query_range()
4949 if (cur->bc_ops->diff_two_keys(cur, &low_key, &high_key) > 0) in xfs_btree_query_range()
4952 if (!(cur->bc_flags & XFS_BTREE_OVERLAPPING)) in xfs_btree_query_range()
4953 return xfs_btree_simple_query_range(cur, &low_key, in xfs_btree_query_range()
4955 return xfs_btree_overlapped_query_range(cur, &low_key, &high_key, in xfs_btree_query_range()
4962 struct xfs_btree_cur *cur, in xfs_btree_query_all() argument
4969 memset(&cur->bc_rec, 0, sizeof(cur->bc_rec)); in xfs_btree_query_all()
4973 return xfs_btree_simple_query_range(cur, &low_key, &high_key, fn, priv); in xfs_btree_query_all()
4978 struct xfs_btree_cur *cur, in xfs_btree_count_blocks_helper() argument
4991 struct xfs_btree_cur *cur, in xfs_btree_count_blocks() argument
4995 return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper, in xfs_btree_count_blocks()
5002 struct xfs_btree_cur *cur, in xfs_btree_diff_two_ptrs() argument
5006 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_diff_two_ptrs()
5014 struct xfs_btree_cur *cur, in xfs_btree_has_record_helper() argument
5024 struct xfs_btree_cur *cur, in xfs_btree_has_record() argument
5031 error = xfs_btree_query_range(cur, low, high, in xfs_btree_has_record()
5044 struct xfs_btree_cur *cur) in xfs_btree_has_more_records() argument
5049 block = xfs_btree_get_block(cur, 0, &bp); in xfs_btree_has_more_records()
5052 if (cur->bc_levels[0].ptr < xfs_btree_get_numrecs(block)) in xfs_btree_has_more_records()
5056 if (cur->bc_flags & XFS_BTREE_LONG_PTRS) in xfs_btree_has_more_records()