1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32 #ifndef __XFS_TRANS_SPACE_H__
33 #define __XFS_TRANS_SPACE_H__
34 
35 /*
36  * Components of space reservations.
37  */
38 #define XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp)    \
39 		(((mp)->m_alloc_mxr[0]) - ((mp)->m_alloc_mnr[0]))
40 #define	XFS_EXTENTADD_SPACE_RES(mp,w)	(XFS_BM_MAXLEVELS(mp,w) - 1)
41 #define XFS_NEXTENTADD_SPACE_RES(mp,b,w)\
42 	(((b + XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp) - 1) / \
43 	  XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp)) * \
44 	  XFS_EXTENTADD_SPACE_RES(mp,w))
45 #define	XFS_DAENTER_1B(mp,w)	((w) == XFS_DATA_FORK ? (mp)->m_dirblkfsbs : 1)
46 #define	XFS_DAENTER_DBS(mp,w)	\
47 	(XFS_DA_NODE_MAXDEPTH + \
48 	 ((XFS_DIR_IS_V2(mp) && (w) == XFS_DATA_FORK) ? 2 : 0))
49 #define	XFS_DAENTER_BLOCKS(mp,w)	\
50 	(XFS_DAENTER_1B(mp,w) * XFS_DAENTER_DBS(mp,w))
51 #define	XFS_DAENTER_BMAP1B(mp,w)	\
52 	XFS_NEXTENTADD_SPACE_RES(mp, XFS_DAENTER_1B(mp, w), w)
53 #define	XFS_DAENTER_BMAPS(mp,w)		\
54 	(XFS_DAENTER_DBS(mp,w) * XFS_DAENTER_BMAP1B(mp,w))
55 #define	XFS_DAENTER_SPACE_RES(mp,w)	\
56 	(XFS_DAENTER_BLOCKS(mp,w) + XFS_DAENTER_BMAPS(mp,w))
57 #define	XFS_DAREMOVE_SPACE_RES(mp,w)	XFS_DAENTER_BMAPS(mp,w)
58 #define	XFS_DIRENTER_MAX_SPLIT(mp,nl)	\
59 	(((mp)->m_sb.sb_blocksize == 512 && \
60 	  XFS_DIR_IS_V1(mp) && \
61 	  (nl) >= XFS_DIR_LEAF_CAN_DOUBLE_SPLIT_LEN) ? 2 : 1)
62 #define	XFS_DIRENTER_SPACE_RES(mp,nl)	\
63 	(XFS_DAENTER_SPACE_RES(mp, XFS_DATA_FORK) * \
64 	 XFS_DIRENTER_MAX_SPLIT(mp,nl))
65 #define	XFS_DIRREMOVE_SPACE_RES(mp)	\
66 	XFS_DAREMOVE_SPACE_RES(mp, XFS_DATA_FORK)
67 #define	XFS_IALLOC_SPACE_RES(mp)	\
68 	(XFS_IALLOC_BLOCKS(mp) + XFS_IN_MAXLEVELS(mp)-1)
69 
70 /*
71  * Space reservation values for various transactions.
72  */
73 #define	XFS_ADDAFORK_SPACE_RES(mp)	\
74 	((mp)->m_dirblkfsbs + \
75 	 (XFS_DIR_IS_V1(mp) ? 0 : XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK)))
76 #define	XFS_ATTRRM_SPACE_RES(mp)	\
77 	XFS_DAREMOVE_SPACE_RES(mp, XFS_ATTR_FORK)
78 /* This macro is not used - see inline code in xfs_attr_set */
79 #define	XFS_ATTRSET_SPACE_RES(mp, v)	\
80 	(XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
81 #define	XFS_CREATE_SPACE_RES(mp,nl)	\
82 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
83 #define	XFS_DIOSTRAT_SPACE_RES(mp, v)	\
84 	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v))
85 #define	XFS_GROWFS_SPACE_RES(mp)	\
86 	(2 * XFS_AG_MAXLEVELS(mp))
87 #define	XFS_GROWFSRT_SPACE_RES(mp,b)	\
88 	((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK))
89 #define	XFS_LINK_SPACE_RES(mp,nl)	\
90 	XFS_DIRENTER_SPACE_RES(mp,nl)
91 #define	XFS_MKDIR_SPACE_RES(mp,nl)	\
92 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
93 #define	XFS_QM_DQALLOC_SPACE_RES(mp)	\
94 	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \
95 	 XFS_DQUOT_CLUSTER_SIZE_FSB)
96 #define	XFS_QM_QINOCREATE_SPACE_RES(mp)	\
97 	XFS_IALLOC_SPACE_RES(mp)
98 #define	XFS_REMOVE_SPACE_RES(mp)	\
99 	XFS_DIRREMOVE_SPACE_RES(mp)
100 #define	XFS_RENAME_SPACE_RES(mp,nl)	\
101 	(XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
102 #define	XFS_SYMLINK_SPACE_RES(mp,nl,b)	\
103 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b))
104 
105 #endif	/* __XFS_TRANS_SPACE_H__ */
106