Skip to content

Commit

Permalink
xfs: convert buffer verifiers to an ops structure.
Browse files Browse the repository at this point in the history
To separate the verifiers from iodone functions and associate read
and write verifiers at the same time, introduce a buffer verifier
operations structure to the xfs_buf.

This avoids the need for assigning the write verifier, clearing the
iodone function and re-running ioend processing in the read
verifier, and gets rid of the nasty "b_pre_io" name for the write
verifier function pointer. If we ever need to, it will also be
easier to add further content specific callbacks to a buffer with an
ops structure in place.

We also avoid needing to export verifier functions, instead we
can simply export the ops structures for those that are needed
outside the function they are defined in.

This patch also fixes a directory block readahead verifier issue
it exposed.

This patch also adds ops callbacks to the inode/alloc btree blocks
initialised by growfs. These will need more work before they will
work with CRCs.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Phil White <pwhite@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
  • Loading branch information
Dave Chinner authored and Ben Myers committed Nov 16, 2012
1 parent b0f539d commit 1813dd6
Show file tree
Hide file tree
Showing 37 changed files with 357 additions and 249 deletions.
4 changes: 4 additions & 0 deletions fs/xfs/xfs_ag.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ typedef struct xfs_agf {
extern int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);

extern const struct xfs_buf_ops xfs_agf_buf_ops;

/*
* Size of the unlinked inode hash table in the agi.
*/
Expand Down Expand Up @@ -161,6 +163,8 @@ typedef struct xfs_agi {
extern int xfs_read_agi(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_agnumber_t agno, struct xfs_buf **bpp);

extern const struct xfs_buf_ops xfs_agi_buf_ops;

/*
* The third a.g. block contains the a.g. freelist, an array
* of block pointers to blocks owned by the allocation btree code.
Expand Down
28 changes: 16 additions & 12 deletions fs/xfs/xfs_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ xfs_agfl_verify(
#endif
}

void
static void
xfs_agfl_write_verify(
struct xfs_buf *bp)
{
Expand All @@ -477,11 +477,13 @@ 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);
}

const struct xfs_buf_ops xfs_agfl_buf_ops = {
.verify_read = xfs_agfl_read_verify,
.verify_write = xfs_agfl_write_verify,
};

/*
* Read in the allocation group free block array.
*/
Expand All @@ -499,7 +501,7 @@ xfs_alloc_read_agfl(
error = xfs_trans_read_buf(
mp, tp, mp->m_ddev_targp,
XFS_AG_DADDR(mp, agno, XFS_AGFL_DADDR(mp)),
XFS_FSS_TO_BB(mp, 1), 0, &bp, xfs_agfl_read_verify);
XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_agfl_buf_ops);
if (error)
return error;
ASSERT(!xfs_buf_geterror(bp));
Expand Down Expand Up @@ -2181,23 +2183,25 @@ xfs_agf_verify(
}
}

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

static void
xfs_agf_read_verify(
xfs_agf_write_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);
}

const struct xfs_buf_ops xfs_agf_buf_ops = {
.verify_read = xfs_agf_read_verify,
.verify_write = xfs_agf_write_verify,
};

/*
* Read in the allocation group header (free/alloc section).
*/
Expand All @@ -2215,7 +2219,7 @@ xfs_read_agf(
error = xfs_trans_read_buf(
mp, tp, mp->m_ddev_targp,
XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
XFS_FSS_TO_BB(mp, 1), flags, bpp, xfs_agf_read_verify);
XFS_FSS_TO_BB(mp, 1), flags, bpp, &xfs_agf_buf_ops);
if (error)
return error;
if (!*bpp)
Expand Down
4 changes: 2 additions & 2 deletions fs/xfs/xfs_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ xfs_alloc_get_rec(
xfs_extlen_t *len, /* output: length of extent */
int *stat); /* output: success/failure */

void xfs_agf_write_verify(struct xfs_buf *bp);
void xfs_agfl_write_verify(struct xfs_buf *bp);
extern const struct xfs_buf_ops xfs_agf_buf_ops;
extern const struct xfs_buf_ops xfs_agfl_buf_ops;

#endif /* __XFS_ALLOC_H__ */
18 changes: 10 additions & 8 deletions fs/xfs/xfs_alloc_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,25 @@ xfs_allocbt_verify(
}

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

void
xfs_allocbt_read_verify(
static void
xfs_allocbt_write_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);
}

