Commit 3d3e6f64 authored by Dave Chinner's avatar Dave Chinner Committed by Ben Myers

xfs: verify btree blocks as they are read from disk

Add an btree block verify callback function and pass it into the
buffer read functions. Because each different btree block type
requires different verification, add a function to the ops structure
that is called from the generic code.

Also, propagate the verification callback functions through the
readahead functions, and into the external bmap and bulkstat inode
readahead code that uses the generic btree buffer read functions.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarPhil White <pwhite@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent af133e86
...@@ -272,6 +272,66 @@ xfs_allocbt_key_diff( ...@@ -272,6 +272,66 @@ xfs_allocbt_key_diff(
return (__int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock; return (__int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock;
} }
void
xfs_allocbt_read_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
struct xfs_perag *pag = bp->b_pag;
unsigned int level;
int sblock_ok; /* block passes checks */
/*
* magic number and level verification
*
* During growfs operations, we can't verify the exact level as the
* perag is not fully initialised and hence not attached to the buffer.
* In this case, check against the maximum tree depth.
*/
level = be16_to_cpu(block->bb_level);
switch (block->bb_magic) {
case cpu_to_be32(XFS_ABTB_MAGIC):
if (pag)
sblock_ok = level < pag->pagf_levels[XFS_BTNUM_BNOi];
else
sblock_ok = level < mp->m_ag_maxlevels;
break;
case cpu_to_be32(XFS_ABTC_MAGIC):
if (pag)
sblock_ok = level < pag->pagf_levels[XFS_BTNUM_CNTi];
else
sblock_ok = level < mp->m_ag_maxlevels;
break;
default:
sblock_ok = 0;
break;
}
/* numrecs verification */
sblock_ok = sblock_ok &&
be16_to_cpu(block->bb_numrecs) <= mp->m_alloc_mxr[level != 0];
/* sibling pointer verification */
sblock_ok = sblock_ok &&
(block->bb_u.s.bb_leftsib == cpu_to_be32(NULLAGBLOCK) ||
be32_to_cpu(block->bb_u.s.bb_leftsib) < mp->m_sb.sb_agblocks) &&
block->bb_u.s.bb_leftsib &&
(block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK) ||
be32_to_cpu(block->bb_u.s.bb_rightsib) < mp->m_sb.sb_agblocks) &&
block->bb_u.s.bb_rightsib;
if (!sblock_ok) {
trace_xfs_btree_corrupt(bp, _RET_IP_);
XFS_CORRUPTION_ERROR("xfs_allocbt_read_verify",
XFS_ERRLEVEL_LOW, mp, block);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
#ifdef DEBUG #ifdef DEBUG
STATIC int STATIC int
xfs_allocbt_keys_inorder( xfs_allocbt_keys_inorder(
...@@ -327,6 +387,7 @@ static const struct xfs_btree_ops xfs_allocbt_ops = { ...@@ -327,6 +387,7 @@ static const struct xfs_btree_ops xfs_allocbt_ops = {
.init_rec_from_cur = xfs_allocbt_init_rec_from_cur, .init_rec_from_cur = xfs_allocbt_init_rec_from_cur,
.init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur,
.key_diff = xfs_allocbt_key_diff, .key_diff = xfs_allocbt_key_diff,
.read_verify = xfs_allocbt_read_verify,
#ifdef DEBUG #ifdef DEBUG
.keys_inorder = xfs_allocbt_keys_inorder, .keys_inorder = xfs_allocbt_keys_inorder,
.recs_inorder = xfs_allocbt_recs_inorder, .recs_inorder = xfs_allocbt_recs_inorder,
......
...@@ -2662,8 +2662,9 @@ xfs_bmap_btree_to_extents( ...@@ -2662,8 +2662,9 @@ xfs_bmap_btree_to_extents(
if ((error = xfs_btree_check_lptr(cur, cbno, 1))) if ((error = xfs_btree_check_lptr(cur, cbno, 1)))
return error; return error;
#endif #endif
if ((error = xfs_btree_read_bufl(mp, tp, cbno, 0, &cbp, error = xfs_btree_read_bufl(mp, tp, cbno, 0, &cbp, XFS_BMAP_BTREE_REF,
XFS_BMAP_BTREE_REF))) xfs_bmbt_read_verify);
if (error)
return error; return error;
cblock = XFS_BUF_TO_BLOCK(cbp); cblock = XFS_BUF_TO_BLOCK(cbp);
if ((error = xfs_btree_check_block(cur, cblock, 0, cbp))) if ((error = xfs_btree_check_block(cur, cblock, 0, cbp)))
...@@ -4078,8 +4079,9 @@ xfs_bmap_read_extents( ...@@ -4078,8 +4079,9 @@ xfs_bmap_read_extents(
* pointer (leftmost) at each level. * pointer (leftmost) at each level.
*/ */
while (level-- > 0) { while (level-- > 0) {
if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp,
XFS_BMAP_BTREE_REF))) XFS_BMAP_BTREE_REF, xfs_bmbt_read_verify);
if (error)
return error; return error;
block = XFS_BUF_TO_BLOCK(bp); block = XFS_BUF_TO_BLOCK(bp);
XFS_WANT_CORRUPTED_GOTO( XFS_WANT_CORRUPTED_GOTO(
...@@ -4124,7 +4126,8 @@ xfs_bmap_read_extents( ...@@ -4124,7 +4126,8 @@ xfs_bmap_read_extents(
*/ */
nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib);
if (nextbno != NULLFSBLOCK) if (nextbno != NULLFSBLOCK)
xfs_btree_reada_bufl(mp, nextbno, 1); xfs_btree_reada_bufl(mp, nextbno, 1,
xfs_bmbt_read_verify);
/* /*
* Copy records into the extent records. * Copy records into the extent records.
*/ */
...@@ -4156,8 +4159,9 @@ xfs_bmap_read_extents( ...@@ -4156,8 +4159,9 @@ xfs_bmap_read_extents(
*/ */
if (bno == NULLFSBLOCK) if (bno == NULLFSBLOCK)
break; break;
if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp,
XFS_BMAP_BTREE_REF))) XFS_BMAP_BTREE_REF, xfs_bmbt_read_verify);
if (error)
return error; return error;
block = XFS_BUF_TO_BLOCK(bp); block = XFS_BUF_TO_BLOCK(bp);
} }
...@@ -5868,15 +5872,16 @@ xfs_bmap_check_leaf_extents( ...@@ -5868,15 +5872,16 @@ xfs_bmap_check_leaf_extents(
*/ */
while (level-- > 0) { while (level-- > 0) {
/* See if buf is in cur first */ /* See if buf is in cur first */
bp_release = 0;
bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno)); bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno));
if (bp) { if (!bp) {
bp_release = 0;
} else {
bp_release = 1; bp_release = 1;
error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp,
XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
if (error)
goto error_norelse;
} }
if (!bp && (error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp,
XFS_BMAP_BTREE_REF)))
goto error_norelse;
block = XFS_BUF_TO_BLOCK(bp); block = XFS_BUF_TO_BLOCK(bp);
XFS_WANT_CORRUPTED_GOTO( XFS_WANT_CORRUPTED_GOTO(
xfs_bmap_sanity_check(mp, bp, level), xfs_bmap_sanity_check(mp, bp, level),
...@@ -5953,15 +5958,16 @@ xfs_bmap_check_leaf_extents( ...@@ -5953,15 +5958,16 @@ xfs_bmap_check_leaf_extents(
if (bno == NULLFSBLOCK) if (bno == NULLFSBLOCK)
break; break;
bp_release = 0;
bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno)); bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno));
if (bp) { if (!bp) {
bp_release = 0;
} else {
bp_release = 1; bp_release = 1;
error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp,
XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
if (error)
goto error_norelse;
} }
if (!bp && (error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp,
XFS_BMAP_BTREE_REF)))
goto error_norelse;
block = XFS_BUF_TO_BLOCK(bp); block = XFS_BUF_TO_BLOCK(bp);
} }
if (bp_release) { if (bp_release) {
...@@ -6052,7 +6058,9 @@ xfs_bmap_count_tree( ...@@ -6052,7 +6058,9 @@ xfs_bmap_count_tree(
struct xfs_btree_block *block, *nextblock; struct xfs_btree_block *block, *nextblock;
int numrecs; int numrecs;
if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, XFS_BMAP_BTREE_REF))) error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
if (error)
return error; return error;
*count += 1; *count += 1;
block = XFS_BUF_TO_BLOCK(bp); block = XFS_BUF_TO_BLOCK(bp);
...@@ -6061,8 +6069,10 @@ xfs_bmap_count_tree( ...@@ -6061,8 +6069,10 @@ xfs_bmap_count_tree(
/* Not at node above leaves, count this level of nodes */ /* Not at node above leaves, count this level of nodes */
nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib);
while (nextbno != NULLFSBLOCK) { while (nextbno != NULLFSBLOCK) {
if ((error = xfs_btree_read_bufl(mp, tp, nextbno, error = xfs_btree_read_bufl(mp, tp, nextbno, 0, &nbp,
0, &nbp, XFS_BMAP_BTREE_REF))) XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
if (error)
return error; return error;
*count += 1; *count += 1;
nextblock = XFS_BUF_TO_BLOCK(nbp); nextblock = XFS_BUF_TO_BLOCK(nbp);
...@@ -6091,8 +6101,10 @@ xfs_bmap_count_tree( ...@@ -6091,8 +6101,10 @@ xfs_bmap_count_tree(
if (nextbno == NULLFSBLOCK) if (nextbno == NULLFSBLOCK)
break; break;
bno = nextbno; bno = nextbno;
if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp,
XFS_BMAP_BTREE_REF))) XFS_BMAP_BTREE_REF,
xfs_bmbt_read_verify);
if (error)
return error; return error;
*count += 1; *count += 1;
block = XFS_BUF_TO_BLOCK(bp); block = XFS_BUF_TO_BLOCK(bp);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "xfs_bmap.h" #include "xfs_bmap.h"
#include "xfs_error.h" #include "xfs_error.h"
#include "xfs_quota.h" #include "xfs_quota.h"
#include "xfs_trace.h"
/* /*
* Determine the extent state. * Determine the extent state.
...@@ -707,6 +708,51 @@ xfs_bmbt_key_diff( ...@@ -707,6 +708,51 @@ xfs_bmbt_key_diff(
cur->bc_rec.b.br_startoff; cur->bc_rec.b.br_startoff;
} }
void
xfs_bmbt_read_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
unsigned int level;
int lblock_ok; /* block passes checks */
/* magic number and level verification.
*
* We don't know waht fork we belong to, so just verify that the level
* is less than the maximum of the two. Later checks will be more
* precise.
*/
level = be16_to_cpu(block->bb_level);
lblock_ok = block->bb_magic == cpu_to_be32(XFS_BMAP_MAGIC) &&
level < max(mp->m_bm_maxlevels[0], mp->m_bm_maxlevels[1]);
/* numrecs verification */
lblock_ok = lblock_ok &&
be16_to_cpu(block->bb_numrecs) <= mp->m_bmap_dmxr[level != 0];
/* sibling pointer verification */
lblock_ok = lblock_ok &&
block->bb_u.l.bb_leftsib &&
(block->bb_u.l.bb_leftsib == cpu_to_be64(NULLDFSBNO) ||
XFS_FSB_SANITY_CHECK(mp,
be64_to_cpu(block->bb_u.l.bb_leftsib))) &&
block->bb_u.l.bb_rightsib &&
(block->bb_u.l.bb_rightsib == cpu_to_be64(NULLDFSBNO) ||
XFS_FSB_SANITY_CHECK(mp,
be64_to_cpu(block->bb_u.l.bb_rightsib)));
if (!lblock_ok) {
trace_xfs_btree_corrupt(bp, _RET_IP_);
XFS_CORRUPTION_ERROR("xfs_bmbt_read_verify",
XFS_ERRLEVEL_LOW, mp, block);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
#ifdef DEBUG #ifdef DEBUG
STATIC int STATIC int
xfs_bmbt_keys_inorder( xfs_bmbt_keys_inorder(
...@@ -746,6 +792,7 @@ static const struct xfs_btree_ops xfs_bmbt_ops = { ...@@ -746,6 +792,7 @@ static const struct xfs_btree_ops xfs_bmbt_ops = {
.init_rec_from_cur = xfs_bmbt_init_rec_from_cur, .init_rec_from_cur = xfs_bmbt_init_rec_from_cur,
.init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur, .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
.key_diff = xfs_bmbt_key_diff, .key_diff = xfs_bmbt_key_diff,
.read_verify = xfs_bmbt_read_verify,
#ifdef DEBUG #ifdef DEBUG
.keys_inorder = xfs_bmbt_keys_inorder, .keys_inorder = xfs_bmbt_keys_inorder,
.recs_inorder = xfs_bmbt_recs_inorder, .recs_inorder = xfs_bmbt_recs_inorder,
......
...@@ -232,6 +232,7 @@ extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int, ...@@ -232,6 +232,7 @@ 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_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
extern int xfs_bmdr_maxrecs(struct xfs_mount *, int blocklen, int leaf); 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 int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
extern void xfs_bmbt_read_verify(struct xfs_buf *bp);
extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
struct xfs_trans *, struct xfs_inode *, int); struct xfs_trans *, struct xfs_inode *, int);
......
...@@ -270,7 +270,8 @@ xfs_btree_dup_cursor( ...@@ -270,7 +270,8 @@ xfs_btree_dup_cursor(
if (bp) { if (bp) {
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
XFS_BUF_ADDR(bp), mp->m_bsize, XFS_BUF_ADDR(bp), mp->m_bsize,
0, &bp, NULL); 0, &bp,
cur->bc_ops->read_verify);
if (error) { if (error) {
xfs_btree_del_cursor(new, error); xfs_btree_del_cursor(new, error);
*ncur = NULL; *ncur = NULL;
...@@ -612,23 +613,24 @@ xfs_btree_offsets( ...@@ -612,23 +613,24 @@ xfs_btree_offsets(
* Get a buffer for the block, return it read in. * Get a buffer for the block, return it read in.
* Long-form addressing. * Long-form addressing.
*/ */
int /* error */ int
xfs_btree_read_bufl( xfs_btree_read_bufl(
xfs_mount_t *mp, /* file system mount point */ struct xfs_mount *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */ struct xfs_trans *tp, /* transaction pointer */
xfs_fsblock_t fsbno, /* file system block number */ xfs_fsblock_t fsbno, /* file system block number */
uint lock, /* lock flags for read_buf */ uint lock, /* lock flags for read_buf */
xfs_buf_t **bpp, /* buffer for fsbno */ struct xfs_buf **bpp, /* buffer for fsbno */
int refval) /* ref count value for buffer */ int refval, /* ref count value for buffer */
{ xfs_buf_iodone_t verify)
xfs_buf_t *bp; /* return value */ {
struct xfs_buf *bp; /* return value */
xfs_daddr_t d; /* real disk block address */ xfs_daddr_t d; /* real disk block address */
int error; int error;
ASSERT(fsbno != NULLFSBLOCK); ASSERT(fsbno != NULLFSBLOCK);
d = XFS_FSB_TO_DADDR(mp, fsbno); d = XFS_FSB_TO_DADDR(mp, fsbno);
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, d, error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, d,
mp->m_bsize, lock, &bp, NULL); mp->m_bsize, lock, &bp, verify);
if (error) if (error)
return error; return error;
ASSERT(!xfs_buf_geterror(bp)); ASSERT(!xfs_buf_geterror(bp));
...@@ -645,15 +647,16 @@ xfs_btree_read_bufl( ...@@ -645,15 +647,16 @@ xfs_btree_read_bufl(
/* ARGSUSED */ /* ARGSUSED */
void void
xfs_btree_reada_bufl( xfs_btree_reada_bufl(
xfs_mount_t *mp, /* file system mount point */ struct xfs_mount *mp, /* file system mount point */
xfs_fsblock_t fsbno, /* file system block number */ xfs_fsblock_t fsbno, /* file system block number */
xfs_extlen_t count) /* count of filesystem blocks */ xfs_extlen_t count, /* count of filesystem blocks */
xfs_buf_iodone_t verify)
{ {
xfs_daddr_t d; xfs_daddr_t d;
ASSERT(fsbno != NULLFSBLOCK); ASSERT(fsbno != NULLFSBLOCK);
d = XFS_FSB_TO_DADDR(mp, fsbno); d = XFS_FSB_TO_DADDR(mp, fsbno);
xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, NULL); xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, verify);
} }
/* /*
...@@ -663,17 +666,18 @@ xfs_btree_reada_bufl( ...@@ -663,17 +666,18 @@ xfs_btree_reada_bufl(
/* ARGSUSED */ /* ARGSUSED */
void void
xfs_btree_reada_bufs( xfs_btree_reada_bufs(
xfs_mount_t *mp, /* file system mount point */ struct xfs_mount *mp, /* file system mount point */
xfs_agnumber_t agno, /* allocation group number */ xfs_agnumber_t agno, /* allocation group number */
xfs_agblock_t agbno, /* allocation group block number */ xfs_agblock_t agbno, /* allocation group block number */
xfs_extlen_t count) /* count of filesystem blocks */ xfs_extlen_t count, /* count of filesystem blocks */
xfs_buf_iodone_t verify)
{ {
xfs_daddr_t d; xfs_daddr_t d;
ASSERT(agno != NULLAGNUMBER); ASSERT(agno != NULLAGNUMBER);
ASSERT(agbno != NULLAGBLOCK); ASSERT(agbno != NULLAGBLOCK);
d = XFS_AGB_TO_DADDR(mp, agno, agbno); d = XFS_AGB_TO_DADDR(mp, agno, agbno);
xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, NULL); xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, verify);
} }
STATIC int STATIC int
...@@ -687,12 +691,14 @@ xfs_btree_readahead_lblock( ...@@ -687,12 +691,14 @@ xfs_btree_readahead_lblock(
xfs_dfsbno_t right = be64_to_cpu(block->bb_u.l.bb_rightsib); xfs_dfsbno_t right = be64_to_cpu(block->bb_u.l.bb_rightsib);
if ((lr & XFS_BTCUR_LEFTRA) && left != NULLDFSBNO) { if ((lr & XFS_BTCUR_LEFTRA) && left != NULLDFSBNO) {
xfs_btree_reada_bufl(cur->bc_mp, left, 1); xfs_btree_reada_bufl(cur->bc_mp, left, 1,
cur->bc_ops->read_verify);
rval++; rval++;
} }
if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLDFSBNO) { if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLDFSBNO) {
xfs_btree_reada_bufl(cur->bc_mp, right, 1); xfs_btree_reada_bufl(cur->bc_mp, right, 1,
cur->bc_ops->read_verify);
rval++; rval++;
} }
...@@ -712,13 +718,13 @@ xfs_btree_readahead_sblock( ...@@ -712,13 +718,13 @@ xfs_btree_readahead_sblock(
if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) { if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) {
xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno, xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno,
left, 1); left, 1, cur->bc_ops->read_verify);
rval++; rval++;
} }
if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) { if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) {
xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno, xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno,
right, 1); right, 1, cur->bc_ops->read_verify);
rval++; rval++;
} }
...@@ -1016,19 +1022,15 @@ xfs_btree_read_buf_block( ...@@ -1016,19 +1022,15 @@ xfs_btree_read_buf_block(
d = xfs_btree_ptr_to_daddr(cur, ptr); d = xfs_btree_ptr_to_daddr(cur, ptr);
error = xfs_trans_read_buf(mp, cur->bc_tp, mp->m_ddev_targp, d, error = xfs_trans_read_buf(mp, cur->bc_tp, mp->m_ddev_targp, d,
mp->m_bsize, flags, bpp, NULL); mp->m_bsize, flags, bpp,
cur->bc_ops->read_verify);
if (error) if (error)
return error; return error;
ASSERT(!xfs_buf_geterror(*bpp)); ASSERT(!xfs_buf_geterror(*bpp));
xfs_btree_set_refs(cur, *bpp); xfs_btree_set_refs(cur, *bpp);
*block = XFS_BUF_TO_BLOCK(*bpp); *block = XFS_BUF_TO_BLOCK(*bpp);
return 0;
error = xfs_btree_check_block(cur, *block, level, *bpp);
if (error)
xfs_trans_brelse(cur->bc_tp, *bpp);
return error;
} }
/* /*
......
...@@ -188,6 +188,7 @@ struct xfs_btree_ops { ...@@ -188,6 +188,7 @@ struct xfs_btree_ops {
__int64_t (*key_diff)(struct xfs_btree_cur *cur, __int64_t (*key_diff)(struct xfs_btree_cur *cur,
union xfs_btree_key *key); union xfs_btree_key *key);
void (*read_verify)(struct xfs_buf *bp);
#ifdef DEBUG #ifdef DEBUG
/* check that k1 is lower than k2 */ /* check that k1 is lower than k2 */
int (*keys_inorder)(struct xfs_btree_cur *cur, int (*keys_inorder)(struct xfs_btree_cur *cur,
...@@ -355,7 +356,8 @@ xfs_btree_read_bufl( ...@@ -355,7 +356,8 @@ xfs_btree_read_bufl(
xfs_fsblock_t fsbno, /* file system block number */ xfs_fsblock_t fsbno, /* file system block number */
uint lock, /* lock flags for read_buf */ uint lock, /* lock flags for read_buf */
struct xfs_buf **bpp, /* buffer for fsbno */ struct xfs_buf **bpp, /* buffer for fsbno */
int refval);/* ref count value for buffer */ int refval, /* ref count value for buffer */
xfs_buf_iodone_t verify);
/* /*
* Read-ahead the block, don't wait for it, don't return a buffer. * Read-ahead the block, don't wait for it, don't return a buffer.
...@@ -365,7 +367,8 @@ void /* error */ ...@@ -365,7 +367,8 @@ void /* error */
xfs_btree_reada_bufl( xfs_btree_reada_bufl(
struct xfs_mount *mp, /* file system mount point */ struct xfs_mount *mp, /* file system mount point */
xfs_fsblock_t fsbno, /* file system block number */ xfs_fsblock_t fsbno, /* file system block number */
xfs_extlen_t count); /* count of filesystem blocks */ xfs_extlen_t count, /* count of filesystem blocks */
xfs_buf_iodone_t verify);
/* /*
* Read-ahead the block, don't wait for it, don't return a buffer. * Read-ahead the block, don't wait for it, don't return a buffer.
...@@ -376,7 +379,8 @@ xfs_btree_reada_bufs( ...@@ -376,7 +379,8 @@ xfs_btree_reada_bufs(
struct xfs_mount *mp, /* file system mount point */ struct xfs_mount *mp, /* file system mount point */
xfs_agnumber_t agno, /* allocation group number */ xfs_agnumber_t agno, /* allocation group number */
xfs_agblock_t agbno, /* allocation group block number */ xfs_agblock_t agbno, /* allocation group block number */
xfs_extlen_t count); /* count of filesystem blocks */ xfs_extlen_t count, /* count of filesystem blocks */
xfs_buf_iodone_t verify);
/* /*
* Initialise a new btree block header * Initialise a new btree block header
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "xfs_ialloc.h" #include "xfs_ialloc.h"
#include "xfs_alloc.h" #include "xfs_alloc.h"
#include "xfs_error.h" #include "xfs_error.h"
#include "xfs_trace.h"
STATIC int STATIC int
...@@ -181,6 +182,44 @@ xfs_inobt_key_diff( ...@@ -181,6 +182,44 @@ xfs_inobt_key_diff(
cur->bc_rec.i.ir_startino; cur->bc_rec.i.ir_startino;
} }
void
xfs_inobt_read_verify(
struct xfs_buf *bp)
{
struct xfs_mount *mp = bp->b_target->bt_mount;
struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
unsigned int level;
int sblock_ok; /* block passes checks */
/* magic number and level verification */
level = be16_to_cpu(block->bb_level);
sblock_ok = block->bb_magic == cpu_to_be32(XFS_IBT_MAGIC) &&
level < mp->m_in_maxlevels;
/* numrecs verification */
sblock_ok = sblock_ok &&
be16_to_cpu(block->bb_numrecs) <= mp->m_inobt_mxr[level != 0];
/* sibling pointer verification */
sblock_ok = sblock_ok &&
(block->bb_u.s.bb_leftsib == cpu_to_be32(NULLAGBLOCK) ||
be32_to_cpu(block->bb_u.s.bb_leftsib) < mp->m_sb.sb_agblocks) &&
block->bb_u.s.bb_leftsib &&
(block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK) ||
be32_to_cpu(block->bb_u.s.bb_rightsib) < mp->m_sb.sb_agblocks) &&
block->bb_u.s.bb_rightsib;
if (!sblock_ok) {
trace_xfs_btree_corrupt(bp, _RET_IP_);
XFS_CORRUPTION_ERROR("xfs_inobt_read_verify",
XFS_ERRLEVEL_LOW, mp, block);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
bp->b_iodone = NULL;
xfs_buf_ioend(bp, 0);
}
#ifdef DEBUG #ifdef DEBUG
STATIC int STATIC int
xfs_inobt_keys_inorder( xfs_inobt_keys_inorder(
...@@ -218,6 +257,7 @@ static const struct xfs_btree_ops xfs_inobt_ops = { ...@@ -218,6 +257,7 @@ static const struct xfs_btree_ops xfs_inobt_ops = {
.init_rec_from_cur = xfs_inobt_init_rec_from_cur, .init_rec_from_cur = xfs_inobt_init_rec_from_cur,
.init_ptr_from_cur = xfs_inobt_init_ptr_from_cur, .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur,
.key_diff = xfs_inobt_key_diff, .key_diff = xfs_inobt_key_diff,
.read_verify = xfs_inobt_read_verify,
#ifdef DEBUG #ifdef DEBUG
.keys_inorder = xfs_inobt_keys_inorder, .keys_inorder = xfs_inobt_keys_inorder,
.recs_inorder = xfs_inobt_recs_inorder, .recs_inorder = xfs_inobt_recs_inorder,
......
...@@ -382,7 +382,7 @@ xfs_inobp_check( ...@@ -382,7 +382,7 @@ xfs_inobp_check(
} }
#endif #endif
static void void
xfs_inode_buf_verify( xfs_inode_buf_verify(
struct xfs_buf *bp) struct xfs_buf *bp)
{ {
......
...@@ -554,6 +554,7 @@ int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *, ...@@ -554,6 +554,7 @@ int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
struct xfs_buf **, uint, uint); struct xfs_buf **, uint, uint);
int xfs_iread(struct xfs_mount *, struct xfs_trans *, int xfs_iread(struct xfs_mount *, struct xfs_trans *,
struct xfs_inode *, uint); struct xfs_inode *, uint);
void xfs_inode_buf_verify(struct xfs_buf *);
void xfs_dinode_to_disk(struct xfs_dinode *, void xfs_dinode_to_disk(struct xfs_dinode *,
struct xfs_icdinode *); struct xfs_icdinode *);
void xfs_idestroy_fork(struct xfs_inode *, int); void xfs_idestroy_fork(struct xfs_inode *, int);
......
...@@ -396,7 +396,8 @@ xfs_bulkstat( ...@@ -396,7 +396,8 @@ xfs_bulkstat(
if (xfs_inobt_maskn(chunkidx, nicluster) if (xfs_inobt_maskn(chunkidx, nicluster)
& ~r.ir_free) & ~r.ir_free)
xfs_btree_reada_bufs(mp, agno, xfs_btree_reada_bufs(mp, agno,
agbno, nbcluster); agbno, nbcluster,
xfs_inode_buf_verify);
} }
irbp->ir_startino = r.ir_startino; irbp->ir_startino = r.ir_startino;
irbp->ir_freecount = r.ir_freecount; irbp->ir_freecount = r.ir_freecount;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment