implement generic xfs_btree_decrement
PATCH 11/26 implement generic xfs_btree_decrement
From: Dave Chinner <[email protected]>
[hch: split out from bigger patch and minor adaptions]
Signed-off-by Christoph Hellwig <[email protected]>
fs/xfs/xfs_btree.c +99 -0
@@ -1052,3 +1052,102 @@ error0:XFS_BTREE_TRACE_CURSOR (cur,XBT_ERROR );return error; } + +/* +* Decrement cursor by one record at the level. +* For nonzero levels the leaf-ward information is untouched. +*/ +int /* error */ +xfs_btree_decrement ( +struct xfs_btree_cur *cur, +int level, +int *stat)/* success/failure */ +{ +struct xfs_btree_block *block; +xfs_buf_t *bp; +int error;/* error return value */ +int lev; +union xfs_btree_ptr ptr; + +XFS_BTREE_TRACE_CURSOR (cur,XBT_ENTRY ); +XFS_BTREE_TRACE_ARGI (cur, level); + +ASSERT (level < cur->bc_nlevels); + +/* Read-ahead to the left at this level. */ +xfs_btree_readahead (cur, level,XFS_BTCUR_LEFTRA ); + +/* We're done if we remain in the block after the decrement. */ +if (--cur->bc_ptrs[level] >0 ) + goto out1; + +/* Get a pointer to the btree block. */ + block =xfs_btree_get_block (cur, level, &bp); + +#ifdef DEBUG + error =xfs_btree_check_block (cur, block, level, bp); +if (error) + goto error0; +#endif + +/* Fail if we just went off the left edge of the tree. */ +xfs_btree_get_sibling (cur, block, &ptr,XFS_BB_LEFTSIB ); +if (xfs_btree_ptr_is_null (cur, &ptr)) + goto out0; + +XFS_BTREE_STATS_INC (cur, decrement); + +/* +* March up the tree decrementing pointers. +* Stop when we don't go off the left edge of a block. +*/ +for (lev = level +1 ; lev < cur->bc_nlevels; lev++) { +if (--cur->bc_ptrs[lev] >0 ) +break ; +/* Read-ahead the left block for the next loop. */ +xfs_btree_readahead (cur, lev,XFS_BTCUR_LEFTRA ); + } + +/* +* If we went off the root then we are seriously confused. +* or the root of the tree is in an inode. +*/ +if (lev == cur->bc_nlevels) { +if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) + goto out0; +ASSERT (0 ); + error =EFSCORRUPTED ; + goto error0; + } +ASSERT (lev < cur->bc_nlevels); + +/* +* Now walk back down the tree, fixing up the cursor's buffer +* pointers and key numbers. +*/ +for (block =xfs_btree_get_block (cur, lev, &bp); lev > level; ) { +union xfs_btree_ptr *ptrp; + + ptrp = cur->bc_ops->ptr_addr (cur, cur->bc_ptrs[lev], block); + error =xfs_btree_read_buf_block (cur, ptrp, --lev, +0 , &block, &bp); +if (error) + goto error0; +xfs_btree_setbuf (cur, lev, bp); + cur->bc_ptrs[lev] =xfs_btree_get_numrecs (block); + } +out1: +XFS_BTREE_TRACE_CURSOR (cur,XBT_EXIT ); + *stat =1 ; +return 0 ; + +out0: +XFS_BTREE_TRACE_CURSOR (cur,XBT_EXIT ); + *stat =0 ; +return 0 ; + +error0: +XFS_BTREE_TRACE_CURSOR (cur,XBT_ERROR ); +return error; +} +
fs/xfs/xfs_alloc.c +6 -6
@@ -961,7 +961,7 @@ xfs_alloc_ag_vextent_near( args->minlen, <bnoa, <lena);if (ltlena >= args->minlen)break ; -if ((error =xfs_alloc_decrement (bno_cur_lt,0 , &i))) +if ((error =xfs_btree_decrement (bno_cur_lt,0 , &i))) goto error0;if (!i) { xfs_btree_del_cursor(bno_cur_lt,
@@ -1162,7 +1162,7 @@ xfs_alloc_ag_vextent_near(/* * Fell off the left end. */ -if ((error =xfs_alloc_decrement ( +if ((error =xfs_btree_decrement ( bno_cur_lt,0 , &i))) goto error0;if (!i) {
@@ -1321,7 +1321,7 @@ xfs_alloc_ag_vextent_size( bestflen = flen; bestfbno = fbno;for (;;) { -if ((error =xfs_alloc_decrement (cnt_cur,0 , &i))) +if ((error =xfs_btree_decrement (cnt_cur,0 , &i))) goto error0;if (i ==0 )break ;
@@ -1416,7 +1416,7 @@ xfs_alloc_ag_vextent_small(xfs_extlen_t flen;int i; -if ((error =xfs_alloc_decrement (ccur,0 , &i))) +if ((error =xfs_btree_decrement (ccur,0 , &i))) goto error0;if (i) {if ((error =xfs_alloc_get_rec (ccur, &fbno, &flen, &i)))
@@ -1607,7 +1607,7 @@ xfs_free_ag_extent(/* * Move the by-block cursor back to the left neighbor. */ -if ((error =xfs_alloc_decrement (bno_cur,0 , &i))) +if ((error =xfs_btree_decrement (bno_cur,0 , &i))) goto error0;XFS_WANT_CORRUPTED_GOTO (i ==1 , error0);#ifdef DEBUG
@@ -1653,7 +1653,7 @@ xfs_free_ag_extent(* Back up the by-block cursor to the left neighbor, and * update its length. */ -if ((error =xfs_alloc_decrement (bno_cur,0 , &i))) +if ((error =xfs_btree_decrement (bno_cur,0 , &i))) goto error0;XFS_WANT_CORRUPTED_GOTO (i ==1 , error0); nbno = ltbno;
fs/xfs/xfs_alloc_btree.c +7 -91
146 lines not on this page · raw message
fs/xfs/xfs_alloc_btree.h +0 -6
@@ -95,12 +95,6 @@ typedef struct xfs_btree_sblock xfs_alloXFS_BTREE_PTR_ADDR (xfs_alloc, bb, i,XFS_ALLOC_BLOCK_MAXRECS (1 , cur))/* -* Decrement cursor by one record at the level. -* For nonzero levels the leaf-ward information is untouched. - */ -extern int xfs_alloc_decrement (struct xfs_btree_cur *cur,int level,int *stat); - -/* * Delete the record pointed to by cur. * The cursor refers to the place where the record was (could be inserted) * when the operation returns.
fs/xfs/xfs_bmap.c +7 -7
@@ -820,7 +820,7 @@ xfs_bmap_add_extent_delay_real(if ((error =xfs_bmbt_delete (cur, &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_decrement (cur,0 , &i))) +if ((error =xfs_btree_decrement (cur,0 , &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); if ((error = xfs_bmbt_update(cur, LEFT.br_startoff,
@@ -1381,13 +1381,13 @@ xfs_bmap_add_extent_unwritten_real(if ((error =xfs_bmbt_delete (cur, &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_decrement (cur,0 , &i))) +if ((error =xfs_btree_decrement (cur,0 , &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done);if ((error =xfs_bmbt_delete (cur, &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_decrement (cur,0 , &i))) +if ((error =xfs_btree_decrement (cur,0 , &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); if ((error = xfs_bmbt_update(cur, LEFT.br_startoff,
@@ -1430,7 +1430,7 @@ xfs_bmap_add_extent_unwritten_real(if ((error =xfs_bmbt_delete (cur, &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_decrement (cur,0 , &i))) +if ((error =xfs_btree_decrement (cur,0 , &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); if ((error = xfs_bmbt_update(cur, LEFT.br_startoff,
@@ -1473,7 +1473,7 @@ xfs_bmap_add_extent_unwritten_real(if ((error =xfs_bmbt_delete (cur, &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_decrement (cur,0 , &i))) +if ((error =xfs_btree_decrement (cur,0 , &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); if ((error = xfs_bmbt_update(cur, new->br_startoff,
@@ -1556,7 +1556,7 @@ xfs_bmap_add_extent_unwritten_real( PREV.br_blockcount - new->br_blockcount, oldext))) goto done; -if ((error =xfs_bmbt_decrement (cur,0 , &i))) +if ((error =xfs_btree_decrement (cur,0 , &i))) goto done; if (xfs_bmbt_update(cur, LEFT.br_startoff, LEFT.br_startblock,
@@ -2108,7 +2108,7 @@ xfs_bmap_add_extent_hole_real(if ((error =xfs_bmbt_delete (cur, &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_decrement (cur,0 , &i))) +if ((error =xfs_btree_decrement (cur,0 , &i))) goto done;XFS_WANT_CORRUPTED_GOTO (i ==1 , done); if ((error = xfs_bmbt_update(cur, left.br_startoff,
fs/xfs/xfs_bmap_btree.c +8 -82
144 lines not on this page · raw message
fs/xfs/xfs_bmap_btree.h +0 -1
@@ -237,7 +237,6 @@ typedef struct xfs_btree_lblock xfs_bmbt* Prototypes for xfs_bmap.c to call. */ extern void xfs_bmdr_to_bmbt (xfs_bmdr_block_t *,int ,xfs_bmbt_block_t *,int ); -extern int xfs_bmbt_decrement (struct xfs_btree_cur *,int ,int *);extern int xfs_bmbt_delete (struct xfs_btree_cur *,int *);extern void xfs_bmbt_get_all (xfs_bmbt_rec_host_t *r,xfs_bmbt_irec_t *s); extern xfs_bmbt_block_t *xfs_bmbt_get_block(struct xfs_btree_cur *cur,
fs/xfs/xfs_ialloc.c +2 -2
@@ -739,7 +739,7 @@ nextag:/* * Search left with tcur, back up 1 record. */ -if ((error =xfs_inobt_decrement (tcur,0 , &i))) +if ((error =xfs_btree_decrement (tcur,0 , &i))) goto error1; doneleft = !i;if (!doneleft) {
@@ -815,7 +815,7 @@ nextag:* further left. */ if (useleft) { -if ((error =xfs_inobt_decrement (tcur,0 , +if ((error =xfs_btree_decrement (tcur,0 , &i))) goto error1; doneleft = !i;
fs/xfs/xfs_ialloc_btree.c +7 -91
146 lines not on this page · raw message
fs/xfs/xfs_ialloc_btree.h +0 -6
@@ -117,12 +117,6 @@ typedef struct xfs_btree_sblock xfs_inob i, XFS_INOBT_BLOCK_MAXRECS(1, cur)))/* -* Decrement cursor by one record at the level. -* For nonzero levels the leaf-ward information is untouched. -*/ -extern int xfs_inobt_decrement (struct xfs_btree_cur *cur,int level,int *stat); - -/* * Delete the record pointed to by cur. * The cursor refers to the place where the record was (could be inserted) * when the operation returns.
fs/xfs/xfs_btree.h +1 -0
@@ -511,6 +511,7 @@ xfs_btree_setbuf(*/ int xfs_btree_increment (struct xfs_btree_cur *,int ,int *); +int xfs_btree_decrement (struct xfs_btree_cur *,int ,int *);/*