]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 LT |
17 | */ |
18 | #ifndef __XFS_TRANS_H__ | |
19 | #define __XFS_TRANS_H__ | |
20 | ||
847fff5c BN |
21 | struct xfs_log_item; |
22 | ||
1da177e4 LT |
23 | /* |
24 | * This is the structure written in the log at the head of | |
25 | * every transaction. It identifies the type and id of the | |
26 | * transaction, and contains the number of items logged by | |
27 | * the transaction so we know how many to expect during recovery. | |
28 | * | |
29 | * Do not change the below structure without redoing the code in | |
30 | * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans(). | |
31 | */ | |
32 | typedef struct xfs_trans_header { | |
33 | uint th_magic; /* magic number */ | |
34 | uint th_type; /* transaction type */ | |
35 | __int32_t th_tid; /* transaction id (unused) */ | |
36 | uint th_num_items; /* num items logged by trans */ | |
37 | } xfs_trans_header_t; | |
38 | ||
39 | #define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */ | |
40 | ||
41 | /* | |
42 | * Log item types. | |
43 | */ | |
1da177e4 LT |
44 | #define XFS_LI_EFI 0x1236 |
45 | #define XFS_LI_EFD 0x1237 | |
46 | #define XFS_LI_IUNLINK 0x1238 | |
1da177e4 LT |
47 | #define XFS_LI_INODE 0x123b /* aligned ino chunks, var-size ibufs */ |
48 | #define XFS_LI_BUF 0x123c /* v2 bufs, variable sized inode bufs */ | |
49 | #define XFS_LI_DQUOT 0x123d | |
50 | #define XFS_LI_QUOTAOFF 0x123e | |
51 | ||
9abbc539 DC |
52 | #define XFS_LI_TYPE_DESC \ |
53 | { XFS_LI_EFI, "XFS_LI_EFI" }, \ | |
54 | { XFS_LI_EFD, "XFS_LI_EFD" }, \ | |
55 | { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \ | |
56 | { XFS_LI_INODE, "XFS_LI_INODE" }, \ | |
57 | { XFS_LI_BUF, "XFS_LI_BUF" }, \ | |
58 | { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \ | |
59 | { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" } | |
60 | ||
1da177e4 LT |
61 | /* |
62 | * Transaction types. Used to distinguish types of buffers. | |
63 | */ | |
64 | #define XFS_TRANS_SETATTR_NOT_SIZE 1 | |
65 | #define XFS_TRANS_SETATTR_SIZE 2 | |
66 | #define XFS_TRANS_INACTIVE 3 | |
67 | #define XFS_TRANS_CREATE 4 | |
68 | #define XFS_TRANS_CREATE_TRUNC 5 | |
69 | #define XFS_TRANS_TRUNCATE_FILE 6 | |
70 | #define XFS_TRANS_REMOVE 7 | |
71 | #define XFS_TRANS_LINK 8 | |
72 | #define XFS_TRANS_RENAME 9 | |
73 | #define XFS_TRANS_MKDIR 10 | |
74 | #define XFS_TRANS_RMDIR 11 | |
75 | #define XFS_TRANS_SYMLINK 12 | |
76 | #define XFS_TRANS_SET_DMATTRS 13 | |
77 | #define XFS_TRANS_GROWFS 14 | |
78 | #define XFS_TRANS_STRAT_WRITE 15 | |
79 | #define XFS_TRANS_DIOSTRAT 16 | |
13e6d5cd | 80 | /* 17 was XFS_TRANS_WRITE_SYNC */ |
1da177e4 LT |
81 | #define XFS_TRANS_WRITEID 18 |
82 | #define XFS_TRANS_ADDAFORK 19 | |
83 | #define XFS_TRANS_ATTRINVAL 20 | |
84 | #define XFS_TRANS_ATRUNCATE 21 | |
85 | #define XFS_TRANS_ATTR_SET 22 | |
86 | #define XFS_TRANS_ATTR_RM 23 | |
87 | #define XFS_TRANS_ATTR_FLAG 24 | |
88 | #define XFS_TRANS_CLEAR_AGI_BUCKET 25 | |
89 | #define XFS_TRANS_QM_SBCHANGE 26 | |
90 | /* | |
91 | * Dummy entries since we use the transaction type to index into the | |
92 | * trans_type[] in xlog_recover_print_trans_head() | |
93 | */ | |
94 | #define XFS_TRANS_DUMMY1 27 | |
95 | #define XFS_TRANS_DUMMY2 28 | |
96 | #define XFS_TRANS_QM_QUOTAOFF 29 | |
97 | #define XFS_TRANS_QM_DQALLOC 30 | |
98 | #define XFS_TRANS_QM_SETQLIM 31 | |
99 | #define XFS_TRANS_QM_DQCLUSTER 32 | |
100 | #define XFS_TRANS_QM_QINOCREATE 33 | |
101 | #define XFS_TRANS_QM_QUOTAOFF_END 34 | |
102 | #define XFS_TRANS_SB_UNIT 35 | |
103 | #define XFS_TRANS_FSYNC_TS 36 | |
104 | #define XFS_TRANS_GROWFSRT_ALLOC 37 | |
105 | #define XFS_TRANS_GROWFSRT_ZERO 38 | |
106 | #define XFS_TRANS_GROWFSRT_FREE 39 | |
107 | #define XFS_TRANS_SWAPEXT 40 | |
92821e2b DC |
108 | #define XFS_TRANS_SB_COUNT 41 |
109 | #define XFS_TRANS_TYPE_MAX 41 | |
1da177e4 LT |
110 | /* new transaction types need to be reflected in xfs_logprint(8) */ |
111 | ||
0b1b213f CH |
112 | #define XFS_TRANS_TYPES \ |
113 | { XFS_TRANS_SETATTR_NOT_SIZE, "SETATTR_NOT_SIZE" }, \ | |
114 | { XFS_TRANS_SETATTR_SIZE, "SETATTR_SIZE" }, \ | |
115 | { XFS_TRANS_INACTIVE, "INACTIVE" }, \ | |
116 | { XFS_TRANS_CREATE, "CREATE" }, \ | |
117 | { XFS_TRANS_CREATE_TRUNC, "CREATE_TRUNC" }, \ | |
118 | { XFS_TRANS_TRUNCATE_FILE, "TRUNCATE_FILE" }, \ | |
119 | { XFS_TRANS_REMOVE, "REMOVE" }, \ | |
120 | { XFS_TRANS_LINK, "LINK" }, \ | |
121 | { XFS_TRANS_RENAME, "RENAME" }, \ | |
122 | { XFS_TRANS_MKDIR, "MKDIR" }, \ | |
123 | { XFS_TRANS_RMDIR, "RMDIR" }, \ | |
124 | { XFS_TRANS_SYMLINK, "SYMLINK" }, \ | |
125 | { XFS_TRANS_SET_DMATTRS, "SET_DMATTRS" }, \ | |
126 | { XFS_TRANS_GROWFS, "GROWFS" }, \ | |
127 | { XFS_TRANS_STRAT_WRITE, "STRAT_WRITE" }, \ | |
128 | { XFS_TRANS_DIOSTRAT, "DIOSTRAT" }, \ | |
129 | { XFS_TRANS_WRITEID, "WRITEID" }, \ | |
130 | { XFS_TRANS_ADDAFORK, "ADDAFORK" }, \ | |
131 | { XFS_TRANS_ATTRINVAL, "ATTRINVAL" }, \ | |
132 | { XFS_TRANS_ATRUNCATE, "ATRUNCATE" }, \ | |
133 | { XFS_TRANS_ATTR_SET, "ATTR_SET" }, \ | |
134 | { XFS_TRANS_ATTR_RM, "ATTR_RM" }, \ | |
135 | { XFS_TRANS_ATTR_FLAG, "ATTR_FLAG" }, \ | |
136 | { XFS_TRANS_CLEAR_AGI_BUCKET, "CLEAR_AGI_BUCKET" }, \ | |
137 | { XFS_TRANS_QM_SBCHANGE, "QM_SBCHANGE" }, \ | |
138 | { XFS_TRANS_QM_QUOTAOFF, "QM_QUOTAOFF" }, \ | |
139 | { XFS_TRANS_QM_DQALLOC, "QM_DQALLOC" }, \ | |
140 | { XFS_TRANS_QM_SETQLIM, "QM_SETQLIM" }, \ | |
141 | { XFS_TRANS_QM_DQCLUSTER, "QM_DQCLUSTER" }, \ | |
142 | { XFS_TRANS_QM_QINOCREATE, "QM_QINOCREATE" }, \ | |
143 | { XFS_TRANS_QM_QUOTAOFF_END, "QM_QOFF_END" }, \ | |
144 | { XFS_TRANS_SB_UNIT, "SB_UNIT" }, \ | |
145 | { XFS_TRANS_FSYNC_TS, "FSYNC_TS" }, \ | |
146 | { XFS_TRANS_GROWFSRT_ALLOC, "GROWFSRT_ALLOC" }, \ | |
147 | { XFS_TRANS_GROWFSRT_ZERO, "GROWFSRT_ZERO" }, \ | |
148 | { XFS_TRANS_GROWFSRT_FREE, "GROWFSRT_FREE" }, \ | |
149 | { XFS_TRANS_SWAPEXT, "SWAPEXT" }, \ | |
150 | { XFS_TRANS_SB_COUNT, "SB_COUNT" }, \ | |
151 | { XFS_TRANS_DUMMY1, "DUMMY1" }, \ | |
152 | { XFS_TRANS_DUMMY2, "DUMMY2" }, \ | |
153 | { XLOG_UNMOUNT_REC_TYPE, "UNMOUNT" } | |
154 | ||
1da177e4 LT |
155 | /* |
156 | * This structure is used to track log items associated with | |
157 | * a transaction. It points to the log item and keeps some | |
158 | * flags to track the state of the log item. It also tracks | |
159 | * the amount of space needed to log the item it describes | |
160 | * once we get to commit processing (see xfs_trans_commit()). | |
161 | */ | |
162 | typedef struct xfs_log_item_desc { | |
847fff5c | 163 | struct xfs_log_item *lid_item; |
1da177e4 LT |
164 | ushort lid_size; |
165 | unsigned char lid_flags; | |
166 | unsigned char lid_index; | |
167 | } xfs_log_item_desc_t; | |
168 | ||
169 | #define XFS_LID_DIRTY 0x1 | |
170 | #define XFS_LID_PINNED 0x2 | |
1da177e4 LT |
171 | |
172 | /* | |
173 | * This structure is used to maintain a chunk list of log_item_desc | |
174 | * structures. The free field is a bitmask indicating which descriptors | |
175 | * in this chunk's array are free. The unused field is the first value | |
176 | * not used since this chunk was allocated. | |
177 | */ | |
178 | #define XFS_LIC_NUM_SLOTS 15 | |
179 | typedef struct xfs_log_item_chunk { | |
180 | struct xfs_log_item_chunk *lic_next; | |
181 | ushort lic_free; | |
182 | ushort lic_unused; | |
183 | xfs_log_item_desc_t lic_descs[XFS_LIC_NUM_SLOTS]; | |
184 | } xfs_log_item_chunk_t; | |
185 | ||
186 | #define XFS_LIC_MAX_SLOT (XFS_LIC_NUM_SLOTS - 1) | |
187 | #define XFS_LIC_FREEMASK ((1 << XFS_LIC_NUM_SLOTS) - 1) | |
188 | ||
189 | ||
190 | /* | |
191 | * Initialize the given chunk. Set the chunk's free descriptor mask | |
192 | * to indicate that all descriptors are free. The caller gets to set | |
193 | * lic_unused to the right value (0 matches all free). The | |
194 | * lic_descs.lid_index values are set up as each desc is allocated. | |
195 | */ | |
a844f451 NS |
196 | static inline void xfs_lic_init(xfs_log_item_chunk_t *cp) |
197 | { | |
198 | cp->lic_free = XFS_LIC_FREEMASK; | |
199 | } | |
200 | ||
a844f451 NS |
201 | static inline void xfs_lic_init_slot(xfs_log_item_chunk_t *cp, int slot) |
202 | { | |
203 | cp->lic_descs[slot].lid_index = (unsigned char)(slot); | |
204 | } | |
205 | ||
a844f451 NS |
206 | static inline int xfs_lic_vacancy(xfs_log_item_chunk_t *cp) |
207 | { | |
208 | return cp->lic_free & XFS_LIC_FREEMASK; | |
209 | } | |
210 | ||
a844f451 NS |
211 | static inline void xfs_lic_all_free(xfs_log_item_chunk_t *cp) |
212 | { | |
213 | cp->lic_free = XFS_LIC_FREEMASK; | |
214 | } | |
215 | ||
a844f451 NS |
216 | static inline int xfs_lic_are_all_free(xfs_log_item_chunk_t *cp) |
217 | { | |
218 | return ((cp->lic_free & XFS_LIC_FREEMASK) == XFS_LIC_FREEMASK); | |
219 | } | |
220 | ||
a844f451 NS |
221 | static inline int xfs_lic_isfree(xfs_log_item_chunk_t *cp, int slot) |
222 | { | |
223 | return (cp->lic_free & (1 << slot)); | |
224 | } | |
225 | ||
a844f451 NS |
226 | static inline void xfs_lic_claim(xfs_log_item_chunk_t *cp, int slot) |
227 | { | |
228 | cp->lic_free &= ~(1 << slot); | |
229 | } | |
230 | ||
a844f451 NS |
231 | static inline void xfs_lic_relse(xfs_log_item_chunk_t *cp, int slot) |
232 | { | |
233 | cp->lic_free |= 1 << slot; | |
234 | } | |
235 | ||
a844f451 NS |
236 | static inline xfs_log_item_desc_t * |
237 | xfs_lic_slot(xfs_log_item_chunk_t *cp, int slot) | |
238 | { | |
239 | return &(cp->lic_descs[slot]); | |
240 | } | |
241 | ||
a844f451 NS |
242 | static inline int xfs_lic_desc_to_slot(xfs_log_item_desc_t *dp) |
243 | { | |
244 | return (uint)dp->lid_index; | |
245 | } | |
246 | ||
1da177e4 LT |
247 | /* |
248 | * Calculate the address of a chunk given a descriptor pointer: | |
249 | * dp - dp->lid_index give the address of the start of the lic_descs array. | |
250 | * From this we subtract the offset of the lic_descs field in a chunk. | |
251 | * All of this yields the address of the chunk, which is | |
252 | * cast to a chunk pointer. | |
253 | */ | |
a844f451 NS |
254 | static inline xfs_log_item_chunk_t * |
255 | xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp) | |
256 | { | |
257 | return (xfs_log_item_chunk_t*) \ | |
258 | (((xfs_caddr_t)((dp) - (dp)->lid_index)) - \ | |
259 | (xfs_caddr_t)(((xfs_log_item_chunk_t*)0)->lic_descs)); | |
260 | } | |
1da177e4 | 261 | |
1da177e4 LT |
262 | #define XFS_TRANS_MAGIC 0x5452414E /* 'TRAN' */ |
263 | /* | |
264 | * Values for t_flags. | |
265 | */ | |
266 | #define XFS_TRANS_DIRTY 0x01 /* something needs to be logged */ | |
267 | #define XFS_TRANS_SB_DIRTY 0x02 /* superblock is modified */ | |
268 | #define XFS_TRANS_PERM_LOG_RES 0x04 /* xact took a permanent log res */ | |
269 | #define XFS_TRANS_SYNC 0x08 /* make commit synchronous */ | |
270 | #define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */ | |
271 | #define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */ | |
272 | ||
273 | /* | |
274 | * Values for call flags parameter. | |
275 | */ | |
276 | #define XFS_TRANS_NOSLEEP 0x1 | |
277 | #define XFS_TRANS_WAIT 0x2 | |
278 | #define XFS_TRANS_RELEASE_LOG_RES 0x4 | |
279 | #define XFS_TRANS_ABORT 0x8 | |
280 | ||
281 | /* | |
282 | * Field values for xfs_trans_mod_sb. | |
283 | */ | |
284 | #define XFS_TRANS_SB_ICOUNT 0x00000001 | |
285 | #define XFS_TRANS_SB_IFREE 0x00000002 | |
286 | #define XFS_TRANS_SB_FDBLOCKS 0x00000004 | |
287 | #define XFS_TRANS_SB_RES_FDBLOCKS 0x00000008 | |
288 | #define XFS_TRANS_SB_FREXTENTS 0x00000010 | |
289 | #define XFS_TRANS_SB_RES_FREXTENTS 0x00000020 | |
290 | #define XFS_TRANS_SB_DBLOCKS 0x00000040 | |
291 | #define XFS_TRANS_SB_AGCOUNT 0x00000080 | |
292 | #define XFS_TRANS_SB_IMAXPCT 0x00000100 | |
293 | #define XFS_TRANS_SB_REXTSIZE 0x00000200 | |
294 | #define XFS_TRANS_SB_RBMBLOCKS 0x00000400 | |
295 | #define XFS_TRANS_SB_RBLOCKS 0x00000800 | |
296 | #define XFS_TRANS_SB_REXTENTS 0x00001000 | |
297 | #define XFS_TRANS_SB_REXTSLOG 0x00002000 | |
298 | ||
299 | ||
300 | /* | |
301 | * Various log reservation values. | |
302 | * These are based on the size of the file system block | |
303 | * because that is what most transactions manipulate. | |
304 | * Each adds in an additional 128 bytes per item logged to | |
305 | * try to account for the overhead of the transaction mechanism. | |
306 | * | |
307 | * Note: | |
308 | * Most of the reservations underestimate the number of allocation | |
309 | * groups into which they could free extents in the xfs_bmap_finish() | |
310 | * call. This is because the number in the worst case is quite high | |
311 | * and quite unusual. In order to fix this we need to change | |
312 | * xfs_bmap_finish() to free extents in only a single AG at a time. | |
313 | * This will require changes to the EFI code as well, however, so that | |
314 | * the EFI for the extents not freed is logged again in each transaction. | |
315 | * See bug 261917. | |
316 | */ | |
317 | ||
318 | /* | |
319 | * Per-extent log reservation for the allocation btree changes | |
320 | * involved in freeing or allocating an extent. | |
321 | * 2 trees * (2 blocks/level * max depth - 1) * block size | |
322 | */ | |
323 | #define XFS_ALLOCFREE_LOG_RES(mp,nx) \ | |
324 | ((nx) * (2 * XFS_FSB_TO_B((mp), 2 * XFS_AG_MAXLEVELS(mp) - 1))) | |
325 | #define XFS_ALLOCFREE_LOG_COUNT(mp,nx) \ | |
326 | ((nx) * (2 * (2 * XFS_AG_MAXLEVELS(mp) - 1))) | |
327 | ||
328 | /* | |
329 | * Per-directory log reservation for any directory change. | |
330 | * dir blocks: (1 btree block per level + data block + free block) * dblock size | |
331 | * bmap btree: (levels + 2) * max depth * block size | |
332 | * v2 directory blocks can be fragmented below the dirblksize down to the fsb | |
333 | * size, so account for that in the DAENTER macros. | |
334 | */ | |
335 | #define XFS_DIROP_LOG_RES(mp) \ | |
336 | (XFS_FSB_TO_B(mp, XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK)) + \ | |
337 | (XFS_FSB_TO_B(mp, XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1))) | |
338 | #define XFS_DIROP_LOG_COUNT(mp) \ | |
339 | (XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK) + \ | |
340 | XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1) | |
341 | ||
342 | /* | |
343 | * In a write transaction we can allocate a maximum of 2 | |
344 | * extents. This gives: | |
345 | * the inode getting the new extents: inode size | |
9da096fd | 346 | * the inode's bmap btree: max depth * block size |
1da177e4 LT |
347 | * the agfs of the ags from which the extents are allocated: 2 * sector |
348 | * the superblock free block counter: sector size | |
349 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
350 | * And the bmap_finish transaction can free bmap blocks in a join: | |
351 | * the agfs of the ags containing the blocks: 2 * sector size | |
352 | * the agfls of the ags containing the blocks: 2 * sector size | |
353 | * the super block free block counter: sector size | |
354 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
355 | */ | |
356 | #define XFS_CALC_WRITE_LOG_RES(mp) \ | |
357 | (MAX( \ | |
358 | ((mp)->m_sb.sb_inodesize + \ | |
359 | XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)) + \ | |
360 | (2 * (mp)->m_sb.sb_sectsize) + \ | |
361 | (mp)->m_sb.sb_sectsize + \ | |
362 | XFS_ALLOCFREE_LOG_RES(mp, 2) + \ | |
363 | (128 * (4 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + XFS_ALLOCFREE_LOG_COUNT(mp, 2)))),\ | |
364 | ((2 * (mp)->m_sb.sb_sectsize) + \ | |
365 | (2 * (mp)->m_sb.sb_sectsize) + \ | |
366 | (mp)->m_sb.sb_sectsize + \ | |
367 | XFS_ALLOCFREE_LOG_RES(mp, 2) + \ | |
368 | (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2)))))) | |
369 | ||
370 | #define XFS_WRITE_LOG_RES(mp) ((mp)->m_reservations.tr_write) | |
371 | ||
372 | /* | |
373 | * In truncating a file we free up to two extents at once. We can modify: | |
374 | * the inode being truncated: inode size | |
9da096fd | 375 | * the inode's bmap btree: (max depth + 1) * block size |
1da177e4 LT |
376 | * And the bmap_finish transaction can free the blocks and bmap blocks: |
377 | * the agf for each of the ags: 4 * sector size | |
378 | * the agfl for each of the ags: 4 * sector size | |
379 | * the super block to reflect the freed blocks: sector size | |
380 | * worst case split in allocation btrees per extent assuming 4 extents: | |
381 | * 4 exts * 2 trees * (2 * max depth - 1) * block size | |
382 | * the inode btree: max depth * blocksize | |
383 | * the allocation btrees: 2 trees * (max depth - 1) * block size | |
384 | */ | |
385 | #define XFS_CALC_ITRUNCATE_LOG_RES(mp) \ | |
386 | (MAX( \ | |
387 | ((mp)->m_sb.sb_inodesize + \ | |
388 | XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1) + \ | |
389 | (128 * (2 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)))), \ | |
390 | ((4 * (mp)->m_sb.sb_sectsize) + \ | |
391 | (4 * (mp)->m_sb.sb_sectsize) + \ | |
392 | (mp)->m_sb.sb_sectsize + \ | |
393 | XFS_ALLOCFREE_LOG_RES(mp, 4) + \ | |
394 | (128 * (9 + XFS_ALLOCFREE_LOG_COUNT(mp, 4))) + \ | |
395 | (128 * 5) + \ | |
396 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ | |
0d87e656 | 397 | (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \ |
1da177e4 LT |
398 | XFS_ALLOCFREE_LOG_COUNT(mp, 1)))))) |
399 | ||
400 | #define XFS_ITRUNCATE_LOG_RES(mp) ((mp)->m_reservations.tr_itruncate) | |
401 | ||
402 | /* | |
403 | * In renaming a files we can modify: | |
404 | * the four inodes involved: 4 * inode size | |
405 | * the two directory btrees: 2 * (max depth + v2) * dir block size | |
406 | * the two directory bmap btrees: 2 * max depth * block size | |
407 | * And the bmap_finish transaction can free dir and bmap blocks (two sets | |
408 | * of bmap blocks) giving: | |
409 | * the agf for the ags in which the blocks live: 3 * sector size | |
410 | * the agfl for the ags in which the blocks live: 3 * sector size | |
411 | * the superblock for the free block count: sector size | |
412 | * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size | |
413 | */ | |
414 | #define XFS_CALC_RENAME_LOG_RES(mp) \ | |
415 | (MAX( \ | |
416 | ((4 * (mp)->m_sb.sb_inodesize) + \ | |
417 | (2 * XFS_DIROP_LOG_RES(mp)) + \ | |
418 | (128 * (4 + 2 * XFS_DIROP_LOG_COUNT(mp)))), \ | |
419 | ((3 * (mp)->m_sb.sb_sectsize) + \ | |
420 | (3 * (mp)->m_sb.sb_sectsize) + \ | |
421 | (mp)->m_sb.sb_sectsize + \ | |
422 | XFS_ALLOCFREE_LOG_RES(mp, 3) + \ | |
423 | (128 * (7 + XFS_ALLOCFREE_LOG_COUNT(mp, 3)))))) | |
424 | ||
425 | #define XFS_RENAME_LOG_RES(mp) ((mp)->m_reservations.tr_rename) | |
426 | ||
427 | /* | |
428 | * For creating a link to an inode: | |
429 | * the parent directory inode: inode size | |
430 | * the linked inode: inode size | |
431 | * the directory btree could split: (max depth + v2) * dir block size | |
432 | * the directory bmap btree could join or split: (max depth + v2) * blocksize | |
433 | * And the bmap_finish transaction can free some bmap blocks giving: | |
434 | * the agf for the ag in which the blocks live: sector size | |
435 | * the agfl for the ag in which the blocks live: sector size | |
436 | * the superblock for the free block count: sector size | |
437 | * the allocation btrees: 2 trees * (2 * max depth - 1) * block size | |
438 | */ | |
439 | #define XFS_CALC_LINK_LOG_RES(mp) \ | |
440 | (MAX( \ | |
441 | ((mp)->m_sb.sb_inodesize + \ | |
442 | (mp)->m_sb.sb_inodesize + \ | |
443 | XFS_DIROP_LOG_RES(mp) + \ | |
444 | (128 * (2 + XFS_DIROP_LOG_COUNT(mp)))), \ | |
445 | ((mp)->m_sb.sb_sectsize + \ | |
446 | (mp)->m_sb.sb_sectsize + \ | |
447 | (mp)->m_sb.sb_sectsize + \ | |
448 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ | |
449 | (128 * (3 + XFS_ALLOCFREE_LOG_COUNT(mp, 1)))))) | |
450 | ||
451 | #define XFS_LINK_LOG_RES(mp) ((mp)->m_reservations.tr_link) | |
452 | ||
453 | /* | |
454 | * For removing a directory entry we can modify: | |
455 | * the parent directory inode: inode size | |
456 | * the removed inode: inode size | |
457 | * the directory btree could join: (max depth + v2) * dir block size | |
458 | * the directory bmap btree could join or split: (max depth + v2) * blocksize | |
459 | * And the bmap_finish transaction can free the dir and bmap blocks giving: | |
460 | * the agf for the ag in which the blocks live: 2 * sector size | |
461 | * the agfl for the ag in which the blocks live: 2 * sector size | |
462 | * the superblock for the free block count: sector size | |
463 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
464 | */ | |
465 | #define XFS_CALC_REMOVE_LOG_RES(mp) \ | |
466 | (MAX( \ | |
467 | ((mp)->m_sb.sb_inodesize + \ | |
468 | (mp)->m_sb.sb_inodesize + \ | |
469 | XFS_DIROP_LOG_RES(mp) + \ | |
470 | (128 * (2 + XFS_DIROP_LOG_COUNT(mp)))), \ | |
471 | ((2 * (mp)->m_sb.sb_sectsize) + \ | |
472 | (2 * (mp)->m_sb.sb_sectsize) + \ | |
473 | (mp)->m_sb.sb_sectsize + \ | |
474 | XFS_ALLOCFREE_LOG_RES(mp, 2) + \ | |
475 | (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2)))))) | |
476 | ||
477 | #define XFS_REMOVE_LOG_RES(mp) ((mp)->m_reservations.tr_remove) | |
478 | ||
479 | /* | |
480 | * For symlink we can modify: | |
481 | * the parent directory inode: inode size | |
482 | * the new inode: inode size | |
483 | * the inode btree entry: 1 block | |
484 | * the directory btree: (max depth + v2) * dir block size | |
9da096fd MP |
485 | * the directory inode's bmap btree: (max depth + v2) * block size |
486 | * the blocks for the symlink: 1 kB | |
1da177e4 LT |
487 | * Or in the first xact we allocate some inodes giving: |
488 | * the agi and agf of the ag getting the new inodes: 2 * sectorsize | |
489 | * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize | |
490 | * the inode btree: max depth * blocksize | |
491 | * the allocation btrees: 2 trees * (2 * max depth - 1) * block size | |
492 | */ | |
493 | #define XFS_CALC_SYMLINK_LOG_RES(mp) \ | |
494 | (MAX( \ | |
495 | ((mp)->m_sb.sb_inodesize + \ | |
496 | (mp)->m_sb.sb_inodesize + \ | |
497 | XFS_FSB_TO_B(mp, 1) + \ | |
498 | XFS_DIROP_LOG_RES(mp) + \ | |
499 | 1024 + \ | |
500 | (128 * (4 + XFS_DIROP_LOG_COUNT(mp)))), \ | |
501 | (2 * (mp)->m_sb.sb_sectsize + \ | |
502 | XFS_FSB_TO_B((mp), XFS_IALLOC_BLOCKS((mp))) + \ | |
0d87e656 | 503 | XFS_FSB_TO_B((mp), (mp)->m_in_maxlevels) + \ |
1da177e4 | 504 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ |
0d87e656 | 505 | (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \ |
1da177e4 LT |
506 | XFS_ALLOCFREE_LOG_COUNT(mp, 1)))))) |
507 | ||
508 | #define XFS_SYMLINK_LOG_RES(mp) ((mp)->m_reservations.tr_symlink) | |
509 | ||
510 | /* | |
511 | * For create we can modify: | |
512 | * the parent directory inode: inode size | |
513 | * the new inode: inode size | |
514 | * the inode btree entry: block size | |
515 | * the superblock for the nlink flag: sector size | |
516 | * the directory btree: (max depth + v2) * dir block size | |
9da096fd | 517 | * the directory inode's bmap btree: (max depth + v2) * block size |
1da177e4 LT |
518 | * Or in the first xact we allocate some inodes giving: |
519 | * the agi and agf of the ag getting the new inodes: 2 * sectorsize | |
520 | * the superblock for the nlink flag: sector size | |
521 | * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize | |
522 | * the inode btree: max depth * blocksize | |
523 | * the allocation btrees: 2 trees * (max depth - 1) * block size | |
524 | */ | |
525 | #define XFS_CALC_CREATE_LOG_RES(mp) \ | |
526 | (MAX( \ | |
527 | ((mp)->m_sb.sb_inodesize + \ | |
528 | (mp)->m_sb.sb_inodesize + \ | |
529 | (mp)->m_sb.sb_sectsize + \ | |
530 | XFS_FSB_TO_B(mp, 1) + \ | |
531 | XFS_DIROP_LOG_RES(mp) + \ | |
532 | (128 * (3 + XFS_DIROP_LOG_COUNT(mp)))), \ | |
533 | (3 * (mp)->m_sb.sb_sectsize + \ | |
534 | XFS_FSB_TO_B((mp), XFS_IALLOC_BLOCKS((mp))) + \ | |
0d87e656 | 535 | XFS_FSB_TO_B((mp), (mp)->m_in_maxlevels) + \ |
1da177e4 | 536 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ |
0d87e656 | 537 | (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \ |
1da177e4 LT |
538 | XFS_ALLOCFREE_LOG_COUNT(mp, 1)))))) |
539 | ||
540 | #define XFS_CREATE_LOG_RES(mp) ((mp)->m_reservations.tr_create) | |
541 | ||
542 | /* | |
543 | * Making a new directory is the same as creating a new file. | |
544 | */ | |
545 | #define XFS_CALC_MKDIR_LOG_RES(mp) XFS_CALC_CREATE_LOG_RES(mp) | |
546 | ||
547 | #define XFS_MKDIR_LOG_RES(mp) ((mp)->m_reservations.tr_mkdir) | |
548 | ||
549 | /* | |
550 | * In freeing an inode we can modify: | |
551 | * the inode being freed: inode size | |
552 | * the super block free inode counter: sector size | |
553 | * the agi hash list and counters: sector size | |
554 | * the inode btree entry: block size | |
555 | * the on disk inode before ours in the agi hash list: inode cluster size | |
556 | * the inode btree: max depth * blocksize | |
557 | * the allocation btrees: 2 trees * (max depth - 1) * block size | |
558 | */ | |
559 | #define XFS_CALC_IFREE_LOG_RES(mp) \ | |
560 | ((mp)->m_sb.sb_inodesize + \ | |
561 | (mp)->m_sb.sb_sectsize + \ | |
562 | (mp)->m_sb.sb_sectsize + \ | |
563 | XFS_FSB_TO_B((mp), 1) + \ | |
564 | MAX((__uint16_t)XFS_FSB_TO_B((mp), 1), XFS_INODE_CLUSTER_SIZE(mp)) + \ | |
565 | (128 * 5) + \ | |
566 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ | |
0d87e656 | 567 | (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \ |
1da177e4 LT |
568 | XFS_ALLOCFREE_LOG_COUNT(mp, 1)))) |
569 | ||
570 | ||
571 | #define XFS_IFREE_LOG_RES(mp) ((mp)->m_reservations.tr_ifree) | |
572 | ||
573 | /* | |
574 | * When only changing the inode we log the inode and possibly the superblock | |
575 | * We also add a bit of slop for the transaction stuff. | |
576 | */ | |
577 | #define XFS_CALC_ICHANGE_LOG_RES(mp) ((mp)->m_sb.sb_inodesize + \ | |
578 | (mp)->m_sb.sb_sectsize + 512) | |
579 | ||
580 | #define XFS_ICHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_ichange) | |
581 | ||
582 | /* | |
583 | * Growing the data section of the filesystem. | |
584 | * superblock | |
585 | * agi and agf | |
586 | * allocation btrees | |
587 | */ | |
588 | #define XFS_CALC_GROWDATA_LOG_RES(mp) \ | |
589 | ((mp)->m_sb.sb_sectsize * 3 + \ | |
590 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ | |
591 | (128 * (3 + XFS_ALLOCFREE_LOG_COUNT(mp, 1)))) | |
592 | ||
593 | #define XFS_GROWDATA_LOG_RES(mp) ((mp)->m_reservations.tr_growdata) | |
594 | ||
595 | /* | |
596 | * Growing the rt section of the filesystem. | |
597 | * In the first set of transactions (ALLOC) we allocate space to the | |
598 | * bitmap or summary files. | |
599 | * superblock: sector size | |
600 | * agf of the ag from which the extent is allocated: sector size | |
601 | * bmap btree for bitmap/summary inode: max depth * blocksize | |
602 | * bitmap/summary inode: inode size | |
603 | * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize | |
604 | */ | |
605 | #define XFS_CALC_GROWRTALLOC_LOG_RES(mp) \ | |
606 | (2 * (mp)->m_sb.sb_sectsize + \ | |
607 | XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)) + \ | |
608 | (mp)->m_sb.sb_inodesize + \ | |
609 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ | |
610 | (128 * \ | |
611 | (3 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + \ | |
612 | XFS_ALLOCFREE_LOG_COUNT(mp, 1)))) | |
613 | ||
614 | #define XFS_GROWRTALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_growrtalloc) | |
615 | ||
616 | /* | |
617 | * Growing the rt section of the filesystem. | |
618 | * In the second set of transactions (ZERO) we zero the new metadata blocks. | |
619 | * one bitmap/summary block: blocksize | |
620 | */ | |
621 | #define XFS_CALC_GROWRTZERO_LOG_RES(mp) \ | |
622 | ((mp)->m_sb.sb_blocksize + 128) | |
623 | ||
624 | #define XFS_GROWRTZERO_LOG_RES(mp) ((mp)->m_reservations.tr_growrtzero) | |
625 | ||
626 | /* | |
627 | * Growing the rt section of the filesystem. | |
628 | * In the third set of transactions (FREE) we update metadata without | |
629 | * allocating any new blocks. | |
630 | * superblock: sector size | |
631 | * bitmap inode: inode size | |
632 | * summary inode: inode size | |
633 | * one bitmap block: blocksize | |
634 | * summary blocks: new summary size | |
635 | */ | |
636 | #define XFS_CALC_GROWRTFREE_LOG_RES(mp) \ | |
637 | ((mp)->m_sb.sb_sectsize + \ | |
638 | 2 * (mp)->m_sb.sb_inodesize + \ | |
639 | (mp)->m_sb.sb_blocksize + \ | |
640 | (mp)->m_rsumsize + \ | |
641 | (128 * 5)) | |
642 | ||
643 | #define XFS_GROWRTFREE_LOG_RES(mp) ((mp)->m_reservations.tr_growrtfree) | |
644 | ||
645 | /* | |
646 | * Logging the inode modification timestamp on a synchronous write. | |
647 | * inode | |
648 | */ | |
649 | #define XFS_CALC_SWRITE_LOG_RES(mp) \ | |
650 | ((mp)->m_sb.sb_inodesize + 128) | |
651 | ||
652 | #define XFS_SWRITE_LOG_RES(mp) ((mp)->m_reservations.tr_swrite) | |
653 | ||
654 | /* | |
655 | * Logging the inode timestamps on an fsync -- same as SWRITE | |
656 | * as long as SWRITE logs the entire inode core | |
657 | */ | |
658 | #define XFS_FSYNC_TS_LOG_RES(mp) ((mp)->m_reservations.tr_swrite) | |
659 | ||
660 | /* | |
661 | * Logging the inode mode bits when writing a setuid/setgid file | |
662 | * inode | |
663 | */ | |
664 | #define XFS_CALC_WRITEID_LOG_RES(mp) \ | |
665 | ((mp)->m_sb.sb_inodesize + 128) | |
666 | ||
667 | #define XFS_WRITEID_LOG_RES(mp) ((mp)->m_reservations.tr_swrite) | |
668 | ||
669 | /* | |
670 | * Converting the inode from non-attributed to attributed. | |
671 | * the inode being converted: inode size | |
672 | * agf block and superblock (for block allocation) | |
673 | * the new block (directory sized) | |
674 | * bmap blocks for the new directory block | |
675 | * allocation btrees | |
676 | */ | |
677 | #define XFS_CALC_ADDAFORK_LOG_RES(mp) \ | |
678 | ((mp)->m_sb.sb_inodesize + \ | |
679 | (mp)->m_sb.sb_sectsize * 2 + \ | |
680 | (mp)->m_dirblksize + \ | |
f6c2d1fa | 681 | XFS_FSB_TO_B(mp, (XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1)) + \ |
1da177e4 | 682 | XFS_ALLOCFREE_LOG_RES(mp, 1) + \ |
f6c2d1fa | 683 | (128 * (4 + (XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1) + \ |
1da177e4 LT |
684 | XFS_ALLOCFREE_LOG_COUNT(mp, 1)))) |
685 | ||
686 | #define XFS_ADDAFORK_LOG_RES(mp) ((mp)->m_reservations.tr_addafork) | |
687 | ||
688 | /* | |
689 | * Removing the attribute fork of a file | |
690 | * the inode being truncated: inode size | |
9da096fd | 691 | * the inode's bmap btree: max depth * block size |
1da177e4 LT |
692 | * And the bmap_finish transaction can free the blocks and bmap blocks: |
693 | * the agf for each of the ags: 4 * sector size | |
694 | * the agfl for each of the ags: 4 * sector size | |
695 | * the super block to reflect the freed blocks: sector size | |
696 | * worst case split in allocation btrees per extent assuming 4 extents: | |
697 | * 4 exts * 2 trees * (2 * max depth - 1) * block size | |
698 | */ | |
699 | #define XFS_CALC_ATTRINVAL_LOG_RES(mp) \ | |
700 | (MAX( \ | |
701 | ((mp)->m_sb.sb_inodesize + \ | |
702 | XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + \ | |
703 | (128 * (1 + XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)))), \ | |
704 | ((4 * (mp)->m_sb.sb_sectsize) + \ | |
705 | (4 * (mp)->m_sb.sb_sectsize) + \ | |
706 | (mp)->m_sb.sb_sectsize + \ | |
707 | XFS_ALLOCFREE_LOG_RES(mp, 4) + \ | |
708 | (128 * (9 + XFS_ALLOCFREE_LOG_COUNT(mp, 4)))))) | |
709 | ||
710 | #define XFS_ATTRINVAL_LOG_RES(mp) ((mp)->m_reservations.tr_attrinval) | |
711 | ||
712 | /* | |
713 | * Setting an attribute. | |
714 | * the inode getting the attribute | |
715 | * the superblock for allocations | |
716 | * the agfs extents are allocated from | |
717 | * the attribute btree * max depth | |
718 | * the inode allocation btree | |
719 | * Since attribute transaction space is dependent on the size of the attribute, | |
720 | * the calculation is done partially at mount time and partially at runtime. | |
721 | */ | |
722 | #define XFS_CALC_ATTRSET_LOG_RES(mp) \ | |
723 | ((mp)->m_sb.sb_inodesize + \ | |
724 | (mp)->m_sb.sb_sectsize + \ | |
725 | XFS_FSB_TO_B((mp), XFS_DA_NODE_MAXDEPTH) + \ | |
726 | (128 * (2 + XFS_DA_NODE_MAXDEPTH))) | |
727 | ||
728 | #define XFS_ATTRSET_LOG_RES(mp, ext) \ | |
729 | ((mp)->m_reservations.tr_attrset + \ | |
730 | (ext * (mp)->m_sb.sb_sectsize) + \ | |
731 | (ext * XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK))) + \ | |
732 | (128 * (ext + (ext * XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK))))) | |
733 | ||
734 | /* | |
735 | * Removing an attribute. | |
736 | * the inode: inode size | |
737 | * the attribute btree could join: max depth * block size | |
738 | * the inode bmap btree could join or split: max depth * block size | |
739 | * And the bmap_finish transaction can free the attr blocks freed giving: | |
740 | * the agf for the ag in which the blocks live: 2 * sector size | |
741 | * the agfl for the ag in which the blocks live: 2 * sector size | |
742 | * the superblock for the free block count: sector size | |
743 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
744 | */ | |
745 | #define XFS_CALC_ATTRRM_LOG_RES(mp) \ | |
746 | (MAX( \ | |
747 | ((mp)->m_sb.sb_inodesize + \ | |
748 | XFS_FSB_TO_B((mp), XFS_DA_NODE_MAXDEPTH) + \ | |
749 | XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + \ | |
750 | (128 * (1 + XFS_DA_NODE_MAXDEPTH + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)))), \ | |
751 | ((2 * (mp)->m_sb.sb_sectsize) + \ | |
752 | (2 * (mp)->m_sb.sb_sectsize) + \ | |
753 | (mp)->m_sb.sb_sectsize + \ | |
754 | XFS_ALLOCFREE_LOG_RES(mp, 2) + \ | |
755 | (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2)))))) | |
756 | ||
757 | #define XFS_ATTRRM_LOG_RES(mp) ((mp)->m_reservations.tr_attrrm) | |
758 | ||
759 | /* | |
760 | * Clearing a bad agino number in an agi hash bucket. | |
761 | */ | |
762 | #define XFS_CALC_CLEAR_AGI_BUCKET_LOG_RES(mp) \ | |
763 | ((mp)->m_sb.sb_sectsize + 128) | |
764 | ||
765 | #define XFS_CLEAR_AGI_BUCKET_LOG_RES(mp) ((mp)->m_reservations.tr_clearagi) | |
766 | ||
767 | ||
768 | /* | |
769 | * Various log count values. | |
770 | */ | |
771 | #define XFS_DEFAULT_LOG_COUNT 1 | |
772 | #define XFS_DEFAULT_PERM_LOG_COUNT 2 | |
773 | #define XFS_ITRUNCATE_LOG_COUNT 2 | |
774 | #define XFS_INACTIVE_LOG_COUNT 2 | |
775 | #define XFS_CREATE_LOG_COUNT 2 | |
776 | #define XFS_MKDIR_LOG_COUNT 3 | |
777 | #define XFS_SYMLINK_LOG_COUNT 3 | |
778 | #define XFS_REMOVE_LOG_COUNT 2 | |
779 | #define XFS_LINK_LOG_COUNT 2 | |
780 | #define XFS_RENAME_LOG_COUNT 2 | |
781 | #define XFS_WRITE_LOG_COUNT 2 | |
782 | #define XFS_ADDAFORK_LOG_COUNT 2 | |
783 | #define XFS_ATTRINVAL_LOG_COUNT 1 | |
784 | #define XFS_ATTRSET_LOG_COUNT 3 | |
785 | #define XFS_ATTRRM_LOG_COUNT 3 | |
786 | ||
787 | /* | |
788 | * Here we centralize the specification of XFS meta-data buffer | |
789 | * reference count values. This determine how hard the buffer | |
790 | * cache tries to hold onto the buffer. | |
791 | */ | |
792 | #define XFS_AGF_REF 4 | |
793 | #define XFS_AGI_REF 4 | |
794 | #define XFS_AGFL_REF 3 | |
795 | #define XFS_INO_BTREE_REF 3 | |
796 | #define XFS_ALLOC_BTREE_REF 2 | |
797 | #define XFS_BMAP_BTREE_REF 2 | |
798 | #define XFS_DIR_BTREE_REF 2 | |
799 | #define XFS_ATTR_BTREE_REF 1 | |
800 | #define XFS_INO_REF 1 | |
801 | #define XFS_DQUOT_REF 1 | |
802 | ||
803 | #ifdef __KERNEL__ | |
847fff5c BN |
804 | |
805 | struct xfs_buf; | |
806 | struct xfs_buftarg; | |
807 | struct xfs_efd_log_item; | |
808 | struct xfs_efi_log_item; | |
809 | struct xfs_inode; | |
810 | struct xfs_item_ops; | |
811 | struct xfs_log_iovec; | |
812 | struct xfs_log_item_desc; | |
813 | struct xfs_mount; | |
814 | struct xfs_trans; | |
815 | struct xfs_dquot_acct; | |
ed3b4d6c | 816 | struct xfs_busy_extent; |
847fff5c BN |
817 | |
818 | typedef struct xfs_log_item { | |
819 | struct list_head li_ail; /* AIL pointers */ | |
820 | xfs_lsn_t li_lsn; /* last on-disk lsn */ | |
821 | struct xfs_log_item_desc *li_desc; /* ptr to current desc*/ | |
822 | struct xfs_mount *li_mountp; /* ptr to fs mount */ | |
fc1829f3 | 823 | struct xfs_ail *li_ailp; /* ptr to AIL */ |
847fff5c BN |
824 | uint li_type; /* item type */ |
825 | uint li_flags; /* misc flags */ | |
826 | struct xfs_log_item *li_bio_list; /* buffer item list */ | |
827 | void (*li_cb)(struct xfs_buf *, | |
828 | struct xfs_log_item *); | |
829 | /* buffer item iodone */ | |
830 | /* callback func */ | |
831 | struct xfs_item_ops *li_ops; /* function list */ | |
832 | } xfs_log_item_t; | |
833 | ||
834 | #define XFS_LI_IN_AIL 0x1 | |
835 | #define XFS_LI_ABORTED 0x2 | |
836 | ||
0b1b213f CH |
837 | #define XFS_LI_FLAGS \ |
838 | { XFS_LI_IN_AIL, "IN_AIL" }, \ | |
839 | { XFS_LI_ABORTED, "ABORTED" } | |
840 | ||
847fff5c BN |
841 | typedef struct xfs_item_ops { |
842 | uint (*iop_size)(xfs_log_item_t *); | |
843 | void (*iop_format)(xfs_log_item_t *, struct xfs_log_iovec *); | |
844 | void (*iop_pin)(xfs_log_item_t *); | |
8e123850 | 845 | void (*iop_unpin)(xfs_log_item_t *); |
847fff5c BN |
846 | void (*iop_unpin_remove)(xfs_log_item_t *, struct xfs_trans *); |
847 | uint (*iop_trylock)(xfs_log_item_t *); | |
848 | void (*iop_unlock)(xfs_log_item_t *); | |
849 | xfs_lsn_t (*iop_committed)(xfs_log_item_t *, xfs_lsn_t); | |
850 | void (*iop_push)(xfs_log_item_t *); | |
851 | void (*iop_pushbuf)(xfs_log_item_t *); | |
852 | void (*iop_committing)(xfs_log_item_t *, xfs_lsn_t); | |
853 | } xfs_item_ops_t; | |
854 | ||
855 | #define IOP_SIZE(ip) (*(ip)->li_ops->iop_size)(ip) | |
856 | #define IOP_FORMAT(ip,vp) (*(ip)->li_ops->iop_format)(ip, vp) | |
857 | #define IOP_PIN(ip) (*(ip)->li_ops->iop_pin)(ip) | |
8e123850 | 858 | #define IOP_UNPIN(ip) (*(ip)->li_ops->iop_unpin)(ip) |
847fff5c BN |
859 | #define IOP_UNPIN_REMOVE(ip,tp) (*(ip)->li_ops->iop_unpin_remove)(ip, tp) |
860 | #define IOP_TRYLOCK(ip) (*(ip)->li_ops->iop_trylock)(ip) | |
861 | #define IOP_UNLOCK(ip) (*(ip)->li_ops->iop_unlock)(ip) | |
862 | #define IOP_COMMITTED(ip, lsn) (*(ip)->li_ops->iop_committed)(ip, lsn) | |
863 | #define IOP_PUSH(ip) (*(ip)->li_ops->iop_push)(ip) | |
864 | #define IOP_PUSHBUF(ip) (*(ip)->li_ops->iop_pushbuf)(ip) | |
865 | #define IOP_COMMITTING(ip, lsn) (*(ip)->li_ops->iop_committing)(ip, lsn) | |
866 | ||
867 | /* | |
868 | * Return values for the IOP_TRYLOCK() routines. | |
869 | */ | |
870 | #define XFS_ITEM_SUCCESS 0 | |
871 | #define XFS_ITEM_PINNED 1 | |
872 | #define XFS_ITEM_LOCKED 2 | |
d808f617 | 873 | #define XFS_ITEM_PUSHBUF 3 |
847fff5c | 874 | |
847fff5c BN |
875 | /* |
876 | * This is the type of function which can be given to xfs_trans_callback() | |
877 | * to be called upon the transaction's commit to disk. | |
878 | */ | |
879 | typedef void (*xfs_trans_callback_t)(struct xfs_trans *, void *); | |
880 | ||
881 | /* | |
882 | * This is the structure maintained for every active transaction. | |
883 | */ | |
884 | typedef struct xfs_trans { | |
885 | unsigned int t_magic; /* magic number */ | |
886 | xfs_log_callback_t t_logcb; /* log callback struct */ | |
887 | unsigned int t_type; /* transaction type */ | |
888 | unsigned int t_log_res; /* amt of log space resvd */ | |
889 | unsigned int t_log_count; /* count for perm log res */ | |
890 | unsigned int t_blk_res; /* # of blocks resvd */ | |
891 | unsigned int t_blk_res_used; /* # of resvd blocks used */ | |
892 | unsigned int t_rtx_res; /* # of rt extents resvd */ | |
893 | unsigned int t_rtx_res_used; /* # of resvd rt extents used */ | |
35a8a72f | 894 | struct xlog_ticket *t_ticket; /* log mgr ticket */ |
847fff5c BN |
895 | xfs_lsn_t t_lsn; /* log seq num of start of |
896 | * transaction. */ | |
897 | xfs_lsn_t t_commit_lsn; /* log seq num of end of | |
898 | * transaction. */ | |
899 | struct xfs_mount *t_mountp; /* ptr to fs mount struct */ | |
900 | struct xfs_dquot_acct *t_dqinfo; /* acctg info for dquots */ | |
901 | xfs_trans_callback_t t_callback; /* transaction callback */ | |
902 | void *t_callarg; /* callback arg */ | |
903 | unsigned int t_flags; /* misc flags */ | |
904 | int64_t t_icount_delta; /* superblock icount change */ | |
905 | int64_t t_ifree_delta; /* superblock ifree change */ | |
906 | int64_t t_fdblocks_delta; /* superblock fdblocks chg */ | |
907 | int64_t t_res_fdblocks_delta; /* on-disk only chg */ | |
908 | int64_t t_frextents_delta;/* superblock freextents chg*/ | |
909 | int64_t t_res_frextents_delta; /* on-disk only chg */ | |
910 | #ifdef DEBUG | |
911 | int64_t t_ag_freeblks_delta; /* debugging counter */ | |
912 | int64_t t_ag_flist_delta; /* debugging counter */ | |
913 | int64_t t_ag_btree_delta; /* debugging counter */ | |
914 | #endif | |
915 | int64_t t_dblocks_delta;/* superblock dblocks change */ | |
916 | int64_t t_agcount_delta;/* superblock agcount change */ | |
917 | int64_t t_imaxpct_delta;/* superblock imaxpct change */ | |
918 | int64_t t_rextsize_delta;/* superblock rextsize chg */ | |
919 | int64_t t_rbmblocks_delta;/* superblock rbmblocks chg */ | |
920 | int64_t t_rblocks_delta;/* superblock rblocks change */ | |
921 | int64_t t_rextents_delta;/* superblocks rextents chg */ | |
922 | int64_t t_rextslog_delta;/* superblocks rextslog chg */ | |
923 | unsigned int t_items_free; /* log item descs free */ | |
924 | xfs_log_item_chunk_t t_items; /* first log item desc chunk */ | |
925 | xfs_trans_header_t t_header; /* header for in-log trans */ | |
ed3b4d6c | 926 | struct list_head t_busy; /* list of busy extents */ |
847fff5c BN |
927 | unsigned long t_pflags; /* saved process flags state */ |
928 | } xfs_trans_t; | |
929 | ||
1da177e4 LT |
930 | /* |
931 | * XFS transaction mechanism exported interfaces that are | |
932 | * actually macros. | |
933 | */ | |
934 | #define xfs_trans_get_log_res(tp) ((tp)->t_log_res) | |
935 | #define xfs_trans_get_log_count(tp) ((tp)->t_log_count) | |
936 | #define xfs_trans_get_block_res(tp) ((tp)->t_blk_res) | |
937 | #define xfs_trans_set_sync(tp) ((tp)->t_flags |= XFS_TRANS_SYNC) | |
938 | ||
939 | #ifdef DEBUG | |
20f4ebf2 DC |
940 | #define xfs_trans_agblocks_delta(tp, d) ((tp)->t_ag_freeblks_delta += (int64_t)d) |
941 | #define xfs_trans_agflist_delta(tp, d) ((tp)->t_ag_flist_delta += (int64_t)d) | |
942 | #define xfs_trans_agbtree_delta(tp, d) ((tp)->t_ag_btree_delta += (int64_t)d) | |
1da177e4 LT |
943 | #else |
944 | #define xfs_trans_agblocks_delta(tp, d) | |
945 | #define xfs_trans_agflist_delta(tp, d) | |
946 | #define xfs_trans_agbtree_delta(tp, d) | |
947 | #endif | |
948 | ||
949 | /* | |
950 | * XFS transaction mechanism exported interfaces. | |
951 | */ | |
1da177e4 | 952 | xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint); |
80641dc6 | 953 | xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, uint); |
1da177e4 LT |
954 | xfs_trans_t *xfs_trans_dup(xfs_trans_t *); |
955 | int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint, | |
956 | uint, uint); | |
20f4ebf2 | 957 | void xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t); |
1da177e4 LT |
958 | struct xfs_buf *xfs_trans_get_buf(xfs_trans_t *, struct xfs_buftarg *, xfs_daddr_t, |
959 | int, uint); | |
960 | int xfs_trans_read_buf(struct xfs_mount *, xfs_trans_t *, | |
961 | struct xfs_buftarg *, xfs_daddr_t, int, uint, | |
962 | struct xfs_buf **); | |
963 | struct xfs_buf *xfs_trans_getsb(xfs_trans_t *, struct xfs_mount *, int); | |
964 | ||
965 | void xfs_trans_brelse(xfs_trans_t *, struct xfs_buf *); | |
966 | void xfs_trans_bjoin(xfs_trans_t *, struct xfs_buf *); | |
967 | void xfs_trans_bhold(xfs_trans_t *, struct xfs_buf *); | |
efa092f3 | 968 | void xfs_trans_bhold_release(xfs_trans_t *, struct xfs_buf *); |
1da177e4 LT |
969 | void xfs_trans_binval(xfs_trans_t *, struct xfs_buf *); |
970 | void xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *); | |
1da177e4 LT |
971 | void xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *); |
972 | void xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint); | |
973 | void xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *); | |
974 | int xfs_trans_iget(struct xfs_mount *, xfs_trans_t *, | |
975 | xfs_ino_t , uint, uint, struct xfs_inode **); | |
976 | void xfs_trans_ijoin(xfs_trans_t *, struct xfs_inode *, uint); | |
977 | void xfs_trans_ihold(xfs_trans_t *, struct xfs_inode *); | |
1da177e4 LT |
978 | void xfs_trans_log_buf(xfs_trans_t *, struct xfs_buf *, uint, uint); |
979 | void xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint); | |
980 | struct xfs_efi_log_item *xfs_trans_get_efi(xfs_trans_t *, uint); | |
981 | void xfs_efi_release(struct xfs_efi_log_item *, uint); | |
982 | void xfs_trans_log_efi_extent(xfs_trans_t *, | |
983 | struct xfs_efi_log_item *, | |
984 | xfs_fsblock_t, | |
985 | xfs_extlen_t); | |
986 | struct xfs_efd_log_item *xfs_trans_get_efd(xfs_trans_t *, | |
987 | struct xfs_efi_log_item *, | |
988 | uint); | |
989 | void xfs_trans_log_efd_extent(xfs_trans_t *, | |
990 | struct xfs_efd_log_item *, | |
991 | xfs_fsblock_t, | |
992 | xfs_extlen_t); | |
f538d4da CH |
993 | int _xfs_trans_commit(xfs_trans_t *, |
994 | uint flags, | |
f538d4da | 995 | int *); |
1c72bf90 | 996 | #define xfs_trans_commit(tp, flags) _xfs_trans_commit(tp, flags, NULL) |
1da177e4 | 997 | void xfs_trans_cancel(xfs_trans_t *, int); |
249a8c11 DC |
998 | int xfs_trans_ail_init(struct xfs_mount *); |
999 | void xfs_trans_ail_destroy(struct xfs_mount *); | |
1da177e4 | 1000 | |
a8272ce0 DC |
1001 | extern kmem_zone_t *xfs_trans_zone; |
1002 | ||
1da177e4 LT |
1003 | #endif /* __KERNEL__ */ |
1004 | ||
847fff5c BN |
1005 | void xfs_trans_init(struct xfs_mount *); |
1006 | int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *); | |
1007 | ||
1da177e4 | 1008 | #endif /* __XFS_TRANS_H__ */ |