aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_trans.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_trans.h')
-rw-r--r--fs/xfs/xfs_trans.h582
1 files changed, 30 insertions, 552 deletions
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
index 79c8bab9dfff..c13c0f97b494 100644
--- a/fs/xfs/xfs_trans.h
+++ b/fs/xfs/xfs_trans.h
@@ -49,6 +49,15 @@ typedef struct xfs_trans_header {
49#define XFS_LI_DQUOT 0x123d 49#define XFS_LI_DQUOT 0x123d
50#define XFS_LI_QUOTAOFF 0x123e 50#define XFS_LI_QUOTAOFF 0x123e
51 51
52#define XFS_LI_TYPE_DESC \
53 { XFS_LI_EFI, "XFS_LI_EFI" }, \
54 { XFS_LI_EFD, "XFS_LI_EFD" }, \
55 { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \
56 { XFS_LI_INODE, "XFS_LI_INODE" }, \
57 { XFS_LI_BUF, "XFS_LI_BUF" }, \
58 { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \
59 { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" }
60
52/* 61/*
53 * Transaction types. Used to distinguish types of buffers. 62 * Transaction types. Used to distinguish types of buffers.
54 */ 63 */
@@ -97,7 +106,8 @@ typedef struct xfs_trans_header {
97#define XFS_TRANS_GROWFSRT_FREE 39 106#define XFS_TRANS_GROWFSRT_FREE 39
98#define XFS_TRANS_SWAPEXT 40 107#define XFS_TRANS_SWAPEXT 40
99#define XFS_TRANS_SB_COUNT 41 108#define XFS_TRANS_SB_COUNT 41
100#define XFS_TRANS_TYPE_MAX 41 109#define XFS_TRANS_CHECKPOINT 42
110#define XFS_TRANS_TYPE_MAX 42
101/* new transaction types need to be reflected in xfs_logprint(8) */ 111/* new transaction types need to be reflected in xfs_logprint(8) */
102 112
103#define XFS_TRANS_TYPES \ 113#define XFS_TRANS_TYPES \
@@ -139,6 +149,7 @@ typedef struct xfs_trans_header {
139 { XFS_TRANS_GROWFSRT_FREE, "GROWFSRT_FREE" }, \ 149 { XFS_TRANS_GROWFSRT_FREE, "GROWFSRT_FREE" }, \
140 { XFS_TRANS_SWAPEXT, "SWAPEXT" }, \ 150 { XFS_TRANS_SWAPEXT, "SWAPEXT" }, \
141 { XFS_TRANS_SB_COUNT, "SB_COUNT" }, \ 151 { XFS_TRANS_SB_COUNT, "SB_COUNT" }, \
152 { XFS_TRANS_CHECKPOINT, "CHECKPOINT" }, \
142 { XFS_TRANS_DUMMY1, "DUMMY1" }, \ 153 { XFS_TRANS_DUMMY1, "DUMMY1" }, \
143 { XFS_TRANS_DUMMY2, "DUMMY2" }, \ 154 { XFS_TRANS_DUMMY2, "DUMMY2" }, \
144 { XLOG_UNMOUNT_REC_TYPE, "UNMOUNT" } 155 { XLOG_UNMOUNT_REC_TYPE, "UNMOUNT" }
@@ -150,106 +161,14 @@ typedef struct xfs_trans_header {
150 * the amount of space needed to log the item it describes 161 * the amount of space needed to log the item it describes
151 * once we get to commit processing (see xfs_trans_commit()). 162 * once we get to commit processing (see xfs_trans_commit()).
152 */ 163 */
153typedef struct xfs_log_item_desc { 164struct xfs_log_item_desc {
154 struct xfs_log_item *lid_item; 165 struct xfs_log_item *lid_item;
155 ushort lid_size; 166 ushort lid_size;
156 unsigned char lid_flags; 167 unsigned char lid_flags;
157 unsigned char lid_index; 168 struct list_head lid_trans;
158} xfs_log_item_desc_t; 169};
159 170
160#define XFS_LID_DIRTY 0x1 171#define XFS_LID_DIRTY 0x1
161#define XFS_LID_PINNED 0x2
162#define XFS_LID_BUF_STALE 0x8
163
164/*
165 * This structure is used to maintain a chunk list of log_item_desc
166 * structures. The free field is a bitmask indicating which descriptors
167 * in this chunk's array are free. The unused field is the first value
168 * not used since this chunk was allocated.
169 */
170#define XFS_LIC_NUM_SLOTS 15
171typedef struct xfs_log_item_chunk {
172 struct xfs_log_item_chunk *lic_next;
173 ushort lic_free;
174 ushort lic_unused;
175 xfs_log_item_desc_t lic_descs[XFS_LIC_NUM_SLOTS];
176} xfs_log_item_chunk_t;
177
178#define XFS_LIC_MAX_SLOT (XFS_LIC_NUM_SLOTS - 1)
179#define XFS_LIC_FREEMASK ((1 << XFS_LIC_NUM_SLOTS) - 1)
180
181
182/*
183 * Initialize the given chunk. Set the chunk's free descriptor mask
184 * to indicate that all descriptors are free. The caller gets to set
185 * lic_unused to the right value (0 matches all free). The
186 * lic_descs.lid_index values are set up as each desc is allocated.
187 */
188static inline void xfs_lic_init(xfs_log_item_chunk_t *cp)
189{
190 cp->lic_free = XFS_LIC_FREEMASK;
191}
192
193static inline void xfs_lic_init_slot(xfs_log_item_chunk_t *cp, int slot)
194{
195 cp->lic_descs[slot].lid_index = (unsigned char)(slot);
196}
197
198static inline int xfs_lic_vacancy(xfs_log_item_chunk_t *cp)
199{
200 return cp->lic_free & XFS_LIC_FREEMASK;
201}
202
203static inline void xfs_lic_all_free(xfs_log_item_chunk_t *cp)
204{
205 cp->lic_free = XFS_LIC_FREEMASK;
206}
207
208static inline int xfs_lic_are_all_free(xfs_log_item_chunk_t *cp)
209{
210 return ((cp->lic_free & XFS_LIC_FREEMASK) == XFS_LIC_FREEMASK);
211}
212
213static inline int xfs_lic_isfree(xfs_log_item_chunk_t *cp, int slot)
214{
215 return (cp->lic_free & (1 << slot));
216}
217
218static inline void xfs_lic_claim(xfs_log_item_chunk_t *cp, int slot)
219{
220 cp->lic_free &= ~(1 << slot);
221}
222
223static inline void xfs_lic_relse(xfs_log_item_chunk_t *cp, int slot)
224{
225 cp->lic_free |= 1 << slot;
226}
227
228static inline xfs_log_item_desc_t *
229xfs_lic_slot(xfs_log_item_chunk_t *cp, int slot)
230{
231 return &(cp->lic_descs[slot]);
232}
233
234static inline int xfs_lic_desc_to_slot(xfs_log_item_desc_t *dp)
235{
236 return (uint)dp->lid_index;
237}
238
239/*
240 * Calculate the address of a chunk given a descriptor pointer:
241 * dp - dp->lid_index give the address of the start of the lic_descs array.
242 * From this we subtract the offset of the lic_descs field in a chunk.
243 * All of this yields the address of the chunk, which is
244 * cast to a chunk pointer.
245 */
246static inline xfs_log_item_chunk_t *
247xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp)
248{
249 return (xfs_log_item_chunk_t*) \
250 (((xfs_caddr_t)((dp) - (dp)->lid_index)) - \
251 (xfs_caddr_t)(((xfs_log_item_chunk_t*)0)->lic_descs));
252}
253 172
254#define XFS_TRANS_MAGIC 0x5452414E /* 'TRAN' */ 173#define XFS_TRANS_MAGIC 0x5452414E /* 'TRAN' */
255/* 174/*
@@ -265,8 +184,6 @@ xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp)
265/* 184/*
266 * Values for call flags parameter. 185 * Values for call flags parameter.
267 */ 186 */
268#define XFS_TRANS_NOSLEEP 0x1
269#define XFS_TRANS_WAIT 0x2
270#define XFS_TRANS_RELEASE_LOG_RES 0x4 187#define XFS_TRANS_RELEASE_LOG_RES 0x4
271#define XFS_TRANS_ABORT 0x8 188#define XFS_TRANS_ABORT 0x8
272 189
@@ -290,24 +207,6 @@ xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp)
290 207
291 208
292/* 209/*
293 * Various log reservation values.
294 * These are based on the size of the file system block
295 * because that is what most transactions manipulate.
296 * Each adds in an additional 128 bytes per item logged to
297 * try to account for the overhead of the transaction mechanism.
298 *
299 * Note:
300 * Most of the reservations underestimate the number of allocation
301 * groups into which they could free extents in the xfs_bmap_finish()
302 * call. This is because the number in the worst case is quite high
303 * and quite unusual. In order to fix this we need to change
304 * xfs_bmap_finish() to free extents in only a single AG at a time.
305 * This will require changes to the EFI code as well, however, so that
306 * the EFI for the extents not freed is logged again in each transaction.
307 * See bug 261917.
308 */
309
310/*
311 * Per-extent log reservation for the allocation btree changes 210 * Per-extent log reservation for the allocation btree changes
312 * involved in freeing or allocating an extent. 211 * involved in freeing or allocating an extent.
313 * 2 trees * (2 blocks/level * max depth - 1) * block size 212 * 2 trees * (2 blocks/level * max depth - 1) * block size
@@ -331,429 +230,36 @@ xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp)
331 (XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK) + \ 230 (XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK) + \
332 XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1) 231 XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1)
333 232
334/*
335 * In a write transaction we can allocate a maximum of 2
336 * extents. This gives:
337 * the inode getting the new extents: inode size
338 * the inode's bmap btree: max depth * block size
339 * the agfs of the ags from which the extents are allocated: 2 * sector
340 * the superblock free block counter: sector size
341 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
342 * And the bmap_finish transaction can free bmap blocks in a join:
343 * the agfs of the ags containing the blocks: 2 * sector size
344 * the agfls of the ags containing the blocks: 2 * sector size
345 * the super block free block counter: sector size
346 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
347 */
348#define XFS_CALC_WRITE_LOG_RES(mp) \
349 (MAX( \
350 ((mp)->m_sb.sb_inodesize + \
351 XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)) + \
352 (2 * (mp)->m_sb.sb_sectsize) + \
353 (mp)->m_sb.sb_sectsize + \
354 XFS_ALLOCFREE_LOG_RES(mp, 2) + \
355 (128 * (4 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + XFS_ALLOCFREE_LOG_COUNT(mp, 2)))),\
356 ((2 * (mp)->m_sb.sb_sectsize) + \
357 (2 * (mp)->m_sb.sb_sectsize) + \
358 (mp)->m_sb.sb_sectsize + \
359 XFS_ALLOCFREE_LOG_RES(mp, 2) + \
360 (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2))))))
361 233
362#define XFS_WRITE_LOG_RES(mp) ((mp)->m_reservations.tr_write) 234#define XFS_WRITE_LOG_RES(mp) ((mp)->m_reservations.tr_write)
363
364/*
365 * In truncating a file we free up to two extents at once. We can modify:
366 * the inode being truncated: inode size
367 * the inode's bmap btree: (max depth + 1) * block size
368 * And the bmap_finish transaction can free the blocks and bmap blocks:
369 * the agf for each of the ags: 4 * sector size
370 * the agfl for each of the ags: 4 * sector size
371 * the super block to reflect the freed blocks: sector size
372 * worst case split in allocation btrees per extent assuming 4 extents:
373 * 4 exts * 2 trees * (2 * max depth - 1) * block size
374 * the inode btree: max depth * blocksize
375 * the allocation btrees: 2 trees * (max depth - 1) * block size
376 */
377#define XFS_CALC_ITRUNCATE_LOG_RES(mp) \
378 (MAX( \
379 ((mp)->m_sb.sb_inodesize + \
380 XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1) + \
381 (128 * (2 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)))), \
382 ((4 * (mp)->m_sb.sb_sectsize) + \
383 (4 * (mp)->m_sb.sb_sectsize) + \
384 (mp)->m_sb.sb_sectsize + \
385 XFS_ALLOCFREE_LOG_RES(mp, 4) + \
386 (128 * (9 + XFS_ALLOCFREE_LOG_COUNT(mp, 4))) + \
387 (128 * 5) + \
388 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
389 (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
390 XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
391
392#define XFS_ITRUNCATE_LOG_RES(mp) ((mp)->m_reservations.tr_itruncate) 235#define XFS_ITRUNCATE_LOG_RES(mp) ((mp)->m_reservations.tr_itruncate)
393
394/*
395 * In renaming a files we can modify:
396 * the four inodes involved: 4 * inode size
397 * the two directory btrees: 2 * (max depth + v2) * dir block size
398 * the two directory bmap btrees: 2 * max depth * block size
399 * And the bmap_finish transaction can free dir and bmap blocks (two sets
400 * of bmap blocks) giving:
401 * the agf for the ags in which the blocks live: 3 * sector size
402 * the agfl for the ags in which the blocks live: 3 * sector size
403 * the superblock for the free block count: sector size
404 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
405 */
406#define XFS_CALC_RENAME_LOG_RES(mp) \
407 (MAX( \
408 ((4 * (mp)->m_sb.sb_inodesize) + \
409 (2 * XFS_DIROP_LOG_RES(mp)) + \
410 (128 * (4 + 2 * XFS_DIROP_LOG_COUNT(mp)))), \
411 ((3 * (mp)->m_sb.sb_sectsize) + \
412 (3 * (mp)->m_sb.sb_sectsize) + \
413 (mp)->m_sb.sb_sectsize + \
414 XFS_ALLOCFREE_LOG_RES(mp, 3) + \
415 (128 * (7 + XFS_ALLOCFREE_LOG_COUNT(mp, 3))))))
416
417#define XFS_RENAME_LOG_RES(mp) ((mp)->m_reservations.tr_rename) 236#define XFS_RENAME_LOG_RES(mp) ((mp)->m_reservations.tr_rename)
418
419/*
420 * For creating a link to an inode:
421 * the parent directory inode: inode size
422 * the linked inode: inode size
423 * the directory btree could split: (max depth + v2) * dir block size
424 * the directory bmap btree could join or split: (max depth + v2) * blocksize
425 * And the bmap_finish transaction can free some bmap blocks giving:
426 * the agf for the ag in which the blocks live: sector size
427 * the agfl for the ag in which the blocks live: sector size
428 * the superblock for the free block count: sector size
429 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
430 */
431#define XFS_CALC_LINK_LOG_RES(mp) \
432 (MAX( \
433 ((mp)->m_sb.sb_inodesize + \
434 (mp)->m_sb.sb_inodesize + \
435 XFS_DIROP_LOG_RES(mp) + \
436 (128 * (2 + XFS_DIROP_LOG_COUNT(mp)))), \
437 ((mp)->m_sb.sb_sectsize + \
438 (mp)->m_sb.sb_sectsize + \
439 (mp)->m_sb.sb_sectsize + \
440 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
441 (128 * (3 + XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
442
443#define XFS_LINK_LOG_RES(mp) ((mp)->m_reservations.tr_link) 237#define XFS_LINK_LOG_RES(mp) ((mp)->m_reservations.tr_link)
444
445/*
446 * For removing a directory entry we can modify:
447 * the parent directory inode: inode size
448 * the removed inode: inode size
449 * the directory btree could join: (max depth + v2) * dir block size
450 * the directory bmap btree could join or split: (max depth + v2) * blocksize
451 * And the bmap_finish transaction can free the dir and bmap blocks giving:
452 * the agf for the ag in which the blocks live: 2 * sector size
453 * the agfl for the ag in which the blocks live: 2 * sector size
454 * the superblock for the free block count: sector size
455 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
456 */
457#define XFS_CALC_REMOVE_LOG_RES(mp) \
458 (MAX( \
459 ((mp)->m_sb.sb_inodesize + \
460 (mp)->m_sb.sb_inodesize + \
461 XFS_DIROP_LOG_RES(mp) + \
462 (128 * (2 + XFS_DIROP_LOG_COUNT(mp)))), \
463 ((2 * (mp)->m_sb.sb_sectsize) + \
464 (2 * (mp)->m_sb.sb_sectsize) + \
465 (mp)->m_sb.sb_sectsize + \
466 XFS_ALLOCFREE_LOG_RES(mp, 2) + \
467 (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2))))))
468
469#define XFS_REMOVE_LOG_RES(mp) ((mp)->m_reservations.tr_remove) 238#define XFS_REMOVE_LOG_RES(mp) ((mp)->m_reservations.tr_remove)
470
471/*
472 * For symlink we can modify:
473 * the parent directory inode: inode size
474 * the new inode: inode size
475 * the inode btree entry: 1 block
476 * the directory btree: (max depth + v2) * dir block size
477 * the directory inode's bmap btree: (max depth + v2) * block size
478 * the blocks for the symlink: 1 kB
479 * Or in the first xact we allocate some inodes giving:
480 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
481 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
482 * the inode btree: max depth * blocksize
483 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
484 */
485#define XFS_CALC_SYMLINK_LOG_RES(mp) \
486 (MAX( \
487 ((mp)->m_sb.sb_inodesize + \
488 (mp)->m_sb.sb_inodesize + \
489 XFS_FSB_TO_B(mp, 1) + \
490 XFS_DIROP_LOG_RES(mp) + \
491 1024 + \
492 (128 * (4 + XFS_DIROP_LOG_COUNT(mp)))), \
493 (2 * (mp)->m_sb.sb_sectsize + \
494 XFS_FSB_TO_B((mp), XFS_IALLOC_BLOCKS((mp))) + \
495 XFS_FSB_TO_B((mp), (mp)->m_in_maxlevels) + \
496 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
497 (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
498 XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
499
500#define XFS_SYMLINK_LOG_RES(mp) ((mp)->m_reservations.tr_symlink) 239#define XFS_SYMLINK_LOG_RES(mp) ((mp)->m_reservations.tr_symlink)
501
502/*
503 * For create we can modify:
504 * the parent directory inode: inode size
505 * the new inode: inode size
506 * the inode btree entry: block size
507 * the superblock for the nlink flag: sector size
508 * the directory btree: (max depth + v2) * dir block size
509 * the directory inode's bmap btree: (max depth + v2) * block size
510 * Or in the first xact we allocate some inodes giving:
511 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
512 * the superblock for the nlink flag: sector size
513 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
514 * the inode btree: max depth * blocksize
515 * the allocation btrees: 2 trees * (max depth - 1) * block size
516 */
517#define XFS_CALC_CREATE_LOG_RES(mp) \
518 (MAX( \
519 ((mp)->m_sb.sb_inodesize + \
520 (mp)->m_sb.sb_inodesize + \
521 (mp)->m_sb.sb_sectsize + \
522 XFS_FSB_TO_B(mp, 1) + \
523 XFS_DIROP_LOG_RES(mp) + \
524 (128 * (3 + XFS_DIROP_LOG_COUNT(mp)))), \
525 (3 * (mp)->m_sb.sb_sectsize + \
526 XFS_FSB_TO_B((mp), XFS_IALLOC_BLOCKS((mp))) + \
527 XFS_FSB_TO_B((mp), (mp)->m_in_maxlevels) + \
528 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
529 (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
530 XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
531
532#define XFS_CREATE_LOG_RES(mp) ((mp)->m_reservations.tr_create) 240#define XFS_CREATE_LOG_RES(mp) ((mp)->m_reservations.tr_create)
533
534/*
535 * Making a new directory is the same as creating a new file.
536 */
537#define XFS_CALC_MKDIR_LOG_RES(mp) XFS_CALC_CREATE_LOG_RES(mp)
538
539#define XFS_MKDIR_LOG_RES(mp) ((mp)->m_reservations.tr_mkdir) 241#define XFS_MKDIR_LOG_RES(mp) ((mp)->m_reservations.tr_mkdir)
540
541/*
542 * In freeing an inode we can modify:
543 * the inode being freed: inode size
544 * the super block free inode counter: sector size
545 * the agi hash list and counters: sector size
546 * the inode btree entry: block size
547 * the on disk inode before ours in the agi hash list: inode cluster size
548 * the inode btree: max depth * blocksize
549 * the allocation btrees: 2 trees * (max depth - 1) * block size
550 */
551#define XFS_CALC_IFREE_LOG_RES(mp) \
552 ((mp)->m_sb.sb_inodesize + \
553 (mp)->m_sb.sb_sectsize + \
554 (mp)->m_sb.sb_sectsize + \
555 XFS_FSB_TO_B((mp), 1) + \
556 MAX((__uint16_t)XFS_FSB_TO_B((mp), 1), XFS_INODE_CLUSTER_SIZE(mp)) + \
557 (128 * 5) + \
558 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
559 (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
560 XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
561
562
563#define XFS_IFREE_LOG_RES(mp) ((mp)->m_reservations.tr_ifree) 242#define XFS_IFREE_LOG_RES(mp) ((mp)->m_reservations.tr_ifree)
564
565/*
566 * When only changing the inode we log the inode and possibly the superblock
567 * We also add a bit of slop for the transaction stuff.
568 */
569#define XFS_CALC_ICHANGE_LOG_RES(mp) ((mp)->m_sb.sb_inodesize + \
570 (mp)->m_sb.sb_sectsize + 512)
571
572#define XFS_ICHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_ichange) 243#define XFS_ICHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_ichange)
573
574/*
575 * Growing the data section of the filesystem.
576 * superblock
577 * agi and agf
578 * allocation btrees
579 */
580#define XFS_CALC_GROWDATA_LOG_RES(mp) \
581 ((mp)->m_sb.sb_sectsize * 3 + \
582 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
583 (128 * (3 + XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
584
585#define XFS_GROWDATA_LOG_RES(mp) ((mp)->m_reservations.tr_growdata) 244#define XFS_GROWDATA_LOG_RES(mp) ((mp)->m_reservations.tr_growdata)
586
587/*
588 * Growing the rt section of the filesystem.
589 * In the first set of transactions (ALLOC) we allocate space to the
590 * bitmap or summary files.
591 * superblock: sector size
592 * agf of the ag from which the extent is allocated: sector size
593 * bmap btree for bitmap/summary inode: max depth * blocksize
594 * bitmap/summary inode: inode size
595 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
596 */
597#define XFS_CALC_GROWRTALLOC_LOG_RES(mp) \
598 (2 * (mp)->m_sb.sb_sectsize + \
599 XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)) + \
600 (mp)->m_sb.sb_inodesize + \
601 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
602 (128 * \
603 (3 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + \
604 XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
605
606#define XFS_GROWRTALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_growrtalloc) 245#define XFS_GROWRTALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_growrtalloc)
607
608/*
609 * Growing the rt section of the filesystem.
610 * In the second set of transactions (ZERO) we zero the new metadata blocks.
611 * one bitmap/summary block: blocksize
612 */
613#define XFS_CALC_GROWRTZERO_LOG_RES(mp) \
614 ((mp)->m_sb.sb_blocksize + 128)
615
616#define XFS_GROWRTZERO_LOG_RES(mp) ((mp)->m_reservations.tr_growrtzero) 246#define XFS_GROWRTZERO_LOG_RES(mp) ((mp)->m_reservations.tr_growrtzero)
617
618/*
619 * Growing the rt section of the filesystem.
620 * In the third set of transactions (FREE) we update metadata without
621 * allocating any new blocks.
622 * superblock: sector size
623 * bitmap inode: inode size
624 * summary inode: inode size
625 * one bitmap block: blocksize
626 * summary blocks: new summary size
627 */
628#define XFS_CALC_GROWRTFREE_LOG_RES(mp) \
629 ((mp)->m_sb.sb_sectsize + \
630 2 * (mp)->m_sb.sb_inodesize + \
631 (mp)->m_sb.sb_blocksize + \
632 (mp)->m_rsumsize + \
633 (128 * 5))
634
635#define XFS_GROWRTFREE_LOG_RES(mp) ((mp)->m_reservations.tr_growrtfree) 247#define XFS_GROWRTFREE_LOG_RES(mp) ((mp)->m_reservations.tr_growrtfree)
636
637/*
638 * Logging the inode modification timestamp on a synchronous write.
639 * inode
640 */
641#define XFS_CALC_SWRITE_LOG_RES(mp) \
642 ((mp)->m_sb.sb_inodesize + 128)
643
644#define XFS_SWRITE_LOG_RES(mp) ((mp)->m_reservations.tr_swrite) 248#define XFS_SWRITE_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
645
646/* 249/*
647 * Logging the inode timestamps on an fsync -- same as SWRITE 250 * Logging the inode timestamps on an fsync -- same as SWRITE
648 * as long as SWRITE logs the entire inode core 251 * as long as SWRITE logs the entire inode core
649 */ 252 */
650#define XFS_FSYNC_TS_LOG_RES(mp) ((mp)->m_reservations.tr_swrite) 253#define XFS_FSYNC_TS_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
651
652/*
653 * Logging the inode mode bits when writing a setuid/setgid file
654 * inode
655 */
656#define XFS_CALC_WRITEID_LOG_RES(mp) \
657 ((mp)->m_sb.sb_inodesize + 128)
658
659#define XFS_WRITEID_LOG_RES(mp) ((mp)->m_reservations.tr_swrite) 254#define XFS_WRITEID_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
660
661/*
662 * Converting the inode from non-attributed to attributed.
663 * the inode being converted: inode size
664 * agf block and superblock (for block allocation)
665 * the new block (directory sized)
666 * bmap blocks for the new directory block
667 * allocation btrees
668 */
669#define XFS_CALC_ADDAFORK_LOG_RES(mp) \
670 ((mp)->m_sb.sb_inodesize + \
671 (mp)->m_sb.sb_sectsize * 2 + \
672 (mp)->m_dirblksize + \
673 XFS_FSB_TO_B(mp, (XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1)) + \
674 XFS_ALLOCFREE_LOG_RES(mp, 1) + \
675 (128 * (4 + (XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1) + \
676 XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
677
678#define XFS_ADDAFORK_LOG_RES(mp) ((mp)->m_reservations.tr_addafork) 255#define XFS_ADDAFORK_LOG_RES(mp) ((mp)->m_reservations.tr_addafork)
679
680/*
681 * Removing the attribute fork of a file
682 * the inode being truncated: inode size
683 * the inode's bmap btree: max depth * block size
684 * And the bmap_finish transaction can free the blocks and bmap blocks:
685 * the agf for each of the ags: 4 * sector size
686 * the agfl for each of the ags: 4 * sector size
687 * the super block to reflect the freed blocks: sector size
688 * worst case split in allocation btrees per extent assuming 4 extents:
689 * 4 exts * 2 trees * (2 * max depth - 1) * block size
690 */
691#define XFS_CALC_ATTRINVAL_LOG_RES(mp) \
692 (MAX( \
693 ((mp)->m_sb.sb_inodesize + \
694 XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + \
695 (128 * (1 + XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)))), \
696 ((4 * (mp)->m_sb.sb_sectsize) + \
697 (4 * (mp)->m_sb.sb_sectsize) + \
698 (mp)->m_sb.sb_sectsize + \
699 XFS_ALLOCFREE_LOG_RES(mp, 4) + \
700 (128 * (9 + XFS_ALLOCFREE_LOG_COUNT(mp, 4))))))
701
702#define XFS_ATTRINVAL_LOG_RES(mp) ((mp)->m_reservations.tr_attrinval) 256#define XFS_ATTRINVAL_LOG_RES(mp) ((mp)->m_reservations.tr_attrinval)
703
704/*
705 * Setting an attribute.
706 * the inode getting the attribute
707 * the superblock for allocations
708 * the agfs extents are allocated from
709 * the attribute btree * max depth
710 * the inode allocation btree
711 * Since attribute transaction space is dependent on the size of the attribute,
712 * the calculation is done partially at mount time and partially at runtime.
713 */
714#define XFS_CALC_ATTRSET_LOG_RES(mp) \
715 ((mp)->m_sb.sb_inodesize + \
716 (mp)->m_sb.sb_sectsize + \
717 XFS_FSB_TO_B((mp), XFS_DA_NODE_MAXDEPTH) + \
718 (128 * (2 + XFS_DA_NODE_MAXDEPTH)))
719
720#define XFS_ATTRSET_LOG_RES(mp, ext) \ 257#define XFS_ATTRSET_LOG_RES(mp, ext) \
721 ((mp)->m_reservations.tr_attrset + \ 258 ((mp)->m_reservations.tr_attrset + \
722 (ext * (mp)->m_sb.sb_sectsize) + \ 259 (ext * (mp)->m_sb.sb_sectsize) + \
723 (ext * XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK))) + \ 260 (ext * XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK))) + \
724 (128 * (ext + (ext * XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK))))) 261 (128 * (ext + (ext * XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)))))
725
726/*
727 * Removing an attribute.
728 * the inode: inode size
729 * the attribute btree could join: max depth * block size
730 * the inode bmap btree could join or split: max depth * block size
731 * And the bmap_finish transaction can free the attr blocks freed giving:
732 * the agf for the ag in which the blocks live: 2 * sector size
733 * the agfl for the ag in which the blocks live: 2 * sector size
734 * the superblock for the free block count: sector size
735 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
736 */
737#define XFS_CALC_ATTRRM_LOG_RES(mp) \
738 (MAX( \
739 ((mp)->m_sb.sb_inodesize + \
740 XFS_FSB_TO_B((mp), XFS_DA_NODE_MAXDEPTH) + \
741 XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + \
742 (128 * (1 + XFS_DA_NODE_MAXDEPTH + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)))), \
743 ((2 * (mp)->m_sb.sb_sectsize) + \
744 (2 * (mp)->m_sb.sb_sectsize) + \
745 (mp)->m_sb.sb_sectsize + \
746 XFS_ALLOCFREE_LOG_RES(mp, 2) + \
747 (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2))))))
748
749#define XFS_ATTRRM_LOG_RES(mp) ((mp)->m_reservations.tr_attrrm) 262#define XFS_ATTRRM_LOG_RES(mp) ((mp)->m_reservations.tr_attrrm)
750
751/*
752 * Clearing a bad agino number in an agi hash bucket.
753 */
754#define XFS_CALC_CLEAR_AGI_BUCKET_LOG_RES(mp) \
755 ((mp)->m_sb.sb_sectsize + 128)
756
757#define XFS_CLEAR_AGI_BUCKET_LOG_RES(mp) ((mp)->m_reservations.tr_clearagi) 263#define XFS_CLEAR_AGI_BUCKET_LOG_RES(mp) ((mp)->m_reservations.tr_clearagi)
758 264
759 265
@@ -805,6 +311,7 @@ struct xfs_log_item_desc;
805struct xfs_mount; 311struct xfs_mount;
806struct xfs_trans; 312struct xfs_trans;
807struct xfs_dquot_acct; 313struct xfs_dquot_acct;
314struct xfs_busy_extent;
808 315
809typedef struct xfs_log_item { 316typedef struct xfs_log_item {
810 struct list_head li_ail; /* AIL pointers */ 317 struct list_head li_ail; /* AIL pointers */
@@ -820,6 +327,11 @@ typedef struct xfs_log_item {
820 /* buffer item iodone */ 327 /* buffer item iodone */
821 /* callback func */ 328 /* callback func */
822 struct xfs_item_ops *li_ops; /* function list */ 329 struct xfs_item_ops *li_ops; /* function list */
330
331 /* delayed logging */
332 struct list_head li_cil; /* CIL pointers */
333 struct xfs_log_vec *li_lv; /* active log vector */
334 xfs_lsn_t li_seq; /* CIL commit seq */
823} xfs_log_item_t; 335} xfs_log_item_t;
824 336
825#define XFS_LI_IN_AIL 0x1 337#define XFS_LI_IN_AIL 0x1
@@ -833,8 +345,7 @@ typedef struct xfs_item_ops {
833 uint (*iop_size)(xfs_log_item_t *); 345 uint (*iop_size)(xfs_log_item_t *);
834 void (*iop_format)(xfs_log_item_t *, struct xfs_log_iovec *); 346 void (*iop_format)(xfs_log_item_t *, struct xfs_log_iovec *);
835 void (*iop_pin)(xfs_log_item_t *); 347 void (*iop_pin)(xfs_log_item_t *);
836 void (*iop_unpin)(xfs_log_item_t *, int); 348 void (*iop_unpin)(xfs_log_item_t *, int remove);
837 void (*iop_unpin_remove)(xfs_log_item_t *, struct xfs_trans *);
838 uint (*iop_trylock)(xfs_log_item_t *); 349 uint (*iop_trylock)(xfs_log_item_t *);
839 void (*iop_unlock)(xfs_log_item_t *); 350 void (*iop_unlock)(xfs_log_item_t *);
840 xfs_lsn_t (*iop_committed)(xfs_log_item_t *, xfs_lsn_t); 351 xfs_lsn_t (*iop_committed)(xfs_log_item_t *, xfs_lsn_t);
@@ -846,8 +357,7 @@ typedef struct xfs_item_ops {
846#define IOP_SIZE(ip) (*(ip)->li_ops->iop_size)(ip) 357#define IOP_SIZE(ip) (*(ip)->li_ops->iop_size)(ip)
847#define IOP_FORMAT(ip,vp) (*(ip)->li_ops->iop_format)(ip, vp) 358#define IOP_FORMAT(ip,vp) (*(ip)->li_ops->iop_format)(ip, vp)
848#define IOP_PIN(ip) (*(ip)->li_ops->iop_pin)(ip) 359#define IOP_PIN(ip) (*(ip)->li_ops->iop_pin)(ip)
849#define IOP_UNPIN(ip, flags) (*(ip)->li_ops->iop_unpin)(ip, flags) 360#define IOP_UNPIN(ip, remove) (*(ip)->li_ops->iop_unpin)(ip, remove)
850#define IOP_UNPIN_REMOVE(ip,tp) (*(ip)->li_ops->iop_unpin_remove)(ip, tp)
851#define IOP_TRYLOCK(ip) (*(ip)->li_ops->iop_trylock)(ip) 361#define IOP_TRYLOCK(ip) (*(ip)->li_ops->iop_trylock)(ip)
852#define IOP_UNLOCK(ip) (*(ip)->li_ops->iop_unlock)(ip) 362#define IOP_UNLOCK(ip) (*(ip)->li_ops->iop_unlock)(ip)
853#define IOP_COMMITTED(ip, lsn) (*(ip)->li_ops->iop_committed)(ip, lsn) 363#define IOP_COMMITTED(ip, lsn) (*(ip)->li_ops->iop_committed)(ip, lsn)
@@ -864,34 +374,6 @@ typedef struct xfs_item_ops {
864#define XFS_ITEM_PUSHBUF 3 374#define XFS_ITEM_PUSHBUF 3
865 375
866/* 376/*
867 * This structure is used to maintain a list of block ranges that have been
868 * freed in the transaction. The ranges are listed in the perag[] busy list
869 * between when they're freed and the transaction is committed to disk.
870 */
871
872typedef struct xfs_log_busy_slot {
873 xfs_agnumber_t lbc_ag;
874 ushort lbc_idx; /* index in perag.busy[] */
875} xfs_log_busy_slot_t;
876
877#define XFS_LBC_NUM_SLOTS 31
878typedef struct xfs_log_busy_chunk {
879 struct xfs_log_busy_chunk *lbc_next;
880 uint lbc_free; /* free slots bitmask */
881 ushort lbc_unused; /* first unused */
882 xfs_log_busy_slot_t lbc_busy[XFS_LBC_NUM_SLOTS];
883} xfs_log_busy_chunk_t;
884
885#define XFS_LBC_MAX_SLOT (XFS_LBC_NUM_SLOTS - 1)
886#define XFS_LBC_FREEMASK ((1U << XFS_LBC_NUM_SLOTS) - 1)
887
888#define XFS_LBC_INIT(cp) ((cp)->lbc_free = XFS_LBC_FREEMASK)
889#define XFS_LBC_CLAIM(cp, slot) ((cp)->lbc_free &= ~(1 << (slot)))
890#define XFS_LBC_SLOT(cp, slot) (&((cp)->lbc_busy[(slot)]))
891#define XFS_LBC_VACANCY(cp) (((cp)->lbc_free) & XFS_LBC_FREEMASK)
892#define XFS_LBC_ISFREE(cp, slot) ((cp)->lbc_free & (1 << (slot)))
893
894/*
895 * This is the type of function which can be given to xfs_trans_callback() 377 * This is the type of function which can be given to xfs_trans_callback()
896 * to be called upon the transaction's commit to disk. 378 * to be called upon the transaction's commit to disk.
897 */ 379 */
@@ -939,11 +421,9 @@ typedef struct xfs_trans {
939 int64_t t_rblocks_delta;/* superblock rblocks change */ 421 int64_t t_rblocks_delta;/* superblock rblocks change */
940 int64_t t_rextents_delta;/* superblocks rextents chg */ 422 int64_t t_rextents_delta;/* superblocks rextents chg */
941 int64_t t_rextslog_delta;/* superblocks rextslog chg */ 423 int64_t t_rextslog_delta;/* superblocks rextslog chg */
942 unsigned int t_items_free; /* log item descs free */ 424 struct list_head t_items; /* log item descriptors */
943 xfs_log_item_chunk_t t_items; /* first log item desc chunk */
944 xfs_trans_header_t t_header; /* header for in-log trans */ 425 xfs_trans_header_t t_header; /* header for in-log trans */
945 unsigned int t_busy_free; /* busy descs free */ 426 struct list_head t_busy; /* list of busy extents */
946 xfs_log_busy_chunk_t t_busy; /* busy/async free blocks */
947 unsigned long t_pflags; /* saved process flags state */ 427 unsigned long t_pflags; /* saved process flags state */
948} xfs_trans_t; 428} xfs_trans_t;
949 429
@@ -993,8 +473,8 @@ void xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint);
993void xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *); 473void xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *);
994int xfs_trans_iget(struct xfs_mount *, xfs_trans_t *, 474int xfs_trans_iget(struct xfs_mount *, xfs_trans_t *,
995 xfs_ino_t , uint, uint, struct xfs_inode **); 475 xfs_ino_t , uint, uint, struct xfs_inode **);
996void xfs_trans_ijoin(xfs_trans_t *, struct xfs_inode *, uint); 476void xfs_trans_ijoin_ref(struct xfs_trans *, struct xfs_inode *, uint);
997void xfs_trans_ihold(xfs_trans_t *, struct xfs_inode *); 477void xfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *);
998void xfs_trans_log_buf(xfs_trans_t *, struct xfs_buf *, uint, uint); 478void xfs_trans_log_buf(xfs_trans_t *, struct xfs_buf *, uint, uint);
999void xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint); 479void xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint);
1000struct xfs_efi_log_item *xfs_trans_get_efi(xfs_trans_t *, uint); 480struct xfs_efi_log_item *xfs_trans_get_efi(xfs_trans_t *, uint);
@@ -1017,11 +497,9 @@ int _xfs_trans_commit(xfs_trans_t *,
1017void xfs_trans_cancel(xfs_trans_t *, int); 497void xfs_trans_cancel(xfs_trans_t *, int);
1018int xfs_trans_ail_init(struct xfs_mount *); 498int xfs_trans_ail_init(struct xfs_mount *);
1019void xfs_trans_ail_destroy(struct xfs_mount *); 499void xfs_trans_ail_destroy(struct xfs_mount *);
1020xfs_log_busy_slot_t *xfs_trans_add_busy(xfs_trans_t *tp,
1021 xfs_agnumber_t ag,
1022 xfs_extlen_t idx);
1023 500
1024extern kmem_zone_t *xfs_trans_zone; 501extern kmem_zone_t *xfs_trans_zone;
502extern kmem_zone_t *xfs_log_item_desc_zone;
1025 503
1026#endif /* __KERNEL__ */ 504#endif /* __KERNEL__ */
1027 505