diff options
author | Dave Chinner <dchinner@redhat.com> | 2012-11-12 06:54:08 -0500 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2012-11-15 22:34:31 -0500 |
commit | 3d3e6f64e22c94115d47de670611bcd3ecda3796 (patch) | |
tree | ec97be647a06d5aef171333624b370cf482285b4 /fs/xfs/xfs_alloc_btree.c | |
parent | af133e8606d32c2aed43870491ebbdc56feec8a8 (diff) |
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: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Phil White <pwhite@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_alloc_btree.c')
-rw-r--r-- | fs/xfs/xfs_alloc_btree.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/fs/xfs/xfs_alloc_btree.c b/fs/xfs/xfs_alloc_btree.c index f7876c6d6165..46961e52e9b8 100644 --- a/fs/xfs/xfs_alloc_btree.c +++ b/fs/xfs/xfs_alloc_btree.c | |||
@@ -272,6 +272,66 @@ xfs_allocbt_key_diff( | |||
272 | return (__int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock; | 272 | return (__int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock; |
273 | } | 273 | } |
274 | 274 | ||
275 | void | ||
276 | xfs_allocbt_read_verify( | ||
277 | struct xfs_buf *bp) | ||
278 | { | ||
279 | struct xfs_mount *mp = bp->b_target->bt_mount; | ||
280 | struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); | ||
281 | struct xfs_perag *pag = bp->b_pag; | ||
282 | unsigned int level; | ||
283 | int sblock_ok; /* block passes checks */ | ||
284 | |||
285 | /* | ||
286 | * magic number and level verification | ||
287 | * | ||
288 | * During growfs operations, we can't verify the exact level as the | ||
289 | * perag is not fully initialised and hence not attached to the buffer. | ||
290 | * In this case, check against the maximum tree depth. | ||
291 | */ | ||
292 | level = be16_to_cpu(block->bb_level); | ||
293 | switch (block->bb_magic) { | ||
294 | case cpu_to_be32(XFS_ABTB_MAGIC): | ||
295 | if (pag) | ||
296 | sblock_ok = level < pag->pagf_levels[XFS_BTNUM_BNOi]; | ||
297 | else | ||
298 | sblock_ok = level < mp->m_ag_maxlevels; | ||
299 | break; | ||
300 | case cpu_to_be32(XFS_ABTC_MAGIC): | ||
301 | if (pag) | ||
302 | sblock_ok = level < pag->pagf_levels[XFS_BTNUM_CNTi]; | ||
303 | else | ||
304 | sblock_ok = level < mp->m_ag_maxlevels; | ||
305 | break; | ||
306 | default: | ||
307 | sblock_ok = 0; | ||
308 | break; | ||
309 | } | ||
310 | |||
311 | /* numrecs verification */ | ||
312 | sblock_ok = sblock_ok && | ||
313 | be16_to_cpu(block->bb_numrecs) <= mp->m_alloc_mxr[level != 0]; | ||
314 | |||
315 | /* sibling pointer verification */ | ||
316 | sblock_ok = sblock_ok && | ||
317 | (block->bb_u.s.bb_leftsib == cpu_to_be32(NULLAGBLOCK) || | ||
318 | be32_to_cpu(block->bb_u.s.bb_leftsib) < mp->m_sb.sb_agblocks) && | ||
319 | block->bb_u.s.bb_leftsib && | ||
320 | (block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK) || | ||
321 | be32_to_cpu(block->bb_u.s.bb_rightsib) < mp->m_sb.sb_agblocks) && | ||
322 | block->bb_u.s.bb_rightsib; | ||
323 | |||
324 | if (!sblock_ok) { | ||
325 | trace_xfs_btree_corrupt(bp, _RET_IP_); | ||
326 | XFS_CORRUPTION_ERROR("xfs_allocbt_read_verify", | ||
327 | XFS_ERRLEVEL_LOW, mp, block); | ||
328 | xfs_buf_ioerror(bp, EFSCORRUPTED); | ||
329 | } | ||
330 | |||
331 | bp->b_iodone = NULL; | ||
332 | xfs_buf_ioend(bp, 0); | ||
333 | } | ||
334 | |||
275 | #ifdef DEBUG | 335 | #ifdef DEBUG |
276 | STATIC int | 336 | STATIC int |
277 | xfs_allocbt_keys_inorder( | 337 | xfs_allocbt_keys_inorder( |
@@ -327,6 +387,7 @@ static const struct xfs_btree_ops xfs_allocbt_ops = { | |||
327 | .init_rec_from_cur = xfs_allocbt_init_rec_from_cur, | 387 | .init_rec_from_cur = xfs_allocbt_init_rec_from_cur, |
328 | .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, | 388 | .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, |
329 | .key_diff = xfs_allocbt_key_diff, | 389 | .key_diff = xfs_allocbt_key_diff, |
390 | .read_verify = xfs_allocbt_read_verify, | ||
330 | #ifdef DEBUG | 391 | #ifdef DEBUG |
331 | .keys_inorder = xfs_allocbt_keys_inorder, | 392 | .keys_inorder = xfs_allocbt_keys_inorder, |
332 | .recs_inorder = xfs_allocbt_recs_inorder, | 393 | .recs_inorder = xfs_allocbt_recs_inorder, |