xfs: split xfs_da3_node_read
Split xfs_da3_node_read into one variant that always looks up the daddr and doesn't accept holes, and one that already has a daddr at hand. This is in preparation of splitting up xfs_da_read_buf in a similar way. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
committed by
Darrick J. Wong
parent
f3fcb314d1
commit
02c57f0a8b
@@ -1266,10 +1266,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
|
|||||||
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
|
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
|
||||||
for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
|
for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
|
||||||
if (blk->disk_blkno) {
|
if (blk->disk_blkno) {
|
||||||
error = xfs_da3_node_read(state->args->trans,
|
error = xfs_da3_node_read_mapped(state->args->trans,
|
||||||
state->args->dp,
|
state->args->dp, blk->disk_blkno,
|
||||||
blk->blkno, blk->disk_blkno,
|
&blk->bp, XFS_ATTR_FORK);
|
||||||
&blk->bp, XFS_ATTR_FORK);
|
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
} else {
|
} else {
|
||||||
@@ -1285,10 +1284,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
|
|||||||
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
|
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
|
||||||
for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
|
for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
|
||||||
if (blk->disk_blkno) {
|
if (blk->disk_blkno) {
|
||||||
error = xfs_da3_node_read(state->args->trans,
|
error = xfs_da3_node_read_mapped(state->args->trans,
|
||||||
state->args->dp,
|
state->args->dp, blk->disk_blkno,
|
||||||
blk->blkno, blk->disk_blkno,
|
&blk->bp, XFS_ATTR_FORK);
|
||||||
&blk->bp, XFS_ATTR_FORK);
|
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -331,46 +331,66 @@ const struct xfs_buf_ops xfs_da3_node_buf_ops = {
|
|||||||
.verify_struct = xfs_da3_node_verify_struct,
|
.verify_struct = xfs_da3_node_verify_struct,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
xfs_da3_node_set_type(
|
||||||
|
struct xfs_trans *tp,
|
||||||
|
struct xfs_buf *bp)
|
||||||
|
{
|
||||||
|
struct xfs_da_blkinfo *info = bp->b_addr;
|
||||||
|
|
||||||
|
switch (be16_to_cpu(info->magic)) {
|
||||||
|
case XFS_DA_NODE_MAGIC:
|
||||||
|
case XFS_DA3_NODE_MAGIC:
|
||||||
|
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DA_NODE_BUF);
|
||||||
|
return 0;
|
||||||
|
case XFS_ATTR_LEAF_MAGIC:
|
||||||
|
case XFS_ATTR3_LEAF_MAGIC:
|
||||||
|
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_ATTR_LEAF_BUF);
|
||||||
|
return 0;
|
||||||
|
case XFS_DIR2_LEAFN_MAGIC:
|
||||||
|
case XFS_DIR3_LEAFN_MAGIC:
|
||||||
|
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_LEAFN_BUF);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, tp->t_mountp,
|
||||||
|
info, sizeof(*info));
|
||||||
|
xfs_trans_brelse(tp, bp);
|
||||||
|
return -EFSCORRUPTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
xfs_da3_node_read(
|
xfs_da3_node_read(
|
||||||
struct xfs_trans *tp,
|
struct xfs_trans *tp,
|
||||||
struct xfs_inode *dp,
|
struct xfs_inode *dp,
|
||||||
xfs_dablk_t bno,
|
xfs_dablk_t bno,
|
||||||
|
struct xfs_buf **bpp,
|
||||||
|
int whichfork)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
|
||||||
|
error = xfs_da_read_buf(tp, dp, bno, -1, bpp, whichfork,
|
||||||
|
&xfs_da3_node_buf_ops);
|
||||||
|
if (error || !*bpp || !tp)
|
||||||
|
return error;
|
||||||
|
return xfs_da3_node_set_type(tp, *bpp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xfs_da3_node_read_mapped(
|
||||||
|
struct xfs_trans *tp,
|
||||||
|
struct xfs_inode *dp,
|
||||||
xfs_daddr_t mappedbno,
|
xfs_daddr_t mappedbno,
|
||||||
struct xfs_buf **bpp,
|
struct xfs_buf **bpp,
|
||||||
int which_fork)
|
int whichfork)
|
||||||
{
|
{
|
||||||
int err;
|
int error;
|
||||||
|
|
||||||
err = xfs_da_read_buf(tp, dp, bno, mappedbno, bpp,
|
error = xfs_da_read_buf(tp, dp, 0, mappedbno, bpp, whichfork,
|
||||||
which_fork, &xfs_da3_node_buf_ops);
|
&xfs_da3_node_buf_ops);
|
||||||
if (!err && tp && *bpp) {
|
if (error || !*bpp || !tp)
|
||||||
struct xfs_da_blkinfo *info = (*bpp)->b_addr;
|
return error;
|
||||||
int type;
|
return xfs_da3_node_set_type(tp, *bpp);
|
||||||
|
|
||||||
switch (be16_to_cpu(info->magic)) {
|
|
||||||
case XFS_DA_NODE_MAGIC:
|
|
||||||
case XFS_DA3_NODE_MAGIC:
|
|
||||||
type = XFS_BLFT_DA_NODE_BUF;
|
|
||||||
break;
|
|
||||||
case XFS_ATTR_LEAF_MAGIC:
|
|
||||||
case XFS_ATTR3_LEAF_MAGIC:
|
|
||||||
type = XFS_BLFT_ATTR_LEAF_BUF;
|
|
||||||
break;
|
|
||||||
case XFS_DIR2_LEAFN_MAGIC:
|
|
||||||
case XFS_DIR3_LEAFN_MAGIC:
|
|
||||||
type = XFS_BLFT_DIR_LEAFN_BUF;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW,
|
|
||||||
tp->t_mountp, info, sizeof(*info));
|
|
||||||
xfs_trans_brelse(tp, *bpp);
|
|
||||||
*bpp = NULL;
|
|
||||||
return -EFSCORRUPTED;
|
|
||||||
}
|
|
||||||
xfs_trans_buf_set_type(tp, *bpp, type);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*========================================================================
|
/*========================================================================
|
||||||
@@ -1166,8 +1186,7 @@ xfs_da3_root_join(
|
|||||||
*/
|
*/
|
||||||
child = be32_to_cpu(oldroothdr.btree[0].before);
|
child = be32_to_cpu(oldroothdr.btree[0].before);
|
||||||
ASSERT(child != 0);
|
ASSERT(child != 0);
|
||||||
error = xfs_da3_node_read(args->trans, dp, child, -1, &bp,
|
error = xfs_da3_node_read(args->trans, dp, child, &bp, args->whichfork);
|
||||||
args->whichfork);
|
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level);
|
xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level);
|
||||||
@@ -1281,8 +1300,8 @@ xfs_da3_node_toosmall(
|
|||||||
blkno = nodehdr.back;
|
blkno = nodehdr.back;
|
||||||
if (blkno == 0)
|
if (blkno == 0)
|
||||||
continue;
|
continue;
|
||||||
error = xfs_da3_node_read(state->args->trans, dp,
|
error = xfs_da3_node_read(state->args->trans, dp, blkno, &bp,
|
||||||
blkno, -1, &bp, state->args->whichfork);
|
state->args->whichfork);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -1570,7 +1589,7 @@ xfs_da3_node_lookup_int(
|
|||||||
*/
|
*/
|
||||||
blk->blkno = blkno;
|
blk->blkno = blkno;
|
||||||
error = xfs_da3_node_read(args->trans, args->dp, blkno,
|
error = xfs_da3_node_read(args->trans, args->dp, blkno,
|
||||||
-1, &blk->bp, args->whichfork);
|
&blk->bp, args->whichfork);
|
||||||
if (error) {
|
if (error) {
|
||||||
blk->blkno = 0;
|
blk->blkno = 0;
|
||||||
state->path.active--;
|
state->path.active--;
|
||||||
@@ -1804,7 +1823,7 @@ xfs_da3_blk_link(
|
|||||||
if (old_info->back) {
|
if (old_info->back) {
|
||||||
error = xfs_da3_node_read(args->trans, dp,
|
error = xfs_da3_node_read(args->trans, dp,
|
||||||
be32_to_cpu(old_info->back),
|
be32_to_cpu(old_info->back),
|
||||||
-1, &bp, args->whichfork);
|
&bp, args->whichfork);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
ASSERT(bp != NULL);
|
ASSERT(bp != NULL);
|
||||||
@@ -1825,7 +1844,7 @@ xfs_da3_blk_link(
|
|||||||
if (old_info->forw) {
|
if (old_info->forw) {
|
||||||
error = xfs_da3_node_read(args->trans, dp,
|
error = xfs_da3_node_read(args->trans, dp,
|
||||||
be32_to_cpu(old_info->forw),
|
be32_to_cpu(old_info->forw),
|
||||||
-1, &bp, args->whichfork);
|
&bp, args->whichfork);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
ASSERT(bp != NULL);
|
ASSERT(bp != NULL);
|
||||||
@@ -1884,7 +1903,7 @@ xfs_da3_blk_unlink(
|
|||||||
if (drop_info->back) {
|
if (drop_info->back) {
|
||||||
error = xfs_da3_node_read(args->trans, args->dp,
|
error = xfs_da3_node_read(args->trans, args->dp,
|
||||||
be32_to_cpu(drop_info->back),
|
be32_to_cpu(drop_info->back),
|
||||||
-1, &bp, args->whichfork);
|
&bp, args->whichfork);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
ASSERT(bp != NULL);
|
ASSERT(bp != NULL);
|
||||||
@@ -1901,7 +1920,7 @@ xfs_da3_blk_unlink(
|
|||||||
if (drop_info->forw) {
|
if (drop_info->forw) {
|
||||||
error = xfs_da3_node_read(args->trans, args->dp,
|
error = xfs_da3_node_read(args->trans, args->dp,
|
||||||
be32_to_cpu(drop_info->forw),
|
be32_to_cpu(drop_info->forw),
|
||||||
-1, &bp, args->whichfork);
|
&bp, args->whichfork);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
ASSERT(bp != NULL);
|
ASSERT(bp != NULL);
|
||||||
@@ -1985,7 +2004,7 @@ xfs_da3_path_shift(
|
|||||||
/*
|
/*
|
||||||
* Read the next child block into a local buffer.
|
* Read the next child block into a local buffer.
|
||||||
*/
|
*/
|
||||||
error = xfs_da3_node_read(args->trans, dp, blkno, -1, &bp,
|
error = xfs_da3_node_read(args->trans, dp, blkno, &bp,
|
||||||
args->whichfork);
|
args->whichfork);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
@@ -2263,7 +2282,7 @@ xfs_da3_swap_lastblock(
|
|||||||
* Read the last block in the btree space.
|
* Read the last block in the btree space.
|
||||||
*/
|
*/
|
||||||
last_blkno = (xfs_dablk_t)lastoff - args->geo->fsbcount;
|
last_blkno = (xfs_dablk_t)lastoff - args->geo->fsbcount;
|
||||||
error = xfs_da3_node_read(tp, dp, last_blkno, -1, &last_buf, w);
|
error = xfs_da3_node_read(tp, dp, last_blkno, &last_buf, w);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
/*
|
/*
|
||||||
@@ -2300,7 +2319,7 @@ xfs_da3_swap_lastblock(
|
|||||||
* If the moved block has a left sibling, fix up the pointers.
|
* If the moved block has a left sibling, fix up the pointers.
|
||||||
*/
|
*/
|
||||||
if ((sib_blkno = be32_to_cpu(dead_info->back))) {
|
if ((sib_blkno = be32_to_cpu(dead_info->back))) {
|
||||||
error = xfs_da3_node_read(tp, dp, sib_blkno, -1, &sib_buf, w);
|
error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w);
|
||||||
if (error)
|
if (error)
|
||||||
goto done;
|
goto done;
|
||||||
sib_info = sib_buf->b_addr;
|
sib_info = sib_buf->b_addr;
|
||||||
@@ -2320,7 +2339,7 @@ xfs_da3_swap_lastblock(
|
|||||||
* If the moved block has a right sibling, fix up the pointers.
|
* If the moved block has a right sibling, fix up the pointers.
|
||||||
*/
|
*/
|
||||||
if ((sib_blkno = be32_to_cpu(dead_info->forw))) {
|
if ((sib_blkno = be32_to_cpu(dead_info->forw))) {
|
||||||
error = xfs_da3_node_read(tp, dp, sib_blkno, -1, &sib_buf, w);
|
error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w);
|
||||||
if (error)
|
if (error)
|
||||||
goto done;
|
goto done;
|
||||||
sib_info = sib_buf->b_addr;
|
sib_info = sib_buf->b_addr;
|
||||||
@@ -2342,7 +2361,7 @@ xfs_da3_swap_lastblock(
|
|||||||
* Walk down the tree looking for the parent of the moved block.
|
* Walk down the tree looking for the parent of the moved block.
|
||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
error = xfs_da3_node_read(tp, dp, par_blkno, -1, &par_buf, w);
|
error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w);
|
||||||
if (error)
|
if (error)
|
||||||
goto done;
|
goto done;
|
||||||
par_node = par_buf->b_addr;
|
par_node = par_buf->b_addr;
|
||||||
@@ -2388,7 +2407,7 @@ xfs_da3_swap_lastblock(
|
|||||||
error = -EFSCORRUPTED;
|
error = -EFSCORRUPTED;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
error = xfs_da3_node_read(tp, dp, par_blkno, -1, &par_buf, w);
|
error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w);
|
||||||
if (error)
|
if (error)
|
||||||
goto done;
|
goto done;
|
||||||
par_node = par_buf->b_addr;
|
par_node = par_buf->b_addr;
|
||||||
|
@@ -188,8 +188,10 @@ int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
|
|||||||
int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
|
int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
|
||||||
xfs_da_state_blk_t *new_blk);
|
xfs_da_state_blk_t *new_blk);
|
||||||
int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
|
int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
|
||||||
xfs_dablk_t bno, xfs_daddr_t mappedbno,
|
xfs_dablk_t bno, struct xfs_buf **bpp, int whichfork);
|
||||||
struct xfs_buf **bpp, int which_fork);
|
int xfs_da3_node_read_mapped(struct xfs_trans *tp, struct xfs_inode *dp,
|
||||||
|
xfs_daddr_t mappedbno, struct xfs_buf **bpp,
|
||||||
|
int whichfork);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Utility routines.
|
* Utility routines.
|
||||||
|
@@ -233,7 +233,7 @@ xfs_attr3_node_inactive(
|
|||||||
* traversal of the tree so we may deal with many blocks
|
* traversal of the tree so we may deal with many blocks
|
||||||
* before we come back to this one.
|
* before we come back to this one.
|
||||||
*/
|
*/
|
||||||
error = xfs_da3_node_read(*trans, dp, child_fsb, -1, &child_bp,
|
error = xfs_da3_node_read(*trans, dp, child_fsb, &child_bp,
|
||||||
XFS_ATTR_FORK);
|
XFS_ATTR_FORK);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
@@ -280,8 +280,8 @@ xfs_attr3_node_inactive(
|
|||||||
if (i + 1 < ichdr.count) {
|
if (i + 1 < ichdr.count) {
|
||||||
struct xfs_da3_icnode_hdr phdr;
|
struct xfs_da3_icnode_hdr phdr;
|
||||||
|
|
||||||
error = xfs_da3_node_read(*trans, dp, 0, parent_blkno,
|
error = xfs_da3_node_read_mapped(*trans, dp,
|
||||||
&bp, XFS_ATTR_FORK);
|
parent_blkno, &bp, XFS_ATTR_FORK);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
xfs_da3_node_hdr_from_disk(dp->i_mount, &phdr,
|
xfs_da3_node_hdr_from_disk(dp->i_mount, &phdr,
|
||||||
@@ -322,7 +322,7 @@ xfs_attr3_root_inactive(
|
|||||||
* the extents in reverse order the extent containing
|
* the extents in reverse order the extent containing
|
||||||
* block 0 must still be there.
|
* block 0 must still be there.
|
||||||
*/
|
*/
|
||||||
error = xfs_da3_node_read(*trans, dp, 0, -1, &bp, XFS_ATTR_FORK);
|
error = xfs_da3_node_read(*trans, dp, 0, &bp, XFS_ATTR_FORK);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
blkno = bp->b_bn;
|
blkno = bp->b_bn;
|
||||||
|
@@ -223,7 +223,7 @@ xfs_attr_node_list_lookup(
|
|||||||
ASSERT(*pbp == NULL);
|
ASSERT(*pbp == NULL);
|
||||||
cursor->blkno = 0;
|
cursor->blkno = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
error = xfs_da3_node_read(tp, dp, cursor->blkno, -1, &bp,
|
error = xfs_da3_node_read(tp, dp, cursor->blkno, &bp,
|
||||||
XFS_ATTR_FORK);
|
XFS_ATTR_FORK);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
@@ -309,8 +309,8 @@ xfs_attr_node_list(
|
|||||||
*/
|
*/
|
||||||
bp = NULL;
|
bp = NULL;
|
||||||
if (cursor->blkno > 0) {
|
if (cursor->blkno > 0) {
|
||||||
error = xfs_da3_node_read(context->tp, dp, cursor->blkno, -1,
|
error = xfs_da3_node_read(context->tp, dp, cursor->blkno, &bp,
|
||||||
&bp, XFS_ATTR_FORK);
|
XFS_ATTR_FORK);
|
||||||
if ((error != 0) && (error != -EFSCORRUPTED))
|
if ((error != 0) && (error != -EFSCORRUPTED))
|
||||||
return error;
|
return error;
|
||||||
if (bp) {
|
if (bp) {
|
||||||
|
Reference in New Issue
Block a user