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