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 bmaps that can be held in a block. */
14  #define XFS_MAX_CONTIG_BMAPS_PER_BLOCK(mp)    \
15  		(((mp)->m_bmap_dmxr[0]) - ((mp)->m_bmap_dmnr[0]))
16  
17  /* Worst case number of rmaps that can be held in a block. */
18  #define XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp)    \
19  		(((mp)->m_rmap_mxr[0]) - ((mp)->m_rmap_mnr[0]))
20  
21  /* Adding one rmap could split every level up to the top of the tree. */
22  #define XFS_RMAPADD_SPACE_RES(mp) ((mp)->m_rmap_maxlevels)
23  
24  /*
25   * Note that we historically set m_rmap_maxlevels to 9 when reflink is enabled,
26   * so we must preserve this behavior to avoid changing the transaction space
27   * reservations and minimum log size calculations for existing filesystems.
28   */
29  #define XFS_OLD_REFLINK_RMAP_MAXLEVELS		9
30  
31  /* Blocks we might need to add "b" rmaps to a tree. */
32  #define XFS_NRMAPADD_SPACE_RES(mp, b)\
33  	(((b + XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp) - 1) / \
34  	  XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp)) * \
35  	  XFS_RMAPADD_SPACE_RES(mp))
36  
37  #define XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp)    \
38  		(((mp)->m_alloc_mxr[0]) - ((mp)->m_alloc_mnr[0]))
39  #define	XFS_EXTENTADD_SPACE_RES(mp,w)	(XFS_BM_MAXLEVELS(mp,w) - 1)
40  #define XFS_NEXTENTADD_SPACE_RES(mp,b,w)\
41  	(((b + XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp) - 1) / \
42  	  XFS_MAX_CONTIG_EXTENTS_PER_BLOCK(mp)) * \
43  	  XFS_EXTENTADD_SPACE_RES(mp,w))
44  
45  /* Blocks we might need to add "b" mappings & rmappings to a file. */
46  #define XFS_SWAP_RMAP_SPACE_RES(mp,b,w)\
47  	(XFS_NEXTENTADD_SPACE_RES((mp), (b), (w)) + \
48  	 XFS_NRMAPADD_SPACE_RES((mp), (b)))
49  
50  #define	XFS_DAENTER_1B(mp,w)	\
51  	((w) == XFS_DATA_FORK ? (mp)->m_dir_geo->fsbcount : 1)
52  #define	XFS_DAENTER_DBS(mp,w)	\
53  	(XFS_DA_NODE_MAXDEPTH + (((w) == XFS_DATA_FORK) ? 2 : 0))
54  #define	XFS_DAENTER_BLOCKS(mp,w)	\
55  	(XFS_DAENTER_1B(mp,w) * XFS_DAENTER_DBS(mp,w))
56  #define	XFS_DAENTER_BMAP1B(mp,w)	\
57  	XFS_NEXTENTADD_SPACE_RES(mp, XFS_DAENTER_1B(mp, w), w)
58  #define	XFS_DAENTER_BMAPS(mp,w)		\
59  	(XFS_DAENTER_DBS(mp,w) * XFS_DAENTER_BMAP1B(mp,w))
60  #define	XFS_DAENTER_SPACE_RES(mp,w)	\
61  	(XFS_DAENTER_BLOCKS(mp,w) + XFS_DAENTER_BMAPS(mp,w))
62  #define	XFS_DAREMOVE_SPACE_RES(mp,w)	XFS_DAENTER_BMAPS(mp,w)
63  #define	XFS_DIRENTER_MAX_SPLIT(mp,nl)	1
64  #define	XFS_DIRENTER_SPACE_RES(mp,nl)	\
65  	(XFS_DAENTER_SPACE_RES(mp, XFS_DATA_FORK) * \
66  	 XFS_DIRENTER_MAX_SPLIT(mp,nl))
67  #define	XFS_DIRREMOVE_SPACE_RES(mp)	\
68  	XFS_DAREMOVE_SPACE_RES(mp, XFS_DATA_FORK)
69  #define	XFS_IALLOC_SPACE_RES(mp)	\
70  	(M_IGEO(mp)->ialloc_blks + \
71  	 ((xfs_has_finobt(mp) ? 2 : 1) * M_IGEO(mp)->inobt_maxlevels))
72  
73  /*
74   * Space reservation values for various transactions.
75   */
76  #define	XFS_ADDAFORK_SPACE_RES(mp)	\
77  	((mp)->m_dir_geo->fsbcount + XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK))
78  #define	XFS_ATTRRM_SPACE_RES(mp)	\
79  	XFS_DAREMOVE_SPACE_RES(mp, XFS_ATTR_FORK)
80  /* This macro is not used - see inline code in xfs_attr_set */
81  #define	XFS_ATTRSET_SPACE_RES(mp, v)	\
82  	(XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
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 * (mp)->m_alloc_maxlevels)
87  #define	XFS_GROWFSRT_SPACE_RES(mp,b)	\
88  	((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK))
89  #define	XFS_QM_DQALLOC_SPACE_RES(mp)	\
90  	(XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \
91  	 XFS_DQUOT_CLUSTER_SIZE_FSB)
92  #define	XFS_QM_QINOCREATE_SPACE_RES(mp)	\
93  	XFS_IALLOC_SPACE_RES(mp)
94  #define XFS_IFREE_SPACE_RES(mp)		\
95  	(xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0)
96  
97  unsigned int xfs_parent_calc_space_res(struct xfs_mount *mp,
98  		unsigned int namelen);
99  
100  unsigned int xfs_create_space_res(struct xfs_mount *mp, unsigned int namelen);
101  unsigned int xfs_mkdir_space_res(struct xfs_mount *mp, unsigned int namelen);
102  unsigned int xfs_link_space_res(struct xfs_mount *mp, unsigned int namelen);
103  unsigned int xfs_symlink_space_res(struct xfs_mount *mp, unsigned int namelen,
104  		unsigned int fsblocks);
105  unsigned int xfs_remove_space_res(struct xfs_mount *mp, unsigned int namelen);
106  
107  unsigned int xfs_rename_space_res(struct xfs_mount *mp,
108  		unsigned int src_namelen, bool target_exists,
109  		unsigned int target_namelen, bool has_whiteout);
110  
111  #endif	/* __XFS_TRANS_SPACE_H__ */
112