2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * Copyright (C) 2010 Red Hat, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "xfs_shared.h"
22 #include "xfs_format.h"
23 #include "xfs_log_format.h"
24 #include "xfs_trans_resv.h"
26 #include "xfs_mount.h"
27 #include "xfs_da_format.h"
28 #include "xfs_da_btree.h"
29 #include "xfs_inode.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_ialloc.h"
32 #include "xfs_quota.h"
33 #include "xfs_trans.h"
35 #include "xfs_trans_space.h"
36 #include "xfs_trace.h"
39 * A buffer has a format structure overhead in the log in addition
40 * to the data, so we need to take this into account when reserving
41 * space in a transaction for a buffer. Round the space required up
42 * to a multiple of 128 bytes so that we don't change the historical
43 * reservation that has been used for this overhead.
46 xfs_buf_log_overhead(void)
48 return round_up(sizeof(struct xlog_op_header) +
49 sizeof(struct xfs_buf_log_format), 128);
53 * Calculate out transaction log reservation per item in bytes.
55 * The nbufs argument is used to indicate the number of items that
56 * will be changed in a transaction. size is used to tell how many
57 * bytes should be reserved per item.
64 return nbufs * (size + xfs_buf_log_overhead());
68 * Logging inodes is really tricksy. They are logged in memory format,
69 * which means that what we write into the log doesn't directly translate into
70 * the amount of space they use on disk.
72 * Case in point - btree format forks in memory format use more space than the
73 * on-disk format. In memory, the buffer contains a normal btree block header so
74 * the btree code can treat it as though it is just another generic buffer.
75 * However, when we write it to the inode fork, we don't write all of this
76 * header as it isn't needed. e.g. the root is only ever in the inode, so
77 * there's no need for sibling pointers which would waste 16 bytes of space.
79 * Hence when we have an inode with a maximally sized btree format fork, then
80 * amount of information we actually log is greater than the size of the inode
81 * on disk. Hence we need an inode reservation function that calculates all this
82 * correctly. So, we log:
84 * - 4 log op headers for object
85 * - for the ilf, the inode core and 2 forks
86 * - inode log format object
88 * - two inode forks containing bmap btree root blocks.
89 * - the btree data contained by both forks will fit into the inode size,
90 * hence when combined with the inode core above, we have a total of the
92 * - the BMBT headers need to be accounted separately, as they are
93 * additional to the records and pointers that fit inside the inode
102 (4 * sizeof(struct xlog_op_header) +
103 sizeof(struct xfs_inode_log_format) +
104 mp->m_sb.sb_inodesize +
105 2 * XFS_BMBT_BLOCK_LEN(mp));
109 * The free inode btree is a conditional feature and the log reservation
110 * requirements differ slightly from that of the traditional inode allocation
111 * btree. The finobt tracks records for inode chunks with at least one free
112 * inode. A record can be removed from the tree for an inode allocation
113 * or free and thus the finobt reservation is unconditional across:
117 * - inode chunk allocation
119 * The 'modify' param indicates to include the record modification scenario. The
120 * 'alloc' param indicates to include the reservation for free space btree
121 * modifications on behalf of finobt modifications. This is required only for
122 * transactions that do not already account for free space btree modifications.
124 * the free inode btree: max depth * block size
125 * the allocation btrees: 2 trees * (max depth - 1) * block size
126 * the free inode btree entry: block size
130 struct xfs_mount *mp,
136 if (!xfs_sb_version_hasfinobt(&mp->m_sb))
139 res = xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1));
141 res += xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
142 XFS_FSB_TO_B(mp, 1));
144 res += (uint)XFS_FSB_TO_B(mp, 1);
150 * Various log reservation values.
152 * These are based on the size of the file system block because that is what
153 * most transactions manipulate. Each adds in an additional 128 bytes per
154 * item logged to try to account for the overhead of the transaction mechanism.
156 * Note: Most of the reservations underestimate the number of allocation
157 * groups into which they could free extents in the xfs_bmap_finish() call.
158 * This is because the number in the worst case is quite high and quite
159 * unusual. In order to fix this we need to change xfs_bmap_finish() to free
160 * extents in only a single AG at a time. This will require changes to the
161 * EFI code as well, however, so that the EFI for the extents not freed is
162 * logged again in each transaction. See SGI PV #261917.
164 * Reservation functions here avoid a huge stack in xfs_trans_init due to
165 * register overflow from temporaries in the calculations.
170 * In a write transaction we can allocate a maximum of 2
171 * extents. This gives:
172 * the inode getting the new extents: inode size
173 * the inode's bmap btree: max depth * block size
174 * the agfs of the ags from which the extents are allocated: 2 * sector
175 * the superblock free block counter: sector size
176 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
177 * And the bmap_finish transaction can free bmap blocks in a join:
178 * the agfs of the ags containing the blocks: 2 * sector size
179 * the agfls of the ags containing the blocks: 2 * sector size
180 * the super block free block counter: sector size
181 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
184 xfs_calc_write_reservation(
185 struct xfs_mount *mp)
187 return XFS_DQUOT_LOGRES(mp) +
188 MAX((xfs_calc_inode_res(mp, 1) +
189 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
190 XFS_FSB_TO_B(mp, 1)) +
191 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
192 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
193 XFS_FSB_TO_B(mp, 1))),
194 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
195 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
196 XFS_FSB_TO_B(mp, 1))));
200 * In truncating a file we free up to two extents at once. We can modify:
201 * the inode being truncated: inode size
202 * the inode's bmap btree: (max depth + 1) * block size
203 * And the bmap_finish transaction can free the blocks and bmap blocks:
204 * the agf for each of the ags: 4 * sector size
205 * the agfl for each of the ags: 4 * sector size
206 * the super block to reflect the freed blocks: sector size
207 * worst case split in allocation btrees per extent assuming 4 extents:
208 * 4 exts * 2 trees * (2 * max depth - 1) * block size
209 * the inode btree: max depth * blocksize
210 * the allocation btrees: 2 trees * (max depth - 1) * block size
213 xfs_calc_itruncate_reservation(
214 struct xfs_mount *mp)
216 return XFS_DQUOT_LOGRES(mp) +
217 MAX((xfs_calc_inode_res(mp, 1) +
218 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
219 XFS_FSB_TO_B(mp, 1))),
220 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
221 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
222 XFS_FSB_TO_B(mp, 1)) +
223 xfs_calc_buf_res(5, 0) +
224 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
225 XFS_FSB_TO_B(mp, 1)) +
226 xfs_calc_buf_res(2 + mp->m_ialloc_blks +
227 mp->m_in_maxlevels, 0)));
231 * In renaming a files we can modify:
232 * the four inodes involved: 4 * inode size
233 * the two directory btrees: 2 * (max depth + v2) * dir block size
234 * the two directory bmap btrees: 2 * max depth * block size
235 * And the bmap_finish transaction can free dir and bmap blocks (two sets
236 * of bmap blocks) giving:
237 * the agf for the ags in which the blocks live: 3 * sector size
238 * the agfl for the ags in which the blocks live: 3 * sector size
239 * the superblock for the free block count: sector size
240 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
243 xfs_calc_rename_reservation(
244 struct xfs_mount *mp)
246 return XFS_DQUOT_LOGRES(mp) +
247 MAX((xfs_calc_inode_res(mp, 4) +
248 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
249 XFS_FSB_TO_B(mp, 1))),
250 (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
251 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3),
252 XFS_FSB_TO_B(mp, 1))));
256 * For removing an inode from unlinked list at first, we can modify:
257 * the agi hash list and counters: sector size
258 * the on disk inode before ours in the agi hash list: inode cluster size
261 xfs_calc_iunlink_remove_reservation(
262 struct xfs_mount *mp)
264 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
265 max_t(uint, XFS_FSB_TO_B(mp, 1), mp->m_inode_cluster_size);
269 * For creating a link to an inode:
270 * the parent directory inode: inode size
271 * the linked inode: inode size
272 * the directory btree could split: (max depth + v2) * dir block size
273 * the directory bmap btree could join or split: (max depth + v2) * blocksize
274 * And the bmap_finish transaction can free some bmap blocks giving:
275 * the agf for the ag in which the blocks live: sector size
276 * the agfl for the ag in which the blocks live: sector size
277 * the superblock for the free block count: sector size
278 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
281 xfs_calc_link_reservation(
282 struct xfs_mount *mp)
284 return XFS_DQUOT_LOGRES(mp) +
285 xfs_calc_iunlink_remove_reservation(mp) +
286 MAX((xfs_calc_inode_res(mp, 2) +
287 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
288 XFS_FSB_TO_B(mp, 1))),
289 (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
290 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
291 XFS_FSB_TO_B(mp, 1))));
295 * For adding an inode to unlinked list we can modify:
296 * the agi hash list: sector size
297 * the unlinked inode: inode size
300 xfs_calc_iunlink_add_reservation(xfs_mount_t *mp)
302 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
303 xfs_calc_inode_res(mp, 1);
307 * For removing a directory entry we can modify:
308 * the parent directory inode: inode size
309 * the removed inode: inode size
310 * the directory btree could join: (max depth + v2) * dir block size
311 * the directory bmap btree could join or split: (max depth + v2) * blocksize
312 * And the bmap_finish transaction can free the dir and bmap blocks giving:
313 * the agf for the ag in which the blocks live: 2 * sector size
314 * the agfl for the ag in which the blocks live: 2 * sector size
315 * the superblock for the free block count: sector size
316 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
319 xfs_calc_remove_reservation(
320 struct xfs_mount *mp)
322 return XFS_DQUOT_LOGRES(mp) +
323 xfs_calc_iunlink_add_reservation(mp) +
324 MAX((xfs_calc_inode_res(mp, 1) +
325 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
326 XFS_FSB_TO_B(mp, 1))),
327 (xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) +
328 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
329 XFS_FSB_TO_B(mp, 1))));
333 * For create, break it in to the two cases that the transaction
334 * covers. We start with the modify case - allocation done by modification
335 * of the state of existing inodes - and the allocation case.
339 * For create we can modify:
340 * the parent directory inode: inode size
341 * the new inode: inode size
342 * the inode btree entry: block size
343 * the superblock for the nlink flag: sector size
344 * the directory btree: (max depth + v2) * dir block size
345 * the directory inode's bmap btree: (max depth + v2) * block size
346 * the finobt (record modification and allocation btrees)
349 xfs_calc_create_resv_modify(
350 struct xfs_mount *mp)
352 return xfs_calc_inode_res(mp, 2) +
353 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
354 (uint)XFS_FSB_TO_B(mp, 1) +
355 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)) +
356 xfs_calc_finobt_res(mp, 1, 1);
360 * For create we can allocate some inodes giving:
361 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
362 * the superblock for the nlink flag: sector size
363 * the inode blocks allocated: mp->m_ialloc_blks * blocksize
364 * the inode btree: max depth * blocksize
365 * the allocation btrees: 2 trees * (max depth - 1) * block size
368 xfs_calc_create_resv_alloc(
369 struct xfs_mount *mp)
371 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
372 mp->m_sb.sb_sectsize +
373 xfs_calc_buf_res(mp->m_ialloc_blks, XFS_FSB_TO_B(mp, 1)) +
374 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
375 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
376 XFS_FSB_TO_B(mp, 1));
380 __xfs_calc_create_reservation(
381 struct xfs_mount *mp)
383 return XFS_DQUOT_LOGRES(mp) +
384 MAX(xfs_calc_create_resv_alloc(mp),
385 xfs_calc_create_resv_modify(mp));
389 * For icreate we can allocate some inodes giving:
390 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
391 * the superblock for the nlink flag: sector size
392 * the inode btree: max depth * blocksize
393 * the allocation btrees: 2 trees * (max depth - 1) * block size
394 * the finobt (record insertion)
397 xfs_calc_icreate_resv_alloc(
398 struct xfs_mount *mp)
400 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
401 mp->m_sb.sb_sectsize +
402 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
403 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
404 XFS_FSB_TO_B(mp, 1)) +
405 xfs_calc_finobt_res(mp, 0, 0);
409 xfs_calc_icreate_reservation(xfs_mount_t *mp)
411 return XFS_DQUOT_LOGRES(mp) +
412 MAX(xfs_calc_icreate_resv_alloc(mp),
413 xfs_calc_create_resv_modify(mp));
417 xfs_calc_create_reservation(
418 struct xfs_mount *mp)
420 if (xfs_sb_version_hascrc(&mp->m_sb))
421 return xfs_calc_icreate_reservation(mp);
422 return __xfs_calc_create_reservation(mp);
427 xfs_calc_create_tmpfile_reservation(
428 struct xfs_mount *mp)
430 uint res = XFS_DQUOT_LOGRES(mp);
432 if (xfs_sb_version_hascrc(&mp->m_sb))
433 res += xfs_calc_icreate_resv_alloc(mp);
435 res += xfs_calc_create_resv_alloc(mp);
437 return res + xfs_calc_iunlink_add_reservation(mp);
441 * Making a new directory is the same as creating a new file.
444 xfs_calc_mkdir_reservation(
445 struct xfs_mount *mp)
447 return xfs_calc_create_reservation(mp);
452 * Making a new symplink is the same as creating a new file, but
453 * with the added blocks for remote symlink data which can be up to 1kB in
454 * length (MAXPATHLEN).
457 xfs_calc_symlink_reservation(
458 struct xfs_mount *mp)
460 return xfs_calc_create_reservation(mp) +
461 xfs_calc_buf_res(1, MAXPATHLEN);
465 * In freeing an inode we can modify:
466 * the inode being freed: inode size
467 * the super block free inode counter: sector size
468 * the agi hash list and counters: sector size
469 * the inode btree entry: block size
470 * the on disk inode before ours in the agi hash list: inode cluster size
471 * the inode btree: max depth * blocksize
472 * the allocation btrees: 2 trees * (max depth - 1) * block size
473 * the finobt (record insertion, removal or modification)
476 xfs_calc_ifree_reservation(
477 struct xfs_mount *mp)
479 return XFS_DQUOT_LOGRES(mp) +
480 xfs_calc_inode_res(mp, 1) +
481 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
482 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
483 xfs_calc_iunlink_remove_reservation(mp) +
484 xfs_calc_buf_res(1, 0) +
485 xfs_calc_buf_res(2 + mp->m_ialloc_blks +
486 mp->m_in_maxlevels, 0) +
487 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
488 XFS_FSB_TO_B(mp, 1)) +
489 xfs_calc_finobt_res(mp, 0, 1);
493 * When only changing the inode we log the inode and possibly the superblock
494 * We also add a bit of slop for the transaction stuff.
497 xfs_calc_ichange_reservation(
498 struct xfs_mount *mp)
500 return XFS_DQUOT_LOGRES(mp) +
501 xfs_calc_inode_res(mp, 1) +
502 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
507 * Growing the data section of the filesystem.
513 xfs_calc_growdata_reservation(
514 struct xfs_mount *mp)
516 return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
517 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
518 XFS_FSB_TO_B(mp, 1));
522 * Growing the rt section of the filesystem.
523 * In the first set of transactions (ALLOC) we allocate space to the
524 * bitmap or summary files.
525 * superblock: sector size
526 * agf of the ag from which the extent is allocated: sector size
527 * bmap btree for bitmap/summary inode: max depth * blocksize
528 * bitmap/summary inode: inode size
529 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
532 xfs_calc_growrtalloc_reservation(
533 struct xfs_mount *mp)
535 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
536 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
537 XFS_FSB_TO_B(mp, 1)) +
538 xfs_calc_inode_res(mp, 1) +
539 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
540 XFS_FSB_TO_B(mp, 1));
544 * Growing the rt section of the filesystem.
545 * In the second set of transactions (ZERO) we zero the new metadata blocks.
546 * one bitmap/summary block: blocksize
549 xfs_calc_growrtzero_reservation(
550 struct xfs_mount *mp)
552 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
556 * Growing the rt section of the filesystem.
557 * In the third set of transactions (FREE) we update metadata without
558 * allocating any new blocks.
559 * superblock: sector size
560 * bitmap inode: inode size
561 * summary inode: inode size
562 * one bitmap block: blocksize
563 * summary blocks: new summary size
566 xfs_calc_growrtfree_reservation(
567 struct xfs_mount *mp)
569 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
570 xfs_calc_inode_res(mp, 2) +
571 xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
572 xfs_calc_buf_res(1, mp->m_rsumsize);
576 * Logging the inode modification timestamp on a synchronous write.
580 xfs_calc_swrite_reservation(
581 struct xfs_mount *mp)
583 return xfs_calc_inode_res(mp, 1);
587 * Logging the inode mode bits when writing a setuid/setgid file
591 xfs_calc_writeid_reservation(
592 struct xfs_mount *mp)
594 return xfs_calc_inode_res(mp, 1);
598 * Converting the inode from non-attributed to attributed.
599 * the inode being converted: inode size
600 * agf block and superblock (for block allocation)
601 * the new block (directory sized)
602 * bmap blocks for the new directory block
606 xfs_calc_addafork_reservation(
607 struct xfs_mount *mp)
609 return XFS_DQUOT_LOGRES(mp) +
610 xfs_calc_inode_res(mp, 1) +
611 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
612 xfs_calc_buf_res(1, mp->m_dir_geo->blksize) +
613 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
614 XFS_FSB_TO_B(mp, 1)) +
615 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
616 XFS_FSB_TO_B(mp, 1));
620 * Removing the attribute fork of a file
621 * the inode being truncated: inode size
622 * the inode's bmap btree: max depth * block size
623 * And the bmap_finish transaction can free the blocks and bmap blocks:
624 * the agf for each of the ags: 4 * sector size
625 * the agfl for each of the ags: 4 * sector size
626 * the super block to reflect the freed blocks: sector size
627 * worst case split in allocation btrees per extent assuming 4 extents:
628 * 4 exts * 2 trees * (2 * max depth - 1) * block size
631 xfs_calc_attrinval_reservation(
632 struct xfs_mount *mp)
634 return MAX((xfs_calc_inode_res(mp, 1) +
635 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
636 XFS_FSB_TO_B(mp, 1))),
637 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
638 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
639 XFS_FSB_TO_B(mp, 1))));
643 * Setting an attribute at mount time.
644 * the inode getting the attribute
645 * the superblock for allocations
646 * the agfs extents are allocated from
647 * the attribute btree * max depth
648 * the inode allocation btree
649 * Since attribute transaction space is dependent on the size of the attribute,
650 * the calculation is done partially at mount time and partially at runtime(see
654 xfs_calc_attrsetm_reservation(
655 struct xfs_mount *mp)
657 return XFS_DQUOT_LOGRES(mp) +
658 xfs_calc_inode_res(mp, 1) +
659 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
660 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1));
664 * Setting an attribute at runtime, transaction space unit per block.
665 * the superblock for allocations: sector size
666 * the inode bmap btree could join or split: max depth * block size
667 * Since the runtime attribute transaction space is dependent on the total
668 * blocks needed for the 1st bmap, here we calculate out the space unit for
669 * one block so that the caller could figure out the total space according
670 * to the attibute extent length in blocks by:
671 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
674 xfs_calc_attrsetrt_reservation(
675 struct xfs_mount *mp)
677 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
678 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
679 XFS_FSB_TO_B(mp, 1));
683 * Removing an attribute.
684 * the inode: inode size
685 * the attribute btree could join: max depth * block size
686 * the inode bmap btree could join or split: max depth * block size
687 * And the bmap_finish transaction can free the attr blocks freed giving:
688 * the agf for the ag in which the blocks live: 2 * sector size
689 * the agfl for the ag in which the blocks live: 2 * sector size
690 * the superblock for the free block count: sector size
691 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
694 xfs_calc_attrrm_reservation(
695 struct xfs_mount *mp)
697 return XFS_DQUOT_LOGRES(mp) +
698 MAX((xfs_calc_inode_res(mp, 1) +
699 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH,
700 XFS_FSB_TO_B(mp, 1)) +
701 (uint)XFS_FSB_TO_B(mp,
702 XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
703 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
704 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
705 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
706 XFS_FSB_TO_B(mp, 1))));
710 * Clearing a bad agino number in an agi hash bucket.
713 xfs_calc_clear_agi_bucket_reservation(
714 struct xfs_mount *mp)
716 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
720 * Clearing the quotaflags in the superblock.
721 * the super block for changing quota flags: sector size
724 xfs_calc_qm_sbchange_reservation(
725 struct xfs_mount *mp)
727 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
731 * Adjusting quota limits.
732 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
735 xfs_calc_qm_setqlim_reservation(
736 struct xfs_mount *mp)
738 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
742 * Allocating quota on disk if needed.
743 * the write transaction log space for quota file extent allocation
744 * the unit of quota allocation: one system block size
747 xfs_calc_qm_dqalloc_reservation(
748 struct xfs_mount *mp)
750 return xfs_calc_write_reservation(mp) +
752 XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
756 * Turning off quotas.
757 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
758 * the superblock for the quota flags: sector size
761 xfs_calc_qm_quotaoff_reservation(
762 struct xfs_mount *mp)
764 return sizeof(struct xfs_qoff_logitem) * 2 +
765 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
769 * End of turning off quotas.
770 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
773 xfs_calc_qm_quotaoff_end_reservation(
774 struct xfs_mount *mp)
776 return sizeof(struct xfs_qoff_logitem) * 2;
780 * Syncing the incore super block changes to disk.
781 * the super block to reflect the changes: sector size
784 xfs_calc_sb_reservation(
785 struct xfs_mount *mp)
787 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
792 struct xfs_mount *mp,
793 struct xfs_trans_resv *resp)
796 * The following transactions are logged in physical format and
797 * require a permanent reservation on space.
799 resp->tr_write.tr_logres = xfs_calc_write_reservation(mp);
800 resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT;
801 resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
803 resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp);
804 resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
805 resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
807 resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp);
808 resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;
809 resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
811 resp->tr_link.tr_logres = xfs_calc_link_reservation(mp);
812 resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT;
813 resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
815 resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp);
816 resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT;
817 resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
819 resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp);
820 resp->tr_symlink.tr_logcount = XFS_SYMLINK_LOG_COUNT;
821 resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
823 resp->tr_create.tr_logres = xfs_calc_create_reservation(mp);
824 resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
825 resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
827 resp->tr_create_tmpfile.tr_logres =
828 xfs_calc_create_tmpfile_reservation(mp);
829 resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT;
830 resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
832 resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
833 resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
834 resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
836 resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp);
837 resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT;
838 resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
840 resp->tr_addafork.tr_logres = xfs_calc_addafork_reservation(mp);
841 resp->tr_addafork.tr_logcount = XFS_ADDAFORK_LOG_COUNT;
842 resp->tr_addafork.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
844 resp->tr_attrinval.tr_logres = xfs_calc_attrinval_reservation(mp);
845 resp->tr_attrinval.tr_logcount = XFS_ATTRINVAL_LOG_COUNT;
846 resp->tr_attrinval.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
848 resp->tr_attrsetm.tr_logres = xfs_calc_attrsetm_reservation(mp);
849 resp->tr_attrsetm.tr_logcount = XFS_ATTRSET_LOG_COUNT;
850 resp->tr_attrsetm.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
852 resp->tr_attrrm.tr_logres = xfs_calc_attrrm_reservation(mp);
853 resp->tr_attrrm.tr_logcount = XFS_ATTRRM_LOG_COUNT;
854 resp->tr_attrrm.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
856 resp->tr_growrtalloc.tr_logres = xfs_calc_growrtalloc_reservation(mp);
857 resp->tr_growrtalloc.tr_logcount = XFS_DEFAULT_PERM_LOG_COUNT;
858 resp->tr_growrtalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
860 resp->tr_qm_dqalloc.tr_logres = xfs_calc_qm_dqalloc_reservation(mp);
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_sbchange.tr_logres = xfs_calc_qm_sbchange_reservation(mp);
869 resp->tr_qm_sbchange.tr_logcount = XFS_DEFAULT_LOG_COUNT;
871 resp->tr_qm_setqlim.tr_logres = xfs_calc_qm_setqlim_reservation(mp);
872 resp->tr_qm_setqlim.tr_logcount = XFS_DEFAULT_LOG_COUNT;
874 resp->tr_qm_quotaoff.tr_logres = xfs_calc_qm_quotaoff_reservation(mp);
875 resp->tr_qm_quotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT;
877 resp->tr_qm_equotaoff.tr_logres =
878 xfs_calc_qm_quotaoff_end_reservation(mp);
879 resp->tr_qm_equotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT;
881 resp->tr_sb.tr_logres = xfs_calc_sb_reservation(mp);
882 resp->tr_sb.tr_logcount = XFS_DEFAULT_LOG_COUNT;
884 /* The following transaction are logged in logical format */
885 resp->tr_ichange.tr_logres = xfs_calc_ichange_reservation(mp);
886 resp->tr_growdata.tr_logres = xfs_calc_growdata_reservation(mp);
887 resp->tr_fsyncts.tr_logres = xfs_calc_swrite_reservation(mp);
888 resp->tr_writeid.tr_logres = xfs_calc_writeid_reservation(mp);
889 resp->tr_attrsetrt.tr_logres = xfs_calc_attrsetrt_reservation(mp);
890 resp->tr_clearagi.tr_logres = xfs_calc_clear_agi_bucket_reservation(mp);
891 resp->tr_growrtzero.tr_logres = xfs_calc_growrtzero_reservation(mp);
892 resp->tr_growrtfree.tr_logres = xfs_calc_growrtfree_reservation(mp);