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