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_ialloc.h"
19 #include "xfs_trans.h"
20 #include "xfs_trans_space.h"
21 #include "xfs_trace.h"
22 #include "xfs_quota_defs.h"
28 * A buffer has a format structure overhead in the log in addition
29 * to the data, so we need to take this into account when reserving
30 * space in a transaction for a buffer. Round the space required up
31 * to a multiple of 128 bytes so that we don't change the historical
32 * reservation that has been used for this overhead.
35 xfs_buf_log_overhead(void)
37 return round_up(sizeof(struct xlog_op_header
) +
38 sizeof(struct xfs_buf_log_format
), 128);
42 * Calculate out transaction log reservation per item in bytes.
44 * The nbufs argument is used to indicate the number of items that
45 * will be changed in a transaction. size is used to tell how many
46 * bytes should be reserved per item.
53 return nbufs
* (size
+ xfs_buf_log_overhead());
57 * Per-extent log reservation for the btree changes involved in freeing or
58 * allocating an extent. In classic XFS there were two trees that will be
59 * modified (bnobt + cntbt). With rmap enabled, there are three trees
60 * (rmapbt). With reflink, there are four trees (refcountbt). The number of
61 * blocks reserved is based on the formula:
63 * num trees * ((2 blocks/level * max depth) - 1)
65 * Keep in mind that max depth is calculated separately for each type of tree.
68 xfs_allocfree_log_count(
74 blocks
= num_ops
* 2 * (2 * mp
->m_ag_maxlevels
- 1);
75 if (xfs_sb_version_hasrmapbt(&mp
->m_sb
))
76 blocks
+= num_ops
* (2 * mp
->m_rmap_maxlevels
- 1);
77 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
78 blocks
+= num_ops
* (2 * mp
->m_refc_maxlevels
- 1);
84 * Logging inodes is really tricksy. They are logged in memory format,
85 * which means that what we write into the log doesn't directly translate into
86 * the amount of space they use on disk.
88 * Case in point - btree format forks in memory format use more space than the
89 * on-disk format. In memory, the buffer contains a normal btree block header so
90 * the btree code can treat it as though it is just another generic buffer.
91 * However, when we write it to the inode fork, we don't write all of this
92 * header as it isn't needed. e.g. the root is only ever in the inode, so
93 * there's no need for sibling pointers which would waste 16 bytes of space.
95 * Hence when we have an inode with a maximally sized btree format fork, then
96 * amount of information we actually log is greater than the size of the inode
97 * on disk. Hence we need an inode reservation function that calculates all this
98 * correctly. So, we log:
100 * - 4 log op headers for object
101 * - for the ilf, the inode core and 2 forks
102 * - inode log format object
104 * - two inode forks containing bmap btree root blocks.
105 * - the btree data contained by both forks will fit into the inode size,
106 * hence when combined with the inode core above, we have a total of the
108 * - the BMBT headers need to be accounted separately, as they are
109 * additional to the records and pointers that fit inside the inode
114 struct xfs_mount
*mp
,
118 (4 * sizeof(struct xlog_op_header
) +
119 sizeof(struct xfs_inode_log_format
) +
120 mp
->m_sb
.sb_inodesize
+
121 2 * XFS_BMBT_BLOCK_LEN(mp
));
125 * Inode btree record insertion/removal modifies the inode btree and free space
126 * btrees (since the inobt does not use the agfl). This requires the following
129 * the inode btree: max depth * blocksize
130 * the allocation btrees: 2 trees * (max depth - 1) * block size
132 * The caller must account for SB and AG header modifications, etc.
136 struct xfs_mount
*mp
)
138 return xfs_calc_buf_res(M_IGEO(mp
)->inobt_maxlevels
,
139 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_ino_geo.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(M_IGEO(mp
)->ialloc_blks
, size
);
201 * Various log reservation values.
203 * These are based on the size of the file system block because that is what
204 * most transactions manipulate. Each adds in an additional 128 bytes per
205 * item logged to try to account for the overhead of the transaction mechanism.
207 * Note: Most of the reservations underestimate the number of allocation
208 * groups into which they could free extents in the xfs_defer_finish() call.
209 * This is because the number in the worst case is quite high and quite
210 * unusual. In order to fix this we need to change xfs_defer_finish() to free
211 * extents in only a single AG at a time. This will require changes to the
212 * EFI code as well, however, so that the EFI for the extents not freed is
213 * logged again in each transaction. See SGI PV #261917.
215 * Reservation functions here avoid a huge stack in xfs_trans_init due to
216 * register overflow from temporaries in the calculations.
221 * In a write transaction we can allocate a maximum of 2
222 * extents. This gives:
223 * the inode getting the new extents: inode size
224 * the inode's bmap btree: max depth * block size
225 * the agfs of the ags from which the extents are allocated: 2 * sector
226 * the superblock free block counter: sector size
227 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
228 * And the bmap_finish transaction can free bmap blocks in a join:
229 * the agfs of the ags containing the blocks: 2 * sector size
230 * the agfls of the ags containing the blocks: 2 * sector size
231 * the super block free block counter: sector size
232 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
235 xfs_calc_write_reservation(
236 struct xfs_mount
*mp
)
238 return XFS_DQUOT_LOGRES(mp
) +
239 max((xfs_calc_inode_res(mp
, 1) +
240 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
241 XFS_FSB_TO_B(mp
, 1)) +
242 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
243 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
244 XFS_FSB_TO_B(mp
, 1))),
245 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
246 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
247 XFS_FSB_TO_B(mp
, 1))));
251 * In truncating a file we free up to two extents at once. We can modify:
252 * the inode being truncated: inode size
253 * the inode's bmap btree: (max depth + 1) * block size
254 * And the bmap_finish transaction can free the blocks and bmap blocks:
255 * the agf for each of the ags: 4 * sector size
256 * the agfl for each of the ags: 4 * sector size
257 * the super block to reflect the freed blocks: sector size
258 * worst case split in allocation btrees per extent assuming 4 extents:
259 * 4 exts * 2 trees * (2 * max depth - 1) * block size
262 xfs_calc_itruncate_reservation(
263 struct xfs_mount
*mp
)
265 return XFS_DQUOT_LOGRES(mp
) +
266 max((xfs_calc_inode_res(mp
, 1) +
267 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1,
268 XFS_FSB_TO_B(mp
, 1))),
269 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
270 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
271 XFS_FSB_TO_B(mp
, 1))));
275 * In renaming a files we can modify:
276 * the four inodes involved: 4 * inode size
277 * the two directory btrees: 2 * (max depth + v2) * dir block size
278 * the two directory bmap btrees: 2 * max depth * block size
279 * And the bmap_finish transaction can free dir and bmap blocks (two sets
280 * of bmap blocks) giving:
281 * the agf for the ags in which the blocks live: 3 * sector size
282 * the agfl for the ags in which the blocks live: 3 * sector size
283 * the superblock for the free block count: sector size
284 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
287 xfs_calc_rename_reservation(
288 struct xfs_mount
*mp
)
290 return XFS_DQUOT_LOGRES(mp
) +
291 max((xfs_calc_inode_res(mp
, 4) +
292 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
293 XFS_FSB_TO_B(mp
, 1))),
294 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
295 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 3),
296 XFS_FSB_TO_B(mp
, 1))));
300 * For removing an inode from unlinked list at first, we can modify:
301 * the agi hash list and counters: sector size
302 * the on disk inode before ours in the agi hash list: inode cluster size
303 * the on disk inode in the agi hash list: inode cluster size
306 xfs_calc_iunlink_remove_reservation(
307 struct xfs_mount
*mp
)
309 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
310 2 * max_t(uint
, XFS_FSB_TO_B(mp
, 1),
311 M_IGEO(mp
)->inode_cluster_size
);
315 * For creating a link to an inode:
316 * the parent directory inode: inode size
317 * the linked inode: inode size
318 * the directory btree could split: (max depth + v2) * dir block size
319 * the directory bmap btree could join or split: (max depth + v2) * blocksize
320 * And the bmap_finish transaction can free some bmap blocks giving:
321 * the agf for the ag in which the blocks live: sector size
322 * the agfl for the ag in which the blocks live: sector size
323 * the superblock for the free block count: sector size
324 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
327 xfs_calc_link_reservation(
328 struct xfs_mount
*mp
)
330 return XFS_DQUOT_LOGRES(mp
) +
331 xfs_calc_iunlink_remove_reservation(mp
) +
332 max((xfs_calc_inode_res(mp
, 2) +
333 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
334 XFS_FSB_TO_B(mp
, 1))),
335 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
336 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
337 XFS_FSB_TO_B(mp
, 1))));
341 * For adding an inode to unlinked list we can modify:
342 * the agi hash list: sector size
343 * the on disk inode: inode cluster size
346 xfs_calc_iunlink_add_reservation(xfs_mount_t
*mp
)
348 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
349 max_t(uint
, XFS_FSB_TO_B(mp
, 1),
350 M_IGEO(mp
)->inode_cluster_size
);
354 * For removing a directory entry we can modify:
355 * the parent directory inode: inode size
356 * the removed inode: inode size
357 * the directory btree could join: (max depth + v2) * dir block size
358 * the directory bmap btree could join or split: (max depth + v2) * blocksize
359 * And the bmap_finish transaction can free the dir and bmap blocks giving:
360 * the agf for the ag in which the blocks live: 2 * sector size
361 * the agfl for the ag in which the blocks live: 2 * sector size
362 * the superblock for the free block count: sector size
363 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
366 xfs_calc_remove_reservation(
367 struct xfs_mount
*mp
)
369 return XFS_DQUOT_LOGRES(mp
) +
370 xfs_calc_iunlink_add_reservation(mp
) +
371 max((xfs_calc_inode_res(mp
, 1) +
372 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
373 XFS_FSB_TO_B(mp
, 1))),
374 (xfs_calc_buf_res(4, mp
->m_sb
.sb_sectsize
) +
375 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
376 XFS_FSB_TO_B(mp
, 1))));
380 * For create, break it in to the two cases that the transaction
381 * covers. We start with the modify case - allocation done by modification
382 * of the state of existing inodes - and the allocation case.
386 * For create we can modify:
387 * the parent directory inode: inode size
388 * the new inode: inode size
389 * the inode btree entry: block size
390 * the superblock for the nlink flag: sector size
391 * the directory btree: (max depth + v2) * dir block size
392 * the directory inode's bmap btree: (max depth + v2) * block size
393 * the finobt (record modification and allocation btrees)
396 xfs_calc_create_resv_modify(
397 struct xfs_mount
*mp
)
399 return xfs_calc_inode_res(mp
, 2) +
400 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
401 (uint
)XFS_FSB_TO_B(mp
, 1) +
402 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1)) +
403 xfs_calc_finobt_res(mp
);
407 * For icreate we can allocate some inodes giving:
408 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
409 * the superblock for the nlink flag: sector size
410 * the inode chunk (allocation, optional init)
411 * the inobt (record insertion)
412 * the finobt (optional, record insertion)
415 xfs_calc_icreate_resv_alloc(
416 struct xfs_mount
*mp
)
418 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
419 mp
->m_sb
.sb_sectsize
+
420 xfs_calc_inode_chunk_res(mp
, _ALLOC
) +
421 xfs_calc_inobt_res(mp
) +
422 xfs_calc_finobt_res(mp
);
426 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
428 return XFS_DQUOT_LOGRES(mp
) +
429 max(xfs_calc_icreate_resv_alloc(mp
),
430 xfs_calc_create_resv_modify(mp
));
434 xfs_calc_create_tmpfile_reservation(
435 struct xfs_mount
*mp
)
437 uint res
= XFS_DQUOT_LOGRES(mp
);
439 res
+= xfs_calc_icreate_resv_alloc(mp
);
440 return res
+ xfs_calc_iunlink_add_reservation(mp
);
444 * Making a new directory is the same as creating a new file.
447 xfs_calc_mkdir_reservation(
448 struct xfs_mount
*mp
)
450 return xfs_calc_icreate_reservation(mp
);
455 * Making a new symplink is the same as creating a new file, but
456 * with the added blocks for remote symlink data which can be up to 1kB in
457 * length (XFS_SYMLINK_MAXLEN).
460 xfs_calc_symlink_reservation(
461 struct xfs_mount
*mp
)
463 return xfs_calc_icreate_reservation(mp
) +
464 xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN
);
468 * In freeing an inode we can modify:
469 * the inode being freed: inode size
470 * the super block free inode counter, AGF and AGFL: sector size
471 * the on disk inode (agi unlinked list removal)
472 * the inode chunk (invalidated, headers only)
474 * the finobt (record insertion, removal or modification)
476 * Note that the inode chunk res. includes an allocfree res. for freeing of the
477 * inode chunk. This is technically extraneous because the inode chunk free is
478 * deferred (it occurs after a transaction roll). Include the extra reservation
479 * anyways since we've had reports of ifree transaction overruns due to too many
480 * agfl fixups during inode chunk frees.
483 xfs_calc_ifree_reservation(
484 struct xfs_mount
*mp
)
486 return XFS_DQUOT_LOGRES(mp
) +
487 xfs_calc_inode_res(mp
, 1) +
488 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
489 xfs_calc_iunlink_remove_reservation(mp
) +
490 xfs_calc_inode_chunk_res(mp
, _FREE
) +
491 xfs_calc_inobt_res(mp
) +
492 xfs_calc_finobt_res(mp
);
496 * When only changing the inode we log the inode and possibly the superblock
497 * We also add a bit of slop for the transaction stuff.
500 xfs_calc_ichange_reservation(
501 struct xfs_mount
*mp
)
503 return XFS_DQUOT_LOGRES(mp
) +
504 xfs_calc_inode_res(mp
, 1) +
505 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
510 * Growing the data section of the filesystem.
516 xfs_calc_growdata_reservation(
517 struct xfs_mount
*mp
)
519 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
520 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
521 XFS_FSB_TO_B(mp
, 1));
525 * Growing the rt section of the filesystem.
526 * In the first set of transactions (ALLOC) we allocate space to the
527 * bitmap or summary files.
528 * superblock: sector size
529 * agf of the ag from which the extent is allocated: sector size
530 * bmap btree for bitmap/summary inode: max depth * blocksize
531 * bitmap/summary inode: inode size
532 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
535 xfs_calc_growrtalloc_reservation(
536 struct xfs_mount
*mp
)
538 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
539 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
540 XFS_FSB_TO_B(mp
, 1)) +
541 xfs_calc_inode_res(mp
, 1) +
542 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
543 XFS_FSB_TO_B(mp
, 1));
547 * Growing the rt section of the filesystem.
548 * In the second set of transactions (ZERO) we zero the new metadata blocks.
549 * one bitmap/summary block: blocksize
552 xfs_calc_growrtzero_reservation(
553 struct xfs_mount
*mp
)
555 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
559 * Growing the rt section of the filesystem.
560 * In the third set of transactions (FREE) we update metadata without
561 * allocating any new blocks.
562 * superblock: sector size
563 * bitmap inode: inode size
564 * summary inode: inode size
565 * one bitmap block: blocksize
566 * summary blocks: new summary size
569 xfs_calc_growrtfree_reservation(
570 struct xfs_mount
*mp
)
572 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
573 xfs_calc_inode_res(mp
, 2) +
574 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
575 xfs_calc_buf_res(1, mp
->m_rsumsize
);
579 * Logging the inode modification timestamp on a synchronous write.
583 xfs_calc_swrite_reservation(
584 struct xfs_mount
*mp
)
586 return xfs_calc_inode_res(mp
, 1);
590 * Logging the inode mode bits when writing a setuid/setgid file
594 xfs_calc_writeid_reservation(
595 struct xfs_mount
*mp
)
597 return xfs_calc_inode_res(mp
, 1);
601 * Converting the inode from non-attributed to attributed.
602 * the inode being converted: inode size
603 * agf block and superblock (for block allocation)
604 * the new block (directory sized)
605 * bmap blocks for the new directory block
609 xfs_calc_addafork_reservation(
610 struct xfs_mount
*mp
)
612 return XFS_DQUOT_LOGRES(mp
) +
613 xfs_calc_inode_res(mp
, 1) +
614 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
615 xfs_calc_buf_res(1, mp
->m_dir_geo
->blksize
) +
616 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
617 XFS_FSB_TO_B(mp
, 1)) +
618 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
619 XFS_FSB_TO_B(mp
, 1));
623 * Removing the attribute fork of a file
624 * the inode being truncated: inode size
625 * the inode's bmap btree: max depth * block size
626 * And the bmap_finish transaction can free the blocks and bmap blocks:
627 * the agf for each of the ags: 4 * sector size
628 * the agfl for each of the ags: 4 * sector size
629 * the super block to reflect the freed blocks: sector size
630 * worst case split in allocation btrees per extent assuming 4 extents:
631 * 4 exts * 2 trees * (2 * max depth - 1) * block size
634 xfs_calc_attrinval_reservation(
635 struct xfs_mount
*mp
)
637 return max((xfs_calc_inode_res(mp
, 1) +
638 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
639 XFS_FSB_TO_B(mp
, 1))),
640 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
641 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
642 XFS_FSB_TO_B(mp
, 1))));
646 * Setting an attribute at mount time.
647 * the inode getting the attribute
648 * the superblock for allocations
649 * the agfs extents are allocated from
650 * the attribute btree * max depth
651 * the inode allocation btree
652 * Since attribute transaction space is dependent on the size of the attribute,
653 * the calculation is done partially at mount time and partially at runtime(see
657 xfs_calc_attrsetm_reservation(
658 struct xfs_mount
*mp
)
660 return XFS_DQUOT_LOGRES(mp
) +
661 xfs_calc_inode_res(mp
, 1) +
662 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
663 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
667 * Setting an attribute at runtime, transaction space unit per block.
668 * the superblock for allocations: sector size
669 * the inode bmap btree could join or split: max depth * block size
670 * Since the runtime attribute transaction space is dependent on the total
671 * blocks needed for the 1st bmap, here we calculate out the space unit for
672 * one block so that the caller could figure out the total space according
673 * to the attibute extent length in blocks by:
674 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
677 xfs_calc_attrsetrt_reservation(
678 struct xfs_mount
*mp
)
680 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
681 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
682 XFS_FSB_TO_B(mp
, 1));
686 * Removing an attribute.
687 * the inode: inode size
688 * the attribute btree could join: max depth * block size
689 * the inode bmap btree could join or split: max depth * block size
690 * And the bmap_finish transaction can free the attr blocks freed giving:
691 * the agf for the ag in which the blocks live: 2 * sector size
692 * the agfl for the ag in which the blocks live: 2 * sector size
693 * the superblock for the free block count: sector size
694 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
697 xfs_calc_attrrm_reservation(
698 struct xfs_mount
*mp
)
700 return XFS_DQUOT_LOGRES(mp
) +
701 max((xfs_calc_inode_res(mp
, 1) +
702 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
703 XFS_FSB_TO_B(mp
, 1)) +
704 (uint
)XFS_FSB_TO_B(mp
,
705 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
706 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
707 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
708 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
709 XFS_FSB_TO_B(mp
, 1))));
713 * Clearing a bad agino number in an agi hash bucket.
716 xfs_calc_clear_agi_bucket_reservation(
717 struct xfs_mount
*mp
)
719 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
723 * Adjusting quota limits.
724 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
727 xfs_calc_qm_setqlim_reservation(void)
729 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot
));
733 * Allocating quota on disk if needed.
734 * the write transaction log space for quota file extent allocation
735 * the unit of quota allocation: one system block size
738 xfs_calc_qm_dqalloc_reservation(
739 struct xfs_mount
*mp
)
741 return xfs_calc_write_reservation(mp
) +
743 XFS_FSB_TO_B(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
) - 1);
747 * Turning off quotas.
748 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
749 * the superblock for the quota flags: sector size
752 xfs_calc_qm_quotaoff_reservation(
753 struct xfs_mount
*mp
)
755 return sizeof(struct xfs_qoff_logitem
) * 2 +
756 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
760 * End of turning off quotas.
761 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
764 xfs_calc_qm_quotaoff_end_reservation(void)
766 return sizeof(struct xfs_qoff_logitem
) * 2;
770 * Syncing the incore super block changes to disk.
771 * the super block to reflect the changes: sector size
774 xfs_calc_sb_reservation(
775 struct xfs_mount
*mp
)
777 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
782 struct xfs_mount
*mp
,
783 struct xfs_trans_resv
*resp
)
786 * The following transactions are logged in physical format and
787 * require a permanent reservation on space.
789 resp
->tr_write
.tr_logres
= xfs_calc_write_reservation(mp
);
790 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
791 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
793 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
794 resp
->tr_write
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
796 resp
->tr_itruncate
.tr_logres
= xfs_calc_itruncate_reservation(mp
);
797 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
798 resp
->tr_itruncate
.tr_logcount
=
799 XFS_ITRUNCATE_LOG_COUNT_REFLINK
;
801 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
802 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
804 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
805 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
806 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
808 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
809 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
810 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
812 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
813 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
814 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
816 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
817 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
818 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
820 resp
->tr_create
.tr_logres
= xfs_calc_icreate_reservation(mp
);
821 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
822 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
824 resp
->tr_create_tmpfile
.tr_logres
=
825 xfs_calc_create_tmpfile_reservation(mp
);
826 resp
->tr_create_tmpfile
.tr_logcount
= XFS_CREATE_TMPFILE_LOG_COUNT
;
827 resp
->tr_create_tmpfile
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
829 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
830 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
831 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
833 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
834 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
835 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
837 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
838 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
839 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
841 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
842 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
843 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
845 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
846 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
847 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
849 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
850 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
851 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
853 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
854 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
855 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
857 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
);
858 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
859 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
861 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
862 resp
->tr_qm_dqalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
865 * The following transactions are logged in logical format with
866 * a default log count.
868 resp
->tr_qm_setqlim
.tr_logres
= xfs_calc_qm_setqlim_reservation();
869 resp
->tr_qm_setqlim
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
871 resp
->tr_qm_quotaoff
.tr_logres
= xfs_calc_qm_quotaoff_reservation(mp
);
872 resp
->tr_qm_quotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
874 resp
->tr_qm_equotaoff
.tr_logres
=
875 xfs_calc_qm_quotaoff_end_reservation();
876 resp
->tr_qm_equotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
878 resp
->tr_sb
.tr_logres
= xfs_calc_sb_reservation(mp
);
879 resp
->tr_sb
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
881 /* growdata requires permanent res; it can free space to the last AG */
882 resp
->tr_growdata
.tr_logres
= xfs_calc_growdata_reservation(mp
);
883 resp
->tr_growdata
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
884 resp
->tr_growdata
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
886 /* The following transaction are logged in logical format */
887 resp
->tr_ichange
.tr_logres
= xfs_calc_ichange_reservation(mp
);
888 resp
->tr_fsyncts
.tr_logres
= xfs_calc_swrite_reservation(mp
);
889 resp
->tr_writeid
.tr_logres
= xfs_calc_writeid_reservation(mp
);
890 resp
->tr_attrsetrt
.tr_logres
= xfs_calc_attrsetrt_reservation(mp
);
891 resp
->tr_clearagi
.tr_logres
= xfs_calc_clear_agi_bucket_reservation(mp
);
892 resp
->tr_growrtzero
.tr_logres
= xfs_calc_growrtzero_reservation(mp
);
893 resp
->tr_growrtfree
.tr_logres
= xfs_calc_growrtfree_reservation(mp
);