diff options
Diffstat (limited to 'fs/xfs/xfs_btree.c')
| -rw-r--r-- | fs/xfs/xfs_btree.c | 105 |
1 files changed, 39 insertions, 66 deletions
diff --git a/fs/xfs/xfs_btree.c b/fs/xfs/xfs_btree.c index aeb87ca69fcc..cc593a84c345 100644 --- a/fs/xfs/xfs_btree.c +++ b/fs/xfs/xfs_btree.c | |||
| @@ -46,38 +46,11 @@ kmem_zone_t *xfs_btree_cur_zone; | |||
| 46 | /* | 46 | /* |
| 47 | * Btree magic numbers. | 47 | * Btree magic numbers. |
| 48 | */ | 48 | */ |
| 49 | const __uint32_t xfs_magics[XFS_BTNUM_MAX] = | 49 | const __uint32_t xfs_magics[XFS_BTNUM_MAX] = { |
| 50 | { | ||
| 51 | XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC | 50 | XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC |
| 52 | }; | 51 | }; |
| 53 | 52 | ||
| 54 | /* | 53 | /* |
| 55 | * Prototypes for internal routines. | ||
| 56 | */ | ||
| 57 | |||
| 58 | /* | ||
| 59 | * Checking routine: return maxrecs for the block. | ||
| 60 | */ | ||
| 61 | STATIC int /* number of records fitting in block */ | ||
| 62 | xfs_btree_maxrecs( | ||
| 63 | xfs_btree_cur_t *cur, /* btree cursor */ | ||
| 64 | xfs_btree_block_t *block);/* generic btree block pointer */ | ||
| 65 | |||
| 66 | /* | ||
| 67 | * Internal routines. | ||
| 68 | */ | ||
| 69 | |||
| 70 | /* | ||
| 71 | * Retrieve the block pointer from the cursor at the given level. | ||
| 72 | * This may be a bmap btree root or from a buffer. | ||
| 73 | */ | ||
| 74 | STATIC xfs_btree_block_t * /* generic btree block pointer */ | ||
| 75 | xfs_btree_get_block( | ||
| 76 | xfs_btree_cur_t *cur, /* btree cursor */ | ||
| 77 | int level, /* level in btree */ | ||
| 78 | struct xfs_buf **bpp); /* buffer containing the block */ | ||
| 79 | |||
| 80 | /* | ||
| 81 | * Checking routine: return maxrecs for the block. | 54 | * Checking routine: return maxrecs for the block. |
| 82 | */ | 55 | */ |
| 83 | STATIC int /* number of records fitting in block */ | 56 | STATIC int /* number of records fitting in block */ |
| @@ -457,35 +430,6 @@ xfs_btree_dup_cursor( | |||
| 457 | } | 430 | } |
| 458 | 431 | ||
| 459 | /* | 432 | /* |
| 460 | * Change the cursor to point to the first record at the given level. | ||
| 461 | * Other levels are unaffected. | ||
| 462 | */ | ||
| 463 | int /* success=1, failure=0 */ | ||
| 464 | xfs_btree_firstrec( | ||
| 465 | xfs_btree_cur_t *cur, /* btree cursor */ | ||
| 466 | int level) /* level to change */ | ||
| 467 | { | ||
| 468 | xfs_btree_block_t *block; /* generic btree block pointer */ | ||
| 469 | xfs_buf_t *bp; /* buffer containing block */ | ||
| 470 | |||
| 471 | /* | ||
| 472 | * Get the block pointer for this level. | ||
| 473 | */ | ||
| 474 | block = xfs_btree_get_block(cur, level, &bp); | ||
| 475 | xfs_btree_check_block(cur, block, level, bp); | ||
| 476 | /* | ||
| 477 | * It's empty, there is no such record. | ||
| 478 | */ | ||
| 479 | if (!block->bb_h.bb_numrecs) | ||
| 480 | return 0; | ||
| 481 | /* | ||
| 482 | * Set the ptr value to 1, that's the first record/key. | ||
| 483 | */ | ||
| 484 | cur->bc_ptrs[level] = 1; | ||
| 485 | return 1; | ||
| 486 | } | ||
| 487 | |||
| 488 | /* | ||
| 489 | * Retrieve the block pointer from the cursor at the given level. | 433 | * Retrieve the block pointer from the cursor at the given level. |
| 490 | * This may be a bmap btree root or from a buffer. | 434 | * This may be a bmap btree root or from a buffer. |
| 491 | */ | 435 | */ |
| @@ -626,6 +570,13 @@ xfs_btree_init_cursor( | |||
| 626 | cur->bc_private.a.agbp = agbp; | 570 | cur->bc_private.a.agbp = agbp; |
| 627 | cur->bc_private.a.agno = agno; | 571 | cur->bc_private.a.agno = agno; |
| 628 | break; | 572 | break; |
| 573 | case XFS_BTNUM_INO: | ||
| 574 | /* | ||
| 575 | * Inode allocation btree fields. | ||
| 576 | */ | ||
| 577 | cur->bc_private.a.agbp = agbp; | ||
| 578 | cur->bc_private.a.agno = agno; | ||
| 579 | break; | ||
| 629 | case XFS_BTNUM_BMAP: | 580 | case XFS_BTNUM_BMAP: |
| 630 | /* | 581 | /* |
| 631 | * Bmap btree fields. | 582 | * Bmap btree fields. |
| @@ -638,13 +589,6 @@ xfs_btree_init_cursor( | |||
| 638 | cur->bc_private.b.flags = 0; | 589 | cur->bc_private.b.flags = 0; |
| 639 | cur->bc_private.b.whichfork = whichfork; | 590 | cur->bc_private.b.whichfork = whichfork; |
| 640 | break; | 591 | break; |
| 641 | case XFS_BTNUM_INO: | ||
| 642 | /* | ||
| 643 | * Inode allocation btree fields. | ||
| 644 | */ | ||
| 645 | cur->bc_private.i.agbp = agbp; | ||
| 646 | cur->bc_private.i.agno = agno; | ||
| 647 | break; | ||
| 648 | default: | 592 | default: |
| 649 | ASSERT(0); | 593 | ASSERT(0); |
| 650 | } | 594 | } |
| @@ -671,6 +615,35 @@ xfs_btree_islastblock( | |||
| 671 | } | 615 | } |
| 672 | 616 | ||
| 673 | /* | 617 | /* |
| 618 | * Change the cursor to point to the first record at the given level. | ||
| 619 | * Other levels are unaffected. | ||
| 620 | */ | ||
| 621 | int /* success=1, failure=0 */ | ||
| 622 | xfs_btree_firstrec( | ||
| 623 | xfs_btree_cur_t *cur, /* btree cursor */ | ||
| 624 | int level) /* level to change */ | ||
| 625 | { | ||
| 626 | xfs_btree_block_t *block; /* generic btree block pointer */ | ||
| 627 | xfs_buf_t *bp; /* buffer containing block */ | ||
| 628 | |||
| 629 | /* | ||
| 630 | * Get the block pointer for this level. | ||
| 631 | */ | ||
| 632 | block = xfs_btree_get_block(cur, level, &bp); | ||
| 633 | xfs_btree_check_block(cur, block, level, bp); | ||
| 634 | /* | ||
| 635 | * It's empty, there is no such record. | ||
| 636 | */ | ||
| 637 | if (!block->bb_h.bb_numrecs) | ||
| 638 | return 0; | ||
| 639 | /* | ||
| 640 | * Set the ptr value to 1, that's the first record/key. | ||
| 641 | */ | ||
| 642 | cur->bc_ptrs[level] = 1; | ||
| 643 | return 1; | ||
| 644 | } | ||
| 645 | |||
| 646 | /* | ||
| 674 | * Change the cursor to point to the last record in the current block | 647 | * Change the cursor to point to the last record in the current block |
| 675 | * at the given level. Other levels are unaffected. | 648 | * at the given level. Other levels are unaffected. |
| 676 | */ | 649 | */ |
| @@ -890,12 +863,12 @@ xfs_btree_readahead_core( | |||
| 890 | case XFS_BTNUM_INO: | 863 | case XFS_BTNUM_INO: |
| 891 | i = XFS_BUF_TO_INOBT_BLOCK(cur->bc_bufs[lev]); | 864 | i = XFS_BUF_TO_INOBT_BLOCK(cur->bc_bufs[lev]); |
| 892 | if ((lr & XFS_BTCUR_LEFTRA) && be32_to_cpu(i->bb_leftsib) != NULLAGBLOCK) { | 865 | if ((lr & XFS_BTCUR_LEFTRA) && be32_to_cpu(i->bb_leftsib) != NULLAGBLOCK) { |
| 893 | xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.i.agno, | 866 | xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno, |
| 894 | be32_to_cpu(i->bb_leftsib), 1); | 867 | be32_to_cpu(i->bb_leftsib), 1); |
| 895 | rval++; | 868 | rval++; |
| 896 | } | 869 | } |
| 897 | if ((lr & XFS_BTCUR_RIGHTRA) && be32_to_cpu(i->bb_rightsib) != NULLAGBLOCK) { | 870 | if ((lr & XFS_BTCUR_RIGHTRA) && be32_to_cpu(i->bb_rightsib) != NULLAGBLOCK) { |
| 898 | xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.i.agno, | 871 | xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno, |
| 899 | be32_to_cpu(i->bb_rightsib), 1); | 872 | be32_to_cpu(i->bb_rightsib), 1); |
| 900 | rval++; | 873 | rval++; |
| 901 | } | 874 | } |
