diff options
author | Dave Chinner <dchinner@redhat.com> | 2012-11-12 06:54:16 -0500 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2012-11-15 22:34:52 -0500 |
commit | ad14c33ac862601c4c22755ed3b59f1906b134e5 (patch) | |
tree | 80d2fe31b0db8c0f763080ca69902cf903764da9 /fs/xfs/xfs_attr_leaf.c | |
parent | e6f7667c4eef42b6f5bc6cdeb31d0bab62fe5f79 (diff) |
xfs: factor and verify attr leaf reads
Some reads are not converted yet because it isn't obvious ahead of
time what the format of the block is going to be. Need to determine
how to tell if the first block in the tree is a node or leaf format
block. That will be done in later patches.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Phil White <pwhite@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_attr_leaf.c')
-rw-r--r-- | fs/xfs/xfs_attr_leaf.c | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/fs/xfs/xfs_attr_leaf.c b/fs/xfs/xfs_attr_leaf.c index ba2b9a2cd236..357971536d50 100644 --- a/fs/xfs/xfs_attr_leaf.c +++ b/fs/xfs/xfs_attr_leaf.c | |||
@@ -88,6 +88,36 @@ STATIC void xfs_attr_leaf_moveents(xfs_attr_leafblock_t *src_leaf, | |||
88 | xfs_mount_t *mp); | 88 | xfs_mount_t *mp); |
89 | STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index); | 89 | STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index); |
90 | 90 | ||
91 | static void | ||
92 | xfs_attr_leaf_verify( | ||
93 | struct xfs_buf *bp) | ||
94 | { | ||
95 | struct xfs_mount *mp = bp->b_target->bt_mount; | ||
96 | struct xfs_attr_leaf_hdr *hdr = bp->b_addr; | ||
97 | int block_ok = 0; | ||
98 | |||
99 | block_ok = hdr->info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC); | ||
100 | if (!block_ok) { | ||
101 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr); | ||
102 | xfs_buf_ioerror(bp, EFSCORRUPTED); | ||
103 | } | ||
104 | |||
105 | bp->b_iodone = NULL; | ||
106 | xfs_buf_ioend(bp, 0); | ||
107 | } | ||
108 | |||
109 | int | ||
110 | xfs_attr_leaf_read( | ||
111 | struct xfs_trans *tp, | ||
112 | struct xfs_inode *dp, | ||
113 | xfs_dablk_t bno, | ||
114 | xfs_daddr_t mappedbno, | ||
115 | struct xfs_buf **bpp) | ||
116 | { | ||
117 | return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp, | ||
118 | XFS_ATTR_FORK, xfs_attr_leaf_verify); | ||
119 | } | ||
120 | |||
91 | /*======================================================================== | 121 | /*======================================================================== |
92 | * Namespace helper routines | 122 | * Namespace helper routines |
93 | *========================================================================*/ | 123 | *========================================================================*/ |
@@ -870,11 +900,10 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args) | |||
870 | error = xfs_da_grow_inode(args, &blkno); | 900 | error = xfs_da_grow_inode(args, &blkno); |
871 | if (error) | 901 | if (error) |
872 | goto out; | 902 | goto out; |
873 | error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp1, | 903 | error = xfs_attr_leaf_read(args->trans, args->dp, 0, -1, &bp1); |
874 | XFS_ATTR_FORK, NULL); | ||
875 | if (error) | 904 | if (error) |
876 | goto out; | 905 | goto out; |
877 | ASSERT(bp1 != NULL); | 906 | |
878 | bp2 = NULL; | 907 | bp2 = NULL; |
879 | error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp2, | 908 | error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp2, |
880 | XFS_ATTR_FORK); | 909 | XFS_ATTR_FORK); |
@@ -1641,18 +1670,16 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) | |||
1641 | blkno = be32_to_cpu(info->back); | 1670 | blkno = be32_to_cpu(info->back); |
1642 | if (blkno == 0) | 1671 | if (blkno == 0) |
1643 | continue; | 1672 | continue; |
1644 | error = xfs_da_read_buf(state->args->trans, state->args->dp, | 1673 | error = xfs_attr_leaf_read(state->args->trans, state->args->dp, |
1645 | blkno, -1, &bp, XFS_ATTR_FORK, NULL); | 1674 | blkno, -1, &bp); |
1646 | if (error) | 1675 | if (error) |
1647 | return(error); | 1676 | return(error); |
1648 | ASSERT(bp != NULL); | ||
1649 | 1677 | ||
1650 | leaf = (xfs_attr_leafblock_t *)info; | 1678 | leaf = (xfs_attr_leafblock_t *)info; |
1651 | count = be16_to_cpu(leaf->hdr.count); | 1679 | count = be16_to_cpu(leaf->hdr.count); |
1652 | bytes = state->blocksize - (state->blocksize>>2); | 1680 | bytes = state->blocksize - (state->blocksize>>2); |
1653 | bytes -= be16_to_cpu(leaf->hdr.usedbytes); | 1681 | bytes -= be16_to_cpu(leaf->hdr.usedbytes); |
1654 | leaf = bp->b_addr; | 1682 | leaf = bp->b_addr; |
1655 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | ||
1656 | count += be16_to_cpu(leaf->hdr.count); | 1683 | count += be16_to_cpu(leaf->hdr.count); |
1657 | bytes -= be16_to_cpu(leaf->hdr.usedbytes); | 1684 | bytes -= be16_to_cpu(leaf->hdr.usedbytes); |
1658 | bytes -= count * sizeof(xfs_attr_leaf_entry_t); | 1685 | bytes -= count * sizeof(xfs_attr_leaf_entry_t); |
@@ -2518,15 +2545,11 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args) | |||
2518 | /* | 2545 | /* |
2519 | * Set up the operation. | 2546 | * Set up the operation. |
2520 | */ | 2547 | */ |
2521 | error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp, | 2548 | error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); |
2522 | XFS_ATTR_FORK, NULL); | 2549 | if (error) |
2523 | if (error) { | ||
2524 | return(error); | 2550 | return(error); |
2525 | } | ||
2526 | ASSERT(bp != NULL); | ||
2527 | 2551 | ||
2528 | leaf = bp->b_addr; | 2552 | leaf = bp->b_addr; |
2529 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | ||
2530 | ASSERT(args->index < be16_to_cpu(leaf->hdr.count)); | 2553 | ASSERT(args->index < be16_to_cpu(leaf->hdr.count)); |
2531 | ASSERT(args->index >= 0); | 2554 | ASSERT(args->index >= 0); |
2532 | entry = &leaf->entries[ args->index ]; | 2555 | entry = &leaf->entries[ args->index ]; |
@@ -2583,15 +2606,11 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args) | |||
2583 | /* | 2606 | /* |
2584 | * Set up the operation. | 2607 | * Set up the operation. |
2585 | */ | 2608 | */ |
2586 | error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp, | 2609 | error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); |
2587 | XFS_ATTR_FORK, NULL); | 2610 | if (error) |
2588 | if (error) { | ||
2589 | return(error); | 2611 | return(error); |
2590 | } | ||
2591 | ASSERT(bp != NULL); | ||
2592 | 2612 | ||
2593 | leaf = bp->b_addr; | 2613 | leaf = bp->b_addr; |
2594 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | ||
2595 | ASSERT(args->index < be16_to_cpu(leaf->hdr.count)); | 2614 | ASSERT(args->index < be16_to_cpu(leaf->hdr.count)); |
2596 | ASSERT(args->index >= 0); | 2615 | ASSERT(args->index >= 0); |
2597 | entry = &leaf->entries[ args->index ]; | 2616 | entry = &leaf->entries[ args->index ]; |
@@ -2640,35 +2659,28 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) | |||
2640 | /* | 2659 | /* |
2641 | * Read the block containing the "old" attr | 2660 | * Read the block containing the "old" attr |
2642 | */ | 2661 | */ |
2643 | error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp1, | 2662 | error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp1); |
2644 | XFS_ATTR_FORK, NULL); | 2663 | if (error) |
2645 | if (error) { | 2664 | return error; |
2646 | return(error); | ||
2647 | } | ||
2648 | ASSERT(bp1 != NULL); | ||
2649 | 2665 | ||
2650 | /* | 2666 | /* |
2651 | * Read the block containing the "new" attr, if it is different | 2667 | * Read the block containing the "new" attr, if it is different |
2652 | */ | 2668 | */ |
2653 | if (args->blkno2 != args->blkno) { | 2669 | if (args->blkno2 != args->blkno) { |
2654 | error = xfs_da_read_buf(args->trans, args->dp, args->blkno2, | 2670 | error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno2, |
2655 | -1, &bp2, XFS_ATTR_FORK, NULL); | 2671 | -1, &bp2); |
2656 | if (error) { | 2672 | if (error) |
2657 | return(error); | 2673 | return error; |
2658 | } | ||
2659 | ASSERT(bp2 != NULL); | ||
2660 | } else { | 2674 | } else { |
2661 | bp2 = bp1; | 2675 | bp2 = bp1; |
2662 | } | 2676 | } |
2663 | 2677 | ||
2664 | leaf1 = bp1->b_addr; | 2678 | leaf1 = bp1->b_addr; |
2665 | ASSERT(leaf1->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | ||
2666 | ASSERT(args->index < be16_to_cpu(leaf1->hdr.count)); | 2679 | ASSERT(args->index < be16_to_cpu(leaf1->hdr.count)); |
2667 | ASSERT(args->index >= 0); | 2680 | ASSERT(args->index >= 0); |
2668 | entry1 = &leaf1->entries[ args->index ]; | 2681 | entry1 = &leaf1->entries[ args->index ]; |
2669 | 2682 | ||
2670 | leaf2 = bp2->b_addr; | 2683 | leaf2 = bp2->b_addr; |
2671 | ASSERT(leaf2->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | ||
2672 | ASSERT(args->index2 < be16_to_cpu(leaf2->hdr.count)); | 2684 | ASSERT(args->index2 < be16_to_cpu(leaf2->hdr.count)); |
2673 | ASSERT(args->index2 >= 0); | 2685 | ASSERT(args->index2 >= 0); |
2674 | entry2 = &leaf2->entries[ args->index2 ]; | 2686 | entry2 = &leaf2->entries[ args->index2 ]; |