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