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_format.h"
22 #include "xfs_shared.h"
24 #include "xfs_trans_resv.h"
25 #include "xfs_trans.h"
28 #include "xfs_mount.h"
29 #include "xfs_error.h"
30 #include "xfs_da_btree.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dinode.h"
35 #include "xfs_inode.h"
36 #include "xfs_btree.h"
37 #include "xfs_ialloc.h"
38 #include "xfs_alloc.h"
39 #include "xfs_extent_busy.h"
41 #include "xfs_bmap_util.h"
42 #include "xfs_quota.h"
44 #include "xfs_trans_space.h"
45 #include "xfs_trace.h"
48 * A buffer has a format structure overhead in the log in addition
49 * to the data, so we need to take this into account when reserving
50 * space in a transaction for a buffer. Round the space required up
51 * to a multiple of 128 bytes so that we don't change the historical
52 * reservation that has been used for this overhead.
55 xfs_buf_log_overhead(void)
57 return round_up(sizeof(struct xlog_op_header) +
58 sizeof(struct xfs_buf_log_format), 128);
62 * Calculate out transaction log reservation per item in bytes.
64 * The nbufs argument is used to indicate the number of items that
65 * will be changed in a transaction. size is used to tell how many
66 * bytes should be reserved per item.
73 return nbufs * (size + xfs_buf_log_overhead());
77 * Logging inodes is really tricksy. They are logged in memory format,
78 * which means that what we write into the log doesn't directly translate into
79 * the amount of space they use on disk.
81 * Case in point - btree format forks in memory format use more space than the
82 * on-disk format. In memory, the buffer contains a normal btree block header so
83 * the btree code can treat it as though it is just another generic buffer.
84 * However, when we write it to the inode fork, we don't write all of this
85 * header as it isn't needed. e.g. the root is only ever in the inode, so
86 * there's no need for sibling pointers which would waste 16 bytes of space.
88 * Hence when we have an inode with a maximally sized btree format fork, then
89 * amount of information we actually log is greater than the size of the inode
90 * on disk. Hence we need an inode reservation function that calculates all this
91 * correctly. So, we log:
93 * - log op headers for object
94 * - inode log format object
95 * - the entire inode contents (core + 2 forks)
96 * - two bmap btree block headers
100 struct xfs_mount *mp,
103 return ninodes * (sizeof(struct xlog_op_header) +
104 sizeof(struct xfs_inode_log_format) +
105 mp->m_sb.sb_inodesize +
106 2 * XFS_BMBT_BLOCK_LEN(mp));
110 * Various log reservation values.
112 * These are based on the size of the file system block because that is what
113 * most transactions manipulate. Each adds in an additional 128 bytes per
114 * item logged to try to account for the overhead of the transaction mechanism.
116 * Note: Most of the reservations underestimate the number of allocation
117 * groups into which they could free extents in the xfs_bmap_finish() call.
118 * This is because the number in the worst case is quite high and quite
119 * unusual. In order to fix this we need to change xfs_bmap_finish() to free
120 * extents in only a single AG at a time. This will require changes to the
121 * EFI code as well, however, so that the EFI for the extents not freed is
122 * logged again in each transaction. See SGI PV #261917.
124 * Reservation functions here avoid a huge stack in xfs_trans_init due to
125 * register overflow from temporaries in the calculations.
130 * In a write transaction we can allocate a maximum of 2
131 * extents. This gives:
132 * the inode getting the new extents: inode size
133 * the inode's bmap btree: max depth * block size
134 * the agfs of the ags from which the extents are allocated: 2 * sector
135 * the superblock free block counter: sector size
136 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
137 * And the bmap_finish transaction can free bmap blocks in a join:
138 * the agfs of the ags containing the blocks: 2 * sector size
139 * the agfls of the ags containing the blocks: 2 * sector size
140 * the super block free block counter: sector size
141 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
144 xfs_calc_write_reservation(
145 struct xfs_mount *mp)
147 return XFS_DQUOT_LOGRES(mp) +
148 MAX((xfs_calc_inode_res(mp, 1) +
149 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
150 XFS_FSB_TO_B(mp, 1)) +
151 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
152 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
153 XFS_FSB_TO_B(mp, 1))),
154 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
155 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
156 XFS_FSB_TO_B(mp, 1))));
160 * In truncating a file we free up to two extents at once. We can modify:
161 * the inode being truncated: inode size
162 * the inode's bmap btree: (max depth + 1) * block size
163 * And the bmap_finish transaction can free the blocks and bmap blocks:
164 * the agf for each of the ags: 4 * sector size
165 * the agfl for each of the ags: 4 * sector size
166 * the super block to reflect the freed blocks: sector size
167 * worst case split in allocation btrees per extent assuming 4 extents:
168 * 4 exts * 2 trees * (2 * max depth - 1) * block size
169 * the inode btree: max depth * blocksize
170 * the allocation btrees: 2 trees * (max depth - 1) * block size
173 xfs_calc_itruncate_reservation(
174 struct xfs_mount *mp)
176 return XFS_DQUOT_LOGRES(mp) +
177 MAX((xfs_calc_inode_res(mp, 1) +
178 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
179 XFS_FSB_TO_B(mp, 1))),
180 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
181 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
182 XFS_FSB_TO_B(mp, 1)) +
183 xfs_calc_buf_res(5, 0) +
184 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
185 XFS_FSB_TO_B(mp, 1)) +
186 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
187 mp->m_in_maxlevels, 0)));
191 * In renaming a files we can modify:
192 * the four inodes involved: 4 * inode size
193 * the two directory btrees: 2 * (max depth + v2) * dir block size
194 * the two directory bmap btrees: 2 * max depth * block size
195 * And the bmap_finish transaction can free dir and bmap blocks (two sets
196 * of bmap blocks) giving:
197 * the agf for the ags in which the blocks live: 3 * sector size
198 * the agfl for the ags in which the blocks live: 3 * sector size
199 * the superblock for the free block count: sector size
200 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
203 xfs_calc_rename_reservation(
204 struct xfs_mount *mp)
206 return XFS_DQUOT_LOGRES(mp) +
207 MAX((xfs_calc_inode_res(mp, 4) +
208 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
209 XFS_FSB_TO_B(mp, 1))),
210 (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
211 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3),
212 XFS_FSB_TO_B(mp, 1))));
216 * For creating a link to an inode:
217 * the parent directory inode: inode size
218 * the linked inode: inode size
219 * the directory btree could split: (max depth + v2) * dir block size
220 * the directory bmap btree could join or split: (max depth + v2) * blocksize
221 * And the bmap_finish transaction can free some bmap blocks giving:
222 * the agf for the ag in which the blocks live: sector size
223 * the agfl for the ag in which the blocks live: sector size
224 * the superblock for the free block count: sector size
225 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
228 xfs_calc_link_reservation(
229 struct xfs_mount *mp)
231 return XFS_DQUOT_LOGRES(mp) +
232 MAX((xfs_calc_inode_res(mp, 2) +
233 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
234 XFS_FSB_TO_B(mp, 1))),
235 (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
236 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
237 XFS_FSB_TO_B(mp, 1))));
241 * For removing a directory entry we can modify:
242 * the parent directory inode: inode size
243 * the removed inode: inode size
244 * the directory btree could join: (max depth + v2) * dir block size
245 * the directory bmap btree could join or split: (max depth + v2) * blocksize
246 * And the bmap_finish transaction can free the dir and bmap blocks giving:
247 * the agf for the ag in which the blocks live: 2 * sector size
248 * the agfl for the ag in which the blocks live: 2 * sector size
249 * the superblock for the free block count: sector size
250 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
253 xfs_calc_remove_reservation(
254 struct xfs_mount *mp)
256 return XFS_DQUOT_LOGRES(mp) +
257 MAX((xfs_calc_inode_res(mp, 2) +
258 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
259 XFS_FSB_TO_B(mp, 1))),
260 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
261 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
262 XFS_FSB_TO_B(mp, 1))));
266 * For create, break it in to the two cases that the transaction
267 * covers. We start with the modify case - allocation done by modification
268 * of the state of existing inodes - and the allocation case.
272 * For create we can modify:
273 * the parent directory inode: inode size
274 * the new inode: inode size
275 * the inode btree entry: block size
276 * the superblock for the nlink flag: sector size
277 * the directory btree: (max depth + v2) * dir block size
278 * the directory inode's bmap btree: (max depth + v2) * block size
281 xfs_calc_create_resv_modify(
282 struct xfs_mount *mp)
284 return xfs_calc_inode_res(mp, 2) +
285 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
286 (uint)XFS_FSB_TO_B(mp, 1) +
287 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1));
291 * For create we can allocate some inodes giving:
292 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
293 * the superblock for the nlink flag: sector size
294 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
295 * the inode btree: max depth * blocksize
296 * the allocation btrees: 2 trees * (max depth - 1) * block size
299 xfs_calc_create_resv_alloc(
300 struct xfs_mount *mp)
302 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
303 mp->m_sb.sb_sectsize +
304 xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp), XFS_FSB_TO_B(mp, 1)) +
305 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
306 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
307 XFS_FSB_TO_B(mp, 1));
311 __xfs_calc_create_reservation(
312 struct xfs_mount *mp)
314 return XFS_DQUOT_LOGRES(mp) +
315 MAX(xfs_calc_create_resv_alloc(mp),
316 xfs_calc_create_resv_modify(mp));
320 * For icreate we can allocate some inodes giving:
321 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
322 * the superblock for the nlink flag: sector size
323 * the inode btree: max depth * blocksize
324 * the allocation btrees: 2 trees * (max depth - 1) * block size
327 xfs_calc_icreate_resv_alloc(
328 struct xfs_mount *mp)
330 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
331 mp->m_sb.sb_sectsize +
332 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
333 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
334 XFS_FSB_TO_B(mp, 1));
338 xfs_calc_icreate_reservation(xfs_mount_t *mp)
340 return XFS_DQUOT_LOGRES(mp) +
341 MAX(xfs_calc_icreate_resv_alloc(mp),
342 xfs_calc_create_resv_modify(mp));
346 xfs_calc_create_reservation(
347 struct xfs_mount *mp)
349 if (xfs_sb_version_hascrc(&mp->m_sb))
350 return xfs_calc_icreate_reservation(mp);
351 return __xfs_calc_create_reservation(mp);
356 * Making a new directory is the same as creating a new file.
359 xfs_calc_mkdir_reservation(
360 struct xfs_mount *mp)
362 return xfs_calc_create_reservation(mp);
367 * Making a new symplink is the same as creating a new file, but
368 * with the added blocks for remote symlink data which can be up to 1kB in
369 * length (MAXPATHLEN).
372 xfs_calc_symlink_reservation(
373 struct xfs_mount *mp)
375 return xfs_calc_create_reservation(mp) +
376 xfs_calc_buf_res(1, MAXPATHLEN);
380 * In freeing an inode we can modify:
381 * the inode being freed: inode size
382 * the super block free inode counter: sector size
383 * the agi hash list and counters: sector size
384 * the inode btree entry: block size
385 * the on disk inode before ours in the agi hash list: inode cluster size
386 * the inode btree: max depth * blocksize
387 * the allocation btrees: 2 trees * (max depth - 1) * block size
390 xfs_calc_ifree_reservation(
391 struct xfs_mount *mp)
393 return XFS_DQUOT_LOGRES(mp) +
394 xfs_calc_inode_res(mp, 1) +
395 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
396 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
397 MAX((__uint16_t)XFS_FSB_TO_B(mp, 1),
398 XFS_INODE_CLUSTER_SIZE(mp)) +
399 xfs_calc_buf_res(1, 0) +
400 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
401 mp->m_in_maxlevels, 0) +
402 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
403 XFS_FSB_TO_B(mp, 1));
407 * When only changing the inode we log the inode and possibly the superblock
408 * We also add a bit of slop for the transaction stuff.
411 xfs_calc_ichange_reservation(
412 struct xfs_mount *mp)
414 return XFS_DQUOT_LOGRES(mp) +
415 xfs_calc_inode_res(mp, 1) +
416 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
421 * Growing the data section of the filesystem.
427 xfs_calc_growdata_reservation(
428 struct xfs_mount *mp)
430 return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
431 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
432 XFS_FSB_TO_B(mp, 1));
436 * Growing the rt section of the filesystem.
437 * In the first set of transactions (ALLOC) we allocate space to the
438 * bitmap or summary files.
439 * superblock: sector size
440 * agf of the ag from which the extent is allocated: sector size
441 * bmap btree for bitmap/summary inode: max depth * blocksize
442 * bitmap/summary inode: inode size
443 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
446 xfs_calc_growrtalloc_reservation(
447 struct xfs_mount *mp)
449 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
450 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
451 XFS_FSB_TO_B(mp, 1)) +
452 xfs_calc_inode_res(mp, 1) +
453 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
454 XFS_FSB_TO_B(mp, 1));
458 * Growing the rt section of the filesystem.
459 * In the second set of transactions (ZERO) we zero the new metadata blocks.
460 * one bitmap/summary block: blocksize
463 xfs_calc_growrtzero_reservation(
464 struct xfs_mount *mp)
466 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
470 * Growing the rt section of the filesystem.
471 * In the third set of transactions (FREE) we update metadata without
472 * allocating any new blocks.
473 * superblock: sector size
474 * bitmap inode: inode size
475 * summary inode: inode size
476 * one bitmap block: blocksize
477 * summary blocks: new summary size
480 xfs_calc_growrtfree_reservation(
481 struct xfs_mount *mp)
483 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
484 xfs_calc_inode_res(mp, 2) +
485 xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
486 xfs_calc_buf_res(1, mp->m_rsumsize);
490 * Logging the inode modification timestamp on a synchronous write.
494 xfs_calc_swrite_reservation(
495 struct xfs_mount *mp)
497 return xfs_calc_inode_res(mp, 1);
501 * Logging the inode mode bits when writing a setuid/setgid file
505 xfs_calc_writeid_reservation(
506 struct xfs_mount *mp)
508 return xfs_calc_inode_res(mp, 1);
512 * Converting the inode from non-attributed to attributed.
513 * the inode being converted: inode size
514 * agf block and superblock (for block allocation)
515 * the new block (directory sized)
516 * bmap blocks for the new directory block
520 xfs_calc_addafork_reservation(
521 struct xfs_mount *mp)
523 return XFS_DQUOT_LOGRES(mp) +
524 xfs_calc_inode_res(mp, 1) +
525 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
526 xfs_calc_buf_res(1, mp->m_dirblksize) +
527 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
528 XFS_FSB_TO_B(mp, 1)) +
529 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
530 XFS_FSB_TO_B(mp, 1));
534 * Removing the attribute fork of a file
535 * the inode being truncated: inode size
536 * the inode's bmap btree: max depth * block size
537 * And the bmap_finish transaction can free the blocks and bmap blocks:
538 * the agf for each of the ags: 4 * sector size
539 * the agfl for each of the ags: 4 * sector size
540 * the super block to reflect the freed blocks: sector size
541 * worst case split in allocation btrees per extent assuming 4 extents:
542 * 4 exts * 2 trees * (2 * max depth - 1) * block size
545 xfs_calc_attrinval_reservation(
546 struct xfs_mount *mp)
548 return MAX((xfs_calc_inode_res(mp, 1) +
549 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
550 XFS_FSB_TO_B(mp, 1))),
551 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
552 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
553 XFS_FSB_TO_B(mp, 1))));
557 * Setting an attribute at mount time.
558 * the inode getting the attribute
559 * the superblock for allocations
560 * the agfs extents are allocated from
561 * the attribute btree * max depth
562 * the inode allocation btree
563 * Since attribute transaction space is dependent on the size of the attribute,
564 * the calculation is done partially at mount time and partially at runtime(see
568 xfs_calc_attrsetm_reservation(
569 struct xfs_mount *mp)
571 return XFS_DQUOT_LOGRES(mp) +
572 xfs_calc_inode_res(mp, 1) +
573 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
574 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1));
578 * Setting an attribute at runtime, transaction space unit per block.
579 * the superblock for allocations: sector size
580 * the inode bmap btree could join or split: max depth * block size
581 * Since the runtime attribute transaction space is dependent on the total
582 * blocks needed for the 1st bmap, here we calculate out the space unit for
583 * one block so that the caller could figure out the total space according
584 * to the attibute extent length in blocks by:
585 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
588 xfs_calc_attrsetrt_reservation(
589 struct xfs_mount *mp)
591 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
592 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
593 XFS_FSB_TO_B(mp, 1));
597 * Removing an attribute.
598 * the inode: inode size
599 * the attribute btree could join: max depth * block size
600 * the inode bmap btree could join or split: max depth * block size
601 * And the bmap_finish transaction can free the attr blocks freed giving:
602 * the agf for the ag in which the blocks live: 2 * sector size
603 * the agfl for the ag in which the blocks live: 2 * sector size
604 * the superblock for the free block count: sector size
605 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
608 xfs_calc_attrrm_reservation(
609 struct xfs_mount *mp)
611 return XFS_DQUOT_LOGRES(mp) +
612 MAX((xfs_calc_inode_res(mp, 1) +
613 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH,
614 XFS_FSB_TO_B(mp, 1)) +
615 (uint)XFS_FSB_TO_B(mp,
616 XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
617 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
618 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
619 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
620 XFS_FSB_TO_B(mp, 1))));
624 * Clearing a bad agino number in an agi hash bucket.
627 xfs_calc_clear_agi_bucket_reservation(
628 struct xfs_mount *mp)
630 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
634 * Clearing the quotaflags in the superblock.
635 * the super block for changing quota flags: sector size
638 xfs_calc_qm_sbchange_reservation(
639 struct xfs_mount *mp)
641 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
645 * Adjusting quota limits.
646 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
649 xfs_calc_qm_setqlim_reservation(
650 struct xfs_mount *mp)
652 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
656 * Allocating quota on disk if needed.
657 * the write transaction log space: M_RES(mp)->tr_write.tr_logres
658 * the unit of quota allocation: one system block size
661 xfs_calc_qm_dqalloc_reservation(
662 struct xfs_mount *mp)
664 ASSERT(M_RES(mp)->tr_write.tr_logres);
665 return M_RES(mp)->tr_write.tr_logres +
667 XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
671 * Turning off quotas.
672 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
673 * the superblock for the quota flags: sector size
676 xfs_calc_qm_quotaoff_reservation(
677 struct xfs_mount *mp)
679 return sizeof(struct xfs_qoff_logitem) * 2 +
680 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
684 * End of turning off quotas.
685 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
688 xfs_calc_qm_quotaoff_end_reservation(
689 struct xfs_mount *mp)
691 return sizeof(struct xfs_qoff_logitem) * 2;
695 * Syncing the incore super block changes to disk.
696 * the super block to reflect the changes: sector size
699 xfs_calc_sb_reservation(
700 struct xfs_mount *mp)
702 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
707 struct xfs_mount *mp,
708 struct xfs_trans_resv *resp)
711 * The following transactions are logged in physical format and
712 * require a permanent reservation on space.
714 resp->tr_write.tr_logres = xfs_calc_write_reservation(mp);
715 resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT;
716 resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
718 resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp);
719 resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
720 resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
722 resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp);
723 resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;
724 resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
726 resp->tr_link.tr_logres = xfs_calc_link_reservation(mp);
727 resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT;
728 resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
730 resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp);
731 resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT;
732 resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
734 resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp);
735 resp->tr_symlink.tr_logcount = XFS_SYMLINK_LOG_COUNT;
736 resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
738 resp->tr_create.tr_logres = xfs_calc_create_reservation(mp);
739 resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
740 resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
742 resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
743 resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
744 resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
746 resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp);
747 resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT;
748 resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
750 resp->tr_addafork.tr_logres = xfs_calc_addafork_reservation(mp);
751 resp->tr_addafork.tr_logcount = XFS_ADDAFORK_LOG_COUNT;
752 resp->tr_addafork.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
754 resp->tr_attrinval.tr_logres = xfs_calc_attrinval_reservation(mp);
755 resp->tr_attrinval.tr_logcount = XFS_ATTRINVAL_LOG_COUNT;
756 resp->tr_attrinval.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
758 resp->tr_attrsetm.tr_logres = xfs_calc_attrsetm_reservation(mp);
759 resp->tr_attrsetm.tr_logcount = XFS_ATTRSET_LOG_COUNT;
760 resp->tr_attrsetm.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
762 resp->tr_attrrm.tr_logres = xfs_calc_attrrm_reservation(mp);
763 resp->tr_attrrm.tr_logcount = XFS_ATTRRM_LOG_COUNT;
764 resp->tr_attrrm.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
766 resp->tr_growrtalloc.tr_logres = xfs_calc_growrtalloc_reservation(mp);
767 resp->tr_growrtalloc.tr_logcount = XFS_DEFAULT_PERM_LOG_COUNT;
768 resp->tr_growrtalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
770 resp->tr_qm_dqalloc.tr_logres = xfs_calc_qm_dqalloc_reservation(mp);
771 resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;
772 resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
775 * The following transactions are logged in logical format with
776 * a default log count.
778 resp->tr_qm_sbchange.tr_logres = xfs_calc_qm_sbchange_reservation(mp);
779 resp->tr_qm_sbchange.tr_logcount = XFS_DEFAULT_LOG_COUNT;
781 resp->tr_qm_setqlim.tr_logres = xfs_calc_qm_setqlim_reservation(mp);
782 resp->tr_qm_setqlim.tr_logcount = XFS_DEFAULT_LOG_COUNT;
784 resp->tr_qm_quotaoff.tr_logres = xfs_calc_qm_quotaoff_reservation(mp);
785 resp->tr_qm_quotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT;
787 resp->tr_qm_equotaoff.tr_logres =
788 xfs_calc_qm_quotaoff_end_reservation(mp);
789 resp->tr_qm_equotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT;
791 resp->tr_sb.tr_logres = xfs_calc_sb_reservation(mp);
792 resp->tr_sb.tr_logcount = XFS_DEFAULT_LOG_COUNT;
794 /* The following transaction are logged in logical format */
795 resp->tr_ichange.tr_logres = xfs_calc_ichange_reservation(mp);
796 resp->tr_growdata.tr_logres = xfs_calc_growdata_reservation(mp);
797 resp->tr_swrite.tr_logres = xfs_calc_swrite_reservation(mp);
798 resp->tr_fsyncts.tr_logres = xfs_calc_swrite_reservation(mp);
799 resp->tr_writeid.tr_logres = xfs_calc_writeid_reservation(mp);
800 resp->tr_attrsetrt.tr_logres = xfs_calc_attrsetrt_reservation(mp);
801 resp->tr_clearagi.tr_logres = xfs_calc_clear_agi_bucket_reservation(mp);
802 resp->tr_growrtzero.tr_logres = xfs_calc_growrtzero_reservation(mp);
803 resp->tr_growrtfree.tr_logres = xfs_calc_growrtfree_reservation(mp);