forked from Minki/linux
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>
This commit is contained in:
parent
e6f7667c4e
commit
ad14c33ac8
@ -903,11 +903,9 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
|
|||||||
*/
|
*/
|
||||||
dp = args->dp;
|
dp = args->dp;
|
||||||
args->blkno = 0;
|
args->blkno = 0;
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
|
||||||
XFS_ATTR_FORK, NULL);
|
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return error;
|
||||||
ASSERT(bp != NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look up the given attribute in the leaf block. Figure out if
|
* Look up the given attribute in the leaf block. Figure out if
|
||||||
@ -1031,12 +1029,12 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
|
|||||||
* Read in the block containing the "old" attr, then
|
* Read in the block containing the "old" attr, then
|
||||||
* remove the "old" attr from that block (neat, huh!)
|
* remove the "old" attr from that block (neat, huh!)
|
||||||
*/
|
*/
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno,
|
||||||
&bp, XFS_ATTR_FORK, NULL);
|
-1, &bp);
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return error;
|
||||||
ASSERT(bp != NULL);
|
|
||||||
(void)xfs_attr_leaf_remove(bp, args);
|
xfs_attr_leaf_remove(bp, args);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the result is small enough, shrink it all into the inode.
|
* If the result is small enough, shrink it all into the inode.
|
||||||
@ -1100,20 +1098,17 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
|
|||||||
*/
|
*/
|
||||||
dp = args->dp;
|
dp = args->dp;
|
||||||
args->blkno = 0;
|
args->blkno = 0;
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
|
||||||
XFS_ATTR_FORK, NULL);
|
if (error)
|
||||||
if (error) {
|
return error;
|
||||||
return(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(bp != NULL);
|
|
||||||
error = xfs_attr_leaf_lookup_int(bp, args);
|
error = xfs_attr_leaf_lookup_int(bp, args);
|
||||||
if (error == ENOATTR) {
|
if (error == ENOATTR) {
|
||||||
xfs_trans_brelse(args->trans, bp);
|
xfs_trans_brelse(args->trans, bp);
|
||||||
return(error);
|
return(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)xfs_attr_leaf_remove(bp, args);
|
xfs_attr_leaf_remove(bp, args);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the result is small enough, shrink it all into the inode.
|
* If the result is small enough, shrink it all into the inode.
|
||||||
@ -1158,11 +1153,9 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
|
|||||||
trace_xfs_attr_leaf_get(args);
|
trace_xfs_attr_leaf_get(args);
|
||||||
|
|
||||||
args->blkno = 0;
|
args->blkno = 0;
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
|
||||||
XFS_ATTR_FORK, NULL);
|
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return error;
|
||||||
ASSERT(bp != NULL);
|
|
||||||
|
|
||||||
error = xfs_attr_leaf_lookup_int(bp, args);
|
error = xfs_attr_leaf_lookup_int(bp, args);
|
||||||
if (error != EEXIST) {
|
if (error != EEXIST) {
|
||||||
@ -1183,25 +1176,15 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
|
|||||||
STATIC int
|
STATIC int
|
||||||
xfs_attr_leaf_list(xfs_attr_list_context_t *context)
|
xfs_attr_leaf_list(xfs_attr_list_context_t *context)
|
||||||
{
|
{
|
||||||
xfs_attr_leafblock_t *leaf;
|
|
||||||
int error;
|
int error;
|
||||||
struct xfs_buf *bp;
|
struct xfs_buf *bp;
|
||||||
|
|
||||||
trace_xfs_attr_leaf_list(context);
|
trace_xfs_attr_leaf_list(context);
|
||||||
|
|
||||||
context->cursor->blkno = 0;
|
context->cursor->blkno = 0;
|
||||||
error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK,
|
error = xfs_attr_leaf_read(NULL, context->dp, 0, -1, &bp);
|
||||||
NULL);
|
|
||||||
if (error)
|
if (error)
|
||||||
return XFS_ERROR(error);
|
return XFS_ERROR(error);
|
||||||
ASSERT(bp != NULL);
|
|
||||||
leaf = bp->b_addr;
|
|
||||||
if (unlikely(leaf->hdr.info.magic != cpu_to_be16(XFS_ATTR_LEAF_MAGIC))) {
|
|
||||||
XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
|
|
||||||
context->dp->i_mount, leaf);
|
|
||||||
xfs_trans_brelse(NULL, bp);
|
|
||||||
return XFS_ERROR(EFSCORRUPTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
error = xfs_attr_leaf_list_int(bp, context);
|
error = xfs_attr_leaf_list_int(bp, context);
|
||||||
xfs_trans_brelse(NULL, bp);
|
xfs_trans_brelse(NULL, bp);
|
||||||
@ -1605,12 +1588,9 @@ xfs_attr_node_removename(xfs_da_args_t *args)
|
|||||||
ASSERT(state->path.blk[0].bp);
|
ASSERT(state->path.blk[0].bp);
|
||||||
state->path.blk[0].bp = NULL;
|
state->path.blk[0].bp = NULL;
|
||||||
|
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
|
error = xfs_attr_leaf_read(args->trans, args->dp, 0, -1, &bp);
|
||||||
XFS_ATTR_FORK, NULL);
|
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
ASSERT((((xfs_attr_leafblock_t *)bp->b_addr)->hdr.info.magic) ==
|
|
||||||
cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
|
|
||||||
|
|
||||||
if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
|
if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
|
||||||
xfs_bmap_init(args->flist, args->firstblock);
|
xfs_bmap_init(args->flist, args->firstblock);
|
||||||
@ -1920,14 +1900,6 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
|
|||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
leaf = bp->b_addr;
|
leaf = bp->b_addr;
|
||||||
if (unlikely(leaf->hdr.info.magic !=
|
|
||||||
cpu_to_be16(XFS_ATTR_LEAF_MAGIC))) {
|
|
||||||
XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
|
|
||||||
XFS_ERRLEVEL_LOW,
|
|
||||||
context->dp->i_mount, leaf);
|
|
||||||
xfs_trans_brelse(NULL, bp);
|
|
||||||
return(XFS_ERROR(EFSCORRUPTED));
|
|
||||||
}
|
|
||||||
error = xfs_attr_leaf_list_int(bp, context);
|
error = xfs_attr_leaf_list_int(bp, context);
|
||||||
if (error) {
|
if (error) {
|
||||||
xfs_trans_brelse(NULL, bp);
|
xfs_trans_brelse(NULL, bp);
|
||||||
@ -1937,16 +1909,10 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
|
|||||||
break;
|
break;
|
||||||
cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
|
cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
|
||||||
xfs_trans_brelse(NULL, bp);
|
xfs_trans_brelse(NULL, bp);
|
||||||
error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
|
error = xfs_attr_leaf_read(NULL, context->dp, cursor->blkno, -1,
|
||||||
&bp, XFS_ATTR_FORK, NULL);
|
&bp);
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return error;
|
||||||
if (unlikely((bp == NULL))) {
|
|
||||||
XFS_ERROR_REPORT("xfs_attr_node_list(5)",
|
|
||||||
XFS_ERRLEVEL_LOW,
|
|
||||||
context->dp->i_mount);
|
|
||||||
return(XFS_ERROR(EFSCORRUPTED));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xfs_trans_brelse(NULL, bp);
|
xfs_trans_brelse(NULL, bp);
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -88,6 +88,36 @@ STATIC void xfs_attr_leaf_moveents(xfs_attr_leafblock_t *src_leaf,
|
|||||||
xfs_mount_t *mp);
|
xfs_mount_t *mp);
|
||||||
STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
|
STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
|
||||||
|
|
||||||
|
static void
|
||||||
|
xfs_attr_leaf_verify(
|
||||||
|
struct xfs_buf *bp)
|
||||||
|
{
|
||||||
|
struct xfs_mount *mp = bp->b_target->bt_mount;
|
||||||
|
struct xfs_attr_leaf_hdr *hdr = bp->b_addr;
|
||||||
|
int block_ok = 0;
|
||||||
|
|
||||||
|
block_ok = hdr->info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC);
|
||||||
|
if (!block_ok) {
|
||||||
|
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr);
|
||||||
|
xfs_buf_ioerror(bp, EFSCORRUPTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
bp->b_iodone = NULL;
|
||||||
|
xfs_buf_ioend(bp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xfs_attr_leaf_read(
|
||||||
|
struct xfs_trans *tp,
|
||||||
|
struct xfs_inode *dp,
|
||||||
|
xfs_dablk_t bno,
|
||||||
|
xfs_daddr_t mappedbno,
|
||||||
|
struct xfs_buf **bpp)
|
||||||
|
{
|
||||||
|
return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp,
|
||||||
|
XFS_ATTR_FORK, xfs_attr_leaf_verify);
|
||||||
|
}
|
||||||
|
|
||||||
/*========================================================================
|
/*========================================================================
|
||||||
* Namespace helper routines
|
* Namespace helper routines
|
||||||
*========================================================================*/
|
*========================================================================*/
|
||||||
@ -870,11 +900,10 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)
|
|||||||
error = xfs_da_grow_inode(args, &blkno);
|
error = xfs_da_grow_inode(args, &blkno);
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp1,
|
error = xfs_attr_leaf_read(args->trans, args->dp, 0, -1, &bp1);
|
||||||
XFS_ATTR_FORK, NULL);
|
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
ASSERT(bp1 != NULL);
|
|
||||||
bp2 = NULL;
|
bp2 = NULL;
|
||||||
error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp2,
|
error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp2,
|
||||||
XFS_ATTR_FORK);
|
XFS_ATTR_FORK);
|
||||||
@ -1641,18 +1670,16 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
|
|||||||
blkno = be32_to_cpu(info->back);
|
blkno = be32_to_cpu(info->back);
|
||||||
if (blkno == 0)
|
if (blkno == 0)
|
||||||
continue;
|
continue;
|
||||||
error = xfs_da_read_buf(state->args->trans, state->args->dp,
|
error = xfs_attr_leaf_read(state->args->trans, state->args->dp,
|
||||||
blkno, -1, &bp, XFS_ATTR_FORK, NULL);
|
blkno, -1, &bp);
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return(error);
|
||||||
ASSERT(bp != NULL);
|
|
||||||
|
|
||||||
leaf = (xfs_attr_leafblock_t *)info;
|
leaf = (xfs_attr_leafblock_t *)info;
|
||||||
count = be16_to_cpu(leaf->hdr.count);
|
count = be16_to_cpu(leaf->hdr.count);
|
||||||
bytes = state->blocksize - (state->blocksize>>2);
|
bytes = state->blocksize - (state->blocksize>>2);
|
||||||
bytes -= be16_to_cpu(leaf->hdr.usedbytes);
|
bytes -= be16_to_cpu(leaf->hdr.usedbytes);
|
||||||
leaf = bp->b_addr;
|
leaf = bp->b_addr;
|
||||||
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
|
|
||||||
count += be16_to_cpu(leaf->hdr.count);
|
count += be16_to_cpu(leaf->hdr.count);
|
||||||
bytes -= be16_to_cpu(leaf->hdr.usedbytes);
|
bytes -= be16_to_cpu(leaf->hdr.usedbytes);
|
||||||
bytes -= count * sizeof(xfs_attr_leaf_entry_t);
|
bytes -= count * sizeof(xfs_attr_leaf_entry_t);
|
||||||
@ -2518,15 +2545,11 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
|
|||||||
/*
|
/*
|
||||||
* Set up the operation.
|
* Set up the operation.
|
||||||
*/
|
*/
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
|
||||||
XFS_ATTR_FORK, NULL);
|
if (error)
|
||||||
if (error) {
|
|
||||||
return(error);
|
return(error);
|
||||||
}
|
|
||||||
ASSERT(bp != NULL);
|
|
||||||
|
|
||||||
leaf = bp->b_addr;
|
leaf = bp->b_addr;
|
||||||
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
|
|
||||||
ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
|
ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
|
||||||
ASSERT(args->index >= 0);
|
ASSERT(args->index >= 0);
|
||||||
entry = &leaf->entries[ args->index ];
|
entry = &leaf->entries[ args->index ];
|
||||||
@ -2583,15 +2606,11 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args)
|
|||||||
/*
|
/*
|
||||||
* Set up the operation.
|
* Set up the operation.
|
||||||
*/
|
*/
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
|
||||||
XFS_ATTR_FORK, NULL);
|
if (error)
|
||||||
if (error) {
|
|
||||||
return(error);
|
return(error);
|
||||||
}
|
|
||||||
ASSERT(bp != NULL);
|
|
||||||
|
|
||||||
leaf = bp->b_addr;
|
leaf = bp->b_addr;
|
||||||
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
|
|
||||||
ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
|
ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
|
||||||
ASSERT(args->index >= 0);
|
ASSERT(args->index >= 0);
|
||||||
entry = &leaf->entries[ args->index ];
|
entry = &leaf->entries[ args->index ];
|
||||||
@ -2640,35 +2659,28 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
|
|||||||
/*
|
/*
|
||||||
* Read the block containing the "old" attr
|
* Read the block containing the "old" attr
|
||||||
*/
|
*/
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp1,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp1);
|
||||||
XFS_ATTR_FORK, NULL);
|
if (error)
|
||||||
if (error) {
|
return error;
|
||||||
return(error);
|
|
||||||
}
|
|
||||||
ASSERT(bp1 != NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the block containing the "new" attr, if it is different
|
* Read the block containing the "new" attr, if it is different
|
||||||
*/
|
*/
|
||||||
if (args->blkno2 != args->blkno) {
|
if (args->blkno2 != args->blkno) {
|
||||||
error = xfs_da_read_buf(args->trans, args->dp, args->blkno2,
|
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno2,
|
||||||
-1, &bp2, XFS_ATTR_FORK, NULL);
|
-1, &bp2);
|
||||||
if (error) {
|
if (error)
|
||||||
return(error);
|
return error;
|
||||||
}
|
|
||||||
ASSERT(bp2 != NULL);
|
|
||||||
} else {
|
} else {
|
||||||
bp2 = bp1;
|
bp2 = bp1;
|
||||||
}
|
}
|
||||||
|
|
||||||
leaf1 = bp1->b_addr;
|
leaf1 = bp1->b_addr;
|
||||||
ASSERT(leaf1->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
|
|
||||||
ASSERT(args->index < be16_to_cpu(leaf1->hdr.count));
|
ASSERT(args->index < be16_to_cpu(leaf1->hdr.count));
|
||||||
ASSERT(args->index >= 0);
|
ASSERT(args->index >= 0);
|
||||||
entry1 = &leaf1->entries[ args->index ];
|
entry1 = &leaf1->entries[ args->index ];
|
||||||
|
|
||||||
leaf2 = bp2->b_addr;
|
leaf2 = bp2->b_addr;
|
||||||
ASSERT(leaf2->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
|
|
||||||
ASSERT(args->index2 < be16_to_cpu(leaf2->hdr.count));
|
ASSERT(args->index2 < be16_to_cpu(leaf2->hdr.count));
|
||||||
ASSERT(args->index2 >= 0);
|
ASSERT(args->index2 >= 0);
|
||||||
entry2 = &leaf2->entries[ args->index2 ];
|
entry2 = &leaf2->entries[ args->index2 ];
|
||||||
|
@ -227,6 +227,9 @@ int xfs_attr_leaf_to_shortform(struct xfs_buf *bp,
|
|||||||
int xfs_attr_leaf_clearflag(struct xfs_da_args *args);
|
int xfs_attr_leaf_clearflag(struct xfs_da_args *args);
|
||||||
int xfs_attr_leaf_setflag(struct xfs_da_args *args);
|
int xfs_attr_leaf_setflag(struct xfs_da_args *args);
|
||||||
int xfs_attr_leaf_flipflags(xfs_da_args_t *args);
|
int xfs_attr_leaf_flipflags(xfs_da_args_t *args);
|
||||||
|
int xfs_attr_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
|
||||||
|
xfs_dablk_t bno, xfs_daddr_t mappedbno,
|
||||||
|
struct xfs_buf **bpp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Routines used for growing the Btree.
|
* Routines used for growing the Btree.
|
||||||
|
Loading…
Reference in New Issue
Block a user