xref: /openbmc/linux/fs/xfs/libxfs/xfs_trans_space.h (revision b78412b8)
1 /*
2  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #ifndef __XFS_TRANS_SPACE_H__
19 #define __XFS_TRANS_SPACE_H__
20 
21 /*
22  * Components of space reservations.
23  */
24 
25 /* Worst case number of rmaps that can be held in a block. */
26 #define XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp)    \
27 		(((mp)->m_rmap_mxr[0]) - ((mp)->m_rmap_mnr[0]))
28 
29 /* Adding one rmap could split every level up to the top of the tree. */
30 #define XFS_RMAPADD_SPACE_RES(mp) ((mp)->m_rmap_maxlevels)
31 
32 /* Blocks we might need to add "b" rmaps to a tree. */
33 #define XFS_NRMAPADD_SPACE_RES(mp, b)\
34 	(((b + XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp) - 1) / \
35 	  XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp)) * \
36 	  XFS_RMAPADD_SPACE_RES(mp))
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 
46 /* Blocks we might need to add "b" mappings & rmappings to a file. */
47 #define XFS_SWAP_RMAP_SPACE_RES(mp,b,w)\
48 	(XFS_NEXTENTADD_SPACE_RES((mp), (b), (w)) + \
49 	 XFS_NRMAPADD_SPACE_RES((mp), (b)))
50 
51 #define	XFS_DAENTER_1B(mp,w)	\
52 	((w) == XFS_DATA_FORK ? (mp)->m_dir_geo->fsbcount : 1)
53 #define	XFS_DAENTER_DBS(mp,w)	\
54 	(XFS_DA_NODE_MAXDEPTH + (((w) == XFS_DATA_FORK) ? 2 : 0))
55 #define	XFS_DAENTER_BLOCKS(mp,w)	\
56 	(XFS_DAENTER_1B(mp,w) * XFS_DAENTER_DBS(mp,w))
57 #define	XFS_DAENTER_BMAP1B(mp,w)	\
58 	XFS_NEXTENTADD_SPACE_RES(mp, XFS_DAENTER_1B(mp, w), w)
59 #define	XFS_DAENTER_BMAPS(mp,w)		\
60 	(XFS_DAENTER_DBS(mp,w) * XFS_DAENTER_BMAP1B(mp,w))
61 #define	XFS_DAENTER_SPACE_RES(mp,w)	\
62 	(XFS_DAENTER_BLOCKS(mp,w) + XFS_DAENTER_BMAPS(mp,w))
63 #define	XFS_DAREMOVE_SPACE_RES(mp,w)	XFS_DAENTER_BMAPS(mp,w)
64 #define	XFS_DIRENTER_MAX_SPLIT(mp,nl)	1
65 #define	XFS_DIRENTER_SPACE_RES(mp,nl)	\
66 	(XFS_DAENTER_SPACE_RES(mp, XFS_DATA_FORK) * \
67 	 XFS_DIRENTER_MAX_SPLIT(mp,nl))
68 #define	XFS_DIRREMOVE_SPACE_RES(mp)	\
69 	XFS_DAREMOVE_SPACE_RES(mp, XFS_DATA_FORK)
70 #define	XFS_IALLOC_SPACE_RES(mp)	\
71 	((mp)->m_ialloc_blks + \
72 	 (xfs_sb_version_hasfinobt(&mp->m_sb) ? 2 : 1 * \
73 	  ((mp)->m_in_maxlevels - 1)))
74 
75 /*
76  * Space reservation values for various transactions.
77  */
78 #define	XFS_ADDAFORK_SPACE_RES(mp)	\
79 	((mp)->m_dir_geo->fsbcount + XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK))
80 #define	XFS_ATTRRM_SPACE_RES(mp)	\
81 	XFS_DAREMOVE_SPACE_RES(mp, XFS_ATTR_FORK)
82 /* This macro is not used - see inline code in xfs_attr_set */
83 #define	XFS_ATTRSET_SPACE_RES(mp, v)	\
84 	(XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
85 #define	XFS_CREATE_SPACE_RES(mp,nl)	\
86 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
87 #define	XFS_DIOSTRAT_SPACE_RES(mp, v)	\
88 	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v))
89 #define	XFS_GROWFS_SPACE_RES(mp)	\
90 	(2 * (mp)->m_ag_maxlevels)
91 #define	XFS_GROWFSRT_SPACE_RES(mp,b)	\
92 	((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK))
93 #define	XFS_LINK_SPACE_RES(mp,nl)	\
94 	XFS_DIRENTER_SPACE_RES(mp,nl)
95 #define	XFS_MKDIR_SPACE_RES(mp,nl)	\
96 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
97 #define	XFS_QM_DQALLOC_SPACE_RES(mp)	\
98 	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \
99 	 XFS_DQUOT_CLUSTER_SIZE_FSB)
100 #define	XFS_QM_QINOCREATE_SPACE_RES(mp)	\
101 	XFS_IALLOC_SPACE_RES(mp)
102 #define	XFS_REMOVE_SPACE_RES(mp)	\
103 	XFS_DIRREMOVE_SPACE_RES(mp)
104 #define	XFS_RENAME_SPACE_RES(mp,nl)	\
105 	(XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
106 #define	XFS_SYMLINK_SPACE_RES(mp,nl,b)	\
107 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b))
108 #define XFS_IFREE_SPACE_RES(mp)		\
109 	(xfs_sb_version_hasfinobt(&mp->m_sb) ? (mp)->m_in_maxlevels : 0)
110 
111 
112 #endif	/* __XFS_TRANS_SPACE_H__ */
113