| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2006-06-09 14:48:12 +10:00
										 |  |  |  * Copyright (c) 2000-2006 Silicon Graphics, Inc. | 
					
						
							| 
									
										
										
										
											2005-11-02 14:58:39 +11:00
										 |  |  |  * All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-02 14:58:39 +11:00
										 |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License as | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-02 14:58:39 +11:00
										 |  |  |  * 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.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-02 14:58:39 +11:00
										 |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | #ifndef __XFS_BMAP_H__
 | 
					
						
							|  |  |  | #define	__XFS_BMAP_H__
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct getbmap; | 
					
						
							|  |  |  | struct xfs_bmbt_irec; | 
					
						
							| 
									
										
										
										
											2006-03-14 13:29:52 +11:00
										 |  |  | struct xfs_ifork; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | struct xfs_inode; | 
					
						
							|  |  |  | struct xfs_mount; | 
					
						
							|  |  |  | struct xfs_trans; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-23 16:28:09 +11:00
										 |  |  | extern kmem_zone_t	*xfs_bmap_free_item_zone; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * List of extents to be free "later". | 
					
						
							|  |  |  |  * The list is kept sorted on xbf_startblock. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | typedef struct xfs_bmap_free_item | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	xfs_fsblock_t		xbfi_startblock;/* starting fs block number */ | 
					
						
							|  |  |  | 	xfs_extlen_t		xbfi_blockcount;/* number of blocks in extent */ | 
					
						
							|  |  |  | 	struct xfs_bmap_free_item *xbfi_next;	/* link to next entry */ | 
					
						
							|  |  |  | } xfs_bmap_free_item_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Header for free extent list. | 
					
						
							| 
									
										
										
										
											2008-06-27 13:33:03 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * xbf_low is used by the allocator to activate the lowspace algorithm - | 
					
						
							|  |  |  |  * when free space is running low the extent allocator may choose to | 
					
						
							|  |  |  |  * allocate an extent from an AG without leaving sufficient space for | 
					
						
							|  |  |  |  * a btree split when inserting the new extent.  In this case the allocator | 
					
						
							|  |  |  |  * will enable the lowspace algorithm which is supposed to allow further | 
					
						
							|  |  |  |  * allocations (such as btree splits and newroots) to allocate from | 
					
						
							|  |  |  |  * sequential AGs.  In order to avoid locking AGs out of order the lowspace | 
					
						
							|  |  |  |  * algorithm will start searching for free space from AG 0.  If the correct | 
					
						
							|  |  |  |  * transaction reservations have been made then this algorithm will eventually | 
					
						
							|  |  |  |  * find all the space it needs. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | typedef	struct xfs_bmap_free | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	xfs_bmap_free_item_t	*xbf_first;	/* list of to-be-free extents */ | 
					
						
							|  |  |  | 	int			xbf_count;	/* count of items on list */ | 
					
						
							| 
									
										
										
										
											2008-06-27 13:33:03 +10:00
										 |  |  | 	int			xbf_low;	/* alloc in low mode */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } xfs_bmap_free_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	XFS_BMAP_MAX_NMAP	4
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2011-09-18 20:40:52 +00:00
										 |  |  |  * Flags for xfs_bmapi_* | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-09-18 20:40:52 +00:00
										 |  |  | #define XFS_BMAPI_ENTIRE	0x001	/* return entire extent, not trimmed */
 | 
					
						
							|  |  |  | #define XFS_BMAPI_METADATA	0x002	/* mapping metadata not user data */
 | 
					
						
							|  |  |  | #define XFS_BMAPI_ATTRFORK	0x004	/* use attribute fork not data */
 | 
					
						
							|  |  |  | #define XFS_BMAPI_PREALLOC	0x008	/* preallocation op: unwritten space */
 | 
					
						
							|  |  |  | #define XFS_BMAPI_IGSTATE	0x010	/* Ignore state - */
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					/* combine contig. space */ | 
					
						
							| 
									
										
										
										
											2011-09-18 20:40:52 +00:00
										 |  |  | #define XFS_BMAPI_CONTIG	0x020	/* must allocate only one extent */
 | 
					
						
							| 
									
										
										
										
											2010-08-24 12:02:11 +10:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * unwritten extent conversion - this needs write cache flushing and no additional | 
					
						
							|  |  |  |  * allocation alignments. When specified with XFS_BMAPI_PREALLOC it converts | 
					
						
							|  |  |  |  * from written to unwritten, otherwise convert from unwritten to written. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-09-18 20:40:52 +00:00
										 |  |  | #define XFS_BMAPI_CONVERT	0x040
 | 
					
						
							| 
									
										
										
										
											2012-10-05 11:06:58 +10:00
										 |  |  | #define XFS_BMAPI_STACK_SWITCH	0x080
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-14 23:14:59 +00:00
										 |  |  | #define XFS_BMAPI_FLAGS \
 | 
					
						
							|  |  |  | 	{ XFS_BMAPI_ENTIRE,	"ENTIRE" }, \ | 
					
						
							|  |  |  | 	{ XFS_BMAPI_METADATA,	"METADATA" }, \ | 
					
						
							|  |  |  | 	{ XFS_BMAPI_ATTRFORK,	"ATTRFORK" }, \ | 
					
						
							|  |  |  | 	{ XFS_BMAPI_PREALLOC,	"PREALLOC" }, \ | 
					
						
							|  |  |  | 	{ XFS_BMAPI_IGSTATE,	"IGSTATE" }, \ | 
					
						
							|  |  |  | 	{ XFS_BMAPI_CONTIG,	"CONTIG" }, \ | 
					
						
							| 
									
										
										
										
											2012-10-05 11:06:58 +10:00
										 |  |  | 	{ XFS_BMAPI_CONVERT,	"CONVERT" }, \ | 
					
						
							|  |  |  | 	{ XFS_BMAPI_STACK_SWITCH, "STACK_SWITCH" } | 
					
						
							| 
									
										
										
										
											2009-12-14 23:14:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-02 14:38:42 +11:00
										 |  |  | static inline int xfs_bmapi_aflag(int w) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (w == XFS_ATTR_FORK ? XFS_BMAPI_ATTRFORK : 0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Special values for xfs_bmbt_irec_t br_startblock field. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define	DELAYSTARTBLOCK		((xfs_fsblock_t)-1LL)
 | 
					
						
							|  |  |  | #define	HOLESTARTBLOCK		((xfs_fsblock_t)-2LL)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-02 14:38:42 +11:00
										 |  |  | static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	((flp)->xbf_first = NULL, (flp)->xbf_count = 0, \ | 
					
						
							| 
									
										
										
										
											2005-11-02 14:38:42 +11:00
										 |  |  | 		(flp)->xbf_low = 0, *(fbp) = NULLFSBLOCK); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 00:00:19 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Flags for xfs_bmap_add_extent*. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define BMAP_LEFT_CONTIG	(1 << 0)
 | 
					
						
							|  |  |  | #define BMAP_RIGHT_CONTIG	(1 << 1)
 | 
					
						
							|  |  |  | #define BMAP_LEFT_FILLING	(1 << 2)
 | 
					
						
							|  |  |  | #define BMAP_RIGHT_FILLING	(1 << 3)
 | 
					
						
							|  |  |  | #define BMAP_LEFT_DELAY		(1 << 4)
 | 
					
						
							|  |  |  | #define BMAP_RIGHT_DELAY	(1 << 5)
 | 
					
						
							|  |  |  | #define BMAP_LEFT_VALID		(1 << 6)
 | 
					
						
							|  |  |  | #define BMAP_RIGHT_VALID	(1 << 7)
 | 
					
						
							| 
									
										
										
										
											2009-11-25 00:00:21 +00:00
										 |  |  | #define BMAP_ATTRFORK		(1 << 8)
 | 
					
						
							| 
									
										
										
										
											2009-11-25 00:00:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-14 23:14:59 +00:00
										 |  |  | #define XFS_BMAP_EXT_FLAGS \
 | 
					
						
							|  |  |  | 	{ BMAP_LEFT_CONTIG,	"LC" }, \ | 
					
						
							|  |  |  | 	{ BMAP_RIGHT_CONTIG,	"RC" }, \ | 
					
						
							|  |  |  | 	{ BMAP_LEFT_FILLING,	"LF" }, \ | 
					
						
							|  |  |  | 	{ BMAP_RIGHT_FILLING,	"RF" }, \ | 
					
						
							|  |  |  | 	{ BMAP_ATTRFORK,	"ATTR" } | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 20:49:51 +10:00
										 |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											2011-09-18 20:41:07 +00:00
										 |  |  | void	xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt, | 
					
						
							|  |  |  | 		int whichfork, unsigned long caller_ip); | 
					
						
							| 
									
										
										
										
											2007-07-11 11:09:47 +10:00
										 |  |  | #define	XFS_BMAP_TRACE_EXLIST(ip,c,w)	\
 | 
					
						
							| 
									
										
										
										
											2009-12-14 23:14:59 +00:00
										 |  |  | 	xfs_bmap_trace_exlist(ip,c,w, _THIS_IP_) | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2007-07-11 11:09:47 +10:00
										 |  |  | #define	XFS_BMAP_TRACE_EXLIST(ip,c,w)
 | 
					
						
							| 
									
										
										
										
											2009-12-14 23:14:59 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-18 20:41:07 +00:00
										 |  |  | int	xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); | 
					
						
							| 
									
										
										
										
											2013-07-10 07:04:00 +10:00
										 |  |  | void	xfs_bmap_local_to_extents_empty(struct xfs_inode *ip, int whichfork); | 
					
						
							| 
									
										
										
										
											2011-09-18 20:41:07 +00:00
										 |  |  | void	xfs_bmap_add_free(xfs_fsblock_t bno, xfs_filblks_t len, | 
					
						
							|  |  |  | 		struct xfs_bmap_free *flist, struct xfs_mount *mp); | 
					
						
							|  |  |  | void	xfs_bmap_cancel(struct xfs_bmap_free *flist); | 
					
						
							|  |  |  | void	xfs_bmap_compute_maxlevels(struct xfs_mount *mp, int whichfork); | 
					
						
							|  |  |  | int	xfs_bmap_first_unused(struct xfs_trans *tp, struct xfs_inode *ip, | 
					
						
							|  |  |  | 		xfs_extlen_t len, xfs_fileoff_t *unused, int whichfork); | 
					
						
							|  |  |  | int	xfs_bmap_last_before(struct xfs_trans *tp, struct xfs_inode *ip, | 
					
						
							|  |  |  | 		xfs_fileoff_t *last_block, int whichfork); | 
					
						
							|  |  |  | int	xfs_bmap_last_offset(struct xfs_trans *tp, struct xfs_inode *ip, | 
					
						
							|  |  |  | 		xfs_fileoff_t *unused, int whichfork); | 
					
						
							|  |  |  | int	xfs_bmap_one_block(struct xfs_inode *ip, int whichfork); | 
					
						
							|  |  |  | int	xfs_bmap_read_extents(struct xfs_trans *tp, struct xfs_inode *ip, | 
					
						
							|  |  |  | 		int whichfork); | 
					
						
							| 
									
										
										
										
											2011-09-18 20:40:45 +00:00
										 |  |  | int	xfs_bmapi_read(struct xfs_inode *ip, xfs_fileoff_t bno, | 
					
						
							|  |  |  | 		xfs_filblks_t len, struct xfs_bmbt_irec *mval, | 
					
						
							|  |  |  | 		int *nmap, int flags); | 
					
						
							| 
									
										
										
										
											2011-09-18 20:40:48 +00:00
										 |  |  | int	xfs_bmapi_delay(struct xfs_inode *ip, xfs_fileoff_t bno, | 
					
						
							|  |  |  | 		xfs_filblks_t len, struct xfs_bmbt_irec *mval, | 
					
						
							|  |  |  | 		int *nmap, int flags); | 
					
						
							| 
									
										
										
										
											2011-09-18 20:40:52 +00:00
										 |  |  | int	xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip, | 
					
						
							|  |  |  | 		xfs_fileoff_t bno, xfs_filblks_t len, int flags, | 
					
						
							|  |  |  | 		xfs_fsblock_t *firstblock, xfs_extlen_t total, | 
					
						
							|  |  |  | 		struct xfs_bmbt_irec *mval, int *nmap, | 
					
						
							|  |  |  | 		struct xfs_bmap_free *flist); | 
					
						
							| 
									
										
										
										
											2011-09-18 20:41:07 +00:00
										 |  |  | int	xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip, | 
					
						
							|  |  |  | 		xfs_fileoff_t bno, xfs_filblks_t len, int flags, | 
					
						
							|  |  |  | 		xfs_extnum_t nexts, xfs_fsblock_t *firstblock, | 
					
						
							|  |  |  | 		struct xfs_bmap_free *flist, int *done); | 
					
						
							|  |  |  | int	xfs_check_nostate_extents(struct xfs_ifork *ifp, xfs_extnum_t idx, | 
					
						
							|  |  |  | 		xfs_extnum_t num); | 
					
						
							|  |  |  | uint	xfs_default_attroffset(struct xfs_inode *ip); | 
					
						
							| 
									
										
										
										
											2009-03-29 19:26:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif	/* __XFS_BMAP_H__ */
 |