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