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