1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4 * Copyright (C) 2010 Red Hat, Inc.
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_ialloc.h"
19 #include "xfs_quota.h"
20 #include "xfs_trans.h"
22 #include "xfs_trans_space.h"
23 #include "xfs_trace.h"
29 * A buffer has a format structure overhead in the log in addition
30 * to the data, so we need to take this into account when reserving
31 * space in a transaction for a buffer. Round the space required up
32 * to a multiple of 128 bytes so that we don't change the historical
33 * reservation that has been used for this overhead.
36 xfs_buf_log_overhead(void)
38 return round_up(sizeof(struct xlog_op_header) +
39 sizeof(struct xfs_buf_log_format), 128);
43 * Calculate out transaction log reservation per item in bytes.
45 * The nbufs argument is used to indicate the number of items that
46 * will be changed in a transaction. size is used to tell how many
47 * bytes should be reserved per item.
54 return nbufs * (size + xfs_buf_log_overhead());
58 * Per-extent log reservation for the btree changes involved in freeing or
59 * allocating an extent. In classic XFS there were two trees that will be
60 * modified (bnobt + cntbt). With rmap enabled, there are three trees
61 * (rmapbt). With reflink, there are four trees (refcountbt). The number of
62 * blocks reserved is based on the formula:
64 * num trees * ((2 blocks/level * max depth) - 1)
66 * Keep in mind that max depth is calculated separately for each type of tree.
69 xfs_allocfree_log_count(
75 blocks = num_ops * 2 * (2 * mp->m_ag_maxlevels - 1);
76 if (xfs_sb_version_hasrmapbt(&mp->m_sb))
77 blocks += num_ops * (2 * mp->m_rmap_maxlevels - 1);
78 if (xfs_sb_version_hasreflink(&mp->m_sb))
79 blocks += num_ops * (2 * mp->m_refc_maxlevels - 1);
85 * Logging inodes is really tricksy. They are logged in memory format,
86 * which means that what we write into the log doesn't directly translate into
87 * the amount of space they use on disk.
89 * Case in point - btree format forks in memory format use more space than the
90 * on-disk format. In memory, the buffer contains a normal btree block header so
91 * the btree code can treat it as though it is just another generic buffer.
92 * However, when we write it to the inode fork, we don't write all of this
93 * header as it isn't needed. e.g. the root is only ever in the inode, so
94 * there's no need for sibling pointers which would waste 16 bytes of space.
96 * Hence when we have an inode with a maximally sized btree format fork, then
97 * amount of information we actually log is greater than the size of the inode
98 * on disk. Hence we need an inode reservation function that calculates all this
99 * correctly. So, we log:
101 * - 4 log op headers for object
102 * - for the ilf, the inode core and 2 forks
103 * - inode log format object
105 * - two inode forks containing bmap btree root blocks.
106 * - the btree data contained by both forks will fit into the inode size,
107 * hence when combined with the inode core above, we have a total of the
109 * - the BMBT headers need to be accounted separately, as they are
110 * additional to the records and pointers that fit inside the inode
115 struct xfs_mount *mp,
119 (4 * sizeof(struct xlog_op_header) +
120 sizeof(struct xfs_inode_log_format) +
121 mp->m_sb.sb_inodesize +
122 2 * XFS_BMBT_BLOCK_LEN(mp));
126 * Inode btree record insertion/removal modifies the inode btree and free space
127 * btrees (since the inobt does not use the agfl). This requires the following
130 * the inode btree: max depth * blocksize
131 * the allocation btrees: 2 trees * (max depth - 1) * block size
133 * The caller must account for SB and AG header modifications, etc.
137 struct xfs_mount *mp)
139 return xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
140 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
141 XFS_FSB_TO_B(mp, 1));
145 * The free inode btree is a conditional feature. The behavior differs slightly
146 * from that of the traditional inode btree in that the finobt tracks records
147 * for inode chunks with at least one free inode. A record can be removed from
148 * the tree during individual inode allocation. Therefore the finobt
149 * reservation is unconditional for both the inode chunk allocation and
150 * individual inode allocation (modify) cases.
152 * Behavior aside, the reservation for finobt modification is equivalent to the
153 * traditional inobt: cover a full finobt shape change plus block allocation.
157 struct xfs_mount *mp)
159 if (!xfs_sb_version_hasfinobt(&mp->m_sb))
162 return xfs_calc_inobt_res(mp);
166 * Calculate the reservation required to allocate or free an inode chunk. This
169 * the allocation btrees: 2 trees * (max depth - 1) * block size
170 * the inode chunk: m_ialloc_blks * N
172 * The size N of the inode chunk reservation depends on whether it is for
173 * allocation or free and which type of create transaction is in use. An inode
174 * chunk free always invalidates the buffers and only requires reservation for
175 * headers (N == 0). An inode chunk allocation requires a chunk sized
176 * reservation on v4 and older superblocks to initialize the chunk. No chunk
177 * reservation is required for allocation on v5 supers, which use ordered
178 * buffers to initialize.
181 xfs_calc_inode_chunk_res(
182 struct xfs_mount *mp,
187 res = xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
188 XFS_FSB_TO_B(mp, 1));
190 /* icreate tx uses ordered buffers */
191 if (xfs_sb_version_hascrc(&mp->m_sb))
193 size = XFS_FSB_TO_B(mp, 1);
196 res += xfs_calc_buf_res(mp->m_ialloc_blks, size);
201 * Per-extent log reservation for the btree changes involved in freeing or
202 * allocating a realtime extent. We have to be able to log as many rtbitmap
203 * blocks as needed to mark inuse MAXEXTLEN blocks' worth of realtime extents,
204 * as well as the realtime summary block.
207 xfs_rtalloc_log_count(
208 struct xfs_mount *mp,
209 unsigned int num_ops)
211 unsigned int blksz = XFS_FSB_TO_B(mp, 1);
212 unsigned int rtbmp_bytes;
214 rtbmp_bytes = (MAXEXTLEN / mp->m_sb.sb_rextsize) / NBBY;
215 return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
219 * Various log reservation values.
221 * These are based on the size of the file system block because that is what
222 * most transactions manipulate. Each adds in an additional 128 bytes per
223 * item logged to try to account for the overhead of the transaction mechanism.
225 * Note: Most of the reservations underestimate the number of allocation
226 * groups into which they could free extents in the xfs_defer_finish() call.
227 * This is because the number in the worst case is quite high and quite
228 * unusual. In order to fix this we need to change xfs_defer_finish() to free
229 * extents in only a single AG at a time. This will require changes to the
230 * EFI code as well, however, so that the EFI for the extents not freed is
231 * logged again in each transaction. See SGI PV #261917.
233 * Reservation functions here avoid a huge stack in xfs_trans_init due to
234 * register overflow from temporaries in the calculations.
239 * In a write transaction we can allocate a maximum of 2
240 * extents. This gives (t1):
241 * the inode getting the new extents: inode size
242 * the inode's bmap btree: max depth * block size
243 * the agfs of the ags from which the extents are allocated: 2 * sector
244 * the superblock free block counter: sector size
245 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
246 * Or, if we're writing to a realtime file (t2):
247 * the inode getting the new extents: inode size
248 * the inode's bmap btree: max depth * block size
249 * the agfs of the ags from which the extents are allocated: 2 * sector
250 * the superblock free block counter: sector size
251 * the realtime bitmap: ((MAXEXTLEN / rtextsize) / NBBY) bytes
252 * the realtime summary: 1 block
253 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
254 * And the bmap_finish transaction can free bmap blocks in a join (t3):
255 * the agfs of the ags containing the blocks: 2 * sector size
256 * the agfls of the ags containing the blocks: 2 * sector size
257 * the super block free block counter: sector size
258 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
261 xfs_calc_write_reservation(
262 struct xfs_mount *mp)
264 unsigned int t1, t2, t3;
265 unsigned int blksz = XFS_FSB_TO_B(mp, 1);
267 t1 = xfs_calc_inode_res(mp, 1) +
268 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), blksz) +
269 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
270 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), blksz);
272 if (xfs_sb_version_hasrealtime(&mp->m_sb)) {
273 t2 = xfs_calc_inode_res(mp, 1) +
274 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
276 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
277 xfs_calc_buf_res(xfs_rtalloc_log_count(mp, 1), blksz) +
278 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), blksz);
283 t3 = xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
284 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), blksz);
286 return XFS_DQUOT_LOGRES(mp) + max3(t1, t2, t3);
290 * In truncating a file we free up to two extents at once. We can modify (t1):
291 * the inode being truncated: inode size
292 * the inode's bmap btree: (max depth + 1) * block size
293 * And the bmap_finish transaction can free the blocks and bmap blocks (t2):
294 * the agf for each of the ags: 4 * sector size
295 * the agfl for each of the ags: 4 * sector size
296 * the super block to reflect the freed blocks: sector size
297 * worst case split in allocation btrees per extent assuming 4 extents:
298 * 4 exts * 2 trees * (2 * max depth - 1) * block size
299 * Or, if it's a realtime file (t3):
300 * the agf for each of the ags: 2 * sector size
301 * the agfl for each of the ags: 2 * sector size
302 * the super block to reflect the freed blocks: sector size
303 * the realtime bitmap: 2 exts * ((MAXEXTLEN / rtextsize) / NBBY) bytes
304 * the realtime summary: 2 exts * 1 block
305 * worst case split in allocation btrees per extent assuming 2 extents:
306 * 2 exts * 2 trees * (2 * max depth - 1) * block size
309 xfs_calc_itruncate_reservation(
310 struct xfs_mount *mp)
312 unsigned int t1, t2, t3;
313 unsigned int blksz = XFS_FSB_TO_B(mp, 1);
315 t1 = xfs_calc_inode_res(mp, 1) +
316 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1, blksz);
318 t2 = xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
319 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4), blksz);
321 if (xfs_sb_version_hasrealtime(&mp->m_sb)) {
322 t3 = xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
323 xfs_calc_buf_res(xfs_rtalloc_log_count(mp, 2), blksz) +
324 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), blksz);
329 return XFS_DQUOT_LOGRES(mp) + max3(t1, t2, t3);
333 * In renaming a files we can modify:
334 * the four inodes involved: 4 * inode size
335 * the two directory btrees: 2 * (max depth + v2) * dir block size
336 * the two directory bmap btrees: 2 * max depth * block size
337 * And the bmap_finish transaction can free dir and bmap blocks (two sets
338 * of bmap blocks) giving:
339 * the agf for the ags in which the blocks live: 3 * sector size
340 * the agfl for the ags in which the blocks live: 3 * sector size
341 * the superblock for the free block count: sector size
342 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
345 xfs_calc_rename_reservation(
346 struct xfs_mount *mp)
348 return XFS_DQUOT_LOGRES(mp) +
349 max((xfs_calc_inode_res(mp, 4) +
350 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
351 XFS_FSB_TO_B(mp, 1))),
352 (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
353 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 3),
354 XFS_FSB_TO_B(mp, 1))));
358 * For removing an inode from unlinked list at first, we can modify:
359 * the agi hash list and counters: sector size
360 * the on disk inode before ours in the agi hash list: inode cluster size
361 * the on disk inode in the agi hash list: inode cluster size
364 xfs_calc_iunlink_remove_reservation(
365 struct xfs_mount *mp)
367 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
368 2 * max_t(uint, XFS_FSB_TO_B(mp, 1), mp->m_inode_cluster_size);
372 * For creating a link to an inode:
373 * the parent directory inode: inode size
374 * the linked inode: inode size
375 * the directory btree could split: (max depth + v2) * dir block size
376 * the directory bmap btree could join or split: (max depth + v2) * blocksize
377 * And the bmap_finish transaction can free some bmap blocks giving:
378 * the agf for the ag in which the blocks live: sector size
379 * the agfl for the ag in which the blocks live: sector size
380 * the superblock for the free block count: sector size
381 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
384 xfs_calc_link_reservation(
385 struct xfs_mount *mp)
387 return XFS_DQUOT_LOGRES(mp) +
388 xfs_calc_iunlink_remove_reservation(mp) +
389 max((xfs_calc_inode_res(mp, 2) +
390 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
391 XFS_FSB_TO_B(mp, 1))),
392 (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
393 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
394 XFS_FSB_TO_B(mp, 1))));
398 * For adding an inode to unlinked list we can modify:
399 * the agi hash list: sector size
400 * the on disk inode: inode cluster size
403 xfs_calc_iunlink_add_reservation(xfs_mount_t *mp)
405 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
406 max_t(uint, XFS_FSB_TO_B(mp, 1), mp->m_inode_cluster_size);
410 * For removing a directory entry we can modify:
411 * the parent directory inode: inode size
412 * the removed inode: inode size
413 * the directory btree could join: (max depth + v2) * dir block size
414 * the directory bmap btree could join or split: (max depth + v2) * blocksize
415 * And the bmap_finish transaction can free the dir and bmap blocks giving:
416 * the agf for the ag in which the blocks live: 2 * sector size
417 * the agfl for the ag in which the blocks live: 2 * sector size
418 * the superblock for the free block count: sector size
419 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
422 xfs_calc_remove_reservation(
423 struct xfs_mount *mp)
425 return XFS_DQUOT_LOGRES(mp) +
426 xfs_calc_iunlink_add_reservation(mp) +
427 max((xfs_calc_inode_res(mp, 1) +
428 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
429 XFS_FSB_TO_B(mp, 1))),
430 (xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) +
431 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
432 XFS_FSB_TO_B(mp, 1))));
436 * For create, break it in to the two cases that the transaction
437 * covers. We start with the modify case - allocation done by modification
438 * of the state of existing inodes - and the allocation case.
442 * For create we can modify:
443 * the parent directory inode: inode size
444 * the new inode: inode size
445 * the inode btree entry: block size
446 * the superblock for the nlink flag: sector size
447 * the directory btree: (max depth + v2) * dir block size
448 * the directory inode's bmap btree: (max depth + v2) * block size
449 * the finobt (record modification and allocation btrees)
452 xfs_calc_create_resv_modify(
453 struct xfs_mount *mp)
455 return xfs_calc_inode_res(mp, 2) +
456 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
457 (uint)XFS_FSB_TO_B(mp, 1) +
458 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)) +
459 xfs_calc_finobt_res(mp);
463 * For icreate we can allocate some inodes giving:
464 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
465 * the superblock for the nlink flag: sector size
466 * the inode chunk (allocation, optional init)
467 * the inobt (record insertion)
468 * the finobt (optional, record insertion)
471 xfs_calc_icreate_resv_alloc(
472 struct xfs_mount *mp)
474 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
475 mp->m_sb.sb_sectsize +
476 xfs_calc_inode_chunk_res(mp, _ALLOC) +
477 xfs_calc_inobt_res(mp) +
478 xfs_calc_finobt_res(mp);
482 xfs_calc_icreate_reservation(xfs_mount_t *mp)
484 return XFS_DQUOT_LOGRES(mp) +
485 max(xfs_calc_icreate_resv_alloc(mp),
486 xfs_calc_create_resv_modify(mp));
490 xfs_calc_create_tmpfile_reservation(
491 struct xfs_mount *mp)
493 uint res = XFS_DQUOT_LOGRES(mp);
495 res += xfs_calc_icreate_resv_alloc(mp);
496 return res + xfs_calc_iunlink_add_reservation(mp);
500 * Making a new directory is the same as creating a new file.
503 xfs_calc_mkdir_reservation(
504 struct xfs_mount *mp)
506 return xfs_calc_icreate_reservation(mp);
511 * Making a new symplink is the same as creating a new file, but
512 * with the added blocks for remote symlink data which can be up to 1kB in
513 * length (XFS_SYMLINK_MAXLEN).
516 xfs_calc_symlink_reservation(
517 struct xfs_mount *mp)
519 return xfs_calc_icreate_reservation(mp) +
520 xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN);
524 * In freeing an inode we can modify:
525 * the inode being freed: inode size
526 * the super block free inode counter, AGF and AGFL: sector size
527 * the on disk inode (agi unlinked list removal)
528 * the inode chunk (invalidated, headers only)
530 * the finobt (record insertion, removal or modification)
532 * Note that the inode chunk res. includes an allocfree res. for freeing of the
533 * inode chunk. This is technically extraneous because the inode chunk free is
534 * deferred (it occurs after a transaction roll). Include the extra reservation
535 * anyways since we've had reports of ifree transaction overruns due to too many
536 * agfl fixups during inode chunk frees.
539 xfs_calc_ifree_reservation(
540 struct xfs_mount *mp)
542 return XFS_DQUOT_LOGRES(mp) +
543 xfs_calc_inode_res(mp, 1) +
544 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
545 xfs_calc_iunlink_remove_reservation(mp) +
546 xfs_calc_inode_chunk_res(mp, _FREE) +
547 xfs_calc_inobt_res(mp) +
548 xfs_calc_finobt_res(mp);
552 * When only changing the inode we log the inode and possibly the superblock
553 * We also add a bit of slop for the transaction stuff.
556 xfs_calc_ichange_reservation(
557 struct xfs_mount *mp)
559 return XFS_DQUOT_LOGRES(mp) +
560 xfs_calc_inode_res(mp, 1) +
561 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
566 * Growing the data section of the filesystem.
572 xfs_calc_growdata_reservation(
573 struct xfs_mount *mp)
575 return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
576 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
577 XFS_FSB_TO_B(mp, 1));
581 * Growing the rt section of the filesystem.
582 * In the first set of transactions (ALLOC) we allocate space to the
583 * bitmap or summary files.
584 * superblock: sector size
585 * agf of the ag from which the extent is allocated: sector size
586 * bmap btree for bitmap/summary inode: max depth * blocksize
587 * bitmap/summary inode: inode size
588 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
591 xfs_calc_growrtalloc_reservation(
592 struct xfs_mount *mp)
594 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
595 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
596 XFS_FSB_TO_B(mp, 1)) +
597 xfs_calc_inode_res(mp, 1) +
598 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
599 XFS_FSB_TO_B(mp, 1));
603 * Growing the rt section of the filesystem.
604 * In the second set of transactions (ZERO) we zero the new metadata blocks.
605 * one bitmap/summary block: blocksize
608 xfs_calc_growrtzero_reservation(
609 struct xfs_mount *mp)
611 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
615 * Growing the rt section of the filesystem.
616 * In the third set of transactions (FREE) we update metadata without
617 * allocating any new blocks.
618 * superblock: sector size
619 * bitmap inode: inode size
620 * summary inode: inode size
621 * one bitmap block: blocksize
622 * summary blocks: new summary size
625 xfs_calc_growrtfree_reservation(
626 struct xfs_mount *mp)
628 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
629 xfs_calc_inode_res(mp, 2) +
630 xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
631 xfs_calc_buf_res(1, mp->m_rsumsize);
635 * Logging the inode modification timestamp on a synchronous write.
639 xfs_calc_swrite_reservation(
640 struct xfs_mount *mp)
642 return xfs_calc_inode_res(mp, 1);
646 * Logging the inode mode bits when writing a setuid/setgid file
650 xfs_calc_writeid_reservation(
651 struct xfs_mount *mp)
653 return xfs_calc_inode_res(mp, 1);
657 * Converting the inode from non-attributed to attributed.
658 * the inode being converted: inode size
659 * agf block and superblock (for block allocation)
660 * the new block (directory sized)
661 * bmap blocks for the new directory block
665 xfs_calc_addafork_reservation(
666 struct xfs_mount *mp)
668 return XFS_DQUOT_LOGRES(mp) +
669 xfs_calc_inode_res(mp, 1) +
670 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
671 xfs_calc_buf_res(1, mp->m_dir_geo->blksize) +
672 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
673 XFS_FSB_TO_B(mp, 1)) +
674 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
675 XFS_FSB_TO_B(mp, 1));
679 * Removing the attribute fork of a file
680 * the inode being truncated: inode size
681 * the inode's bmap btree: max depth * block size
682 * And the bmap_finish transaction can free the blocks and bmap blocks:
683 * the agf for each of the ags: 4 * sector size
684 * the agfl for each of the ags: 4 * sector size
685 * the super block to reflect the freed blocks: sector size
686 * worst case split in allocation btrees per extent assuming 4 extents:
687 * 4 exts * 2 trees * (2 * max depth - 1) * block size
690 xfs_calc_attrinval_reservation(
691 struct xfs_mount *mp)
693 return max((xfs_calc_inode_res(mp, 1) +
694 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
695 XFS_FSB_TO_B(mp, 1))),
696 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
697 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4),
698 XFS_FSB_TO_B(mp, 1))));
702 * Setting an attribute at mount time.
703 * the inode getting the attribute
704 * the superblock for allocations
705 * the agfs extents are allocated from
706 * the attribute btree * max depth
707 * the inode allocation btree
708 * Since attribute transaction space is dependent on the size of the attribute,
709 * the calculation is done partially at mount time and partially at runtime(see
713 xfs_calc_attrsetm_reservation(
714 struct xfs_mount *mp)
716 return XFS_DQUOT_LOGRES(mp) +
717 xfs_calc_inode_res(mp, 1) +
718 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
719 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1));
723 * Setting an attribute at runtime, transaction space unit per block.
724 * the superblock for allocations: sector size
725 * the inode bmap btree could join or split: max depth * block size
726 * Since the runtime attribute transaction space is dependent on the total
727 * blocks needed for the 1st bmap, here we calculate out the space unit for
728 * one block so that the caller could figure out the total space according
729 * to the attibute extent length in blocks by:
730 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
733 xfs_calc_attrsetrt_reservation(
734 struct xfs_mount *mp)
736 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
737 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
738 XFS_FSB_TO_B(mp, 1));
742 * Removing an attribute.
743 * the inode: inode size
744 * the attribute btree could join: max depth * block size
745 * the inode bmap btree could join or split: max depth * block size
746 * And the bmap_finish transaction can free the attr blocks freed giving:
747 * the agf for the ag in which the blocks live: 2 * sector size
748 * the agfl for the ag in which the blocks live: 2 * sector size
749 * the superblock for the free block count: sector size
750 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
753 xfs_calc_attrrm_reservation(
754 struct xfs_mount *mp)
756 return XFS_DQUOT_LOGRES(mp) +
757 max((xfs_calc_inode_res(mp, 1) +
758 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH,
759 XFS_FSB_TO_B(mp, 1)) +
760 (uint)XFS_FSB_TO_B(mp,
761 XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
762 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
763 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
764 xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
765 XFS_FSB_TO_B(mp, 1))));
769 * Clearing a bad agino number in an agi hash bucket.
772 xfs_calc_clear_agi_bucket_reservation(
773 struct xfs_mount *mp)
775 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
779 * Adjusting quota limits.
780 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
783 xfs_calc_qm_setqlim_reservation(void)
785 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
789 * Allocating quota on disk if needed.
790 * the write transaction log space for quota file extent allocation
791 * the unit of quota allocation: one system block size
794 xfs_calc_qm_dqalloc_reservation(
795 struct xfs_mount *mp)
797 return xfs_calc_write_reservation(mp) +
799 XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
803 * Turning off quotas.
804 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
805 * the superblock for the quota flags: sector size
808 xfs_calc_qm_quotaoff_reservation(
809 struct xfs_mount *mp)
811 return sizeof(struct xfs_qoff_logitem) * 2 +
812 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
816 * End of turning off quotas.
817 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
820 xfs_calc_qm_quotaoff_end_reservation(void)
822 return sizeof(struct xfs_qoff_logitem) * 2;
826 * Syncing the incore super block changes to disk.
827 * the super block to reflect the changes: sector size
830 xfs_calc_sb_reservation(
831 struct xfs_mount *mp)
833 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
838 struct xfs_mount *mp,
839 struct xfs_trans_resv *resp)
842 * The following transactions are logged in physical format and
843 * require a permanent reservation on space.
845 resp->tr_write.tr_logres = xfs_calc_write_reservation(mp);
846 if (xfs_sb_version_hasreflink(&mp->m_sb))
847 resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT_REFLINK;
849 resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT;
850 resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
852 resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp);
853 if (xfs_sb_version_hasreflink(&mp->m_sb))
854 resp->tr_itruncate.tr_logcount =
855 XFS_ITRUNCATE_LOG_COUNT_REFLINK;
857 resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
858 resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
860 resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp);
861 resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;
862 resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
864 resp->tr_link.tr_logres = xfs_calc_link_reservation(mp);
865 resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT;
866 resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
868 resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp);
869 resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT;
870 resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
872 resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp);
873 resp->tr_symlink.tr_logcount = XFS_SYMLINK_LOG_COUNT;
874 resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
876 resp->tr_create.tr_logres = xfs_calc_icreate_reservation(mp);
877 resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
878 resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
880 resp->tr_create_tmpfile.tr_logres =
881 xfs_calc_create_tmpfile_reservation(mp);
882 resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT;
883 resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
885 resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
886 resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
887 resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
889 resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp);
890 resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT;
891 resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
893 resp->tr_addafork.tr_logres = xfs_calc_addafork_reservation(mp);
894 resp->tr_addafork.tr_logcount = XFS_ADDAFORK_LOG_COUNT;
895 resp->tr_addafork.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
897 resp->tr_attrinval.tr_logres = xfs_calc_attrinval_reservation(mp);
898 resp->tr_attrinval.tr_logcount = XFS_ATTRINVAL_LOG_COUNT;
899 resp->tr_attrinval.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
901 resp->tr_attrsetm.tr_logres = xfs_calc_attrsetm_reservation(mp);
902 resp->tr_attrsetm.tr_logcount = XFS_ATTRSET_LOG_COUNT;
903 resp->tr_attrsetm.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
905 resp->tr_attrrm.tr_logres = xfs_calc_attrrm_reservation(mp);
906 resp->tr_attrrm.tr_logcount = XFS_ATTRRM_LOG_COUNT;
907 resp->tr_attrrm.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
909 resp->tr_growrtalloc.tr_logres = xfs_calc_growrtalloc_reservation(mp);
910 resp->tr_growrtalloc.tr_logcount = XFS_DEFAULT_PERM_LOG_COUNT;
911 resp->tr_growrtalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
913 resp->tr_qm_dqalloc.tr_logres = xfs_calc_qm_dqalloc_reservation(mp);
914 if (xfs_sb_version_hasreflink(&mp->m_sb))
915 resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT_REFLINK;
917 resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;
918 resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
921 * The following transactions are logged in logical format with
922 * a default log count.
924 resp->tr_qm_setqlim.tr_logres = xfs_calc_qm_setqlim_reservation();
925 resp->tr_qm_setqlim.tr_logcount = XFS_DEFAULT_LOG_COUNT;
927 resp->tr_qm_quotaoff.tr_logres = xfs_calc_qm_quotaoff_reservation(mp);
928 resp->tr_qm_quotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT;
930 resp->tr_qm_equotaoff.tr_logres =
931 xfs_calc_qm_quotaoff_end_reservation();
932 resp->tr_qm_equotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT;
934 resp->tr_sb.tr_logres = xfs_calc_sb_reservation(mp);
935 resp->tr_sb.tr_logcount = XFS_DEFAULT_LOG_COUNT;
937 /* The following transaction are logged in logical format */
938 resp->tr_ichange.tr_logres = xfs_calc_ichange_reservation(mp);
939 resp->tr_growdata.tr_logres = xfs_calc_growdata_reservation(mp);
940 resp->tr_fsyncts.tr_logres = xfs_calc_swrite_reservation(mp);
941 resp->tr_writeid.tr_logres = xfs_calc_writeid_reservation(mp);
942 resp->tr_attrsetrt.tr_logres = xfs_calc_attrsetrt_reservation(mp);
943 resp->tr_clearagi.tr_logres = xfs_calc_clear_agi_bucket_reservation(mp);
944 resp->tr_growrtzero.tr_logres = xfs_calc_growrtzero_reservation(mp);
945 resp->tr_growrtfree.tr_logres = xfs_calc_growrtfree_reservation(mp);