1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4 * Copyright (C) 2010 Red Hat, Inc.
7 #include "libxfs_priv.h"
9 #include "xfs_shared.h"
10 #include "xfs_format.h"
11 #include "xfs_log_format.h"
12 #include "xfs_trans_resv.h"
13 #include "xfs_mount.h"
14 #include "xfs_da_format.h"
15 #include "xfs_da_btree.h"
16 #include "xfs_inode.h"
17 #include "xfs_bmap_btree.h"
18 #include "xfs_trans.h"
19 #include "xfs_trans_space.h"
20 #include "xfs_quota_defs.h"
26 * A buffer has a format structure overhead in the log in addition
27 * to the data, so we need to take this into account when reserving
28 * space in a transaction for a buffer. Round the space required up
29 * to a multiple of 128 bytes so that we don't change the historical
30 * reservation that has been used for this overhead.
33 xfs_buf_log_overhead(void)
35 return round_up(sizeof(struct xlog_op_header
) +
36 sizeof(struct xfs_buf_log_format
), 128);
40 * Calculate out transaction log reservation per item in bytes.
42 * The nbufs argument is used to indicate the number of items that
43 * will be changed in a transaction. size is used to tell how many
44 * bytes should be reserved per item.
51 return nbufs
* (size
+ xfs_buf_log_overhead());
55 * Per-extent log reservation for the btree changes involved in freeing or
56 * allocating an extent. In classic XFS there were two trees that will be
57 * modified (bnobt + cntbt). With rmap enabled, there are three trees
58 * (rmapbt). The number of blocks reserved is based on the formula:
60 * num trees * ((2 blocks/level * max depth) - 1)
62 * Keep in mind that max depth is calculated separately for each type of tree.
65 xfs_allocfree_block_count(
71 blocks
= num_ops
* 2 * (2 * mp
->m_alloc_maxlevels
- 1);
72 if (xfs_has_rmapbt(mp
))
73 blocks
+= num_ops
* (2 * mp
->m_rmap_maxlevels
- 1);
79 * Per-extent log reservation for refcount btree changes. These are never done
80 * in the same transaction as an allocation or a free, so we compute them
84 xfs_refcountbt_block_count(
88 return num_ops
* (2 * mp
->m_refc_maxlevels
- 1);
92 * Logging inodes is really tricksy. They are logged in memory format,
93 * which means that what we write into the log doesn't directly translate into
94 * the amount of space they use on disk.
96 * Case in point - btree format forks in memory format use more space than the
97 * on-disk format. In memory, the buffer contains a normal btree block header so
98 * the btree code can treat it as though it is just another generic buffer.
99 * However, when we write it to the inode fork, we don't write all of this
100 * header as it isn't needed. e.g. the root is only ever in the inode, so
101 * there's no need for sibling pointers which would waste 16 bytes of space.
103 * Hence when we have an inode with a maximally sized btree format fork, then
104 * amount of information we actually log is greater than the size of the inode
105 * on disk. Hence we need an inode reservation function that calculates all this
106 * correctly. So, we log:
108 * - 4 log op headers for object
109 * - for the ilf, the inode core and 2 forks
110 * - inode log format object
112 * - two inode forks containing bmap btree root blocks.
113 * - the btree data contained by both forks will fit into the inode size,
114 * hence when combined with the inode core above, we have a total of the
116 * - the BMBT headers need to be accounted separately, as they are
117 * additional to the records and pointers that fit inside the inode
122 struct xfs_mount
*mp
,
126 (4 * sizeof(struct xlog_op_header
) +
127 sizeof(struct xfs_inode_log_format
) +
128 mp
->m_sb
.sb_inodesize
+
129 2 * XFS_BMBT_BLOCK_LEN(mp
));
133 * Inode btree record insertion/removal modifies the inode btree and free space
134 * btrees (since the inobt does not use the agfl). This requires the following
137 * the inode btree: max depth * blocksize
138 * the allocation btrees: 2 trees * (max depth - 1) * block size
140 * The caller must account for SB and AG header modifications, etc.
144 struct xfs_mount
*mp
)
146 return xfs_calc_buf_res(M_IGEO(mp
)->inobt_maxlevels
,
147 XFS_FSB_TO_B(mp
, 1)) +
148 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 1),
149 XFS_FSB_TO_B(mp
, 1));
153 * The free inode btree is a conditional feature. The behavior differs slightly
154 * from that of the traditional inode btree in that the finobt tracks records
155 * for inode chunks with at least one free inode. A record can be removed from
156 * the tree during individual inode allocation. Therefore the finobt
157 * reservation is unconditional for both the inode chunk allocation and
158 * individual inode allocation (modify) cases.
160 * Behavior aside, the reservation for finobt modification is equivalent to the
161 * traditional inobt: cover a full finobt shape change plus block allocation.
165 struct xfs_mount
*mp
)
167 if (!xfs_has_finobt(mp
))
170 return xfs_calc_inobt_res(mp
);
174 * Calculate the reservation required to allocate or free an inode chunk. This
177 * the allocation btrees: 2 trees * (max depth - 1) * block size
178 * the inode chunk: m_ino_geo.ialloc_blks * N
180 * The size N of the inode chunk reservation depends on whether it is for
181 * allocation or free and which type of create transaction is in use. An inode
182 * chunk free always invalidates the buffers and only requires reservation for
183 * headers (N == 0). An inode chunk allocation requires a chunk sized
184 * reservation on v4 and older superblocks to initialize the chunk. No chunk
185 * reservation is required for allocation on v5 supers, which use ordered
186 * buffers to initialize.
189 xfs_calc_inode_chunk_res(
190 struct xfs_mount
*mp
,
195 res
= xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 1),
196 XFS_FSB_TO_B(mp
, 1));
198 /* icreate tx uses ordered buffers */
199 if (xfs_has_v3inodes(mp
))
201 size
= XFS_FSB_TO_B(mp
, 1);
204 res
+= xfs_calc_buf_res(M_IGEO(mp
)->ialloc_blks
, size
);
209 * Per-extent log reservation for the btree changes involved in freeing or
210 * allocating a realtime extent. We have to be able to log as many rtbitmap
211 * blocks as needed to mark inuse XFS_BMBT_MAX_EXTLEN blocks' worth of realtime
212 * extents, as well as the realtime summary block.
215 xfs_rtalloc_block_count(
216 struct xfs_mount
*mp
,
217 unsigned int num_ops
)
219 unsigned int blksz
= XFS_FSB_TO_B(mp
, 1);
220 unsigned int rtbmp_bytes
;
222 rtbmp_bytes
= (XFS_MAX_BMBT_EXTLEN
/ mp
->m_sb
.sb_rextsize
) / NBBY
;
223 return (howmany(rtbmp_bytes
, blksz
) + 1) * num_ops
;
227 * Various log reservation values.
229 * These are based on the size of the file system block because that is what
230 * most transactions manipulate. Each adds in an additional 128 bytes per
231 * item logged to try to account for the overhead of the transaction mechanism.
233 * Note: Most of the reservations underestimate the number of allocation
234 * groups into which they could free extents in the xfs_defer_finish() call.
235 * This is because the number in the worst case is quite high and quite
236 * unusual. In order to fix this we need to change xfs_defer_finish() to free
237 * extents in only a single AG at a time. This will require changes to the
238 * EFI code as well, however, so that the EFI for the extents not freed is
239 * logged again in each transaction. See SGI PV #261917.
241 * Reservation functions here avoid a huge stack in xfs_trans_init due to
242 * register overflow from temporaries in the calculations.
246 * Compute the log reservation required to handle the refcount update
247 * transaction. Refcount updates are always done via deferred log items.
249 * This is calculated as:
250 * Data device refcount updates (t1):
251 * the agfs of the ags containing the blocks: nr_ops * sector size
252 * the refcount btrees: nr_ops * 1 trees * (2 * max depth - 1) * block size
255 xfs_calc_refcountbt_reservation(
256 struct xfs_mount
*mp
,
259 unsigned int blksz
= XFS_FSB_TO_B(mp
, 1);
261 if (!xfs_has_reflink(mp
))
264 return xfs_calc_buf_res(nr_ops
, mp
->m_sb
.sb_sectsize
) +
265 xfs_calc_buf_res(xfs_refcountbt_block_count(mp
, nr_ops
), blksz
);
269 * In a write transaction we can allocate a maximum of 2
270 * extents. This gives (t1):
271 * the inode getting the new extents: inode size
272 * the inode's bmap btree: max depth * block size
273 * the agfs of the ags from which the extents are allocated: 2 * sector
274 * the superblock free block counter: sector size
275 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
276 * Or, if we're writing to a realtime file (t2):
277 * the inode getting the new extents: inode size
278 * the inode's bmap btree: max depth * block size
279 * the agfs of the ags from which the extents are allocated: 2 * sector
280 * the superblock free block counter: sector size
281 * the realtime bitmap: ((XFS_BMBT_MAX_EXTLEN / rtextsize) / NBBY) bytes
282 * the realtime summary: 1 block
283 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
284 * And the bmap_finish transaction can free bmap blocks in a join (t3):
285 * the agfs of the ags containing the blocks: 2 * sector size
286 * the agfls of the ags containing the blocks: 2 * sector size
287 * the super block free block counter: sector size
288 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
289 * And any refcount updates that happen in a separate transaction (t4).
292 xfs_calc_write_reservation(
293 struct xfs_mount
*mp
,
296 unsigned int t1
, t2
, t3
, t4
;
297 unsigned int blksz
= XFS_FSB_TO_B(mp
, 1);
299 t1
= xfs_calc_inode_res(mp
, 1) +
300 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), blksz
) +
301 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
302 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 2), blksz
);
304 if (xfs_has_realtime(mp
)) {
305 t2
= xfs_calc_inode_res(mp
, 1) +
306 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
308 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
309 xfs_calc_buf_res(xfs_rtalloc_block_count(mp
, 1), blksz
) +
310 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 1), blksz
);
315 t3
= xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
316 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 2), blksz
);
319 * In the early days of reflink, we included enough reservation to log
320 * two refcountbt splits for each transaction. The codebase runs
321 * refcountbt updates in separate transactions now, so to compute the
322 * minimum log size, add the refcountbtree splits back to t1 and t3 and
323 * do not account them separately as t4. Reflink did not support
324 * realtime when the reservations were established, so no adjustment to
327 if (for_minlogsize
) {
328 unsigned int adj
= 0;
330 if (xfs_has_reflink(mp
))
331 adj
= xfs_calc_buf_res(
332 xfs_refcountbt_block_count(mp
, 2),
336 return XFS_DQUOT_LOGRES(mp
) + max3(t1
, t2
, t3
);
339 t4
= xfs_calc_refcountbt_reservation(mp
, 1);
340 return XFS_DQUOT_LOGRES(mp
) + max(t4
, max3(t1
, t2
, t3
));
344 xfs_calc_write_reservation_minlogsize(
345 struct xfs_mount
*mp
)
347 return xfs_calc_write_reservation(mp
, true);
351 * In truncating a file we free up to two extents at once. We can modify (t1):
352 * the inode being truncated: inode size
353 * the inode's bmap btree: (max depth + 1) * block size
354 * And the bmap_finish transaction can free the blocks and bmap blocks (t2):
355 * the agf for each of the ags: 4 * sector size
356 * the agfl for each of the ags: 4 * sector size
357 * the super block to reflect the freed blocks: sector size
358 * worst case split in allocation btrees per extent assuming 4 extents:
359 * 4 exts * 2 trees * (2 * max depth - 1) * block size
360 * Or, if it's a realtime file (t3):
361 * the agf for each of the ags: 2 * sector size
362 * the agfl for each of the ags: 2 * sector size
363 * the super block to reflect the freed blocks: sector size
364 * the realtime bitmap:
365 * 2 exts * ((XFS_BMBT_MAX_EXTLEN / rtextsize) / NBBY) bytes
366 * the realtime summary: 2 exts * 1 block
367 * worst case split in allocation btrees per extent assuming 2 extents:
368 * 2 exts * 2 trees * (2 * max depth - 1) * block size
369 * And any refcount updates that happen in a separate transaction (t4).
372 xfs_calc_itruncate_reservation(
373 struct xfs_mount
*mp
,
376 unsigned int t1
, t2
, t3
, t4
;
377 unsigned int blksz
= XFS_FSB_TO_B(mp
, 1);
379 t1
= xfs_calc_inode_res(mp
, 1) +
380 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1, blksz
);
382 t2
= xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
383 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 4), blksz
);
385 if (xfs_has_realtime(mp
)) {
386 t3
= xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
387 xfs_calc_buf_res(xfs_rtalloc_block_count(mp
, 2), blksz
) +
388 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 2), blksz
);
394 * In the early days of reflink, we included enough reservation to log
395 * four refcountbt splits in the same transaction as bnobt/cntbt
396 * updates. The codebase runs refcountbt updates in separate
397 * transactions now, so to compute the minimum log size, add the
398 * refcount btree splits back here and do not compute them separately
399 * as t4. Reflink did not support realtime when the reservations were
400 * established, so do not adjust t3.
402 if (for_minlogsize
) {
403 if (xfs_has_reflink(mp
))
404 t2
+= xfs_calc_buf_res(
405 xfs_refcountbt_block_count(mp
, 4),
408 return XFS_DQUOT_LOGRES(mp
) + max3(t1
, t2
, t3
);
411 t4
= xfs_calc_refcountbt_reservation(mp
, 2);
412 return XFS_DQUOT_LOGRES(mp
) + max(t4
, max3(t1
, t2
, t3
));
416 xfs_calc_itruncate_reservation_minlogsize(
417 struct xfs_mount
*mp
)
419 return xfs_calc_itruncate_reservation(mp
, true);
423 * In renaming a files we can modify:
424 * the five inodes involved: 5 * inode size
425 * the two directory btrees: 2 * (max depth + v2) * dir block size
426 * the two directory bmap btrees: 2 * max depth * block size
427 * And the bmap_finish transaction can free dir and bmap blocks (two sets
428 * of bmap blocks) giving:
429 * the agf for the ags in which the blocks live: 3 * sector size
430 * the agfl for the ags in which the blocks live: 3 * sector size
431 * the superblock for the free block count: sector size
432 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
435 xfs_calc_rename_reservation(
436 struct xfs_mount
*mp
)
438 return XFS_DQUOT_LOGRES(mp
) +
439 max((xfs_calc_inode_res(mp
, 5) +
440 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
441 XFS_FSB_TO_B(mp
, 1))),
442 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
443 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 3),
444 XFS_FSB_TO_B(mp
, 1))));
448 * For removing an inode from unlinked list at first, we can modify:
449 * the agi hash list and counters: sector size
450 * the on disk inode before ours in the agi hash list: inode cluster size
451 * the on disk inode in the agi hash list: inode cluster size
454 xfs_calc_iunlink_remove_reservation(
455 struct xfs_mount
*mp
)
457 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
458 2 * M_IGEO(mp
)->inode_cluster_size
;
462 * For creating a link to an inode:
463 * the parent directory inode: inode size
464 * the linked inode: inode size
465 * the directory btree could split: (max depth + v2) * dir block size
466 * the directory bmap btree could join or split: (max depth + v2) * blocksize
467 * And the bmap_finish transaction can free some bmap blocks giving:
468 * the agf for the ag in which the blocks live: sector size
469 * the agfl for the ag in which the blocks live: sector size
470 * the superblock for the free block count: sector size
471 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
474 xfs_calc_link_reservation(
475 struct xfs_mount
*mp
)
477 return XFS_DQUOT_LOGRES(mp
) +
478 xfs_calc_iunlink_remove_reservation(mp
) +
479 max((xfs_calc_inode_res(mp
, 2) +
480 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
481 XFS_FSB_TO_B(mp
, 1))),
482 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
483 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 1),
484 XFS_FSB_TO_B(mp
, 1))));
488 * For adding an inode to unlinked list we can modify:
489 * the agi hash list: sector size
490 * the on disk inode: inode cluster size
493 xfs_calc_iunlink_add_reservation(xfs_mount_t
*mp
)
495 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
496 M_IGEO(mp
)->inode_cluster_size
;
500 * For removing a directory entry we can modify:
501 * the parent directory inode: inode size
502 * the removed inode: inode size
503 * the directory btree could join: (max depth + v2) * dir block size
504 * the directory bmap btree could join or split: (max depth + v2) * blocksize
505 * And the bmap_finish transaction can free the dir and bmap blocks giving:
506 * the agf for the ag in which the blocks live: 2 * sector size
507 * the agfl for the ag in which the blocks live: 2 * sector size
508 * the superblock for the free block count: sector size
509 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
512 xfs_calc_remove_reservation(
513 struct xfs_mount
*mp
)
515 return XFS_DQUOT_LOGRES(mp
) +
516 xfs_calc_iunlink_add_reservation(mp
) +
517 max((xfs_calc_inode_res(mp
, 2) +
518 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
519 XFS_FSB_TO_B(mp
, 1))),
520 (xfs_calc_buf_res(4, mp
->m_sb
.sb_sectsize
) +
521 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 2),
522 XFS_FSB_TO_B(mp
, 1))));
526 * For create, break it in to the two cases that the transaction
527 * covers. We start with the modify case - allocation done by modification
528 * of the state of existing inodes - and the allocation case.
532 * For create we can modify:
533 * the parent directory inode: inode size
534 * the new inode: inode size
535 * the inode btree entry: block size
536 * the superblock for the nlink flag: sector size
537 * the directory btree: (max depth + v2) * dir block size
538 * the directory inode's bmap btree: (max depth + v2) * block size
539 * the finobt (record modification and allocation btrees)
542 xfs_calc_create_resv_modify(
543 struct xfs_mount
*mp
)
545 return xfs_calc_inode_res(mp
, 2) +
546 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
547 (uint
)XFS_FSB_TO_B(mp
, 1) +
548 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1)) +
549 xfs_calc_finobt_res(mp
);
553 * For icreate we can allocate some inodes giving:
554 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
555 * the superblock for the nlink flag: sector size
556 * the inode chunk (allocation, optional init)
557 * the inobt (record insertion)
558 * the finobt (optional, record insertion)
561 xfs_calc_icreate_resv_alloc(
562 struct xfs_mount
*mp
)
564 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
565 mp
->m_sb
.sb_sectsize
+
566 xfs_calc_inode_chunk_res(mp
, _ALLOC
) +
567 xfs_calc_inobt_res(mp
) +
568 xfs_calc_finobt_res(mp
);
572 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
574 return XFS_DQUOT_LOGRES(mp
) +
575 max(xfs_calc_icreate_resv_alloc(mp
),
576 xfs_calc_create_resv_modify(mp
));
580 xfs_calc_create_tmpfile_reservation(
581 struct xfs_mount
*mp
)
583 uint res
= XFS_DQUOT_LOGRES(mp
);
585 res
+= xfs_calc_icreate_resv_alloc(mp
);
586 return res
+ xfs_calc_iunlink_add_reservation(mp
);
590 * Making a new directory is the same as creating a new file.
593 xfs_calc_mkdir_reservation(
594 struct xfs_mount
*mp
)
596 return xfs_calc_icreate_reservation(mp
);
601 * Making a new symplink is the same as creating a new file, but
602 * with the added blocks for remote symlink data which can be up to 1kB in
603 * length (XFS_SYMLINK_MAXLEN).
606 xfs_calc_symlink_reservation(
607 struct xfs_mount
*mp
)
609 return xfs_calc_icreate_reservation(mp
) +
610 xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN
);
614 * In freeing an inode we can modify:
615 * the inode being freed: inode size
616 * the super block free inode counter, AGF and AGFL: sector size
617 * the on disk inode (agi unlinked list removal)
618 * the inode chunk (invalidated, headers only)
620 * the finobt (record insertion, removal or modification)
622 * Note that the inode chunk res. includes an allocfree res. for freeing of the
623 * inode chunk. This is technically extraneous because the inode chunk free is
624 * deferred (it occurs after a transaction roll). Include the extra reservation
625 * anyways since we've had reports of ifree transaction overruns due to too many
626 * agfl fixups during inode chunk frees.
629 xfs_calc_ifree_reservation(
630 struct xfs_mount
*mp
)
632 return XFS_DQUOT_LOGRES(mp
) +
633 xfs_calc_inode_res(mp
, 1) +
634 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
635 xfs_calc_iunlink_remove_reservation(mp
) +
636 xfs_calc_inode_chunk_res(mp
, _FREE
) +
637 xfs_calc_inobt_res(mp
) +
638 xfs_calc_finobt_res(mp
);
642 * When only changing the inode we log the inode and possibly the superblock
643 * We also add a bit of slop for the transaction stuff.
646 xfs_calc_ichange_reservation(
647 struct xfs_mount
*mp
)
649 return XFS_DQUOT_LOGRES(mp
) +
650 xfs_calc_inode_res(mp
, 1) +
651 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
656 * Growing the data section of the filesystem.
662 xfs_calc_growdata_reservation(
663 struct xfs_mount
*mp
)
665 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
666 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 1),
667 XFS_FSB_TO_B(mp
, 1));
671 * Growing the rt section of the filesystem.
672 * In the first set of transactions (ALLOC) we allocate space to the
673 * bitmap or summary files.
674 * superblock: sector size
675 * agf of the ag from which the extent is allocated: sector size
676 * bmap btree for bitmap/summary inode: max depth * blocksize
677 * bitmap/summary inode: inode size
678 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
681 xfs_calc_growrtalloc_reservation(
682 struct xfs_mount
*mp
)
684 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
685 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
686 XFS_FSB_TO_B(mp
, 1)) +
687 xfs_calc_inode_res(mp
, 1) +
688 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 1),
689 XFS_FSB_TO_B(mp
, 1));
693 * Growing the rt section of the filesystem.
694 * In the second set of transactions (ZERO) we zero the new metadata blocks.
695 * one bitmap/summary block: blocksize
698 xfs_calc_growrtzero_reservation(
699 struct xfs_mount
*mp
)
701 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
705 * Growing the rt section of the filesystem.
706 * In the third set of transactions (FREE) we update metadata without
707 * allocating any new blocks.
708 * superblock: sector size
709 * bitmap inode: inode size
710 * summary inode: inode size
711 * one bitmap block: blocksize
712 * summary blocks: new summary size
715 xfs_calc_growrtfree_reservation(
716 struct xfs_mount
*mp
)
718 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
719 xfs_calc_inode_res(mp
, 2) +
720 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
721 xfs_calc_buf_res(1, mp
->m_rsumsize
);
725 * Logging the inode modification timestamp on a synchronous write.
729 xfs_calc_swrite_reservation(
730 struct xfs_mount
*mp
)
732 return xfs_calc_inode_res(mp
, 1);
736 * Logging the inode mode bits when writing a setuid/setgid file
740 xfs_calc_writeid_reservation(
741 struct xfs_mount
*mp
)
743 return xfs_calc_inode_res(mp
, 1);
747 * Converting the inode from non-attributed to attributed.
748 * the inode being converted: inode size
749 * agf block and superblock (for block allocation)
750 * the new block (directory sized)
751 * bmap blocks for the new directory block
755 xfs_calc_addafork_reservation(
756 struct xfs_mount
*mp
)
758 return XFS_DQUOT_LOGRES(mp
) +
759 xfs_calc_inode_res(mp
, 1) +
760 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
761 xfs_calc_buf_res(1, mp
->m_dir_geo
->blksize
) +
762 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
763 XFS_FSB_TO_B(mp
, 1)) +
764 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 1),
765 XFS_FSB_TO_B(mp
, 1));
769 * Removing the attribute fork of a file
770 * the inode being truncated: inode size
771 * the inode's bmap btree: max depth * block size
772 * And the bmap_finish transaction can free the blocks and bmap blocks:
773 * the agf for each of the ags: 4 * sector size
774 * the agfl for each of the ags: 4 * sector size
775 * the super block to reflect the freed blocks: sector size
776 * worst case split in allocation btrees per extent assuming 4 extents:
777 * 4 exts * 2 trees * (2 * max depth - 1) * block size
780 xfs_calc_attrinval_reservation(
781 struct xfs_mount
*mp
)
783 return max((xfs_calc_inode_res(mp
, 1) +
784 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
785 XFS_FSB_TO_B(mp
, 1))),
786 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
787 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 4),
788 XFS_FSB_TO_B(mp
, 1))));
792 * Setting an attribute at mount time.
793 * the inode getting the attribute
794 * the superblock for allocations
795 * the agfs extents are allocated from
796 * the attribute btree * max depth
797 * the inode allocation btree
798 * Since attribute transaction space is dependent on the size of the attribute,
799 * the calculation is done partially at mount time and partially at runtime(see
803 xfs_calc_attrsetm_reservation(
804 struct xfs_mount
*mp
)
806 return XFS_DQUOT_LOGRES(mp
) +
807 xfs_calc_inode_res(mp
, 1) +
808 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
809 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
813 * Setting an attribute at runtime, transaction space unit per block.
814 * the superblock for allocations: sector size
815 * the inode bmap btree could join or split: max depth * block size
816 * Since the runtime attribute transaction space is dependent on the total
817 * blocks needed for the 1st bmap, here we calculate out the space unit for
818 * one block so that the caller could figure out the total space according
819 * to the attibute extent length in blocks by:
820 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
823 xfs_calc_attrsetrt_reservation(
824 struct xfs_mount
*mp
)
826 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
827 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
828 XFS_FSB_TO_B(mp
, 1));
832 * Removing an attribute.
833 * the inode: inode size
834 * the attribute btree could join: max depth * block size
835 * the inode bmap btree could join or split: max depth * block size
836 * And the bmap_finish transaction can free the attr blocks freed giving:
837 * the agf for the ag in which the blocks live: 2 * sector size
838 * the agfl for the ag in which the blocks live: 2 * sector size
839 * the superblock for the free block count: sector size
840 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
843 xfs_calc_attrrm_reservation(
844 struct xfs_mount
*mp
)
846 return XFS_DQUOT_LOGRES(mp
) +
847 max((xfs_calc_inode_res(mp
, 1) +
848 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
849 XFS_FSB_TO_B(mp
, 1)) +
850 (uint
)XFS_FSB_TO_B(mp
,
851 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
852 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
853 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
854 xfs_calc_buf_res(xfs_allocfree_block_count(mp
, 2),
855 XFS_FSB_TO_B(mp
, 1))));
859 * Clearing a bad agino number in an agi hash bucket.
862 xfs_calc_clear_agi_bucket_reservation(
863 struct xfs_mount
*mp
)
865 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
869 * Adjusting quota limits.
870 * the disk quota buffer: sizeof(struct xfs_disk_dquot)
873 xfs_calc_qm_setqlim_reservation(void)
875 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot
));
879 * Allocating quota on disk if needed.
880 * the write transaction log space for quota file extent allocation
881 * the unit of quota allocation: one system block size
884 xfs_calc_qm_dqalloc_reservation(
885 struct xfs_mount
*mp
,
888 return xfs_calc_write_reservation(mp
, for_minlogsize
) +
890 XFS_FSB_TO_B(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
) - 1);
894 xfs_calc_qm_dqalloc_reservation_minlogsize(
895 struct xfs_mount
*mp
)
897 return xfs_calc_qm_dqalloc_reservation(mp
, true);
901 * Syncing the incore super block changes to disk.
902 * the super block to reflect the changes: sector size
905 xfs_calc_sb_reservation(
906 struct xfs_mount
*mp
)
908 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
913 struct xfs_mount
*mp
,
914 struct xfs_trans_resv
*resp
)
916 int logcount_adj
= 0;
919 * The following transactions are logged in physical format and
920 * require a permanent reservation on space.
922 resp
->tr_write
.tr_logres
= xfs_calc_write_reservation(mp
, false);
923 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
924 resp
->tr_write
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
926 resp
->tr_itruncate
.tr_logres
= xfs_calc_itruncate_reservation(mp
, false);
927 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
928 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
930 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
931 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
932 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
934 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
935 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
936 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
938 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
939 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
940 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
942 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
943 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
944 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
946 resp
->tr_create
.tr_logres
= xfs_calc_icreate_reservation(mp
);
947 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
948 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
950 resp
->tr_create_tmpfile
.tr_logres
=
951 xfs_calc_create_tmpfile_reservation(mp
);
952 resp
->tr_create_tmpfile
.tr_logcount
= XFS_CREATE_TMPFILE_LOG_COUNT
;
953 resp
->tr_create_tmpfile
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
955 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
956 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
957 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
959 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
960 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
961 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
963 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
964 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
965 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
967 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
968 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
969 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
971 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
972 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
973 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
975 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
976 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
977 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
979 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
980 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
981 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
983 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
,
985 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
986 resp
->tr_qm_dqalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
989 * The following transactions are logged in logical format with
990 * a default log count.
992 resp
->tr_qm_setqlim
.tr_logres
= xfs_calc_qm_setqlim_reservation();
993 resp
->tr_qm_setqlim
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
995 resp
->tr_sb
.tr_logres
= xfs_calc_sb_reservation(mp
);
996 resp
->tr_sb
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
998 /* growdata requires permanent res; it can free space to the last AG */
999 resp
->tr_growdata
.tr_logres
= xfs_calc_growdata_reservation(mp
);
1000 resp
->tr_growdata
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
1001 resp
->tr_growdata
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
1003 /* The following transaction are logged in logical format */
1004 resp
->tr_ichange
.tr_logres
= xfs_calc_ichange_reservation(mp
);
1005 resp
->tr_fsyncts
.tr_logres
= xfs_calc_swrite_reservation(mp
);
1006 resp
->tr_writeid
.tr_logres
= xfs_calc_writeid_reservation(mp
);
1007 resp
->tr_attrsetrt
.tr_logres
= xfs_calc_attrsetrt_reservation(mp
);
1008 resp
->tr_clearagi
.tr_logres
= xfs_calc_clear_agi_bucket_reservation(mp
);
1009 resp
->tr_growrtzero
.tr_logres
= xfs_calc_growrtzero_reservation(mp
);
1010 resp
->tr_growrtfree
.tr_logres
= xfs_calc_growrtfree_reservation(mp
);
1013 * Add one logcount for BUI items that appear with rmap or reflink,
1014 * one logcount for refcount intent items, and one logcount for rmap
1017 if (xfs_has_reflink(mp
) || xfs_has_rmapbt(mp
))
1019 if (xfs_has_reflink(mp
))
1021 if (xfs_has_rmapbt(mp
))
1024 resp
->tr_itruncate
.tr_logcount
+= logcount_adj
;
1025 resp
->tr_write
.tr_logcount
+= logcount_adj
;
1026 resp
->tr_qm_dqalloc
.tr_logcount
+= logcount_adj
;