aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_alloc_btree.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2008-10-30 01:55:58 -0400
committerLachlan McIlroy <lachlan@sgi.com>2008-10-30 01:55:58 -0400
commit8df4da4a0a642d3a016028c0d922bcb4d5a4a6d7 (patch)
tree29b07230f8269ef12a10665d757a6e935c4e2e49 /fs/xfs/xfs_alloc_btree.c
parent637aa50f461b8ea6b1e8bf9877b0d13d00085043 (diff)
[XFS] implement generic xfs_btree_decrement
From: Dave Chinner <dgc@sgi.com> [hch: split out from bigger patch and minor adaptions] SGI-PV: 985583 SGI-Modid: xfs-linux-melb:xfs-kern:32191a Signed-off-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Lachlan McIlroy <lachlan@sgi.com> Signed-off-by: Bill O'Donnell <billodo@sgi.com> Signed-off-by: David Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs/xfs_alloc_btree.c')
-rw-r--r--fs/xfs/xfs_alloc_btree.c98
1 files changed, 7 insertions, 91 deletions
diff --git a/fs/xfs/xfs_alloc_btree.c b/fs/xfs/xfs_alloc_btree.c
index febc2d5ea295..6b45481ad5b0 100644
--- a/fs/xfs/xfs_alloc_btree.c
+++ b/fs/xfs/xfs_alloc_btree.c
@@ -256,7 +256,7 @@ xfs_alloc_delrec(
256 xfs_btree_setbuf(cur, level, NULL); 256 xfs_btree_setbuf(cur, level, NULL);
257 cur->bc_nlevels--; 257 cur->bc_nlevels--;
258 } else if (level > 0 && 258 } else if (level > 0 &&
259 (error = xfs_alloc_decrement(cur, level, &i))) 259 (error = xfs_btree_decrement(cur, level, &i)))
260 return error; 260 return error;
261 *stat = 1; 261 *stat = 1;
262 return 0; 262 return 0;
@@ -272,7 +272,7 @@ xfs_alloc_delrec(
272 * the minimum, we're done. 272 * the minimum, we're done.
273 */ 273 */
274 if (numrecs >= XFS_ALLOC_BLOCK_MINRECS(level, cur)) { 274 if (numrecs >= XFS_ALLOC_BLOCK_MINRECS(level, cur)) {
275 if (level > 0 && (error = xfs_alloc_decrement(cur, level, &i))) 275 if (level > 0 && (error = xfs_btree_decrement(cur, level, &i)))
276 return error; 276 return error;
277 *stat = 1; 277 *stat = 1;
278 return 0; 278 return 0;
@@ -336,7 +336,7 @@ xfs_alloc_delrec(
336 xfs_btree_del_cursor(tcur, 336 xfs_btree_del_cursor(tcur,
337 XFS_BTREE_NOERROR); 337 XFS_BTREE_NOERROR);
338 if (level > 0 && 338 if (level > 0 &&
339 (error = xfs_alloc_decrement(cur, level, 339 (error = xfs_btree_decrement(cur, level,
340 &i))) 340 &i)))
341 return error; 341 return error;
342 *stat = 1; 342 *stat = 1;
@@ -352,7 +352,7 @@ xfs_alloc_delrec(
352 if (lbno != NULLAGBLOCK) { 352 if (lbno != NULLAGBLOCK) {
353 i = xfs_btree_firstrec(tcur, level); 353 i = xfs_btree_firstrec(tcur, level);
354 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 354 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
355 if ((error = xfs_alloc_decrement(tcur, level, &i))) 355 if ((error = xfs_btree_decrement(tcur, level, &i)))
356 goto error0; 356 goto error0;
357 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 357 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
358 } 358 }
@@ -368,7 +368,7 @@ xfs_alloc_delrec(
368 */ 368 */
369 i = xfs_btree_firstrec(tcur, level); 369 i = xfs_btree_firstrec(tcur, level);
370 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 370 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
371 if ((error = xfs_alloc_decrement(tcur, level, &i))) 371 if ((error = xfs_btree_decrement(tcur, level, &i)))
372 goto error0; 372 goto error0;
373 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 373 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
374 xfs_btree_firstrec(tcur, level); 374 xfs_btree_firstrec(tcur, level);
@@ -468,7 +468,7 @@ xfs_alloc_delrec(
468 * Just return. This is probably a logic error, but it's not fatal. 468 * Just return. This is probably a logic error, but it's not fatal.
469 */ 469 */
470 else { 470 else {
471 if (level > 0 && (error = xfs_alloc_decrement(cur, level, &i))) 471 if (level > 0 && (error = xfs_btree_decrement(cur, level, &i)))
472 return error; 472 return error;
473 *stat = 1; 473 *stat = 1;
474 return 0; 474 return 0;
@@ -1780,90 +1780,6 @@ xfs_alloc_updkey(
1780 */ 1780 */
1781 1781
1782/* 1782/*
1783 * Decrement cursor by one record at the level.
1784 * For nonzero levels the leaf-ward information is untouched.
1785 */
1786int /* error */
1787xfs_alloc_decrement(
1788 xfs_btree_cur_t *cur, /* btree cursor */
1789 int level, /* level in btree, 0 is leaf */
1790 int *stat) /* success/failure */
1791{
1792 xfs_alloc_block_t *block; /* btree block */
1793 int error; /* error return value */
1794 int lev; /* btree level */
1795
1796 ASSERT(level < cur->bc_nlevels);
1797 /*
1798 * Read-ahead to the left at this level.
1799 */
1800 xfs_btree_readahead(cur, level, XFS_BTCUR_LEFTRA);
1801 /*
1802 * Decrement the ptr at this level. If we're still in the block
1803 * then we're done.
1804 */
1805 if (--cur->bc_ptrs[level] > 0) {
1806 *stat = 1;
1807 return 0;
1808 }
1809 /*
1810 * Get a pointer to the btree block.
1811 */
1812 block = XFS_BUF_TO_ALLOC_BLOCK(cur->bc_bufs[level]);
1813#ifdef DEBUG
1814 if ((error = xfs_btree_check_sblock(cur, block, level,
1815 cur->bc_bufs[level])))
1816 return error;
1817#endif
1818 /*
1819 * If we just went off the left edge of the tree, return failure.
1820 */
1821 if (be32_to_cpu(block->bb_leftsib) == NULLAGBLOCK) {
1822 *stat = 0;
1823 return 0;
1824 }
1825 /*
1826 * March up the tree decrementing pointers.
1827 * Stop when we don't go off the left edge of a block.
1828 */
1829 for (lev = level + 1; lev < cur->bc_nlevels; lev++) {
1830 if (--cur->bc_ptrs[lev] > 0)
1831 break;
1832 /*
1833 * Read-ahead the left block, we're going to read it
1834 * in the next loop.
1835 */
1836 xfs_btree_readahead(cur, lev, XFS_BTCUR_LEFTRA);
1837 }
1838 /*
1839 * If we went off the root then we are seriously confused.
1840 */
1841 ASSERT(lev < cur->bc_nlevels);
1842 /*
1843 * Now walk back down the tree, fixing up the cursor's buffer
1844 * pointers and key numbers.
1845 */
1846 for (block = XFS_BUF_TO_ALLOC_BLOCK(cur->bc_bufs[lev]); lev > level; ) {
1847 xfs_agblock_t agbno; /* block number of btree block */
1848 xfs_buf_t *bp; /* buffer pointer for block */
1849
1850 agbno = be32_to_cpu(*XFS_ALLOC_PTR_ADDR(block, cur->bc_ptrs[lev], cur));
1851 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp,
1852 cur->bc_private.a.agno, agbno, 0, &bp,
1853 XFS_ALLOC_BTREE_REF)))
1854 return error;
1855 lev--;
1856 xfs_btree_setbuf(cur, lev, bp);
1857 block = XFS_BUF_TO_ALLOC_BLOCK(bp);
1858 if ((error = xfs_btree_check_sblock(cur, block, lev, bp)))
1859 return error;
1860 cur->bc_ptrs[lev] = be16_to_cpu(block->bb_numrecs);
1861 }
1862 *stat = 1;
1863 return 0;
1864}
1865
1866/*
1867 * Delete the record pointed to by cur. 1783 * Delete the record pointed to by cur.
1868 * The cursor refers to the place where the record was (could be inserted) 1784 * The cursor refers to the place where the record was (could be inserted)
1869 * when the operation returns. 1785 * when the operation returns.
@@ -1889,7 +1805,7 @@ xfs_alloc_delete(
1889 if (i == 0) { 1805 if (i == 0) {
1890 for (level = 1; level < cur->bc_nlevels; level++) { 1806 for (level = 1; level < cur->bc_nlevels; level++) {
1891 if (cur->bc_ptrs[level] == 0) { 1807 if (cur->bc_ptrs[level] == 0) {
1892 if ((error = xfs_alloc_decrement(cur, level, &i))) 1808 if ((error = xfs_btree_decrement(cur, level, &i)))
1893 return error; 1809 return error;
1894 break; 1810 break;
1895 } 1811 }