2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_dir2_sf.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_btree.h"
38 #include "xfs_ialloc.h"
39 #include "xfs_error.h"
42 * Cursor allocation zone.
44 kmem_zone_t
*xfs_btree_cur_zone
;
47 * Btree magic numbers.
49 const __uint32_t xfs_magics
[XFS_BTNUM_MAX
] = {
50 XFS_ABTB_MAGIC
, XFS_ABTC_MAGIC
, XFS_BMAP_MAGIC
, XFS_IBT_MAGIC
59 * Debug routine: check that keys are in the right order.
63 xfs_btnum_t btnum
, /* btree identifier */
64 void *ak1
, /* pointer to left (lower) key */
65 void *ak2
) /* pointer to right (higher) key */
74 ASSERT(be32_to_cpu(k1
->ar_startblock
) < be32_to_cpu(k2
->ar_startblock
));
83 ASSERT(be32_to_cpu(k1
->ar_blockcount
) < be32_to_cpu(k2
->ar_blockcount
) ||
84 (k1
->ar_blockcount
== k2
->ar_blockcount
&&
85 be32_to_cpu(k1
->ar_startblock
) < be32_to_cpu(k2
->ar_startblock
)));
88 case XFS_BTNUM_BMAP
: {
94 ASSERT(be64_to_cpu(k1
->br_startoff
) < be64_to_cpu(k2
->br_startoff
));
103 ASSERT(be32_to_cpu(k1
->ir_startino
) < be32_to_cpu(k2
->ir_startino
));
112 * Debug routine: check that records are in the right order.
116 xfs_btnum_t btnum
, /* btree identifier */
117 void *ar1
, /* pointer to left (lower) record */
118 void *ar2
) /* pointer to right (higher) record */
121 case XFS_BTNUM_BNO
: {
127 ASSERT(be32_to_cpu(r1
->ar_startblock
) +
128 be32_to_cpu(r1
->ar_blockcount
) <=
129 be32_to_cpu(r2
->ar_startblock
));
132 case XFS_BTNUM_CNT
: {
138 ASSERT(be32_to_cpu(r1
->ar_blockcount
) < be32_to_cpu(r2
->ar_blockcount
) ||
139 (r1
->ar_blockcount
== r2
->ar_blockcount
&&
140 be32_to_cpu(r1
->ar_startblock
) < be32_to_cpu(r2
->ar_startblock
)));
143 case XFS_BTNUM_BMAP
: {
149 ASSERT(xfs_bmbt_disk_get_startoff(r1
) +
150 xfs_bmbt_disk_get_blockcount(r1
) <=
151 xfs_bmbt_disk_get_startoff(r2
));
154 case XFS_BTNUM_INO
: {
160 ASSERT(be32_to_cpu(r1
->ir_startino
) + XFS_INODES_PER_CHUNK
<=
161 be32_to_cpu(r2
->ir_startino
));
170 int /* error (0 or EFSCORRUPTED) */
171 xfs_btree_check_lblock(
172 struct xfs_btree_cur
*cur
, /* btree cursor */
173 struct xfs_btree_lblock
*block
, /* btree long form block pointer */
174 int level
, /* level of the btree block */
175 struct xfs_buf
*bp
) /* buffer for block, if any */
177 int lblock_ok
; /* block passes checks */
178 struct xfs_mount
*mp
; /* file system mount point */
182 be32_to_cpu(block
->bb_magic
) == xfs_magics
[cur
->bc_btnum
] &&
183 be16_to_cpu(block
->bb_level
) == level
&&
184 be16_to_cpu(block
->bb_numrecs
) <=
185 cur
->bc_ops
->get_maxrecs(cur
, level
) &&
187 (be64_to_cpu(block
->bb_leftsib
) == NULLDFSBNO
||
188 XFS_FSB_SANITY_CHECK(mp
, be64_to_cpu(block
->bb_leftsib
))) &&
189 block
->bb_rightsib
&&
190 (be64_to_cpu(block
->bb_rightsib
) == NULLDFSBNO
||
191 XFS_FSB_SANITY_CHECK(mp
, be64_to_cpu(block
->bb_rightsib
)));
192 if (unlikely(XFS_TEST_ERROR(!lblock_ok
, mp
,
193 XFS_ERRTAG_BTREE_CHECK_LBLOCK
,
194 XFS_RANDOM_BTREE_CHECK_LBLOCK
))) {
196 xfs_buftrace("LBTREE ERROR", bp
);
197 XFS_ERROR_REPORT("xfs_btree_check_lblock", XFS_ERRLEVEL_LOW
,
199 return XFS_ERROR(EFSCORRUPTED
);
204 int /* error (0 or EFSCORRUPTED) */
205 xfs_btree_check_sblock(
206 struct xfs_btree_cur
*cur
, /* btree cursor */
207 struct xfs_btree_sblock
*block
, /* btree short form block pointer */
208 int level
, /* level of the btree block */
209 struct xfs_buf
*bp
) /* buffer containing block */
211 struct xfs_buf
*agbp
; /* buffer for ag. freespace struct */
212 struct xfs_agf
*agf
; /* ag. freespace structure */
213 xfs_agblock_t agflen
; /* native ag. freespace length */
214 int sblock_ok
; /* block passes checks */
216 agbp
= cur
->bc_private
.a
.agbp
;
217 agf
= XFS_BUF_TO_AGF(agbp
);
218 agflen
= be32_to_cpu(agf
->agf_length
);
220 be32_to_cpu(block
->bb_magic
) == xfs_magics
[cur
->bc_btnum
] &&
221 be16_to_cpu(block
->bb_level
) == level
&&
222 be16_to_cpu(block
->bb_numrecs
) <=
223 cur
->bc_ops
->get_maxrecs(cur
, level
) &&
224 (be32_to_cpu(block
->bb_leftsib
) == NULLAGBLOCK
||
225 be32_to_cpu(block
->bb_leftsib
) < agflen
) &&
227 (be32_to_cpu(block
->bb_rightsib
) == NULLAGBLOCK
||
228 be32_to_cpu(block
->bb_rightsib
) < agflen
) &&
230 if (unlikely(XFS_TEST_ERROR(!sblock_ok
, cur
->bc_mp
,
231 XFS_ERRTAG_BTREE_CHECK_SBLOCK
,
232 XFS_RANDOM_BTREE_CHECK_SBLOCK
))) {
234 xfs_buftrace("SBTREE ERROR", bp
);
235 XFS_ERROR_REPORT("xfs_btree_check_sblock", XFS_ERRLEVEL_LOW
,
237 return XFS_ERROR(EFSCORRUPTED
);
243 * Debug routine: check that block header is ok.
246 xfs_btree_check_block(
247 struct xfs_btree_cur
*cur
, /* btree cursor */
248 struct xfs_btree_block
*block
, /* generic btree block pointer */
249 int level
, /* level of the btree block */
250 struct xfs_buf
*bp
) /* buffer containing block, if any */
252 if (cur
->bc_flags
& XFS_BTREE_LONG_PTRS
) {
253 return xfs_btree_check_lblock(cur
,
254 (struct xfs_btree_lblock
*)block
, level
, bp
);
256 return xfs_btree_check_sblock(cur
,
257 (struct xfs_btree_sblock
*)block
, level
, bp
);
262 * Check that (long) pointer is ok.
264 int /* error (0 or EFSCORRUPTED) */
265 xfs_btree_check_lptr(
266 struct xfs_btree_cur
*cur
, /* btree cursor */
267 xfs_dfsbno_t bno
, /* btree block disk address */
268 int level
) /* btree block level */
270 XFS_WANT_CORRUPTED_RETURN(
273 XFS_FSB_SANITY_CHECK(cur
->bc_mp
, bno
));
278 * Check that (short) pointer is ok.
280 int /* error (0 or EFSCORRUPTED) */
281 xfs_btree_check_sptr(
282 struct xfs_btree_cur
*cur
, /* btree cursor */
283 xfs_agblock_t bno
, /* btree block disk address */
284 int level
) /* btree block level */
286 xfs_agblock_t agblocks
= cur
->bc_mp
->m_sb
.sb_agblocks
;
288 XFS_WANT_CORRUPTED_RETURN(
290 bno
!= NULLAGBLOCK
&&
297 * Check that block ptr is ok.
299 int /* error (0 or EFSCORRUPTED) */
301 struct xfs_btree_cur
*cur
, /* btree cursor */
302 union xfs_btree_ptr
*ptr
, /* btree block disk address */
303 int index
, /* offset from ptr to check */
304 int level
) /* btree block level */
306 if (cur
->bc_flags
& XFS_BTREE_LONG_PTRS
) {
307 return xfs_btree_check_lptr(cur
,
308 be64_to_cpu((&ptr
->l
)[index
]), level
);
310 return xfs_btree_check_sptr(cur
,
311 be32_to_cpu((&ptr
->s
)[index
]), level
);
316 * Delete the btree cursor.
319 xfs_btree_del_cursor(
320 xfs_btree_cur_t
*cur
, /* btree cursor */
321 int error
) /* del because of error */
323 int i
; /* btree level */
326 * Clear the buffer pointers, and release the buffers.
327 * If we're doing this in the face of an error, we
328 * need to make sure to inspect all of the entries
329 * in the bc_bufs array for buffers to be unlocked.
330 * This is because some of the btree code works from
331 * level n down to 0, and if we get an error along
332 * the way we won't have initialized all the entries
335 for (i
= 0; i
< cur
->bc_nlevels
; i
++) {
337 xfs_btree_setbuf(cur
, i
, NULL
);
342 * Can't free a bmap cursor without having dealt with the
343 * allocated indirect blocks' accounting.
345 ASSERT(cur
->bc_btnum
!= XFS_BTNUM_BMAP
||
346 cur
->bc_private
.b
.allocated
== 0);
350 kmem_zone_free(xfs_btree_cur_zone
, cur
);
354 * Duplicate the btree cursor.
355 * Allocate a new one, copy the record, re-get the buffers.
358 xfs_btree_dup_cursor(
359 xfs_btree_cur_t
*cur
, /* input cursor */
360 xfs_btree_cur_t
**ncur
) /* output cursor */
362 xfs_buf_t
*bp
; /* btree block's buffer pointer */
363 int error
; /* error return value */
364 int i
; /* level number of btree block */
365 xfs_mount_t
*mp
; /* mount structure for filesystem */
366 xfs_btree_cur_t
*new; /* new cursor value */
367 xfs_trans_t
*tp
; /* transaction pointer, can be NULL */
373 * Allocate a new cursor like the old one.
375 new = cur
->bc_ops
->dup_cursor(cur
);
378 * Copy the record currently in the cursor.
380 new->bc_rec
= cur
->bc_rec
;
383 * For each level current, re-get the buffer and copy the ptr value.
385 for (i
= 0; i
< new->bc_nlevels
; i
++) {
386 new->bc_ptrs
[i
] = cur
->bc_ptrs
[i
];
387 new->bc_ra
[i
] = cur
->bc_ra
[i
];
388 if ((bp
= cur
->bc_bufs
[i
])) {
389 if ((error
= xfs_trans_read_buf(mp
, tp
, mp
->m_ddev_targp
,
390 XFS_BUF_ADDR(bp
), mp
->m_bsize
, 0, &bp
))) {
391 xfs_btree_del_cursor(new, error
);
395 new->bc_bufs
[i
] = bp
;
397 ASSERT(!XFS_BUF_GETERROR(bp
));
399 new->bc_bufs
[i
] = NULL
;
406 * Get a the root block which is stored in the inode.
408 * For now this btree implementation assumes the btree root is always
409 * stored in the if_broot field of an inode fork.
411 STATIC
struct xfs_btree_block
*
413 struct xfs_btree_cur
*cur
)
415 struct xfs_ifork
*ifp
;
417 ifp
= XFS_IFORK_PTR(cur
->bc_private
.b
.ip
, cur
->bc_private
.b
.whichfork
);
418 return (struct xfs_btree_block
*)ifp
->if_broot
;
422 * Retrieve the block pointer from the cursor at the given level.
423 * This may be an inode btree root or from a buffer.
425 STATIC
struct xfs_btree_block
* /* generic btree block pointer */
427 struct xfs_btree_cur
*cur
, /* btree cursor */
428 int level
, /* level in btree */
429 struct xfs_buf
**bpp
) /* buffer containing the block */
431 if ((cur
->bc_flags
& XFS_BTREE_ROOT_IN_INODE
) &&
432 (level
== cur
->bc_nlevels
- 1)) {
434 return xfs_btree_get_iroot(cur
);
437 *bpp
= cur
->bc_bufs
[level
];
438 return XFS_BUF_TO_BLOCK(*bpp
);
442 * Get a buffer for the block, return it with no data read.
443 * Long-form addressing.
445 xfs_buf_t
* /* buffer for fsbno */
447 xfs_mount_t
*mp
, /* file system mount point */
448 xfs_trans_t
*tp
, /* transaction pointer */
449 xfs_fsblock_t fsbno
, /* file system block number */
450 uint lock
) /* lock flags for get_buf */
452 xfs_buf_t
*bp
; /* buffer pointer (return value) */
453 xfs_daddr_t d
; /* real disk block address */
455 ASSERT(fsbno
!= NULLFSBLOCK
);
456 d
= XFS_FSB_TO_DADDR(mp
, fsbno
);
457 bp
= xfs_trans_get_buf(tp
, mp
->m_ddev_targp
, d
, mp
->m_bsize
, lock
);
459 ASSERT(!XFS_BUF_GETERROR(bp
));
464 * Get a buffer for the block, return it with no data read.
465 * Short-form addressing.
467 xfs_buf_t
* /* buffer for agno/agbno */
469 xfs_mount_t
*mp
, /* file system mount point */
470 xfs_trans_t
*tp
, /* transaction pointer */
471 xfs_agnumber_t agno
, /* allocation group number */
472 xfs_agblock_t agbno
, /* allocation group block number */
473 uint lock
) /* lock flags for get_buf */
475 xfs_buf_t
*bp
; /* buffer pointer (return value) */
476 xfs_daddr_t d
; /* real disk block address */
478 ASSERT(agno
!= NULLAGNUMBER
);
479 ASSERT(agbno
!= NULLAGBLOCK
);
480 d
= XFS_AGB_TO_DADDR(mp
, agno
, agbno
);
481 bp
= xfs_trans_get_buf(tp
, mp
->m_ddev_targp
, d
, mp
->m_bsize
, lock
);
483 ASSERT(!XFS_BUF_GETERROR(bp
));
488 * Check for the cursor referring to the last block at the given level.
490 int /* 1=is last block, 0=not last block */
491 xfs_btree_islastblock(
492 xfs_btree_cur_t
*cur
, /* btree cursor */
493 int level
) /* level to check */
495 xfs_btree_block_t
*block
; /* generic btree block pointer */
496 xfs_buf_t
*bp
; /* buffer containing block */
498 block
= xfs_btree_get_block(cur
, level
, &bp
);
499 xfs_btree_check_block(cur
, block
, level
, bp
);
500 if (cur
->bc_flags
& XFS_BTREE_LONG_PTRS
)
501 return be64_to_cpu(block
->bb_u
.l
.bb_rightsib
) == NULLDFSBNO
;
503 return be32_to_cpu(block
->bb_u
.s
.bb_rightsib
) == NULLAGBLOCK
;
507 * Change the cursor to point to the first record at the given level.
508 * Other levels are unaffected.
510 int /* success=1, failure=0 */
512 xfs_btree_cur_t
*cur
, /* btree cursor */
513 int level
) /* level to change */
515 xfs_btree_block_t
*block
; /* generic btree block pointer */
516 xfs_buf_t
*bp
; /* buffer containing block */
519 * Get the block pointer for this level.
521 block
= xfs_btree_get_block(cur
, level
, &bp
);
522 xfs_btree_check_block(cur
, block
, level
, bp
);
524 * It's empty, there is no such record.
526 if (!block
->bb_numrecs
)
529 * Set the ptr value to 1, that's the first record/key.
531 cur
->bc_ptrs
[level
] = 1;
536 * Change the cursor to point to the last record in the current block
537 * at the given level. Other levels are unaffected.
539 int /* success=1, failure=0 */
541 xfs_btree_cur_t
*cur
, /* btree cursor */
542 int level
) /* level to change */
544 xfs_btree_block_t
*block
; /* generic btree block pointer */
545 xfs_buf_t
*bp
; /* buffer containing block */
548 * Get the block pointer for this level.
550 block
= xfs_btree_get_block(cur
, level
, &bp
);
551 xfs_btree_check_block(cur
, block
, level
, bp
);
553 * It's empty, there is no such record.
555 if (!block
->bb_numrecs
)
558 * Set the ptr value to numrecs, that's the last record/key.
560 cur
->bc_ptrs
[level
] = be16_to_cpu(block
->bb_numrecs
);
565 * Compute first and last byte offsets for the fields given.
566 * Interprets the offsets table, which contains struct field offsets.
570 __int64_t fields
, /* bitmask of fields */
571 const short *offsets
, /* table of field offsets */
572 int nbits
, /* number of bits to inspect */
573 int *first
, /* output: first byte offset */
574 int *last
) /* output: last byte offset */
576 int i
; /* current bit number */
577 __int64_t imask
; /* mask for current bit number */
581 * Find the lowest bit, so the first byte offset.
583 for (i
= 0, imask
= 1LL; ; i
++, imask
<<= 1) {
584 if (imask
& fields
) {
590 * Find the highest bit, so the last byte offset.
592 for (i
= nbits
- 1, imask
= 1LL << i
; ; i
--, imask
>>= 1) {
593 if (imask
& fields
) {
594 *last
= offsets
[i
+ 1] - 1;
601 * Get a buffer for the block, return it read in.
602 * Long-form addressing.
606 xfs_mount_t
*mp
, /* file system mount point */
607 xfs_trans_t
*tp
, /* transaction pointer */
608 xfs_fsblock_t fsbno
, /* file system block number */
609 uint lock
, /* lock flags for read_buf */
610 xfs_buf_t
**bpp
, /* buffer for fsbno */
611 int refval
) /* ref count value for buffer */
613 xfs_buf_t
*bp
; /* return value */
614 xfs_daddr_t d
; /* real disk block address */
617 ASSERT(fsbno
!= NULLFSBLOCK
);
618 d
= XFS_FSB_TO_DADDR(mp
, fsbno
);
619 if ((error
= xfs_trans_read_buf(mp
, tp
, mp
->m_ddev_targp
, d
,
620 mp
->m_bsize
, lock
, &bp
))) {
623 ASSERT(!bp
|| !XFS_BUF_GETERROR(bp
));
625 XFS_BUF_SET_VTYPE_REF(bp
, B_FS_MAP
, refval
);
632 * Get a buffer for the block, return it read in.
633 * Short-form addressing.
637 xfs_mount_t
*mp
, /* file system mount point */
638 xfs_trans_t
*tp
, /* transaction pointer */
639 xfs_agnumber_t agno
, /* allocation group number */
640 xfs_agblock_t agbno
, /* allocation group block number */
641 uint lock
, /* lock flags for read_buf */
642 xfs_buf_t
**bpp
, /* buffer for agno/agbno */
643 int refval
) /* ref count value for buffer */
645 xfs_buf_t
*bp
; /* return value */
646 xfs_daddr_t d
; /* real disk block address */
649 ASSERT(agno
!= NULLAGNUMBER
);
650 ASSERT(agbno
!= NULLAGBLOCK
);
651 d
= XFS_AGB_TO_DADDR(mp
, agno
, agbno
);
652 if ((error
= xfs_trans_read_buf(mp
, tp
, mp
->m_ddev_targp
, d
,
653 mp
->m_bsize
, lock
, &bp
))) {
656 ASSERT(!bp
|| !XFS_BUF_GETERROR(bp
));
659 case XFS_ALLOC_BTREE_REF
:
660 XFS_BUF_SET_VTYPE_REF(bp
, B_FS_MAP
, refval
);
662 case XFS_INO_BTREE_REF
:
663 XFS_BUF_SET_VTYPE_REF(bp
, B_FS_INOMAP
, refval
);
672 * Read-ahead the block, don't wait for it, don't return a buffer.
673 * Long-form addressing.
677 xfs_btree_reada_bufl(
678 xfs_mount_t
*mp
, /* file system mount point */
679 xfs_fsblock_t fsbno
, /* file system block number */
680 xfs_extlen_t count
) /* count of filesystem blocks */
684 ASSERT(fsbno
!= NULLFSBLOCK
);
685 d
= XFS_FSB_TO_DADDR(mp
, fsbno
);
686 xfs_baread(mp
->m_ddev_targp
, d
, mp
->m_bsize
* count
);
690 * Read-ahead the block, don't wait for it, don't return a buffer.
691 * Short-form addressing.
695 xfs_btree_reada_bufs(
696 xfs_mount_t
*mp
, /* file system mount point */
697 xfs_agnumber_t agno
, /* allocation group number */
698 xfs_agblock_t agbno
, /* allocation group block number */
699 xfs_extlen_t count
) /* count of filesystem blocks */
703 ASSERT(agno
!= NULLAGNUMBER
);
704 ASSERT(agbno
!= NULLAGBLOCK
);
705 d
= XFS_AGB_TO_DADDR(mp
, agno
, agbno
);
706 xfs_baread(mp
->m_ddev_targp
, d
, mp
->m_bsize
* count
);
710 xfs_btree_readahead_lblock(
711 struct xfs_btree_cur
*cur
,
713 struct xfs_btree_block
*block
)
716 xfs_fsblock_t left
= be64_to_cpu(block
->bb_u
.l
.bb_leftsib
);
717 xfs_fsblock_t right
= be64_to_cpu(block
->bb_u
.l
.bb_rightsib
);
719 if ((lr
& XFS_BTCUR_LEFTRA
) && left
!= NULLDFSBNO
) {
720 xfs_btree_reada_bufl(cur
->bc_mp
, left
, 1);
724 if ((lr
& XFS_BTCUR_RIGHTRA
) && right
!= NULLDFSBNO
) {
725 xfs_btree_reada_bufl(cur
->bc_mp
, right
, 1);
733 xfs_btree_readahead_sblock(
734 struct xfs_btree_cur
*cur
,
736 struct xfs_btree_block
*block
)
739 xfs_agblock_t left
= be32_to_cpu(block
->bb_u
.s
.bb_leftsib
);
740 xfs_agblock_t right
= be32_to_cpu(block
->bb_u
.s
.bb_rightsib
);
743 if ((lr
& XFS_BTCUR_LEFTRA
) && left
!= NULLAGBLOCK
) {
744 xfs_btree_reada_bufs(cur
->bc_mp
, cur
->bc_private
.a
.agno
,
749 if ((lr
& XFS_BTCUR_RIGHTRA
) && right
!= NULLAGBLOCK
) {
750 xfs_btree_reada_bufs(cur
->bc_mp
, cur
->bc_private
.a
.agno
,
759 * Read-ahead btree blocks, at the given level.
760 * Bits in lr are set from XFS_BTCUR_{LEFT,RIGHT}RA.
764 struct xfs_btree_cur
*cur
, /* btree cursor */
765 int lev
, /* level in btree */
766 int lr
) /* left/right bits */
768 struct xfs_btree_block
*block
;
771 * No readahead needed if we are at the root level and the
772 * btree root is stored in the inode.
774 if ((cur
->bc_flags
& XFS_BTREE_ROOT_IN_INODE
) &&
775 (lev
== cur
->bc_nlevels
- 1))
778 if ((cur
->bc_ra
[lev
] | lr
) == cur
->bc_ra
[lev
])
781 cur
->bc_ra
[lev
] |= lr
;
782 block
= XFS_BUF_TO_BLOCK(cur
->bc_bufs
[lev
]);
784 if (cur
->bc_flags
& XFS_BTREE_LONG_PTRS
)
785 return xfs_btree_readahead_lblock(cur
, lr
, block
);
786 return xfs_btree_readahead_sblock(cur
, lr
, block
);
790 * Set the buffer for level "lev" in the cursor to bp, releasing
791 * any previous buffer.
795 xfs_btree_cur_t
*cur
, /* btree cursor */
796 int lev
, /* level in btree */
797 xfs_buf_t
*bp
) /* new buffer to set */
799 xfs_btree_block_t
*b
; /* btree block */
800 xfs_buf_t
*obp
; /* old buffer pointer */
802 obp
= cur
->bc_bufs
[lev
];
804 xfs_trans_brelse(cur
->bc_tp
, obp
);
805 cur
->bc_bufs
[lev
] = bp
;
809 b
= XFS_BUF_TO_BLOCK(bp
);
810 if (cur
->bc_flags
& XFS_BTREE_LONG_PTRS
) {
811 if (be64_to_cpu(b
->bb_u
.l
.bb_leftsib
) == NULLDFSBNO
)
812 cur
->bc_ra
[lev
] |= XFS_BTCUR_LEFTRA
;
813 if (be64_to_cpu(b
->bb_u
.l
.bb_rightsib
) == NULLDFSBNO
)
814 cur
->bc_ra
[lev
] |= XFS_BTCUR_RIGHTRA
;
816 if (be32_to_cpu(b
->bb_u
.s
.bb_leftsib
) == NULLAGBLOCK
)
817 cur
->bc_ra
[lev
] |= XFS_BTCUR_LEFTRA
;
818 if (be32_to_cpu(b
->bb_u
.s
.bb_rightsib
) == NULLAGBLOCK
)
819 cur
->bc_ra
[lev
] |= XFS_BTCUR_RIGHTRA
;