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