xfs_bmap.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 2,050 行 · 第 1/5 页

C
2,050
字号
/* * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Further, this software is distributed without any warranty that it is * free of the rightful claim of any third person regarding infringement * or the like.  Any license provided herein, whether implied or * otherwise, applies only to this software file.  Patent licenses, if * any, provided herein do not apply to combinations of this program with * other software, or any other product whatsoever. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, * Mountain View, CA  94043, or: * * http://www.sgi.com * * For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ */#include "xfs.h"#include "xfs_macros.h"#include "xfs_types.h"#include "xfs_inum.h"#include "xfs_log.h"#include "xfs_trans.h"#include "xfs_sb.h"#include "xfs_ag.h"#include "xfs_dir.h"#include "xfs_dir2.h"#include "xfs_dmapi.h"#include "xfs_mount.h"#include "xfs_alloc_btree.h"#include "xfs_bmap_btree.h"#include "xfs_ialloc_btree.h"#include "xfs_btree.h"#include "xfs_ialloc.h"#include "xfs_attr_sf.h"#include "xfs_dir_sf.h"#include "xfs_dir2_sf.h"#include "xfs_dinode.h"#include "xfs_inode_item.h"#include "xfs_inode.h"#include "xfs_itable.h"#include "xfs_extfree_item.h"#include "xfs_alloc.h"#include "xfs_bmap.h"#include "xfs_rtalloc.h"#include "xfs_error.h"#include "xfs_da_btree.h"#include "xfs_dir_leaf.h"#include "xfs_bit.h"#include "xfs_rw.h"#include "xfs_quota.h"#include "xfs_trans_space.h"#include "xfs_buf_item.h"#ifdef DEBUGSTATIC voidxfs_bmap_check_leaf_extents(xfs_btree_cur_t *cur, xfs_inode_t *ip, int whichfork);#endifkmem_zone_t		*xfs_bmap_free_item_zone;/* * Prototypes for internal bmap routines. *//* * Called from xfs_bmap_add_attrfork to handle extents format files. */STATIC int					/* error */xfs_bmap_add_attrfork_extents(	xfs_trans_t		*tp,		/* transaction pointer */	xfs_inode_t		*ip,		/* incore inode pointer */	xfs_fsblock_t		*firstblock,	/* first block allocated */	xfs_bmap_free_t		*flist,		/* blocks to free at commit */	int			*flags);	/* inode logging flags *//* * Called from xfs_bmap_add_attrfork to handle local format files. */STATIC int					/* error */xfs_bmap_add_attrfork_local(	xfs_trans_t		*tp,		/* transaction pointer */	xfs_inode_t		*ip,		/* incore inode pointer */	xfs_fsblock_t		*firstblock,	/* first block allocated */	xfs_bmap_free_t		*flist,		/* blocks to free at commit */	int			*flags);	/* inode logging flags *//* * Called by xfs_bmapi to update extent list structure and the btree * after allocating space (or doing a delayed allocation). */STATIC int				/* error */xfs_bmap_add_extent(	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_extnum_t		idx,	/* extent number to update/insert */	xfs_btree_cur_t		**curp,	/* if *curp is null, not a btree */	xfs_bmbt_irec_t		*new,	/* new data to put in extent list */	xfs_fsblock_t		*first,	/* pointer to firstblock variable */	xfs_bmap_free_t		*flist,	/* list of extents to be freed */	int			*logflagsp, /* inode logging flags */	int			whichfork, /* data or attr fork */	int			rsvd);	/* OK to allocate reserved blocks *//* * Called by xfs_bmap_add_extent to handle cases converting a delayed * allocation to a real allocation. */STATIC int				/* error */xfs_bmap_add_extent_delay_real(	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_extnum_t		idx,	/* extent number to update/insert */	xfs_btree_cur_t		**curp,	/* if *curp is null, not a btree */	xfs_bmbt_irec_t		*new,	/* new data to put in extent list */	xfs_filblks_t		*dnew,	/* new delayed-alloc indirect blocks */	xfs_fsblock_t		*first,	/* pointer to firstblock variable */	xfs_bmap_free_t		*flist,	/* list of extents to be freed */	int			*logflagsp, /* inode logging flags */	int			rsvd);	/* OK to allocate reserved blocks *//* * Called by xfs_bmap_add_extent to handle cases converting a hole * to a delayed allocation. */STATIC int				/* error */xfs_bmap_add_extent_hole_delay(	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_extnum_t		idx,	/* extent number to update/insert */	xfs_btree_cur_t		*cur,	/* if null, not a btree */	xfs_bmbt_irec_t		*new,	/* new data to put in extent list */	int			*logflagsp,/* inode logging flags */	int			rsvd);	/* OK to allocate reserved blocks *//* * Called by xfs_bmap_add_extent to handle cases converting a hole * to a real allocation. */STATIC int				/* error */xfs_bmap_add_extent_hole_real(	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_extnum_t		idx,	/* extent number to update/insert */	xfs_btree_cur_t		*cur,	/* if null, not a btree */	xfs_bmbt_irec_t		*new,	/* new data to put in extent list */	int			*logflagsp, /* inode logging flags */	int			whichfork); /* data or attr fork *//* * Called by xfs_bmap_add_extent to handle cases converting an unwritten * allocation to a real allocation or vice versa. */STATIC int				/* error */xfs_bmap_add_extent_unwritten_real(	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_extnum_t		idx,	/* extent number to update/insert */	xfs_btree_cur_t		**curp,	/* if *curp is null, not a btree */	xfs_bmbt_irec_t		*new,	/* new data to put in extent list */	int			*logflagsp); /* inode logging flags *//* * xfs_bmap_alloc is called by xfs_bmapi to allocate an extent for a file. * It figures out where to ask the underlying allocator to put the new extent. */STATIC int				/* error */xfs_bmap_alloc(	xfs_bmalloca_t		*ap);	/* bmap alloc argument struct *//* * Transform a btree format file with only one leaf node, where the * extents list will fit in the inode, into an extents format file. * Since the extent list is already in-core, all we have to do is * give up the space for the btree root and pitch the leaf block. */STATIC int				/* error */xfs_bmap_btree_to_extents(	xfs_trans_t		*tp,	/* transaction pointer */	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_btree_cur_t		*cur,	/* btree cursor */	int			*logflagsp, /* inode logging flags */	int			whichfork); /* data or attr fork */#ifdef DEBUG/* * Check that the extents list for the inode ip is in the right order. */STATIC voidxfs_bmap_check_extents(	xfs_inode_t		*ip,		/* incore inode pointer */	int			whichfork);	/* data or attr fork */#endif/* * Called by xfs_bmapi to update extent list structure and the btree * after removing space (or undoing a delayed allocation). */STATIC int				/* error */xfs_bmap_del_extent(	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_trans_t		*tp,	/* current trans pointer */	xfs_extnum_t		idx,	/* extent number to update/insert */	xfs_bmap_free_t		*flist,	/* list of extents to be freed */	xfs_btree_cur_t		*cur,	/* if null, not a btree */	xfs_bmbt_irec_t		*new,	/* new data to put in extent list */	int			*logflagsp,/* inode logging flags */	int			whichfork, /* data or attr fork */	int			rsvd);	 /* OK to allocate reserved blocks *//* * Remove the entry "free" from the free item list.  Prev points to the * previous entry, unless "free" is the head of the list. */STATIC voidxfs_bmap_del_free(	xfs_bmap_free_t		*flist,	/* free item list header */	xfs_bmap_free_item_t	*prev,	/* previous item on list, if any */	xfs_bmap_free_item_t	*free);	/* list item to be freed *//* * Remove count entries from the extents array for inode "ip", starting * at index "idx".  Copies the remaining items down over the deleted ones, * and gives back the excess memory. */STATIC voidxfs_bmap_delete_exlist(	xfs_inode_t	*ip,		/* incode inode pointer */	xfs_extnum_t	idx,		/* starting delete index */	xfs_extnum_t	count,		/* count of items to delete */	int		whichfork);	/* data or attr fork *//* * Convert an extents-format file into a btree-format file. * The new file will have a root block (in the inode) and a single child block. */STATIC int					/* error */xfs_bmap_extents_to_btree(	xfs_trans_t		*tp,		/* transaction pointer */	xfs_inode_t		*ip,		/* incore inode pointer */	xfs_fsblock_t		*firstblock,	/* first-block-allocated */	xfs_bmap_free_t		*flist,		/* blocks freed in xaction */	xfs_btree_cur_t		**curp,		/* cursor returned to caller */	int			wasdel,		/* converting a delayed alloc */	int			*logflagsp,	/* inode logging flags */	int			whichfork);	/* data or attr fork *//* * Insert new item(s) in the extent list for inode "ip". * Count new items are inserted at offset idx. */STATIC voidxfs_bmap_insert_exlist(	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_extnum_t	idx,		/* starting index of new items */	xfs_extnum_t	count,		/* number of inserted items */	xfs_bmbt_irec_t	*new,		/* items to insert */	int		whichfork);	/* data or attr fork *//* * Convert a local file to an extents file. * This code is sort of bogus, since the file data needs to get * logged so it won't be lost.  The bmap-level manipulations are ok, though. */STATIC int				/* error */xfs_bmap_local_to_extents(	xfs_trans_t	*tp,		/* transaction pointer */	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_fsblock_t	*firstblock,	/* first block allocated in xaction */	xfs_extlen_t	total,		/* total blocks needed by transaction */	int		*logflagsp,	/* inode logging flags */	int		whichfork);	/* data or attr fork *//* * Search the extents list for the inode, for the extent containing bno. * If bno lies in a hole, point to the next entry.  If bno lies past eof, * *eofp will be set, and *prevp will contain the last entry (null if none). * Else, *lastxp will be set to the index of the found * entry; *gotp will contain the entry. */STATIC xfs_bmbt_rec_t *			/* pointer to found extent entry */xfs_bmap_search_extents(	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_fileoff_t	bno,		/* block number searched for */	int		whichfork,	/* data or attr fork */	int		*eofp,		/* out: end of file found */	xfs_extnum_t	*lastxp,	/* out: last extent index */	xfs_bmbt_irec_t	*gotp,		/* out: extent entry found */	xfs_bmbt_irec_t	*prevp);	/* out: previous extent entry found */#ifdef XFS_BMAP_TRACE/* * Add a bmap trace buffer entry.  Base routine for the others. */STATIC voidxfs_bmap_trace_addentry(	int		opcode,		/* operation */	char		*fname,		/* function name */	char		*desc,		/* operation description */	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_extnum_t	idx,		/* index of entry(ies) */	xfs_extnum_t	cnt,		/* count of entries, 1 or 2 */	xfs_bmbt_rec_t	*r1,		/* first record */	xfs_bmbt_rec_t	*r2,		/* second record or null */	int		whichfork);	/* data or attr fork *//* * Add bmap trace entry prior to a call to xfs_bmap_delete_exlist. */STATIC voidxfs_bmap_trace_delete(	char		*fname,		/* function name */	char		*desc,		/* operation description */	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_extnum_t	idx,		/* index of entry(entries) deleted */	xfs_extnum_t	cnt,		/* count of entries deleted, 1 or 2 */	int		whichfork);	/* data or attr fork *//* * Add bmap trace entry prior to a call to xfs_bmap_insert_exlist, or * reading in the extents list from the disk (in the btree). */STATIC voidxfs_bmap_trace_insert(	char		*fname,		/* function name */	char		*desc,		/* operation description */	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_extnum_t	idx,		/* index of entry(entries) inserted */	xfs_extnum_t	cnt,		/* count of entries inserted, 1 or 2 */	xfs_bmbt_irec_t	*r1,		/* inserted record 1 */	xfs_bmbt_irec_t	*r2,		/* inserted record 2 or null */	int		whichfork);	/* data or attr fork *//* * Add bmap trace entry after updating an extent list entry in place. */STATIC voidxfs_bmap_trace_post_update(	char		*fname,		/* function name */	char		*desc,		/* operation description */	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_extnum_t	idx,		/* index of entry updated */	int		whichfork);	/* data or attr fork *//* * Add bmap trace entry prior to updating an extent list entry in place. */STATIC voidxfs_bmap_trace_pre_update(	char		*fname,		/* function name */	char		*desc,		/* operation description */	xfs_inode_t	*ip,		/* incore inode pointer */	xfs_extnum_t	idx,		/* index of entry to be updated */	int		whichfork);	/* data or attr fork */#else#define	xfs_bmap_trace_delete(f,d,ip,i,c,w)#define	xfs_bmap_trace_insert(f,d,ip,i,c,r1,r2,w)#define	xfs_bmap_trace_post_update(f,d,ip,i,w)#define	xfs_bmap_trace_pre_update(f,d,ip,i,w)#endif	/* XFS_BMAP_TRACE *//* * Compute the worst-case number of indirect blocks that will be used * for ip's delayed extent of length "len". */STATIC xfs_filblks_txfs_bmap_worst_indlen(	xfs_inode_t		*ip,	/* incore inode pointer */	xfs_filblks_t		len);	/* delayed extent length */#ifdef DEBUG/* * Perform various validation checks on the values being returned * from xfs_bmapi(). */STATIC voidxfs_bmap_validate_ret(	xfs_fileoff_t		bno,	xfs_filblks_t		len,	int			flags,	xfs_bmbt_irec_t		*mval,	int			nmap,	int			ret_nmap);#else#define	xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)#endif /* DEBUG */#if defined(XFS_RW_TRACE)STATIC voidxfs_bunmap_trace(	xfs_inode_t		*ip,	xfs_fileoff_t		bno,	xfs_filblks_t		len,	int			flags,	inst_t			*ra);#else

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?