blob: 88221c7a04ccfedd9a78aff832dbdef3ffb29673 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_TRANS_SPACE_H__
7#define __XFS_TRANS_SPACE_H__
8
9/*
10 * Components of space reservations.
11 */
Darrick J. Wongfe0be232017-04-12 12:26:07 -070012
13/* Worst case number of rmaps that can be held in a block. */
Darrick J. Wong1f08af52016-10-03 09:11:53 -070014#define XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp) \
15 (((mp)->m_rmap_mxr[0]) - ((mp)->m_rmap_mnr[0]))
Darrick J. Wongfe0be232017-04-12 12:26:07 -070016
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#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))
Darrick J. Wongfe0be232017-04-12 12:26:07 -070033
34/* Blocks we might need to add "b" mappings & rmappings to a file. */
Darrick J. Wong1f08af52016-10-03 09:11:53 -070035#define XFS_SWAP_RMAP_SPACE_RES(mp,b,w)\
Darrick J. Wongfe0be232017-04-12 12:26:07 -070036 (XFS_NEXTENTADD_SPACE_RES((mp), (b), (w)) + \
37 XFS_NRMAPADD_SPACE_RES((mp), (b)))
38
Dave Chinnerd6cf1302014-06-06 15:14:11 +100039#define XFS_DAENTER_1B(mp,w) \
40 ((w) == XFS_DATA_FORK ? (mp)->m_dir_geo->fsbcount : 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define XFS_DAENTER_DBS(mp,w) \
Nathan Scottf6c2d1f2006-06-20 13:04:51 +100042 (XFS_DA_NODE_MAXDEPTH + (((w) == XFS_DATA_FORK) ? 2 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#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)
Nathan Scottf6c2d1f2006-06-20 13:04:51 +100052#define XFS_DIRENTER_MAX_SPLIT(mp,nl) 1
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#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) \
Darrick J. Wongef325952019-06-05 11:19:34 -070059 (M_IGEO(mp)->ialloc_blks + \
Brian Foster9d43b182014-04-24 16:00:52 +100060 (xfs_sb_version_hasfinobt(&mp->m_sb) ? 2 : 1 * \
Darrick J. Wongef325952019-06-05 11:19:34 -070061 (M_IGEO(mp)->inobt_maxlevels - 1)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/*
64 * Space reservation values for various transactions.
65 */
66#define XFS_ADDAFORK_SPACE_RES(mp) \
Dave Chinnerd6cf1302014-06-06 15:14:11 +100067 ((mp)->m_dir_geo->fsbcount + XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK))
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define XFS_ATTRRM_SPACE_RES(mp) \
69 XFS_DAREMOVE_SPACE_RES(mp, XFS_ATTR_FORK)
70/* This macro is not used - see inline code in xfs_attr_set */
71#define XFS_ATTRSET_SPACE_RES(mp, v) \
72 (XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v))
73#define XFS_CREATE_SPACE_RES(mp,nl) \
74 (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
75#define XFS_DIOSTRAT_SPACE_RES(mp, v) \
76 (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v))
77#define XFS_GROWFS_SPACE_RES(mp) \
Dave Chinner496817b2015-06-22 10:13:30 +100078 (2 * (mp)->m_ag_maxlevels)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define XFS_GROWFSRT_SPACE_RES(mp,b) \
80 ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK))
81#define XFS_LINK_SPACE_RES(mp,nl) \
82 XFS_DIRENTER_SPACE_RES(mp,nl)
83#define XFS_MKDIR_SPACE_RES(mp,nl) \
84 (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
85#define XFS_QM_DQALLOC_SPACE_RES(mp) \
86 (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \
87 XFS_DQUOT_CLUSTER_SIZE_FSB)
88#define XFS_QM_QINOCREATE_SPACE_RES(mp) \
89 XFS_IALLOC_SPACE_RES(mp)
90#define XFS_REMOVE_SPACE_RES(mp) \
91 XFS_DIRREMOVE_SPACE_RES(mp)
92#define XFS_RENAME_SPACE_RES(mp,nl) \
93 (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
94#define XFS_SYMLINK_SPACE_RES(mp,nl,b) \
95 (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b))
Brian Foster9d43b182014-04-24 16:00:52 +100096#define XFS_IFREE_SPACE_RES(mp) \
Darrick J. Wongef325952019-06-05 11:19:34 -070097 (xfs_sb_version_hasfinobt(&mp->m_sb) ? \
98 M_IGEO(mp)->inobt_maxlevels : 0)
Brian Foster9d43b182014-04-24 16:00:52 +100099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101#endif /* __XFS_TRANS_SPACE_H__ */