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