diff options
author | Christoph Hellwig <hch@infradead.org> | 2008-10-30 01:55:58 -0400 |
---|---|---|
committer | Lachlan McIlroy <lachlan@sgi.com> | 2008-10-30 01:55:58 -0400 |
commit | 8df4da4a0a642d3a016028c0d922bcb4d5a4a6d7 (patch) | |
tree | 29b07230f8269ef12a10665d757a6e935c4e2e49 /fs/xfs/xfs_bmap_btree.c | |
parent | 637aa50f461b8ea6b1e8bf9877b0d13d00085043 (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_bmap_btree.c')
-rw-r--r-- | fs/xfs/xfs_bmap_btree.c | 90 |
1 files changed, 8 insertions, 82 deletions
diff --git a/fs/xfs/xfs_bmap_btree.c b/fs/xfs/xfs_bmap_btree.c index 2d29a4980cf7..7b5181d34a5b 100644 --- a/fs/xfs/xfs_bmap_btree.c +++ b/fs/xfs/xfs_bmap_btree.c | |||
@@ -203,7 +203,7 @@ xfs_bmbt_delrec( | |||
203 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 203 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
204 | goto error0; | 204 | goto error0; |
205 | } | 205 | } |
206 | if (level > 0 && (error = xfs_bmbt_decrement(cur, level, &j))) { | 206 | if (level > 0 && (error = xfs_btree_decrement(cur, level, &j))) { |
207 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 207 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
208 | goto error0; | 208 | goto error0; |
209 | } | 209 | } |
@@ -216,7 +216,7 @@ xfs_bmbt_delrec( | |||
216 | goto error0; | 216 | goto error0; |
217 | } | 217 | } |
218 | if (numrecs >= XFS_BMAP_BLOCK_IMINRECS(level, cur)) { | 218 | if (numrecs >= XFS_BMAP_BLOCK_IMINRECS(level, cur)) { |
219 | if (level > 0 && (error = xfs_bmbt_decrement(cur, level, &j))) { | 219 | if (level > 0 && (error = xfs_btree_decrement(cur, level, &j))) { |
220 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 220 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
221 | goto error0; | 221 | goto error0; |
222 | } | 222 | } |
@@ -237,7 +237,7 @@ xfs_bmbt_delrec( | |||
237 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 237 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
238 | goto error0; | 238 | goto error0; |
239 | } | 239 | } |
240 | if (level > 0 && (error = xfs_bmbt_decrement(cur, level, &i))) { | 240 | if (level > 0 && (error = xfs_btree_decrement(cur, level, &i))) { |
241 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 241 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
242 | goto error0; | 242 | goto error0; |
243 | } | 243 | } |
@@ -282,7 +282,7 @@ xfs_bmbt_delrec( | |||
282 | xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR); | 282 | xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR); |
283 | tcur = NULL; | 283 | tcur = NULL; |
284 | if (level > 0) { | 284 | if (level > 0) { |
285 | if ((error = xfs_bmbt_decrement(cur, | 285 | if ((error = xfs_btree_decrement(cur, |
286 | level, &i))) { | 286 | level, &i))) { |
287 | XFS_BMBT_TRACE_CURSOR(cur, | 287 | XFS_BMBT_TRACE_CURSOR(cur, |
288 | ERROR); | 288 | ERROR); |
@@ -298,7 +298,7 @@ xfs_bmbt_delrec( | |||
298 | if (lbno != NULLFSBLOCK) { | 298 | if (lbno != NULLFSBLOCK) { |
299 | i = xfs_btree_firstrec(tcur, level); | 299 | i = xfs_btree_firstrec(tcur, level); |
300 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | 300 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); |
301 | if ((error = xfs_bmbt_decrement(tcur, level, &i))) { | 301 | if ((error = xfs_btree_decrement(tcur, level, &i))) { |
302 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 302 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
303 | goto error0; | 303 | goto error0; |
304 | } | 304 | } |
@@ -311,7 +311,7 @@ xfs_bmbt_delrec( | |||
311 | /* | 311 | /* |
312 | * decrement to last in block | 312 | * decrement to last in block |
313 | */ | 313 | */ |
314 | if ((error = xfs_bmbt_decrement(tcur, level, &i))) { | 314 | if ((error = xfs_btree_decrement(tcur, level, &i))) { |
315 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 315 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
316 | goto error0; | 316 | goto error0; |
317 | } | 317 | } |
@@ -383,7 +383,7 @@ xfs_bmbt_delrec( | |||
383 | } | 383 | } |
384 | lrecs = be16_to_cpu(left->bb_numrecs); | 384 | lrecs = be16_to_cpu(left->bb_numrecs); |
385 | } else { | 385 | } else { |
386 | if (level > 0 && (error = xfs_bmbt_decrement(cur, level, &i))) { | 386 | if (level > 0 && (error = xfs_btree_decrement(cur, level, &i))) { |
387 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 387 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
388 | goto error0; | 388 | goto error0; |
389 | } | 389 | } |
@@ -1487,80 +1487,6 @@ xfs_bmdr_to_bmbt( | |||
1487 | } | 1487 | } |
1488 | 1488 | ||
1489 | /* | 1489 | /* |
1490 | * Decrement cursor by one record at the level. | ||
1491 | * For nonzero levels the leaf-ward information is untouched. | ||
1492 | */ | ||
1493 | int /* error */ | ||
1494 | xfs_bmbt_decrement( | ||
1495 | xfs_btree_cur_t *cur, | ||
1496 | int level, | ||
1497 | int *stat) /* success/failure */ | ||
1498 | { | ||
1499 | xfs_bmbt_block_t *block; | ||
1500 | xfs_buf_t *bp; | ||
1501 | int error; /* error return value */ | ||
1502 | xfs_fsblock_t fsbno; | ||
1503 | int lev; | ||
1504 | xfs_mount_t *mp; | ||
1505 | xfs_trans_t *tp; | ||
1506 | |||
1507 | XFS_BMBT_TRACE_CURSOR(cur, ENTRY); | ||
1508 | XFS_BMBT_TRACE_ARGI(cur, level); | ||
1509 | ASSERT(level < cur->bc_nlevels); | ||
1510 | |||
1511 | xfs_btree_readahead(cur, level, XFS_BTCUR_LEFTRA); | ||
1512 | |||
1513 | if (--cur->bc_ptrs[level] > 0) { | ||
1514 | XFS_BMBT_TRACE_CURSOR(cur, EXIT); | ||
1515 | *stat = 1; | ||
1516 | return 0; | ||
1517 | } | ||
1518 | block = xfs_bmbt_get_block(cur, level, &bp); | ||
1519 | #ifdef DEBUG | ||
1520 | if ((error = xfs_btree_check_lblock(cur, block, level, bp))) { | ||
1521 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | ||
1522 | return error; | ||
1523 | } | ||
1524 | #endif | ||
1525 | if (be64_to_cpu(block->bb_leftsib) == NULLDFSBNO) { | ||
1526 | XFS_BMBT_TRACE_CURSOR(cur, EXIT); | ||
1527 | *stat = 0; | ||
1528 | return 0; | ||
1529 | } | ||
1530 | for (lev = level + 1; lev < cur->bc_nlevels; lev++) { | ||
1531 | if (--cur->bc_ptrs[lev] > 0) | ||
1532 | break; | ||
1533 | xfs_btree_readahead(cur, lev, XFS_BTCUR_LEFTRA); | ||
1534 | } | ||
1535 | if (lev == cur->bc_nlevels) { | ||
1536 | XFS_BMBT_TRACE_CURSOR(cur, EXIT); | ||
1537 | *stat = 0; | ||
1538 | return 0; | ||
1539 | } | ||
1540 | tp = cur->bc_tp; | ||
1541 | mp = cur->bc_mp; | ||
1542 | for (block = xfs_bmbt_get_block(cur, lev, &bp); lev > level; ) { | ||
1543 | fsbno = be64_to_cpu(*XFS_BMAP_PTR_IADDR(block, cur->bc_ptrs[lev], cur)); | ||
1544 | if ((error = xfs_btree_read_bufl(mp, tp, fsbno, 0, &bp, | ||
1545 | XFS_BMAP_BTREE_REF))) { | ||
1546 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | ||
1547 | return error; | ||
1548 | } | ||
1549 | lev--; | ||
1550 | xfs_btree_setbuf(cur, lev, bp); | ||
1551 | block = XFS_BUF_TO_BMBT_BLOCK(bp); | ||
1552 | if ((error = xfs_btree_check_lblock(cur, block, lev, bp))) { | ||
1553 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | ||
1554 | return error; | ||
1555 | } | ||
1556 | cur->bc_ptrs[lev] = be16_to_cpu(block->bb_numrecs); | ||
1557 | } | ||
1558 | XFS_BMBT_TRACE_CURSOR(cur, EXIT); | ||
1559 | *stat = 1; | ||
1560 | return 0; | ||
1561 | } | ||
1562 | |||
1563 | /* | ||
1564 | * Delete the record pointed to by cur. | 1490 | * Delete the record pointed to by cur. |
1565 | */ | 1491 | */ |
1566 | int /* error */ | 1492 | int /* error */ |
@@ -1582,7 +1508,7 @@ xfs_bmbt_delete( | |||
1582 | if (i == 0) { | 1508 | if (i == 0) { |
1583 | for (level = 1; level < cur->bc_nlevels; level++) { | 1509 | for (level = 1; level < cur->bc_nlevels; level++) { |
1584 | if (cur->bc_ptrs[level] == 0) { | 1510 | if (cur->bc_ptrs[level] == 0) { |
1585 | if ((error = xfs_bmbt_decrement(cur, level, | 1511 | if ((error = xfs_btree_decrement(cur, level, |
1586 | &i))) { | 1512 | &i))) { |
1587 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); | 1513 | XFS_BMBT_TRACE_CURSOR(cur, ERROR); |
1588 | return error; | 1514 | return error; |