• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_TRANS_SPACE_H__
7 #define __XFS_TRANS_SPACE_H__
8 
9 /*
10  * Components of space reservations.
11  */
12 
13 /* Worst case number of rmaps that can be held in a block. */
14 #define XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp)    \
15 		(((mp)->m_rmap_mxr[0]) - ((mp)->m_rmap_mnr[0]))
16 
17 /* Adding one rmap could split every level up to the top of the tree. */
18 #define XFS_RMAPADD_SPACE_RES(mp) ((mp)->m_rmap_maxlevels)
19 
20 /* Blocks we might need to add "b" rmaps to a tree. */
21 #define XFS_NRMAPADD_SPACE_RES(mp, b)\
22 	(((b + XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp) - 1) / \
23 	  XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp)) * \
24 	  XFS_RMAPADD_SPACE_RES(mp))
25 
26 #define XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp)    \
27 		(((mp)->m_alloc_mxr[0]) - ((mp)->m_alloc_mnr[0]))
28 #define	XFS_EXTENTADD_SPACE_RES(mp,w)	(XFS_BM_MAXLEVELS(mp,w) - 1)
29 #define XFS_NEXTENTADD_SPACE_RES(mp,b,w)\
30 	(((b + XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp) - 1) / \
31 	  XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp)) * \
32 	  XFS_EXTENTADD_SPACE_RES(mp,w))
33 
34 /* Blocks we might need to add "b" mappings & rmappings to a file. */
35 #define XFS_SWAP_RMAP_SPACE_RES(mp,b,w)\
36 	(XFS_NEXTENTADD_SPACE_RES((mp), (b), (w)) + \
37 	 XFS_NRMAPADD_SPACE_RES((mp), (b)))
38 
39 #define	XFS_DAENTER_1B(mp,w)	\
40 	((w) == XFS_DATA_FORK ? (mp)->m_dir_geo->fsbcount : 1)
41 #define	XFS_DAENTER_DBS(mp,w)	\
42 	(XFS_DA_NODE_MAXDEPTH + (((w) == XFS_DATA_FORK) ? 2 : 0))
43 #define	XFS_DAENTER_BLOCKS(mp,w)	\
44 	(XFS_DAENTER_1B(mp,w) * XFS_DAENTER_DBS(mp,w))
45 #define	XFS_DAENTER_BMAP1B(mp,w)	\
46 	XFS_NEXTENTADD_SPACE_RES(mp, XFS_DAENTER_1B(mp, w), w)
47 #define	XFS_DAENTER_BMAPS(mp,w)		\
48 	(XFS_DAENTER_DBS(mp,w) * XFS_DAENTER_BMAP1B(mp,w))
49 #define	XFS_DAENTER_SPACE_RES(mp,w)	\
50 	(XFS_DAENTER_BLOCKS(mp,w) + XFS_DAENTER_BMAPS(mp,w))
51 #define	XFS_DAREMOVE_SPACE_RES(mp,w)	XFS_DAENTER_BMAPS(mp,w)
52 #define	XFS_DIRENTER_MAX_SPLIT(mp,nl)	1
53 #define	XFS_DIRENTER_SPACE_RES(mp,nl)	\
54 	(XFS_DAENTER_SPACE_RES(mp, XFS_DATA_FORK) * \
55 	 XFS_DIRENTER_MAX_SPLIT(mp,nl))
56 #define	XFS_DIRREMOVE_SPACE_RES(mp)	\
57 	XFS_DAREMOVE_SPACE_RES(mp, XFS_DATA_FORK)
58 #define	XFS_IALLOC_SPACE_RES(mp)	\
59 	(M_IGEO(mp)->ialloc_blks + \
60 	 ((xfs_has_finobt(mp) ? 2 : 1) * M_IGEO(mp)->inobt_maxlevels))
61 
62 /*
63  * Space reservation values for various transactions.
64  */
65 #define	XFS_ADDAFORK_SPACE_RES(mp)	\
66 	((mp)->m_dir_geo->fsbcount + XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK))
67 #define	XFS_ATTRRM_SPACE_RES(mp)	\
68 	XFS_DAREMOVE_SPACE_RES(mp, XFS_ATTR_FORK)
69 /* This macro is not used - see inline code in xfs_attr_set */
70 #define	XFS_ATTRSET_SPACE_RES(mp, v)	\
71 	(XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
72 #define	XFS_CREATE_SPACE_RES(mp,nl)	\
73 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
74 #define	XFS_DIOSTRAT_SPACE_RES(mp, v)	\
75 	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v))
76 #define	XFS_GROWFS_SPACE_RES(mp)	\
77 	(2 * (mp)->m_ag_maxlevels)
78 #define	XFS_GROWFSRT_SPACE_RES(mp,b)	\
79 	((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK))
80 #define	XFS_LINK_SPACE_RES(mp,nl)	\
81 	XFS_DIRENTER_SPACE_RES(mp,nl)
82 #define	XFS_MKDIR_SPACE_RES(mp,nl)	\
83 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
84 #define	XFS_QM_DQALLOC_SPACE_RES(mp)	\
85 	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \
86 	 XFS_DQUOT_CLUSTER_SIZE_FSB)
87 #define	XFS_QM_QINOCREATE_SPACE_RES(mp)	\
88 	XFS_IALLOC_SPACE_RES(mp)
89 #define	XFS_REMOVE_SPACE_RES(mp)	\
90 	XFS_DIRREMOVE_SPACE_RES(mp)
91 #define	XFS_RENAME_SPACE_RES(mp,nl)	\
92 	(XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
93 #define	XFS_SYMLINK_SPACE_RES(mp,nl,b)	\
94 	(XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b))
95 #define XFS_IFREE_SPACE_RES(mp)		\
96 	(xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0)
97 
98 
99 #endif	/* __XFS_TRANS_SPACE_H__ */
100