const struct xfs_buf_ops xfs_allocbt_buf_ops = {
.verify_read = xfs_allocbt_read_verify,
.verify_write = xfs_allocbt_write_verify,
};


#ifdef DEBUG
STATIC int
xfs_allocbt_keys_inorder(
Expand Down Expand Up @@ -400,8 +403,7 @@ static const struct xfs_btree_ops xfs_allocbt_ops = {
.init_rec_from_cur = xfs_allocbt_init_rec_from_cur,
.init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur,
.key_diff = xfs_allocbt_key_diff,
.read_verify = xfs_allocbt_read_verify,
.write_verify = xfs_allocbt_write_verify,
.buf_ops = &xfs_allocbt_buf_ops,
#ifdef DEBUG
.keys_inorder = xfs_allocbt_keys_inorder,
.recs_inorder = xfs_allocbt_recs_inorder,
Expand Down
2 changes: 2 additions & 0 deletions fs/xfs/xfs_alloc_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *,
xfs_agnumber_t, xfs_btnum_t);
extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int);

extern const struct xfs_buf_ops xfs_allocbt_buf_ops;

#endif /* __XFS_ALLOC_BTREE_H__ */
19 changes: 10 additions & 9 deletions fs/xfs/xfs_attr_leaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,23 @@ xfs_attr_leaf_verify(
}

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

void
xfs_attr_leaf_read_verify(
static void
xfs_attr_leaf_write_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);
}

const struct xfs_buf_ops xfs_attr_leaf_buf_ops = {
.verify_read = xfs_attr_leaf_read_verify,
.verify_write = xfs_attr_leaf_write_verify,
};

int
xfs_attr_leaf_read(
Expand All @@ -130,7 +131,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_read_verify);
XFS_ATTR_FORK, &xfs_attr_leaf_buf_ops);
}

