65 cur->
bc_ops->get_maxrecs(cur, level) &&
66 block->
bb_u.
l.bb_leftsib &&
70 block->
bb_u.
l.bb_rightsib &&
78 trace_xfs_btree_corrupt(bp,
_RET_IP_);
105 cur->
bc_ops->get_maxrecs(cur, level) &&
108 block->
bb_u.
s.bb_leftsib &&
111 block->
bb_u.
s.bb_rightsib;
116 trace_xfs_btree_corrupt(bp,
_RET_IP_);
161 xfs_btree_check_sptr(
190 return xfs_btree_check_sptr(cur,
256 new = cur->
bc_ops->dup_cursor(cur);
261 new->bc_rec = cur->
bc_rec;
266 for (i = 0; i <
new->bc_nlevels; i++) {
270 if ((error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
276 new->bc_bufs[
i] = bp;
277 ASSERT(!xfs_buf_geterror(bp));
279 new->bc_bufs[
i] =
NULL;
318 static inline size_t xfs_btree_block_len(
struct xfs_btree_cur *cur)
328 static inline size_t xfs_btree_ptr_len(
struct xfs_btree_cur *cur)
342 return xfs_btree_block_len(cur) +
343 (n - 1) * cur->
bc_ops->rec_len;
354 return xfs_btree_block_len(cur) +
355 (n - 1) * cur->
bc_ops->key_len;
367 return xfs_btree_block_len(cur) +
368 cur->
bc_ops->get_maxrecs(cur, level) * cur->
bc_ops->key_len +
369 (n - 1) * xfs_btree_ptr_len(cur);
407 int level = xfs_btree_get_level(block);
467 bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, lock);
468 ASSERT(!xfs_buf_geterror(bp));
490 bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, lock);
491 ASSERT(!xfs_buf_geterror(bp));
579 const short *offsets,
591 for (i = 0, imask = 1
LL; ; i++, imask <<= 1) {
592 if (imask & fields) {
600 for (i = nbits - 1, imask = 1
LL << i; ; i--, imask >>= 1) {
601 if (imask & fields) {
602 *last = offsets[i + 1] - 1;
627 if ((error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, d,
628 mp->m_bsize, lock, &bp))) {
631 ASSERT(!xfs_buf_geterror(bp));
633 xfs_buf_set_ref(bp, refval);
653 xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count);
673 xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count);
745 if ((cur->
bc_ra[lev] | lr) == cur->
bc_ra[lev])
823 ptr->
l = block->
bb_u.
l.bb_rightsib;
825 ptr->
l = block->
bb_u.
l.bb_leftsib;
828 ptr->
s = block->
bb_u.
s.bb_rightsib;
830 ptr->
s = block->
bb_u.
s.bb_leftsib;
845 block->
bb_u.
l.bb_rightsib = ptr->
l;
847 block->
bb_u.
l.bb_leftsib = ptr->
l;
850 block->
bb_u.
s.bb_rightsib = ptr->
s;
852 block->
bb_u.
s.bb_leftsib = ptr->
s;
962 struct xfs_mount *
mp = cur->
bc_mp;
969 *bpp = xfs_trans_get_buf(cur->
bc_tp, mp->m_ddev_targp, d,
992 struct xfs_mount *
mp = cur->
bc_mp;
1000 error = xfs_trans_read_buf(mp, cur->
bc_tp, mp->m_ddev_targp, d,
1001 mp->m_bsize, flags, bpp);
1005 ASSERT(!xfs_buf_geterror(*bpp));
1027 memcpy(dst_key, src_key, numkeys * cur->
bc_ops->key_len);
1041 memcpy(dst_rec, src_rec, numrecs * cur->
bc_ops->rec_len);
1055 memcpy(dst_ptr, src_ptr, numptrs * xfs_btree_ptr_len(cur));
1071 ASSERT(dir == 1 || dir == -1);
1073 dst_key = (
char *)key + (dir * cur->
bc_ops->key_len);
1090 ASSERT(dir == 1 || dir == -1);
1092 dst_rec = (
char *)rec + (dir * cur->
bc_ops->rec_len);
1109 ASSERT(dir == 1 || dir == -1);
1111 dst_ptr = (
char *)ptr + (dir * xfs_btree_ptr_len(cur));
1112 memmove(dst_ptr, ptr, numptrs * xfs_btree_ptr_len(cur));
1175 int level = xfs_btree_get_level(block);
1199 static const short soffsets[] = {
1207 static const short loffsets[] = {
1222 loffsets : soffsets,
1252 ASSERT(level < cur->bc_nlevels);
1267 if (++cur->
bc_ptrs[level] <= xfs_btree_get_numrecs(block))
1281 for (lev = level + 1; lev < cur->
bc_nlevels; lev++) {
1290 if (++cur->
bc_ptrs[lev] <= xfs_btree_get_numrecs(block))
1308 ASSERT(lev < cur->bc_nlevels);
1360 ASSERT(level < cur->bc_nlevels);
1366 if (--cur->
bc_ptrs[level] > 0)
1389 for (lev = level + 1; lev < cur->
bc_nlevels; lev++) {
1407 ASSERT(lev < cur->bc_nlevels);
1422 cur->
bc_ptrs[lev] = xfs_btree_get_numrecs(block);
1490 cur->
bc_ops->init_key_from_rec(kp,
1525 cur->
bc_ops->init_ptr_from_cur(cur, &ptr);
1534 for (level = cur->
bc_nlevels - 1, diff = 1; level >= 0; level--) {
1554 high = xfs_btree_get_numrecs(block);
1566 while (low <= high) {
1573 keyno = (low +
high) >> 1;
1577 keyno, block, &key);
1585 diff = cur->
bc_ops->key_diff(cur, kp);
1604 if (diff > 0 && --keyno < 1)
1609 error = xfs_btree_check_ptr(cur, pp, 0, level);
1626 keyno > xfs_btree_get_numrecs(block) &&
1644 if (keyno == 0 || keyno > xfs_btree_get_numrecs(block))
1683 for (ptr = 1; ptr == 1 && level < cur->
bc_nlevels; level++) {
1745 cur->
bc_ops->update_lastrec(cur, block, rec,
1753 cur->
bc_ops->init_key_from_rec(&key, rec);
1824 lrecs = xfs_btree_get_numrecs(left);
1825 if (lrecs == cur->
bc_ops->get_maxrecs(cur, level))
1828 rrecs = xfs_btree_get_numrecs(right);
1856 error = xfs_btree_check_ptr(cur, rpp, 0, level);
1882 xfs_btree_set_numrecs(left, lrecs);
1885 xfs_btree_set_numrecs(right, rrecs);
1897 for (i = 0; i < rrecs; i++) {
1898 error = xfs_btree_check_ptr(cur, rpp, i + 1, level);
1923 cur->
bc_ops->init_key_from_rec(&key,
1998 lrecs = xfs_btree_get_numrecs(left);
1999 if (cur->
bc_ptrs[level] >= lrecs)
2008 rrecs = xfs_btree_get_numrecs(right);
2009 if (rrecs == cur->
bc_ops->get_maxrecs(cur, level))
2031 for (i = rrecs - 1; i >= 0; i--) {
2032 error = xfs_btree_check_ptr(cur, rpp, i, level);
2042 error = xfs_btree_check_ptr(cur, lpp, 0, level);
2070 cur->
bc_ops->init_key_from_rec(&key, rrp);
2080 xfs_btree_set_numrecs(left, --lrecs);
2083 xfs_btree_set_numrecs(right, ++rrecs);
2173 error = cur->
bc_ops->alloc_block(cur, &lptr, &rptr, 1, stat);
2193 lrecs = xfs_btree_get_numrecs(left);
2195 if ((lrecs & 1) && cur->
bc_ptrs[level] <= rrecs + 1)
2197 src_index = (lrecs - rrecs + 1);
2219 for (i = src_index; i < rrecs; i++) {
2220 error = xfs_btree_check_ptr(cur, lpp, i, level);
2245 cur->
bc_ops->init_key_from_rec(key,
2260 xfs_btree_set_numrecs(left, lrecs);
2261 xfs_btree_set_numrecs(right, xfs_btree_get_numrecs(right) + rrecs);
2272 0, &rrblock, &rrbp);
2283 if (cur->
bc_ptrs[level] > lrecs + 1) {
2295 (*curp)->bc_ptrs[level + 1]++;
2346 error = cur->
bc_ops->alloc_block(cur, pp, &nptr, 1, stat);
2360 memcpy(cblock, block, xfs_btree_block_len(cur));
2363 xfs_btree_set_numrecs(block, 1);
2374 error = xfs_btree_check_ptr(cur, pp, i, level);
2382 error = xfs_btree_check_ptr(cur, &nptr, 0, level);
2389 1 - xfs_btree_get_numrecs(cblock),
2437 cur->
bc_ops->init_ptr_from_cur(cur, &rptr);
2440 error = cur->
bc_ops->alloc_block(cur, &rptr, &lptr, 1, stat);
2453 cur->
bc_ops->set_root(cur, &lptr, 1);
2501 if (xfs_btree_get_level(left) > 0) {
2509 cur->
bc_ops->init_key_from_rec(
2512 cur->
bc_ops->init_key_from_rec(
2560 if (numrecs < cur->bc_ops->get_dmaxrecs(cur, level)) {
2569 if (error || *stat == 0)
2600 if (error || *stat == 0)
2605 cur->
bc_ops->init_rec_from_key(&key, nrec);
2663 cur->
bc_ops->init_key_from_rec(&key, recp);
2671 numrecs = xfs_btree_get_numrecs(block);
2679 if (ptr <= numrecs) {
2695 if (numrecs == cur->
bc_ops->get_maxrecs(cur, level)) {
2697 &optr, &ptr, &nptr, &ncur, &nrec, stat);
2698 if (error || *stat == 0)
2707 numrecs = xfs_btree_get_numrecs(block);
2730 for (i = numrecs - ptr; i >= 0; i--) {
2731 error = xfs_btree_check_ptr(cur, pp, i, level);
2741 error = xfs_btree_check_ptr(cur, ptrp, 0, level);
2750 xfs_btree_set_numrecs(block, numrecs);
2754 if (ptr < numrecs) {
2769 xfs_btree_set_numrecs(block, ++numrecs);
2772 if (ptr < numrecs) {
2794 cur->
bc_ops->update_lastrec(cur, block, recp,
2842 cur->
bc_ops->init_rec_from_cur(cur, &rec);
2872 if (cur->
bc_ops->update_cursor)
2873 cur->
bc_ops->update_cursor(pcur, cur);
2939 if (xfs_btree_get_numrecs(block) != 1)
2943 numrecs = xfs_btree_get_numrecs(cblock);
2950 if (numrecs > cur->
bc_ops->get_dmaxrecs(cur, level))
2962 index = numrecs - cur->
bc_ops->get_maxrecs(cur, level);
2979 for (i = 0; i < numrecs; i++) {
2982 error = xfs_btree_check_ptr(cur, cpp, i, level - 1);
2991 cur->
bc_ops->free_block(cur, cbp);
2995 be16_add_cpu(&block->
bb_level, -1);
3023 cur->
bc_ops->set_root(cur, newroot, -1);
3025 error = cur->
bc_ops->free_block(cur, bp);
3109 numrecs = xfs_btree_get_numrecs(block);
3118 if (ptr > numrecs) {
3137 for (i = 0; i < numrecs -
ptr; i++) {
3138 error = xfs_btree_check_ptr(cur, lpp, i, level);
3144 if (ptr < numrecs) {
3159 if (ptr < numrecs) {
3171 cur->
bc_ops->init_key_from_rec(&key,
3180 xfs_btree_set_numrecs(block, --numrecs);
3188 cur->
bc_ops->update_lastrec(cur, block,
NULL,
3218 if (numrecs == 1 && level > 0) {
3228 }
else if (level > 0) {
3251 if (numrecs >= cur->
bc_ops->get_minrecs(cur, level)) {
3330 if (xfs_btree_get_numrecs(right) - 1 >=
3331 cur->
bc_ops->get_minrecs(tcur, level)) {
3336 ASSERT(xfs_btree_get_numrecs(block) >=
3337 cur->
bc_ops->get_minrecs(tcur, level));
3354 rrecs = xfs_btree_get_numrecs(right);
3399 if (xfs_btree_get_numrecs(left) - 1 >=
3400 cur->
bc_ops->get_minrecs(tcur, level)) {
3405 ASSERT(xfs_btree_get_numrecs(block) >=
3406 cur->
bc_ops->get_minrecs(tcur, level));
3421 lrecs = xfs_btree_get_numrecs(left);
3432 lrecs + xfs_btree_get_numrecs(block) <=
3433 cur->
bc_ops->get_maxrecs(cur, level)) {
3450 rrecs + xfs_btree_get_numrecs(block) <=
3451 cur->
bc_ops->get_maxrecs(cur, level)) {
3475 rrecs = xfs_btree_get_numrecs(right);
3476 lrecs = xfs_btree_get_numrecs(left);
3495 for (i = 1; i < rrecs; i++) {
3496 error = xfs_btree_check_ptr(cur, rpp, i, level);
3524 xfs_btree_set_numrecs(left, lrecs + rrecs);
3533 0, &rrblock, &rrbp);
3541 error = cur->
bc_ops->free_block(cur, rbp);
3609 for (level = 0, i = 2; i == 2; level++) {
3616 for (level = 1; level < cur->
bc_nlevels; level++) {
3617 if (cur->
bc_ptrs[level] == 0) {
3662 if (ptr > xfs_btree_get_numrecs(block) || ptr <= 0) {