Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * Copyright (c) 2013 Red Hat, Inc.
5 * All Rights Reserved.
6 */
7#ifndef __XFS_SHARED_H__
8#define __XFS_SHARED_H__
9
10/*
11 * Definitions shared between kernel and userspace that don't fit into any other
12 * header file that is shared with userspace.
13 */
14struct xfs_ifork;
15struct xfs_buf;
16struct xfs_buf_ops;
17struct xfs_mount;
18struct xfs_trans;
19struct xfs_inode;
20
21/*
22 * Buffer verifier operations are widely used, including userspace tools
23 */
24extern const struct xfs_buf_ops xfs_agf_buf_ops;
25extern const struct xfs_buf_ops xfs_agfl_buf_ops;
26extern const struct xfs_buf_ops xfs_agi_buf_ops;
27extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;
28extern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;
29extern const struct xfs_buf_ops xfs_bmbt_buf_ops;
30extern const struct xfs_buf_ops xfs_bnobt_buf_ops;
31extern const struct xfs_buf_ops xfs_cntbt_buf_ops;
32extern const struct xfs_buf_ops xfs_da3_node_buf_ops;
33extern const struct xfs_buf_ops xfs_dquot_buf_ops;
34extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;
35extern const struct xfs_buf_ops xfs_finobt_buf_ops;
36extern const struct xfs_buf_ops xfs_inobt_buf_ops;
37extern const struct xfs_buf_ops xfs_inode_buf_ops;
38extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;
39extern const struct xfs_buf_ops xfs_refcountbt_buf_ops;
40extern const struct xfs_buf_ops xfs_rmapbt_buf_ops;
41extern const struct xfs_buf_ops xfs_rtbitmap_buf_ops;
42extern const struct xfs_buf_ops xfs_rtsummary_buf_ops;
43extern const struct xfs_buf_ops xfs_rtbuf_ops;
44extern const struct xfs_buf_ops xfs_rtsb_buf_ops;
45extern const struct xfs_buf_ops xfs_sb_buf_ops;
46extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;
47extern const struct xfs_buf_ops xfs_symlink_buf_ops;
48
49/* btree ops */
50extern const struct xfs_btree_ops xfs_bnobt_ops;
51extern const struct xfs_btree_ops xfs_cntbt_ops;
52extern const struct xfs_btree_ops xfs_inobt_ops;
53extern const struct xfs_btree_ops xfs_finobt_ops;
54extern const struct xfs_btree_ops xfs_bmbt_ops;
55extern const struct xfs_btree_ops xfs_refcountbt_ops;
56extern const struct xfs_btree_ops xfs_rmapbt_ops;
57extern const struct xfs_btree_ops xfs_rmapbt_mem_ops;
58
59static inline bool xfs_btree_is_bno(const struct xfs_btree_ops *ops)
60{
61 return ops == &xfs_bnobt_ops;
62}
63
64static inline bool xfs_btree_is_cnt(const struct xfs_btree_ops *ops)
65{
66 return ops == &xfs_cntbt_ops;
67}
68
69static inline bool xfs_btree_is_bmap(const struct xfs_btree_ops *ops)
70{
71 return ops == &xfs_bmbt_ops;
72}
73
74static inline bool xfs_btree_is_ino(const struct xfs_btree_ops *ops)
75{
76 return ops == &xfs_inobt_ops;
77}
78
79static inline bool xfs_btree_is_fino(const struct xfs_btree_ops *ops)
80{
81 return ops == &xfs_finobt_ops;
82}
83
84static inline bool xfs_btree_is_refcount(const struct xfs_btree_ops *ops)
85{
86 return ops == &xfs_refcountbt_ops;
87}
88
89static inline bool xfs_btree_is_rmap(const struct xfs_btree_ops *ops)
90{
91 return ops == &xfs_rmapbt_ops;
92}
93
94#ifdef CONFIG_XFS_BTREE_IN_MEM
95static inline bool xfs_btree_is_mem_rmap(const struct xfs_btree_ops *ops)
96{
97 return ops == &xfs_rmapbt_mem_ops;
98}
99#else
100# define xfs_btree_is_mem_rmap(...) (false)
101#endif
102
103/* log size calculation functions */
104int xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
105int xfs_log_calc_minimum_size(struct xfs_mount *);
106
107struct xfs_trans_res;
108void xfs_log_get_max_trans_res(struct xfs_mount *mp,
109 struct xfs_trans_res *max_resp);
110
111/*
112 * Values for t_flags.
113 */
114/* Transaction needs to be logged */
115#define XFS_TRANS_DIRTY (1u << 0)
116/* Superblock is dirty and needs to be logged */
117#define XFS_TRANS_SB_DIRTY (1u << 1)
118/* Transaction took a permanent log reservation */
119#define XFS_TRANS_PERM_LOG_RES (1u << 2)
120/* Synchronous transaction commit needed */
121#define XFS_TRANS_SYNC (1u << 3)
122/* Transaction can use reserve block pool */
123#define XFS_TRANS_RESERVE (1u << 4)
124/* Transaction should avoid VFS level superblock write accounting */
125#define XFS_TRANS_NO_WRITECOUNT (1u << 5)
126/* Transaction has freed blocks returned to it's reservation */
127#define XFS_TRANS_RES_FDBLKS (1u << 6)
128/* Transaction contains an intent done log item */
129#define XFS_TRANS_HAS_INTENT_DONE (1u << 7)
130/*
131 * LOWMODE is used by the allocator to activate the lowspace algorithm - when
132 * free space is running low the extent allocator may choose to allocate an
133 * extent from an AG without leaving sufficient space for a btree split when
134 * inserting the new extent. In this case the allocator will enable the
135 * lowspace algorithm which is supposed to allow further allocations (such as
136 * btree splits and newroots) to allocate from sequential AGs. In order to
137 * avoid locking AGs out of order the lowspace algorithm will start searching
138 * for free space from AG 0. If the correct transaction reservations have been
139 * made then this algorithm will eventually find all the space it needs.
140 */
141#define XFS_TRANS_LOWMODE (1u << 8)
142
143/* Transaction has locked the rtbitmap and rtsum inodes */
144#define XFS_TRANS_RTBITMAP_LOCKED (1u << 9)
145
146/*
147 * Field values for xfs_trans_mod_sb.
148 */
149#define XFS_TRANS_SB_ICOUNT 0x00000001
150#define XFS_TRANS_SB_IFREE 0x00000002
151#define XFS_TRANS_SB_FDBLOCKS 0x00000004
152#define XFS_TRANS_SB_RES_FDBLOCKS 0x00000008
153#define XFS_TRANS_SB_FREXTENTS 0x00000010
154#define XFS_TRANS_SB_RES_FREXTENTS 0x00000020
155#define XFS_TRANS_SB_DBLOCKS 0x00000040
156#define XFS_TRANS_SB_AGCOUNT 0x00000080
157#define XFS_TRANS_SB_IMAXPCT 0x00000100
158#define XFS_TRANS_SB_REXTSIZE 0x00000200
159#define XFS_TRANS_SB_RBMBLOCKS 0x00000400
160#define XFS_TRANS_SB_RBLOCKS 0x00000800
161#define XFS_TRANS_SB_REXTENTS 0x00001000
162#define XFS_TRANS_SB_REXTSLOG 0x00002000
163#define XFS_TRANS_SB_RGCOUNT 0x00004000
164
165/*
166 * Here we centralize the specification of XFS meta-data buffer reference count
167 * values. This determines how hard the buffer cache tries to hold onto the
168 * buffer.
169 */
170#define XFS_AGF_REF 4
171#define XFS_AGI_REF 4
172#define XFS_AGFL_REF 3
173#define XFS_INO_BTREE_REF 3
174#define XFS_ALLOC_BTREE_REF 2
175#define XFS_BMAP_BTREE_REF 2
176#define XFS_RMAP_BTREE_REF 2
177#define XFS_DIR_BTREE_REF 2
178#define XFS_INO_REF 2
179#define XFS_ATTR_BTREE_REF 1
180#define XFS_DQUOT_REF 1
181#define XFS_REFC_BTREE_REF 1
182#define XFS_SSB_REF 0
183
184/* Computed inode geometry for the filesystem. */
185struct xfs_ino_geometry {
186 /* Maximum inode count in this filesystem. */
187 uint64_t maxicount;
188
189 /* Actual inode cluster buffer size, in bytes. */
190 unsigned int inode_cluster_size;
191
192 /*
193 * Desired inode cluster buffer size, in bytes. This value is not
194 * rounded up to at least one filesystem block, which is necessary for
195 * the sole purpose of validating sb_spino_align. Runtime code must
196 * only ever use inode_cluster_size.
197 */
198 unsigned int inode_cluster_size_raw;
199
200 /* Inode cluster sizes, adjusted to be at least 1 fsb. */
201 unsigned int inodes_per_cluster;
202 unsigned int blocks_per_cluster;
203
204 /* Inode cluster alignment. */
205 unsigned int cluster_align;
206 unsigned int cluster_align_inodes;
207 unsigned int inoalign_mask; /* mask sb_inoalignmt if used */
208
209 unsigned int inobt_mxr[2]; /* max inobt btree records */
210 unsigned int inobt_mnr[2]; /* min inobt btree records */
211 unsigned int inobt_maxlevels; /* max inobt btree levels. */
212
213 /* Size of inode allocations under normal operation. */
214 unsigned int ialloc_inos;
215 unsigned int ialloc_blks;
216
217 /* Minimum inode blocks for a sparse allocation. */
218 unsigned int ialloc_min_blks;
219
220 /* stripe unit inode alignment */
221 unsigned int ialloc_align;
222
223 unsigned int agino_log; /* #bits for agino in inum */
224
225 /* precomputed default inode attribute fork offset */
226 unsigned int attr_fork_offset;
227
228 /* precomputed value for di_flags2 */
229 uint64_t new_diflags2;
230
231 /* minimum folio order of a page cache allocation */
232 unsigned int min_folio_order;
233
234};
235
236#endif /* __XFS_SHARED_H__ */
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * Copyright (c) 2013 Red Hat, Inc.
5 * All Rights Reserved.
6 */
7#ifndef __XFS_SHARED_H__
8#define __XFS_SHARED_H__
9
10/*
11 * Definitions shared between kernel and userspace that don't fit into any other
12 * header file that is shared with userspace.
13 */
14struct xfs_ifork;
15struct xfs_buf;
16struct xfs_buf_ops;
17struct xfs_mount;
18struct xfs_trans;
19struct xfs_inode;
20
21/*
22 * Buffer verifier operations are widely used, including userspace tools
23 */
24extern const struct xfs_buf_ops xfs_agf_buf_ops;
25extern const struct xfs_buf_ops xfs_agi_buf_ops;
26extern const struct xfs_buf_ops xfs_agf_buf_ops;
27extern const struct xfs_buf_ops xfs_agfl_buf_ops;
28extern const struct xfs_buf_ops xfs_bnobt_buf_ops;
29extern const struct xfs_buf_ops xfs_cntbt_buf_ops;
30extern const struct xfs_buf_ops xfs_rmapbt_buf_ops;
31extern const struct xfs_buf_ops xfs_refcountbt_buf_ops;
32extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;
33extern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;
34extern const struct xfs_buf_ops xfs_bmbt_buf_ops;
35extern const struct xfs_buf_ops xfs_da3_node_buf_ops;
36extern const struct xfs_buf_ops xfs_dquot_buf_ops;
37extern const struct xfs_buf_ops xfs_symlink_buf_ops;
38extern const struct xfs_buf_ops xfs_agi_buf_ops;
39extern const struct xfs_buf_ops xfs_inobt_buf_ops;
40extern const struct xfs_buf_ops xfs_finobt_buf_ops;
41extern const struct xfs_buf_ops xfs_inode_buf_ops;
42extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;
43extern const struct xfs_buf_ops xfs_dquot_buf_ops;
44extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;
45extern const struct xfs_buf_ops xfs_sb_buf_ops;
46extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;
47extern const struct xfs_buf_ops xfs_symlink_buf_ops;
48extern const struct xfs_buf_ops xfs_rtbuf_ops;
49
50/* log size calculation functions */
51int xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
52int xfs_log_calc_minimum_size(struct xfs_mount *);
53
54struct xfs_trans_res;
55void xfs_log_get_max_trans_res(struct xfs_mount *mp,
56 struct xfs_trans_res *max_resp);
57
58/*
59 * Values for t_flags.
60 */
61#define XFS_TRANS_DIRTY 0x01 /* something needs to be logged */
62#define XFS_TRANS_SB_DIRTY 0x02 /* superblock is modified */
63#define XFS_TRANS_PERM_LOG_RES 0x04 /* xact took a permanent log res */
64#define XFS_TRANS_SYNC 0x08 /* make commit synchronous */
65#define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */
66#define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */
67#define XFS_TRANS_NO_WRITECOUNT 0x40 /* do not elevate SB writecount */
68/*
69 * LOWMODE is used by the allocator to activate the lowspace algorithm - when
70 * free space is running low the extent allocator may choose to allocate an
71 * extent from an AG without leaving sufficient space for a btree split when
72 * inserting the new extent. In this case the allocator will enable the
73 * lowspace algorithm which is supposed to allow further allocations (such as
74 * btree splits and newroots) to allocate from sequential AGs. In order to
75 * avoid locking AGs out of order the lowspace algorithm will start searching
76 * for free space from AG 0. If the correct transaction reservations have been
77 * made then this algorithm will eventually find all the space it needs.
78 */
79#define XFS_TRANS_LOWMODE 0x100 /* allocate in low space mode */
80
81/*
82 * Field values for xfs_trans_mod_sb.
83 */
84#define XFS_TRANS_SB_ICOUNT 0x00000001
85#define XFS_TRANS_SB_IFREE 0x00000002
86#define XFS_TRANS_SB_FDBLOCKS 0x00000004
87#define XFS_TRANS_SB_RES_FDBLOCKS 0x00000008
88#define XFS_TRANS_SB_FREXTENTS 0x00000010
89#define XFS_TRANS_SB_RES_FREXTENTS 0x00000020
90#define XFS_TRANS_SB_DBLOCKS 0x00000040
91#define XFS_TRANS_SB_AGCOUNT 0x00000080
92#define XFS_TRANS_SB_IMAXPCT 0x00000100
93#define XFS_TRANS_SB_REXTSIZE 0x00000200
94#define XFS_TRANS_SB_RBMBLOCKS 0x00000400
95#define XFS_TRANS_SB_RBLOCKS 0x00000800
96#define XFS_TRANS_SB_REXTENTS 0x00001000
97#define XFS_TRANS_SB_REXTSLOG 0x00002000
98
99/*
100 * Here we centralize the specification of XFS meta-data buffer reference count
101 * values. This determines how hard the buffer cache tries to hold onto the
102 * buffer.
103 */
104#define XFS_AGF_REF 4
105#define XFS_AGI_REF 4
106#define XFS_AGFL_REF 3
107#define XFS_INO_BTREE_REF 3
108#define XFS_ALLOC_BTREE_REF 2
109#define XFS_BMAP_BTREE_REF 2
110#define XFS_RMAP_BTREE_REF 2
111#define XFS_DIR_BTREE_REF 2
112#define XFS_INO_REF 2
113#define XFS_ATTR_BTREE_REF 1
114#define XFS_DQUOT_REF 1
115#define XFS_REFC_BTREE_REF 1
116#define XFS_SSB_REF 0
117
118/*
119 * Flags for xfs_trans_ichgtime().
120 */
121#define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
122#define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */
123#define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */
124
125
126/*
127 * Symlink decoding/encoding functions
128 */
129int xfs_symlink_blocks(struct xfs_mount *mp, int pathlen);
130int xfs_symlink_hdr_set(struct xfs_mount *mp, xfs_ino_t ino, uint32_t offset,
131 uint32_t size, struct xfs_buf *bp);
132bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset,
133 uint32_t size, struct xfs_buf *bp);
134void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp,
135 struct xfs_inode *ip, struct xfs_ifork *ifp);
136xfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip);
137
138/* Computed inode geometry for the filesystem. */
139struct xfs_ino_geometry {
140 /* Maximum inode count in this filesystem. */
141 uint64_t maxicount;
142
143 /* Actual inode cluster buffer size, in bytes. */
144 unsigned int inode_cluster_size;
145
146 /*
147 * Desired inode cluster buffer size, in bytes. This value is not
148 * rounded up to at least one filesystem block, which is necessary for
149 * the sole purpose of validating sb_spino_align. Runtime code must
150 * only ever use inode_cluster_size.
151 */
152 unsigned int inode_cluster_size_raw;
153
154 /* Inode cluster sizes, adjusted to be at least 1 fsb. */
155 unsigned int inodes_per_cluster;
156 unsigned int blocks_per_cluster;
157
158 /* Inode cluster alignment. */
159 unsigned int cluster_align;
160 unsigned int cluster_align_inodes;
161 unsigned int inoalign_mask; /* mask sb_inoalignmt if used */
162
163 unsigned int inobt_mxr[2]; /* max inobt btree records */
164 unsigned int inobt_mnr[2]; /* min inobt btree records */
165 unsigned int inobt_maxlevels; /* max inobt btree levels. */
166
167 /* Size of inode allocations under normal operation. */
168 unsigned int ialloc_inos;
169 unsigned int ialloc_blks;
170
171 /* Minimum inode blocks for a sparse allocation. */
172 unsigned int ialloc_min_blks;
173
174 /* stripe unit inode alignment */
175 unsigned int ialloc_align;
176
177 unsigned int agino_log; /* #bits for agino in inum */
178};
179
180#endif /* __XFS_SHARED_H__ */