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