diff options
Diffstat (limited to 'fs/xfs/xfs_ialloc_btree.c')
| -rw-r--r-- | fs/xfs/xfs_ialloc_btree.c | 254 | 
1 files changed, 165 insertions, 89 deletions
diff --git a/fs/xfs/xfs_ialloc_btree.c b/fs/xfs/xfs_ialloc_btree.c index 16921f55c54..726f83a681a 100644 --- a/fs/xfs/xfs_ialloc_btree.c +++ b/fs/xfs/xfs_ialloc_btree.c @@ -17,24 +17,23 @@   */  #include "xfs.h"  #include "xfs_fs.h" -#include "xfs_types.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h"  #include "xfs_bit.h" -#include "xfs_log.h" -#include "xfs_inum.h" -#include "xfs_trans.h"  #include "xfs_sb.h"  #include "xfs_ag.h"  #include "xfs_mount.h" -#include "xfs_bmap_btree.h" -#include "xfs_alloc_btree.h" -#include "xfs_ialloc_btree.h" -#include "xfs_dinode.h"  #include "xfs_inode.h"  #include "xfs_btree.h" -#include "xfs_btree_trace.h"  #include "xfs_ialloc.h" +#include "xfs_ialloc_btree.h"  #include "xfs_alloc.h"  #include "xfs_error.h" +#include "xfs_trace.h" +#include "xfs_cksum.h" +#include "xfs_trans.h"  STATIC int @@ -50,7 +49,8 @@ xfs_inobt_dup_cursor(  	struct xfs_btree_cur	*cur)  {  	return xfs_inobt_init_cursor(cur->bc_mp, cur->bc_tp, -			cur->bc_private.a.agbp, cur->bc_private.a.agno); +			cur->bc_private.a.agbp, cur->bc_private.a.agno, +			cur->bc_btnum);  }  STATIC void @@ -67,12 +67,26 @@ xfs_inobt_set_root(  	xfs_ialloc_log_agi(cur->bc_tp, agbp, XFS_AGI_ROOT | XFS_AGI_LEVEL);  } +STATIC void +xfs_finobt_set_root( +	struct xfs_btree_cur	*cur, +	union xfs_btree_ptr	*nptr, +	int			inc)	/* level change */ +{ +	struct xfs_buf		*agbp = cur->bc_private.a.agbp; +	struct xfs_agi		*agi = XFS_BUF_TO_AGI(agbp); + +	agi->agi_free_root = nptr->s; +	be32_add_cpu(&agi->agi_free_level, inc); +	xfs_ialloc_log_agi(cur->bc_tp, agbp, +			   XFS_AGI_FREE_ROOT | XFS_AGI_FREE_LEVEL); +} +  STATIC int  xfs_inobt_alloc_block(  	struct xfs_btree_cur	*cur,  	union xfs_btree_ptr	*start,  	union xfs_btree_ptr	*new, -	int			length,  	int			*stat)  {  	xfs_alloc_arg_t		args;		/* block allocation args */ @@ -174,6 +188,17 @@ xfs_inobt_init_ptr_from_cur(  	ptr->s = agi->agi_root;  } +STATIC void +xfs_finobt_init_ptr_from_cur( +	struct xfs_btree_cur	*cur, +	union xfs_btree_ptr	*ptr) +{ +	struct xfs_agi		*agi = XFS_BUF_TO_AGI(cur->bc_private.a.agbp); + +	ASSERT(cur->bc_private.a.agno == be32_to_cpu(agi->agi_seqno)); +	ptr->s = agi->agi_free_root; +} +  STATIC __int64_t  xfs_inobt_key_diff(  	struct xfs_btree_cur	*cur, @@ -183,7 +208,100 @@ xfs_inobt_key_diff(  			  cur->bc_rec.i.ir_startino;  } -#ifdef DEBUG +static int +xfs_inobt_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; + +	/* +	 * During growfs operations, we can't verify the exact owner as the +	 * perag is not fully initialised and hence not attached to the buffer. +	 * +	 * Similarly, during log recovery we will have a perag structure +	 * attached, but the agi information will not yet have been initialised +	 * from the on disk AGI. We don't currently use any of this information, +	 * but beware of the landmine (i.e. need to check pag->pagi_init) if we +	 * ever do. +	 */ +	switch (block->bb_magic) { +	case cpu_to_be32(XFS_IBT_CRC_MAGIC): +	case cpu_to_be32(XFS_FIBT_CRC_MAGIC): +		if (!xfs_sb_version_hascrc(&mp->m_sb)) +			return false; +		if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_uuid)) +			return false; +		if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) +			return false; +		if (pag && +		    be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) +			return false; +		/* fall through */ +	case cpu_to_be32(XFS_IBT_MAGIC): +	case cpu_to_be32(XFS_FIBT_MAGIC): +		break; +	default: +		return 0; +	} + +	/* numrecs and level verification */ +	level = be16_to_cpu(block->bb_level); +	if (level >= mp->m_in_maxlevels) +		return false; +	if (be16_to_cpu(block->bb_numrecs) > mp->m_inobt_mxr[level != 0]) +		return false; + +	/* sibling pointer verification */ +	if (!block->bb_u.s.bb_leftsib || +	    (be32_to_cpu(block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks && +	     block->bb_u.s.bb_leftsib != cpu_to_be32(NULLAGBLOCK))) +		return false; +	if (!block->bb_u.s.bb_rightsib || +	    (be32_to_cpu(block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks && +	     block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK))) +		return false; + +	return true; +} + +static void +xfs_inobt_read_verify( +	struct xfs_buf	*bp) +{ +	if (!xfs_btree_sblock_verify_crc(bp)) +		xfs_buf_ioerror(bp, EFSBADCRC); +	else if (!xfs_inobt_verify(bp)) +		xfs_buf_ioerror(bp, EFSCORRUPTED); + +	if (bp->b_error) { +		trace_xfs_btree_corrupt(bp, _RET_IP_); +		xfs_verifier_error(bp); +	} +} + +static void +xfs_inobt_write_verify( +	struct xfs_buf	*bp) +{ +	if (!xfs_inobt_verify(bp)) { +		trace_xfs_btree_corrupt(bp, _RET_IP_); +		xfs_buf_ioerror(bp, EFSCORRUPTED); +		xfs_verifier_error(bp); +		return; +	} +	xfs_btree_sblock_calc_crc(bp); + +} + +const struct xfs_buf_ops xfs_inobt_buf_ops = { +	.verify_read = xfs_inobt_read_verify, +	.verify_write = xfs_inobt_write_verify, +}; + +#if defined(DEBUG) || defined(XFS_WARN)  STATIC int  xfs_inobt_keys_inorder(  	struct xfs_btree_cur	*cur, @@ -205,72 +323,6 @@ xfs_inobt_recs_inorder(  }  #endif	/* DEBUG */ -#ifdef XFS_BTREE_TRACE -ktrace_t	*xfs_inobt_trace_buf; - -STATIC void -xfs_inobt_trace_enter( -	struct xfs_btree_cur	*cur, -	const char		*func, -	char			*s, -	int			type, -	int			line, -	__psunsigned_t		a0, -	__psunsigned_t		a1, -	__psunsigned_t		a2, -	__psunsigned_t		a3, -	__psunsigned_t		a4, -	__psunsigned_t		a5, -	__psunsigned_t		a6, -	__psunsigned_t		a7, -	__psunsigned_t		a8, -	__psunsigned_t		a9, -	__psunsigned_t		a10) -{ -	ktrace_enter(xfs_inobt_trace_buf, (void *)(__psint_t)type, -		(void *)func, (void *)s, NULL, (void *)cur, -		(void *)a0, (void *)a1, (void *)a2, (void *)a3, -		(void *)a4, (void *)a5, (void *)a6, (void *)a7, -		(void *)a8, (void *)a9, (void *)a10); -} - -STATIC void -xfs_inobt_trace_cursor( -	struct xfs_btree_cur	*cur, -	__uint32_t		*s0, -	__uint64_t		*l0, -	__uint64_t		*l1) -{ -	*s0 = cur->bc_private.a.agno; -	*l0 = cur->bc_rec.i.ir_startino; -	*l1 = cur->bc_rec.i.ir_free; -} - -STATIC void -xfs_inobt_trace_key( -	struct xfs_btree_cur	*cur, -	union xfs_btree_key	*key, -	__uint64_t		*l0, -	__uint64_t		*l1) -{ -	*l0 = be32_to_cpu(key->inobt.ir_startino); -	*l1 = 0; -} - -STATIC void -xfs_inobt_trace_record( -	struct xfs_btree_cur	*cur, -	union xfs_btree_rec	*rec, -	__uint64_t		*l0, -	__uint64_t		*l1, -	__uint64_t		*l2) -{ -	*l0 = be32_to_cpu(rec->inobt.ir_startino); -	*l1 = be32_to_cpu(rec->inobt.ir_freecount); -	*l2 = be64_to_cpu(rec->inobt.ir_free); -} -#endif /* XFS_BTREE_TRACE */ -  static const struct xfs_btree_ops xfs_inobt_ops = {  	.rec_len		= sizeof(xfs_inobt_rec_t),  	.key_len		= sizeof(xfs_inobt_key_t), @@ -286,17 +338,32 @@ static const struct xfs_btree_ops xfs_inobt_ops = {  	.init_rec_from_cur	= xfs_inobt_init_rec_from_cur,  	.init_ptr_from_cur	= xfs_inobt_init_ptr_from_cur,  	.key_diff		= xfs_inobt_key_diff, - -#ifdef DEBUG +	.buf_ops		= &xfs_inobt_buf_ops, +#if defined(DEBUG) || defined(XFS_WARN)  	.keys_inorder		= xfs_inobt_keys_inorder,  	.recs_inorder		= xfs_inobt_recs_inorder,  #endif +}; + +static const struct xfs_btree_ops xfs_finobt_ops = { +	.rec_len		= sizeof(xfs_inobt_rec_t), +	.key_len		= sizeof(xfs_inobt_key_t), -#ifdef XFS_BTREE_TRACE -	.trace_enter		= xfs_inobt_trace_enter, -	.trace_cursor		= xfs_inobt_trace_cursor, -	.trace_key		= xfs_inobt_trace_key, -	.trace_record		= xfs_inobt_trace_record, +	.dup_cursor		= xfs_inobt_dup_cursor, +	.set_root		= xfs_finobt_set_root, +	.alloc_block		= xfs_inobt_alloc_block, +	.free_block		= xfs_inobt_free_block, +	.get_minrecs		= xfs_inobt_get_minrecs, +	.get_maxrecs		= xfs_inobt_get_maxrecs, +	.init_key_from_rec	= xfs_inobt_init_key_from_rec, +	.init_rec_from_key	= xfs_inobt_init_rec_from_key, +	.init_rec_from_cur	= xfs_inobt_init_rec_from_cur, +	.init_ptr_from_cur	= xfs_finobt_init_ptr_from_cur, +	.key_diff		= xfs_inobt_key_diff, +	.buf_ops		= &xfs_inobt_buf_ops, +#if defined(DEBUG) || defined(XFS_WARN) +	.keys_inorder		= xfs_inobt_keys_inorder, +	.recs_inorder		= xfs_inobt_recs_inorder,  #endif  }; @@ -308,7 +375,8 @@ xfs_inobt_init_cursor(  	struct xfs_mount	*mp,		/* file system mount point */  	struct xfs_trans	*tp,		/* transaction pointer */  	struct xfs_buf		*agbp,		/* buffer for agi structure */ -	xfs_agnumber_t		agno)		/* allocation group number */ +	xfs_agnumber_t		agno,		/* allocation group number */ +	xfs_btnum_t		btnum)		/* ialloc or free ino btree */  {  	struct xfs_agi		*agi = XFS_BUF_TO_AGI(agbp);  	struct xfs_btree_cur	*cur; @@ -317,11 +385,19 @@ xfs_inobt_init_cursor(  	cur->bc_tp = tp;  	cur->bc_mp = mp; -	cur->bc_nlevels = be32_to_cpu(agi->agi_level); -	cur->bc_btnum = XFS_BTNUM_INO; +	cur->bc_btnum = btnum; +	if (btnum == XFS_BTNUM_INO) { +		cur->bc_nlevels = be32_to_cpu(agi->agi_level); +		cur->bc_ops = &xfs_inobt_ops; +	} else { +		cur->bc_nlevels = be32_to_cpu(agi->agi_free_level); +		cur->bc_ops = &xfs_finobt_ops; +	} +  	cur->bc_blocklog = mp->m_sb.sb_blocklog; -	cur->bc_ops = &xfs_inobt_ops; +	if (xfs_sb_version_hascrc(&mp->m_sb)) +		cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;  	cur->bc_private.a.agbp = agbp;  	cur->bc_private.a.agno = agno;  | 
