aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_ialloc_btree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_ialloc_btree.c')
-rw-r--r--fs/xfs/xfs_ialloc_btree.c98
1 files changed, 7 insertions, 91 deletions
diff --git a/fs/xfs/xfs_ialloc_btree.c b/fs/xfs/xfs_ialloc_btree.c
index 41717da63696..9099a32f9972 100644
--- a/fs/xfs/xfs_ialloc_btree.c
+++ b/fs/xfs/xfs_ialloc_btree.c
@@ -205,7 +205,7 @@ xfs_inobt_delrec(
205 cur->bc_bufs[level] = NULL; 205 cur->bc_bufs[level] = NULL;
206 cur->bc_nlevels--; 206 cur->bc_nlevels--;
207 } else if (level > 0 && 207 } else if (level > 0 &&
208 (error = xfs_inobt_decrement(cur, level, &i))) 208 (error = xfs_btree_decrement(cur, level, &i)))
209 return error; 209 return error;
210 *stat = 1; 210 *stat = 1;
211 return 0; 211 return 0;
@@ -222,7 +222,7 @@ xfs_inobt_delrec(
222 */ 222 */
223 if (numrecs >= XFS_INOBT_BLOCK_MINRECS(level, cur)) { 223 if (numrecs >= XFS_INOBT_BLOCK_MINRECS(level, cur)) {
224 if (level > 0 && 224 if (level > 0 &&
225 (error = xfs_inobt_decrement(cur, level, &i))) 225 (error = xfs_btree_decrement(cur, level, &i)))
226 return error; 226 return error;
227 *stat = 1; 227 *stat = 1;
228 return 0; 228 return 0;
@@ -286,7 +286,7 @@ xfs_inobt_delrec(
286 xfs_btree_del_cursor(tcur, 286 xfs_btree_del_cursor(tcur,
287 XFS_BTREE_NOERROR); 287 XFS_BTREE_NOERROR);
288 if (level > 0 && 288 if (level > 0 &&
289 (error = xfs_inobt_decrement(cur, level, 289 (error = xfs_btree_decrement(cur, level,
290 &i))) 290 &i)))
291 return error; 291 return error;
292 *stat = 1; 292 *stat = 1;
@@ -301,7 +301,7 @@ xfs_inobt_delrec(
301 rrecs = be16_to_cpu(right->bb_numrecs); 301 rrecs = be16_to_cpu(right->bb_numrecs);
302 if (lbno != NULLAGBLOCK) { 302 if (lbno != NULLAGBLOCK) {
303 xfs_btree_firstrec(tcur, level); 303 xfs_btree_firstrec(tcur, level);
304 if ((error = xfs_inobt_decrement(tcur, level, &i))) 304 if ((error = xfs_btree_decrement(tcur, level, &i)))
305 goto error0; 305 goto error0;
306 } 306 }
307 } 307 }
@@ -315,7 +315,7 @@ xfs_inobt_delrec(
315 * previous block. 315 * previous block.
316 */ 316 */
317 xfs_btree_firstrec(tcur, level); 317 xfs_btree_firstrec(tcur, level);
318 if ((error = xfs_inobt_decrement(tcur, level, &i))) 318 if ((error = xfs_btree_decrement(tcur, level, &i)))
319 goto error0; 319 goto error0;
320 xfs_btree_firstrec(tcur, level); 320 xfs_btree_firstrec(tcur, level);
321 /* 321 /*
@@ -414,7 +414,7 @@ xfs_inobt_delrec(
414 * Just return. This is probably a logic error, but it's not fatal. 414 * Just return. This is probably a logic error, but it's not fatal.
415 */ 415 */
416 else { 416 else {
417 if (level > 0 && (error = xfs_inobt_decrement(cur, level, &i))) 417 if (level > 0 && (error = xfs_btree_decrement(cur, level, &i)))
418 return error; 418 return error;
419 *stat = 1; 419 *stat = 1;
420 return 0; 420 return 0;
@@ -1656,90 +1656,6 @@ xfs_inobt_updkey(
1656 */ 1656 */
1657 1657
1658/* 1658/*
1659 * Decrement cursor by one record at the level.
1660 * For nonzero levels the leaf-ward information is untouched.
1661 */
1662int /* error */
1663xfs_inobt_decrement(
1664 xfs_btree_cur_t *cur, /* btree cursor */
1665 int level, /* level in btree, 0 is leaf */
1666 int *stat) /* success/failure */
1667{
1668 xfs_inobt_block_t *block; /* btree block */
1669 int error;
1670 int lev; /* btree level */
1671
1672 ASSERT(level < cur->bc_nlevels);
1673 /*
1674 * Read-ahead to the left at this level.
1675 */
1676 xfs_btree_readahead(cur, level, XFS_BTCUR_LEFTRA);
1677 /*
1678 * Decrement the ptr at this level. If we're still in the block
1679 * then we're done.
1680 */
1681 if (--cur->bc_ptrs[level] > 0) {
1682 *stat = 1;
1683 return 0;
1684 }
1685 /*
1686 * Get a pointer to the btree block.
1687 */
1688 block = XFS_BUF_TO_INOBT_BLOCK(cur->bc_bufs[level]);
1689#ifdef DEBUG
1690 if ((error = xfs_btree_check_sblock(cur, block, level,
1691 cur->bc_bufs[level])))
1692 return error;
1693#endif
1694 /*
1695 * If we just went off the left edge of the tree, return failure.
1696 */
1697 if (be32_to_cpu(block->bb_leftsib) == NULLAGBLOCK) {
1698 *stat = 0;
1699 return 0;
1700 }
1701 /*
1702 * March up the tree decrementing pointers.
1703 * Stop when we don't go off the left edge of a block.
1704 */
1705 for (lev = level + 1; lev < cur->bc_nlevels; lev++) {
1706 if (--cur->bc_ptrs[lev] > 0)
1707 break;
1708 /*
1709 * Read-ahead the left block, we're going to read it
1710 * in the next loop.
1711 */
1712 xfs_btree_readahead(cur, lev, XFS_BTCUR_LEFTRA);
1713 }
1714 /*
1715 * If we went off the root then we are seriously confused.
1716 */
1717 ASSERT(lev < cur->bc_nlevels);
1718 /*
1719 * Now walk back down the tree, fixing up the cursor's buffer
1720 * pointers and key numbers.
1721 */
1722 for (block = XFS_BUF_TO_INOBT_BLOCK(cur->bc_bufs[lev]); lev > level; ) {
1723 xfs_agblock_t agbno; /* block number of btree block */
1724 xfs_buf_t *bp; /* buffer containing btree block */
1725
1726 agbno = be32_to_cpu(*XFS_INOBT_PTR_ADDR(block, cur->bc_ptrs[lev], cur));
1727 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp,
1728 cur->bc_private.a.agno, agbno, 0, &bp,
1729 XFS_INO_BTREE_REF)))
1730 return error;
1731 lev--;
1732 xfs_btree_setbuf(cur, lev, bp);
1733 block = XFS_BUF_TO_INOBT_BLOCK(bp);
1734 if ((error = xfs_btree_check_sblock(cur, block, lev, bp)))
1735 return error;
1736 cur->bc_ptrs[lev] = be16_to_cpu(block->bb_numrecs);
1737 }
1738 *stat = 1;
1739 return 0;
1740}
1741
1742/*
1743 * Delete the record pointed to by cur. 1659 * Delete the record pointed to by cur.
1744 * The cursor refers to the place where the record was (could be inserted) 1660 * The cursor refers to the place where the record was (could be inserted)
1745 * when the operation returns. 1661 * when the operation returns.
@@ -1765,7 +1681,7 @@ xfs_inobt_delete(
1765 if (i == 0) { 1681 if (i == 0) {
1766 for (level = 1; level < cur->bc_nlevels; level++) { 1682 for (level = 1; level < cur->bc_nlevels; level++) {
1767 if (cur->bc_ptrs[level] == 0) { 1683 if (cur->bc_ptrs[level] == 0) {
1768 if ((error = xfs_inobt_decrement(cur, level, &i))) 1684 if ((error = xfs_btree_decrement(cur, level, &i)))
1769 return error; 1685 return error;
1770 break; 1686 break;
1771 } 1687 }