/*========================================================================
Expand Down Expand Up @@ -924,7 +925,7 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)
XFS_ATTR_FORK);
if (error)
goto out;
bp2->b_pre_io = bp1->b_pre_io;
bp2->b_ops = bp1->b_ops;
memcpy(bp2->b_addr, bp1->b_addr, XFS_LBSIZE(dp->i_mount));
bp1 = NULL;
xfs_trans_log_buf(args->trans, bp2, 0, XFS_LBSIZE(dp->i_mount) - 1);
Expand Down Expand Up @@ -978,7 +979,7 @@ xfs_attr_leaf_create(
XFS_ATTR_FORK);
if (error)
return(error);
bp->b_pre_io = xfs_attr_leaf_write_verify;
bp->b_ops = &xfs_attr_leaf_buf_ops;
leaf = bp->b_addr;
memset((char *)leaf, 0, XFS_LBSIZE(dp->i_mount));
hdr = &leaf->hdr;
Expand Down
3 changes: 2 additions & 1 deletion fs/xfs/xfs_attr_leaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ 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_read_verify(struct xfs_buf *bp);

extern const struct xfs_buf_ops xfs_attr_leaf_buf_ops;

#endif /* __XFS_ATTR_LEAF_H__ */
22 changes: 11 additions & 11 deletions fs/xfs/xfs_bmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,7 @@ xfs_bmap_btree_to_extents(
return error;
#endif
error = xfs_btree_read_bufl(mp, tp, cbno, 0, &cbp, XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
&xfs_bmbt_buf_ops);
if (error)
return error;
cblock = XFS_BUF_TO_BLOCK(cbp);
Expand Down Expand Up @@ -3124,7 +3124,7 @@ xfs_bmap_extents_to_btree(
/*
* Fill in the child block.
*/
abp->b_pre_io = xfs_bmbt_write_verify;
abp->b_ops = &xfs_bmbt_buf_ops;
ablock = XFS_BUF_TO_BLOCK(abp);
ablock->bb_magic = cpu_to_be32(XFS_BMAP_MAGIC);
ablock->bb_level = 0;
Expand Down Expand Up @@ -3271,7 +3271,7 @@ xfs_bmap_local_to_extents(
ASSERT(args.len == 1);
*firstblock = args.fsbno;
bp = xfs_btree_get_bufl(args.mp, tp, args.fsbno, 0);
bp->b_pre_io = xfs_bmbt_write_verify;
bp->b_ops = &xfs_bmbt_buf_ops;
memcpy(bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes);
xfs_trans_log_buf(tp, bp, 0, ifp->if_bytes - 1);
xfs_bmap_forkoff_reset(args.mp, ip, whichfork);
Expand Down Expand Up @@ -4082,7 +4082,7 @@ xfs_bmap_read_extents(
*/
while (level-- > 0) {
error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp,
XFS_BMAP_BTREE_REF, xfs_bmbt_read_verify);
XFS_BMAP_BTREE_REF, &xfs_bmbt_buf_ops);
if (error)
return error;
block = XFS_BUF_TO_BLOCK(bp);
Expand Down Expand Up @@ -4129,7 +4129,7 @@ xfs_bmap_read_extents(
nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib);
if (nextbno != NULLFSBLOCK)
xfs_btree_reada_bufl(mp, nextbno, 1,
xfs_bmbt_read_verify);
&xfs_bmbt_buf_ops);
/*
* Copy records into the extent records.
*/
Expand Down Expand Up @@ -4162,7 +4162,7 @@ xfs_bmap_read_extents(
if (bno == NULLFSBLOCK)
break;
error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp,
XFS_BMAP_BTREE_REF, xfs_bmbt_read_verify);
XFS_BMAP_BTREE_REF, &xfs_bmbt_buf_ops);
if (error)
return error;
block = XFS_BUF_TO_BLOCK(bp);
Expand Down Expand Up @@ -5880,7 +5880,7 @@ xfs_bmap_check_leaf_extents(
bp_release = 1;
error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp,
XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
&xfs_bmbt_buf_ops);
if (error)
goto error_norelse;
}
Expand Down Expand Up @@ -5966,7 +5966,7 @@ xfs_bmap_check_leaf_extents(
bp_release = 1;
error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp,
XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
&xfs_bmbt_buf_ops);
if (error)
goto error_norelse;
}
Expand Down Expand Up @@ -6061,7 +6061,7 @@ xfs_bmap_count_tree(
int numrecs;

error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
&xfs_bmbt_buf_ops);
if (error)
return error;
*count += 1;
Expand All @@ -6073,7 +6073,7 @@ xfs_bmap_count_tree(
while (nextbno != NULLFSBLOCK) {
error = xfs_btree_read_bufl(mp, tp, nextbno, 0, &nbp,
XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
&xfs_bmbt_buf_ops);
if (error)
return error;
*count += 1;
Expand Down Expand Up @@ -6105,7 +6105,7 @@ xfs_bmap_count_tree(
bno = nextbno;
error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp,
XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
&xfs_bmbt_buf_ops);
if (error)
return error;
*count += 1;
Expand Down
20 changes: 11 additions & 9 deletions fs/xfs/xfs_bmap_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,23 +749,26 @@ xfs_bmbt_verify(
}
}

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

void
xfs_bmbt_read_verify(
static void
xfs_bmbt_write_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);
}

const struct xfs_buf_ops xfs_bmbt_buf_ops = {
.verify_read = xfs_bmbt_read_verify,
.verify_write = xfs_bmbt_write_verify,
};


#ifdef DEBUG
STATIC int
xfs_bmbt_keys_inorder(
Expand Down Expand Up @@ -805,8 +808,7 @@ static const struct xfs_btree_ops xfs_bmbt_ops = {
.init_rec_from_cur = xfs_bmbt_init_rec_from_cur,
.init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
.key_diff = xfs_bmbt_key_diff,
.read_verify = xfs_bmbt_read_verify,
.write_verify = xfs_bmbt_write_verify,
.buf_ops = &xfs_bmbt_buf_ops,
#ifdef DEBUG
.keys_inorder = xfs_bmbt_keys_inorder,
.recs_inorder = xfs_bmbt_recs_inorder,
Expand Down
3 changes: 1 addition & 2 deletions fs/xfs/xfs_bmap_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
extern int xfs_bmdr_maxrecs(struct xfs_mount *, int blocklen, int leaf);
extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
extern void xfs_bmbt_read_verify(struct xfs_buf *bp);
extern void xfs_bmbt_write_verify(struct xfs_buf *bp);

extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
struct xfs_trans *, struct xfs_inode *, int);

extern const struct xfs_buf_ops xfs_bmbt_buf_ops;

#endif /* __XFS_BMAP_BTREE_H__ */
Loading

0 comments on commit 1813dd6

Please sign in to comment.