Lines Matching refs:block

121 	struct xfs_btree_block	*block,
128 if (!uuid_equal(&block->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid))
130 if (block->bb_u.l.bb_blkno !=
133 if (block->bb_u.l.bb_pad != cpu_to_be32(0))
137 if (be32_to_cpu(block->bb_magic) != xfs_btree_magic(mp, cur->bc_ops))
139 if (be16_to_cpu(block->bb_level) != level)
141 if (be16_to_cpu(block->bb_numrecs) >
149 * Check a long btree block header. Return the address of the failing check,
155 struct xfs_btree_block *block,
163 fa = __xfs_btree_check_lblock_hdr(cur, block, level, bp);
168 * For inode-rooted btrees, the root block sits in the inode fork. In
169 * that case bp is NULL, and the block must not have any siblings.
172 if (block->bb_u.l.bb_leftsib != cpu_to_be64(NULLFSBLOCK))
174 if (block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK))
181 block->bb_u.l.bb_leftsib);
184 block->bb_u.l.bb_rightsib);
189 * Check an in-memory btree block header. Return the address of the failing
195 struct xfs_btree_block *block,
203 fa = __xfs_btree_check_lblock_hdr(cur, block, level, bp);
209 block->bb_u.l.bb_leftsib);
212 block->bb_u.l.bb_rightsib);
217 * Check a short btree block header. Return the address of the failing check,
223 struct xfs_btree_block *block,
233 if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
235 if (block->bb_u.s.bb_blkno != cpu_to_be64(xfs_buf_daddr(bp)))
239 if (be32_to_cpu(block->bb_magic) != xfs_btree_magic(mp, cur->bc_ops))
241 if (be16_to_cpu(block->bb_level) != level)
243 if (be16_to_cpu(block->bb_numrecs) >
249 block->bb_u.s.bb_leftsib);
252 block->bb_u.s.bb_rightsib);
257 * Internal btree block check.
259 * Return NULL if the block is ok or the address of the failed check otherwise.
264 struct xfs_btree_block *block,
270 return __xfs_btree_check_memblock(cur, block, level, bp);
272 return __xfs_btree_check_agblock(cur, block, level, bp);
274 return __xfs_btree_check_fsblock(cur, block, level, bp);
289 * Debug routine: check that block header is ok.
294 struct xfs_btree_block *block, /* generic btree block pointer */
295 int level, /* level of the btree block */
296 struct xfs_buf *bp) /* buffer containing block, if any */
301 fa = __xfs_btree_check_block(cur, block, level, bp);
392 * Calculate CRC on the whole btree block and stuff it into the
403 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
409 block->bb_u.l.bb_lsn = cpu_to_be64(bip->bli_item.li_lsn);
417 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
421 if (!xfs_log_check_lsn(mp, be64_to_cpu(block->bb_u.l.bb_lsn)))
430 * Calculate CRC on the whole btree block and stuff it into the
441 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
447 block->bb_u.s.bb_lsn = cpu_to_be64(bip->bli_item.li_lsn);
455 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
459 if (!xfs_log_check_lsn(mp, be64_to_cpu(block->bb_u.s.bb_lsn)))
477 * Don't allow block freeing for a staging cursor, because staging
553 /* Return the block size (in units of 512b sectors) for this btree. */
626 * XFS btree block layout and addressing:
631 * the values. A non-leaf block also starts with the same header, and
644 * and comes in different versions for short (32bit) and long (64bit) block
646 * and opaque to the btree core. The block pointers are simple disk endian
650 * into a btree block (xfs_btree_*_offset) or return a pointer to the given
652 * inside the btree block is done using indices starting at one, not zero!
658 * indexing the lowest key available in the block(s) below (the same behavior
660 * available in the block(s) below. Because records are /not/ sorted by the
661 * highest key, all leaf block updates require us to compute the highest key
688 * Now say we want to map block (B+D) into file A at offset (C+D). Ideally,
700 * Return size of the btree block header for this btree instance.
715 * Calculate offset of the n-th record in a btree block.
727 * Calculate offset of the n-th key in a btree block.
739 * Calculate offset of the n-th high key in a btree block.
751 * Calculate offset of the n-th block pointer in a btree block.
765 * Return a pointer to the n-th record in the btree block.
771 struct xfs_btree_block *block)
774 ((char *)block + xfs_btree_rec_offset(cur, n));
778 * Return a pointer to the n-th key in the btree block.
784 struct xfs_btree_block *block)
787 ((char *)block + xfs_btree_key_offset(cur, n));
791 * Return a pointer to the n-th high key in the btree block.
797 struct xfs_btree_block *block)
800 ((char *)block + xfs_btree_high_key_offset(cur, n));
804 * Return a pointer to the n-th block pointer in the btree block.
810 struct xfs_btree_block *block)
812 int level = xfs_btree_get_level(block);
814 ASSERT(block->bb_level != 0);
817 ((char *)block + xfs_btree_ptr_offset(cur, n, level));
832 * Get the root block which is stored in the inode.
847 * Retrieve the block pointer from the cursor at the given level.
850 struct xfs_btree_block * /* generic btree block pointer */
854 struct xfs_buf **bpp) /* buffer containing the block */
874 struct xfs_btree_block *block; /* generic btree block pointer */
875 struct xfs_buf *bp; /* buffer containing block */
878 * Get the block pointer for this level.
880 block = xfs_btree_get_block(cur, level, &bp);
881 if (xfs_btree_check_block(cur, block, level, bp))
886 if (!block->bb_numrecs)
896 * Change the cursor to point to the last record in the current block
904 struct xfs_btree_block *block; /* generic btree block pointer */
905 struct xfs_buf *bp; /* buffer containing block */
908 * Get the block pointer for this level.
910 block = xfs_btree_get_block(cur, level, &bp);
911 if (xfs_btree_check_block(cur, block, level, bp))
916 if (!block->bb_numrecs)
921 cur->bc_levels[level].ptr = be16_to_cpu(block->bb_numrecs);
965 struct xfs_btree_block *block)
968 xfs_fsblock_t left = be64_to_cpu(block->bb_u.l.bb_leftsib);
969 xfs_fsblock_t right = be64_to_cpu(block->bb_u.l.bb_rightsib);
991 struct xfs_btree_block *block)
994 xfbno_t left = be64_to_cpu(block->bb_u.l.bb_leftsib);
995 xfbno_t right = be64_to_cpu(block->bb_u.l.bb_rightsib);
1017 struct xfs_btree_block *block)
1021 xfs_agblock_t left = be32_to_cpu(block->bb_u.s.bb_leftsib);
1022 xfs_agblock_t right = be32_to_cpu(block->bb_u.s.bb_rightsib);
1052 struct xfs_btree_block *block;
1065 block = XFS_BUF_TO_BLOCK(cur->bc_levels[lev].bp);
1069 return xfs_btree_readahead_agblock(cur, lr, block);
1071 return xfs_btree_readahead_fsblock(cur, lr, block);
1073 return xfs_btree_readahead_memblock(cur, lr, block);
1138 struct xfs_btree_block *b; /* btree block */
1198 struct xfs_btree_block *block,
1206 ptr->l = block->bb_u.l.bb_rightsib;
1208 ptr->l = block->bb_u.l.bb_leftsib;
1211 ptr->s = block->bb_u.s.bb_rightsib;
1213 ptr->s = block->bb_u.s.bb_leftsib;
1220 struct xfs_btree_block *block,
1228 block->bb_u.l.bb_rightsib = ptr->l;
1230 block->bb_u.l.bb_leftsib = ptr->l;
1233 block->bb_u.s.bb_rightsib = ptr->s;
1235 block->bb_u.s.bb_leftsib = ptr->s;
1282 struct xfs_btree_block *block,
1288 __xfs_btree_init_block(mp, block, ops, XFS_BUF_DADDR_NULL, level,
1342 struct xfs_btree_block *block,
1352 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB);
1391 struct xfs_btree_block **block,
1406 *block = XFS_BUF_TO_BLOCK(*bpp);
1412 * the block pointer within the buffer.
1419 struct xfs_btree_block **block,
1441 *block = XFS_BUF_TO_BLOCK(*bpp);
1446 * Copy keys from one btree block to another.
1460 * Copy records from one btree block to another.
1474 * Copy block pointers from one btree block to another.
1488 * Shift keys one index left/right inside a single btree block.
1507 * Shift records one index left/right inside a single btree block.
1526 * Shift block pointers one index left/right inside a single btree block.
1545 * Log key values from the btree block.
1567 * Log record values from the btree block.
1585 * Log block pointer fields from a btree block (nonleaf).
1590 struct xfs_buf *bp, /* buffer containing btree block */
1596 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
1597 int level = xfs_btree_get_level(block);
1611 * Log fields from a btree block header.
1616 struct xfs_buf *bp, /* buffer containing btree block */
1655 * block but instead recreate it during log
1688 struct xfs_btree_block *block;
1699 /* Get a pointer to the btree block. */
1700 block = xfs_btree_get_block(cur, level, &bp);
1703 error = xfs_btree_check_block(cur, block, level, bp);
1708 /* We're done if we remain in the block after the increment. */
1709 if (++cur->bc_levels[level].ptr <= xfs_btree_get_numrecs(block))
1713 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB);
1721 * Stop when we don't go off the right edge of a block.
1724 block = xfs_btree_get_block(cur, lev, &bp);
1727 error = xfs_btree_check_block(cur, block, lev, bp);
1732 if (++cur->bc_levels[lev].ptr <= xfs_btree_get_numrecs(block))
1735 /* Read-ahead the right block for the next loop. */
1757 for (block = xfs_btree_get_block(cur, lev, &bp); lev > level; ) {
1760 ptrp = xfs_btree_ptr_addr(cur, cur->bc_levels[lev].ptr, block);
1762 error = xfs_btree_read_buf_block(cur, ptrp, 0, &block, &bp);
1791 struct xfs_btree_block *block;
1802 /* We're done if we remain in the block after the decrement. */
1806 /* Get a pointer to the btree block. */
1807 block = xfs_btree_get_block(cur, level, &bp);
1810 error = xfs_btree_check_block(cur, block, level, bp);
1816 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_LEFTSIB);
1824 * Stop when we don't go off the left edge of a block.
1829 /* Read-ahead the left block for the next loop. */
1851 for (block = xfs_btree_get_block(cur, lev, &bp); lev > level; ) {
1854 ptrp = xfs_btree_ptr_addr(cur, cur->bc_levels[lev].ptr, block);
1856 error = xfs_btree_read_buf_block(cur, ptrp, 0, &block, &bp);
1860 cur->bc_levels[lev].ptr = xfs_btree_get_numrecs(block);
1875 * Check the btree block owner now that we have the context to know who the
1881 struct xfs_btree_block *block)
1891 if (be64_to_cpu(block->bb_u.l.bb_owner) != owner)
1894 if (be32_to_cpu(block->bb_u.s.bb_owner) != owner)
1905 const union xfs_btree_ptr *pp, /* ptr to btree block */
1906 struct xfs_btree_block **blkp) /* return btree block */
1908 struct xfs_buf *bp; /* buffer pointer for btree block */
1912 /* special case the root block if in an inode */
1970 struct xfs_btree_block *block,
1975 xfs_btree_rec_addr(cur, keyno, block));
1979 return xfs_btree_key_addr(cur, keyno, block);
1983 * Initialize a pointer to the root block.
2013 struct xfs_btree_block *block; /* current btree block */
2018 union xfs_btree_ptr *pp; /* ptr to btree block */
2019 union xfs_btree_ptr ptr; /* ptr to btree block */
2029 block = NULL;
2039 * on the lookup record, then follow the corresponding block
2043 /* Get the block we need to do the lookup on. */
2044 error = xfs_btree_lookup_get_block(cur, level, pp, &block);
2051 * know we need to use the first entry in this block.
2055 /* Otherwise search this block. Do a binary search. */
2062 high = xfs_btree_get_numrecs(block);
2068 cur->bc_mp, block,
2069 sizeof(*block));
2079 /* Binary search the block. */
2091 keyno, block, &key);
2111 * by getting the block number and filling in the cursor.
2120 pp = xfs_btree_ptr_addr(cur, keyno, block);
2134 * If ge search and we went off the end of the block, but it's
2135 * not the last block, we're in the wrong block.
2137 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB);
2139 keyno > xfs_btree_get_numrecs(block) &&
2159 if (keyno == 0 || keyno > xfs_btree_get_numrecs(block))
2182 /* Determine the low (and high if overlapped) keys of a leaf block */
2186 struct xfs_btree_block *block,
2195 rec = xfs_btree_rec_addr(cur, 1, block);
2201 for (n = 2; n <= xfs_btree_get_numrecs(block); n++) {
2202 rec = xfs_btree_rec_addr(cur, n, block);
2213 /* Determine the low (and high if overlapped) keys of a node block */
2217 struct xfs_btree_block *block,
2226 memcpy(key, xfs_btree_key_addr(cur, 1, block),
2229 max_hkey = xfs_btree_high_key_addr(cur, 1, block);
2230 for (n = 2; n <= xfs_btree_get_numrecs(block); n++) {
2231 hkey = xfs_btree_high_key_addr(cur, n, block);
2239 memcpy(key, xfs_btree_key_addr(cur, 1, block),
2244 /* Derive the keys for any btree block. */
2248 struct xfs_btree_block *block,
2251 if (be16_to_cpu(block->bb_level) == 0)
2252 xfs_btree_get_leaf_keys(cur, block, key);
2254 xfs_btree_get_node_keys(cur, block, key);
2258 * Decide if we need to update the parent keys of a btree block. For
2262 * in the block.
2281 struct xfs_btree_block *block,
2303 xfs_btree_get_keys(cur, block, lkey);
2308 block = xfs_btree_get_block(cur, level, &bp);
2311 error = xfs_btree_check_block(cur, block, level, bp);
2316 nlkey = xfs_btree_key_addr(cur, ptr, block);
2317 nhkey = xfs_btree_high_key_addr(cur, ptr, block);
2326 xfs_btree_get_node_keys(cur, block, lkey);
2339 struct xfs_btree_block *block;
2341 block = xfs_btree_get_block(cur, level, &bp);
2342 return __xfs_btree_updkeys(cur, level, block, bp, true);
2353 struct xfs_btree_block *block;
2361 block = xfs_btree_get_block(cur, level, &bp);
2363 return __xfs_btree_updkeys(cur, level, block, bp, false);
2369 * at the first entry in the block.
2371 xfs_btree_get_keys(cur, block, &key);
2376 block = xfs_btree_get_block(cur, level, &bp);
2378 error = xfs_btree_check_block(cur, block, level, bp);
2383 kp = xfs_btree_key_addr(cur, ptr, block);
2401 struct xfs_btree_block *block;
2407 /* Pick up the current block. */
2408 block = xfs_btree_get_block(cur, 0, &bp);
2411 error = xfs_btree_check_block(cur, block, 0, bp);
2417 rp = xfs_btree_rec_addr(cur, ptr, block);
2427 if (xfs_btree_is_lastrec(cur, block, 0)) {
2428 cur->bc_ops->update_lastrec(cur, block, rec,
2456 struct xfs_btree_block *left; /* left btree block */
2459 struct xfs_btree_block *right; /* right btree block */
2472 /* Set up variables for this block as "right". */
2517 * If non-leaf, copy a key and a ptr to the left block.
2518 * Log the changes to the left block.
2594 * block on the left.
2611 /* Update the parent high keys of the left block, if needed. */
2619 /* Update the parent keys of the right block. */
2653 struct xfs_btree_block *left; /* left btree block */
2655 struct xfs_btree_block *right; /* right btree block */
2657 union xfs_btree_ptr rptr; /* right block pointer */
2667 /* Set up variables for this block as "left". */
2703 * Make a hole at the start of the right neighbor block, then
2704 * copy the last left block entry to the hole.
2765 * block on the right.
2781 /* Update the parent high keys of the left block, if needed. */
2788 /* Update the parent keys of the right block. */
2820 * Don't allow block allocation for a staging cursor, because staging
2837 * Split cur/level block in half.
2838 * Return new block number and the key to its first
2850 union xfs_btree_ptr lptr; /* left sibling block ptr */
2852 struct xfs_btree_block *left; /* left btree block */
2853 union xfs_btree_ptr rptr; /* right sibling block ptr */
2855 struct xfs_btree_block *right; /* right btree block */
2858 struct xfs_btree_block *rrblock; /* right-right btree block */
2867 /* Set up left block (current one). */
2878 /* Allocate the new block. If we can't do it, we're toast. Give up. */
2886 /* Set up the new block as "right". */
2891 /* Fill in the btree header for the new right block. */
2895 * Split the entries between the old and the new block evenly.
2897 * each new block will have the same number of entries.
2913 * Copy btree block entries from the left block over to the
2914 * new block, the right. Update the right block and log the
2935 /* Copy the keys & pointers to the new block. */
2942 /* Stash the keys of the new block for later insertion. */
2952 /* Copy records to the new block. */
2956 /* Stash the keys of the new block for later insertion. */
2961 * Find the left block number by looking in the buffer.
2973 * If there's a block to the new block's right, make that block
2985 /* Update the parent high keys of the left block, if needed. */
2993 * If the cursor is really in the right block, move it there.
3003 * the right block, no matter where this cursor was.
3051 * temporarily to ensure that we don't block waiting for memory reclaim
3080 * AGF <> worker queue deadlocks if the BMBT block allocation has to lock new
3127 * Copy the old inode root contents into a real block and make the
3137 struct xfs_btree_block *block; /* btree block */
3138 struct xfs_btree_block *cblock; /* child btree block */
3142 union xfs_btree_ptr *pp; /* pointer to block addr */
3143 union xfs_btree_ptr nptr; /* new block addr */
3154 block = xfs_btree_get_iroot(cur);
3155 pp = xfs_btree_ptr_addr(cur, 1, block);
3157 /* Allocate the new block. If we can't do it, we're toast. Give up. */
3166 /* Copy the root into a real block. */
3175 memcpy(cblock, block, xfs_btree_block_len(cur));
3184 be16_add_cpu(&block->bb_level, 1);
3185 xfs_btree_set_numrecs(block, 1);
3190 kp = xfs_btree_key_addr(cur, 1, block);
3247 * Allocate a new root block, fill it in.
3254 struct xfs_btree_block *block; /* one half of the old root block */
3255 struct xfs_buf *bp; /* buffer containing block */
3258 struct xfs_btree_block *left; /* left btree block */
3260 struct xfs_btree_block *new; /* new (root) btree block */
3263 struct xfs_btree_block *right; /* right btree block */
3272 /* Allocate the new block. If we can't do it, we're toast. Give up. */
3280 /* Set up the new block. */
3290 * and the new block generated when it was split. We don't know which
3294 block = xfs_btree_get_block(cur, cur->bc_nlevels - 1, &bp);
3297 error = xfs_btree_check_block(cur, block, cur->bc_nlevels - 1, bp);
3302 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB);
3304 /* Our block is left, pick up the right block. */
3307 left = block;
3314 /* Our block is right, pick up the left block. */
3317 right = block;
3326 /* Fill in the new block's btree header and log it. */
3335 * Get the keys for the left block's keys and put them directly
3336 * in the parent block. Do the same for the right block.
3344 * Get the keys for the left block's records and put them
3345 * directly in the parent block. Do the same for the right
3346 * block.
3380 int numrecs,/* # of recs in block */
3385 union xfs_btree_key *key, /* key of new block */
3394 /* A root block that can be made bigger. */
3398 /* A root block that needs replacing */
3427 * Next, try splitting the current block in half.
3430 * could be in a different block now.
3449 union xfs_btree_ptr *ptrp, /* i/o: block number inserted */
3451 union xfs_btree_key *key, /* i/o: block key for ptrp */
3455 struct xfs_btree_block *block; /* btree block */
3456 struct xfs_buf *bp; /* buffer for block */
3457 union xfs_btree_ptr nptr; /* new block ptr */
3459 union xfs_btree_key nkey; /* new block key */
3473 * root level, allocate a new root block and we're done.
3494 /* Get pointers to the btree buffer and block. */
3495 block = xfs_btree_get_block(cur, level, &bp);
3497 numrecs = xfs_btree_get_numrecs(block);
3500 error = xfs_btree_check_block(cur, block, level, bp);
3508 xfs_btree_rec_addr(cur, ptr, block)));
3511 xfs_btree_key_addr(cur, ptr, block)));
3517 * If the block is full, we can't insert the new entry until we
3518 * make the block un-full.
3529 * The current block may have changed if the block was
3532 block = xfs_btree_get_block(cur, level, &bp);
3533 numrecs = xfs_btree_get_numrecs(block);
3536 error = xfs_btree_check_block(cur, block, level, bp);
3542 * At this point we know there's room for our new entry in the block
3552 kp = xfs_btree_key_addr(cur, ptr, block);
3553 pp = xfs_btree_ptr_addr(cur, ptr, block);
3572 xfs_btree_set_numrecs(block, numrecs);
3578 xfs_btree_key_addr(cur, ptr + 1, block)));
3585 rp = xfs_btree_rec_addr(cur, ptr, block);
3591 xfs_btree_set_numrecs(block, ++numrecs);
3596 xfs_btree_rec_addr(cur, ptr + 1, block)));
3605 * If we just inserted into a new tree block, we have to
3608 * Otherwise we're just updating an existing block (having shoved
3609 * some records into the new tree block), so use the regular key
3613 xfs_btree_get_keys(cur, block, lkey);
3624 if (xfs_btree_is_lastrec(cur, block, level)) {
3625 cur->bc_ops->update_lastrec(cur, block, rec,
3630 * Return the new block number, if any.
3663 union xfs_btree_ptr nptr; /* new block number (split result) */
3666 union xfs_btree_key bkey; /* key of block to insert */
3683 * Stop when we don't get a split block, that must mean that
3734 * Try to merge a non-leaf block back into the inode root.
3737 * killing the old root block. But because we can't just delete the
3738 * inode we have to copy the single block it was pointing to into the
3748 struct xfs_btree_block *block;
3768 * Don't deal with the root block needs to be a leaf case.
3778 block = xfs_btree_get_iroot(cur);
3779 if (xfs_btree_get_numrecs(block) != 1)
3796 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_LEFTSIB);
3798 xfs_btree_get_sibling(cur, block, &ptr, XFS_BB_RIGHTSIB);
3806 block = ifp->if_broot;
3809 be16_add_cpu(&block->bb_numrecs, index);
3810 ASSERT(block->bb_numrecs == cblock->bb_numrecs);
3812 kp = xfs_btree_key_addr(cur, 1, block);
3816 pp = xfs_btree_ptr_addr(cur, 1, block);
3832 be16_add_cpu(&block->bb_level, -1);
3893 * Remove the record from its block then rebalance the tree.
3902 struct xfs_btree_block *block; /* btree block */
3903 union xfs_btree_ptr cptr; /* current block ptr */
3904 struct xfs_buf *bp; /* buffer for block */
3907 union xfs_btree_ptr lptr; /* left sibling block ptr */
3909 struct xfs_btree_block *left; /* left btree block */
3912 union xfs_btree_ptr rptr; /* right sibling block ptr */
3914 struct xfs_btree_block *right; /* right btree block */
3915 struct xfs_btree_block *rrblock; /* right-right btree block */
3930 /* Get the buffer & block containing the record or key/ptr. */
3931 block = xfs_btree_get_block(cur, level, &bp);
3932 numrecs = xfs_btree_get_numrecs(block);
3935 error = xfs_btree_check_block(cur, block, level, bp);
3940 /* Fail if we're off the end of the block. */
3955 lkp = xfs_btree_key_addr(cur, ptr + 1, block);
3956 lpp = xfs_btree_ptr_addr(cur, ptr + 1, block);
3974 xfs_btree_rec_addr(cur, ptr + 1, block),
3981 * Decrement and log the number of entries in the block.
3983 xfs_btree_set_numrecs(block, --numrecs);
3990 if (xfs_btree_is_lastrec(cur, block, level)) {
3991 cur->bc_ops->update_lastrec(cur, block, NULL,
3996 * We're at the root level. First, shrink the root block in-memory.
4022 * pp is still set to the first pointer in the block.
4025 pp = xfs_btree_ptr_addr(cur, 1, block);
4039 * If we deleted the leftmost entry in the block, update the
4049 * If the number of records remaining in the block is at least
4064 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB);
4065 xfs_btree_get_sibling(cur, block, &lptr, XFS_BB_LEFTSIB);
4102 * Move the temp cursor to the last entry in the next block.
4128 /* Grab a pointer to the block. */
4135 /* Grab the current block number, for future use. */
4139 * If right block is full enough so that removing one entry
4149 ASSERT(xfs_btree_get_numrecs(block) >=
4165 * to our block again (last record).
4194 * previous block.
4213 /* Grab a pointer to the block. */
4220 /* Grab the current block number, for future use. */
4224 * If left block is full enough so that removing one entry
4234 ASSERT(xfs_btree_get_numrecs(block) >=
4261 lrecs + xfs_btree_get_numrecs(block) <=
4264 * Set "right" to be the starting block,
4268 right = block;
4275 * If that won't work, see if we can join with the right neighbor block.
4278 rrecs + xfs_btree_get_numrecs(block) <=
4281 * Set "left" to be the starting block,
4285 left = block;
4348 * Fix up the number of records and right block pointer in the
4349 * surviving block, and log it.
4356 /* If there is a right sibling, point it to the remaining block. */
4366 /* Free the deleted block. */
4373 * cursor to the left block, and fix up the index.
4403 * bc_levels[level + 1].ptr points to the old block so that the caller
4485 struct xfs_btree_block *block; /* btree block */
4493 block = xfs_btree_get_block(cur, 0, &bp);
4496 error = xfs_btree_check_block(cur, block, 0, bp);
4504 if (ptr > xfs_btree_get_numrecs(block) || ptr <= 0) {
4512 *recp = xfs_btree_rec_addr(cur, ptr, block);
4517 /* Visit a block in a btree. */
4525 struct xfs_btree_block *block;
4532 block = xfs_btree_get_block(cur, level, &bp);
4534 /* process the block */
4539 /* now read rh sibling block for next iteration */
4540 xfs_btree_get_sibling(cur, block, &rptr, XFS_BB_RIGHTSIB);
4547 * return the same block without checking if the right sibling points
4556 return xfs_btree_lookup_get_block(cur, level, &rptr, &block);
4560 /* Visit every block in a btree. */
4570 struct xfs_btree_block *block = NULL;
4577 /* grab the left hand block */
4578 error = xfs_btree_lookup_get_block(cur, level, &lptr, &block);
4582 /* readahead the left most block for the next level down */
4586 ptr = xfs_btree_ptr_addr(cur, 1, block);
4623 * as the amount of CPU work we have to do before moving to the next block is
4626 * For each btree block that we load, modify the owner appropriately, set the
4646 struct xfs_btree_block *block;
4650 block = xfs_btree_get_block(cur, level, &bp);
4652 if (block->bb_u.l.bb_owner == cpu_to_be64(bbcoi->new_owner))
4654 block->bb_u.l.bb_owner = cpu_to_be64(bbcoi->new_owner);
4656 if (block->bb_u.s.bb_owner == cpu_to_be32(bbcoi->new_owner))
4658 block->bb_u.s.bb_owner = cpu_to_be32(bbcoi->new_owner);
4662 * If the block is a root block hosted in an inode, we might not have a
4665 * block is formatted into the on-disk inode fork. We still change it,
4701 /* Verify the v5 fields of a long-format btree block. */
4708 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
4712 if (!uuid_equal(&block->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid))
4714 if (block->bb_u.l.bb_blkno != cpu_to_be64(xfs_buf_daddr(bp)))
4717 be64_to_cpu(block->bb_u.l.bb_owner) != owner)
4722 /* Verify a long-format btree block. */
4729 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
4736 if (be16_to_cpu(block->bb_numrecs) > max_recs)
4742 block->bb_u.l.bb_leftsib);
4745 block->bb_u.l.bb_rightsib);
4749 /* Verify an in-memory btree block. */
4755 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
4763 if (be16_to_cpu(block->bb_numrecs) > max_recs)
4769 block->bb_u.l.bb_leftsib);
4773 block->bb_u.l.bb_rightsib);
4781 * btree block
4783 * @bp: buffer containing the btree block
4790 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
4795 if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
4797 if (block->bb_u.s.bb_blkno != cpu_to_be64(xfs_buf_daddr(bp)))
4799 if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
4805 * xfs_btree_agblock_verify() -- verify a short-format btree block
4807 * @bp: buffer containing the btree block
4816 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
4823 if (be16_to_cpu(block->bb_numrecs) > max_recs)
4829 block->bb_u.s.bb_leftsib);
4832 block->bb_u.s.bb_rightsib);
4837 * For the given limits on leaf and keyptr records per block, calculate the
4857 * For the given limits on leaf and keyptr records per block, calculate the
4882 * We start by assuming a single level tree consumes a single block, then track
4894 * The root btree block can have fewer than minrecs pointers in it
5003 * As an optimization, we stop scanning a block when we find a low key
5021 struct xfs_btree_block *block;
5030 error = xfs_btree_lookup_get_block(cur, level, &ptr, &block);
5036 error = xfs_btree_check_block(cur, block, level, bp);
5043 block = xfs_btree_get_block(cur, level, &bp);
5047 be16_to_cpu(block->bb_numrecs)) {
5058 block);
5065 * are no more interesting records in this block. Pop
5084 lkp = xfs_btree_key_addr(cur, cur->bc_levels[level].ptr, block);
5086 block);
5087 pp = xfs_btree_ptr_addr(cur, cur->bc_levels[level].ptr, block);
5091 * more interesting keys in this block. Pop up one leaf level
5103 &block);
5109 error = xfs_btree_check_block(cur, block, level, bp);
5122 * block, a subsequent non-error cursor deletion will not release
5372 struct xfs_btree_block *block;
5375 block = xfs_btree_get_block(cur, 0, &bp);
5377 /* There are still records in this block. */
5378 if (cur->bc_levels[0].ptr < xfs_btree_get_numrecs(block))
5383 return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
5385 return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);