Skip to content

Commit

Permalink
xfs: add pre-write metadata buffer verifier callbacks
Browse files Browse the repository at this point in the history
These verifiers are essentially the same code as the read verifiers,
but do not require ioend processing. Hence factor the read verifier
functions and add a new write verifier wrapper that is used as the
callback.

This is done as one large patch for all verifiers rather than one
patch per verifier as the change is largely mechanical. This
includes hooking up the write verifier via the read verifier
function.

Hooking up the write verifier for buffers obtained via
xfs_trans_get_buf() will be done in a separate patch as that touches
code in many different places rather than just the verifier
functions.

Signed-off-by: Dave Chinner <[email protected]>
Reviewed-by: Mark Tinguely <[email protected]>
Signed-off-by: Ben Myers <[email protected]>
  • Loading branch information
Dave Chinner authored and Ben Myers committed Nov 16, 2012
1 parent cfb0285 commit 612cfbf
Show file tree
Hide file tree
Showing 20 changed files with 273 additions and 56 deletions.
35 changes: 32 additions & 3 deletions fs/xfs/xfs_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ xfs_alloc_fixup_trees(
return 0;
}

void
xfs_agfl_read_verify(
static void
xfs_agfl_verify(
struct xfs_buf *bp)
{
#ifdef WHEN_CRCS_COME_ALONG
Expand Down Expand Up @@ -463,6 +463,21 @@ xfs_agfl_read_verify(
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
#endif
}

static void
xfs_agfl_write_verify(
struct xfs_buf *bp)
{
xfs_agfl_verify(bp);
}

void
xfs_agfl_read_verify(
struct xfs_buf *bp)
{
xfs_agfl_verify(bp);
bp->b_pre_io = xfs_agfl_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
Expand Down Expand Up @@ -2129,7 +2144,7 @@ xfs_alloc_put_freelist(
}

static void
xfs_agf_read_verify(
xfs_agf_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
Expand Down Expand Up @@ -2164,7 +2179,21 @@ xfs_agf_read_verify(
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, agf);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
}

static void
xfs_agf_write_verify(
struct xfs_buf *bp)
{
xfs_agf_verify(bp);
}

void
xfs_agf_read_verify(
struct xfs_buf *bp)
{
xfs_agf_verify(bp);
bp->b_pre_io = xfs_agf_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
Expand Down
21 changes: 17 additions & 4 deletions fs/xfs/xfs_alloc_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ xfs_allocbt_key_diff(
return (__int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock;
}

void
xfs_allocbt_read_verify(
static void
xfs_allocbt_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
Expand Down Expand Up @@ -323,11 +323,24 @@ xfs_allocbt_read_verify(

if (!sblock_ok) {
trace_xfs_btree_corrupt(bp, _RET_IP_);
XFS_CORRUPTION_ERROR("xfs_allocbt_read_verify",
XFS_ERRLEVEL_LOW, mp, block);
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, block);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
}

static void
xfs_allocbt_write_verify(
struct xfs_buf *bp)
{
xfs_allocbt_verify(bp);
}

void
xfs_allocbt_read_verify(
struct xfs_buf *bp)
{
xfs_allocbt_verify(bp);
bp->b_pre_io = xfs_allocbt_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
Expand Down
19 changes: 17 additions & 2 deletions fs/xfs/xfs_attr_leaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ STATIC void xfs_attr_leaf_moveents(xfs_attr_leafblock_t *src_leaf,
xfs_mount_t *mp);
STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);

void
static void
xfs_attr_leaf_verify(
struct xfs_buf *bp)
{
Expand All @@ -101,11 +101,26 @@ xfs_attr_leaf_verify(
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
}

static void
xfs_attr_leaf_write_verify(
struct xfs_buf *bp)
{
xfs_attr_leaf_verify(bp);
}

void
xfs_attr_leaf_read_verify(
struct xfs_buf *bp)
{
xfs_attr_leaf_verify(bp);
bp->b_pre_io = xfs_attr_leaf_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}


int
xfs_attr_leaf_read(
struct xfs_trans *tp,
Expand All @@ -115,7 +130,7 @@ xfs_attr_leaf_read(
struct xfs_buf **bpp)
{
return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp,
XFS_ATTR_FORK, xfs_attr_leaf_verify);
XFS_ATTR_FORK, xfs_attr_leaf_read_verify);
}

/*========================================================================
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/xfs_attr_leaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@ int xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize,
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);
void xfs_attr_leaf_verify(struct xfs_buf *bp);
void xfs_attr_leaf_read_verify(struct xfs_buf *bp);

#endif /* __XFS_ATTR_LEAF_H__ */
21 changes: 17 additions & 4 deletions fs/xfs/xfs_bmap_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ xfs_bmbt_key_diff(
cur->bc_rec.b.br_startoff;
}

void
xfs_bmbt_read_verify(
static void
xfs_bmbt_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
Expand Down Expand Up @@ -744,11 +744,24 @@ xfs_bmbt_read_verify(

if (!lblock_ok) {
trace_xfs_btree_corrupt(bp, _RET_IP_);
XFS_CORRUPTION_ERROR("xfs_bmbt_read_verify",
XFS_ERRLEVEL_LOW, mp, block);
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, block);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
}

static void
xfs_bmbt_write_verify(
struct xfs_buf *bp)
{
xfs_bmbt_verify(bp);
}

void
xfs_bmbt_read_verify(
struct xfs_buf *bp)
{
xfs_bmbt_verify(bp);
bp->b_pre_io = xfs_bmbt_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
Expand Down
37 changes: 25 additions & 12 deletions fs/xfs/xfs_da_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ STATIC int xfs_da_blk_unlink(xfs_da_state_t *state,
STATIC void xfs_da_state_kill_altpath(xfs_da_state_t *state);

static void
__xfs_da_node_verify(
xfs_da_node_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
Expand All @@ -108,34 +108,40 @@ __xfs_da_node_verify(
xfs_buf_ioerror(bp, EFSCORRUPTED);
}

bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}

static void
xfs_da_node_verify(
xfs_da_node_write_verify(
struct xfs_buf *bp)
{
xfs_da_node_verify(bp);
}

static void
xfs_da_node_read_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
struct xfs_da_blkinfo *info = bp->b_addr;

switch (be16_to_cpu(info->magic)) {
case XFS_DA_NODE_MAGIC:
__xfs_da_node_verify(bp);
return;
xfs_da_node_verify(bp);
break;
case XFS_ATTR_LEAF_MAGIC:
xfs_attr_leaf_verify(bp);
xfs_attr_leaf_read_verify(bp);
return;
case XFS_DIR2_LEAFN_MAGIC:
xfs_dir2_leafn_verify(bp);
xfs_dir2_leafn_read_verify(bp);
return;
default:
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW,
mp, info);
xfs_buf_ioerror(bp, EFSCORRUPTED);
break;
}

XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, info);
xfs_buf_ioerror(bp, EFSCORRUPTED);

bp->b_pre_io = xfs_da_node_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
Expand All @@ -150,7 +156,7 @@ xfs_da_node_read(
int which_fork)
{
return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp,
which_fork, xfs_da_node_verify);
which_fork, xfs_da_node_read_verify);
}

/*========================================================================
Expand Down Expand Up @@ -816,7 +822,14 @@ xfs_da_root_join(xfs_da_state_t *state, xfs_da_state_blk_t *root_blk)
xfs_da_blkinfo_onlychild_validate(bp->b_addr,
be16_to_cpu(oldroot->hdr.level));

/*
* This could be copying a leaf back into the root block in the case of
* there only being a single leaf block left in the tree. Hence we have
* to update the pre_io pointer as well to match the buffer type change
* that could occur.
*/
memcpy(root_blk->bp->b_addr, bp->b_addr, state->blocksize);
root_blk->bp->b_pre_io = bp->b_pre_io;
xfs_trans_log_buf(args->trans, root_blk->bp, 0, state->blocksize - 1);
error = xfs_da_shrink_inode(args, child, bp);
return(error);
Expand Down
16 changes: 15 additions & 1 deletion fs/xfs/xfs_dir2_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,21 @@ xfs_dir2_block_verify(
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
}

static void
xfs_dir2_block_write_verify(
struct xfs_buf *bp)
{
xfs_dir2_block_verify(bp);
}

void
xfs_dir2_block_read_verify(
struct xfs_buf *bp)
{
xfs_dir2_block_verify(bp);
bp->b_pre_io = xfs_dir2_block_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
Expand All @@ -85,7 +99,7 @@ xfs_dir2_block_read(
struct xfs_mount *mp = dp->i_mount;

return xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, bpp,
XFS_DATA_FORK, xfs_dir2_block_verify);
XFS_DATA_FORK, xfs_dir2_block_read_verify);
}

static void
Expand Down
19 changes: 17 additions & 2 deletions fs/xfs/xfs_dir2_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,26 @@ xfs_dir2_data_verify(
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
}

static void
xfs_dir2_data_write_verify(
struct xfs_buf *bp)
{
xfs_dir2_data_verify(bp);
}

void
xfs_dir2_data_read_verify(
struct xfs_buf *bp)
{
xfs_dir2_data_verify(bp);
bp->b_pre_io = xfs_dir2_data_write_verify;
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}


int
xfs_dir2_data_read(
struct xfs_trans *tp,
Expand All @@ -214,7 +229,7 @@ xfs_dir2_data_read(
struct xfs_buf **bpp)
{
return xfs_da_read_buf(tp, dp, bno, mapped_bno, bpp,
XFS_DATA_FORK, xfs_dir2_data_verify);
XFS_DATA_FORK, xfs_dir2_data_read_verify);
}

int
Expand All @@ -225,7 +240,7 @@ xfs_dir2_data_readahead(
xfs_daddr_t mapped_bno)
{
return xfs_da_reada_buf(tp, dp, bno, mapped_bno,
XFS_DATA_FORK, xfs_dir2_data_verify);
XFS_DATA_FORK, xfs_dir2_data_read_verify);
}

/*
Expand Down
Loading

0 comments on commit 612cfbf

Please sign in to comment.