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
19 #include "libxfs_priv.h"
21 #include "xfs_shared.h"
22 #include "xfs_format.h"
23 #include "xfs_log_format.h"
24 #include "xfs_trans_resv.h"
25 #include "xfs_mount.h"
26 #include "xfs_da_format.h"
27 #include "xfs_da_btree.h"
28 #include "xfs_inode.h"
29 #include "xfs_bmap_btree.h"
30 #include "xfs_ialloc.h"
31 #include "xfs_trans.h"
32 #include "xfs_trans_space.h"
33 #include "xfs_trace.h"
34 #include "xfs_quota_defs.h"
37 * A buffer has a format structure overhead in the log in addition
38 * to the data, so we need to take this into account when reserving
39 * space in a transaction for a buffer. Round the space required up
40 * to a multiple of 128 bytes so that we don't change the historical
41 * reservation that has been used for this overhead.
44 xfs_buf_log_overhead(void)
46 return round_up(sizeof(struct xlog_op_header
) +
47 sizeof(struct xfs_buf_log_format
), 128);
51 * Calculate out transaction log reservation per item in bytes.
53 * The nbufs argument is used to indicate the number of items that
54 * will be changed in a transaction. size is used to tell how many
55 * bytes should be reserved per item.
62 return nbufs
* (size
+ xfs_buf_log_overhead());
66 * Per-extent log reservation for the btree changes involved in freeing or
67 * allocating an extent. In classic XFS there were two trees that will be
68 * modified (bnobt + cntbt). With rmap enabled, there are three trees
69 * (rmapbt). With reflink, there are four trees (refcountbt). The number of
70 * blocks reserved is based on the formula:
72 * num trees * ((2 blocks/level * max depth) - 1)
74 * Keep in mind that max depth is calculated separately for each type of tree.
77 xfs_allocfree_log_count(
83 blocks
= num_ops
* 2 * (2 * mp
->m_ag_maxlevels
- 1);
84 if (xfs_sb_version_hasrmapbt(&mp
->m_sb
))
85 blocks
+= num_ops
* (2 * mp
->m_rmap_maxlevels
- 1);
86 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
87 blocks
+= num_ops
* (2 * mp
->m_refc_maxlevels
- 1);
93 * Logging inodes is really tricksy. They are logged in memory format,
94 * which means that what we write into the log doesn't directly translate into
95 * the amount of space they use on disk.
97 * Case in point - btree format forks in memory format use more space than the
98 * on-disk format. In memory, the buffer contains a normal btree block header so
99 * the btree code can treat it as though it is just another generic buffer.
100 * However, when we write it to the inode fork, we don't write all of this
101 * header as it isn't needed. e.g. the root is only ever in the inode, so
102 * there's no need for sibling pointers which would waste 16 bytes of space.
104 * Hence when we have an inode with a maximally sized btree format fork, then
105 * amount of information we actually log is greater than the size of the inode
106 * on disk. Hence we need an inode reservation function that calculates all this
107 * correctly. So, we log:
109 * - 4 log op headers for object
110 * - for the ilf, the inode core and 2 forks
111 * - inode log format object
113 * - two inode forks containing bmap btree root blocks.
114 * - the btree data contained by both forks will fit into the inode size,
115 * hence when combined with the inode core above, we have a total of the
117 * - the BMBT headers need to be accounted separately, as they are
118 * additional to the records and pointers that fit inside the inode
123 struct xfs_mount
*mp
,
127 (4 * sizeof(struct xlog_op_header
) +
128 sizeof(struct xfs_inode_log_format
) +
129 mp
->m_sb
.sb_inodesize
+
130 2 * XFS_BMBT_BLOCK_LEN(mp
));
134 * The free inode btree is a conditional feature and the log reservation
135 * requirements differ slightly from that of the traditional inode allocation
136 * btree. The finobt tracks records for inode chunks with at least one free
137 * inode. A record can be removed from the tree for an inode allocation
138 * or free and thus the finobt reservation is unconditional across:
142 * - inode chunk allocation
144 * The 'modify' param indicates to include the record modification scenario. The
145 * 'alloc' param indicates to include the reservation for free space btree
146 * modifications on behalf of finobt modifications. This is required only for
147 * transactions that do not already account for free space btree modifications.
149 * the free inode btree: max depth * block size
150 * the allocation btrees: 2 trees * (max depth - 1) * block size
151 * the free inode btree entry: block size
155 struct xfs_mount
*mp
,
161 if (!xfs_sb_version_hasfinobt(&mp
->m_sb
))
164 res
= xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1));
166 res
+= xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
167 XFS_FSB_TO_B(mp
, 1));
169 res
+= (uint
)XFS_FSB_TO_B(mp
, 1);
175 * Various log reservation values.
177 * These are based on the size of the file system block because that is what
178 * most transactions manipulate. Each adds in an additional 128 bytes per
179 * item logged to try to account for the overhead of the transaction mechanism.
181 * Note: Most of the reservations underestimate the number of allocation
182 * groups into which they could free extents in the xfs_defer_finish() call.
183 * This is because the number in the worst case is quite high and quite
184 * unusual. In order to fix this we need to change xfs_defer_finish() to free
185 * extents in only a single AG at a time. This will require changes to the
186 * EFI code as well, however, so that the EFI for the extents not freed is
187 * logged again in each transaction. See SGI PV #261917.
189 * Reservation functions here avoid a huge stack in xfs_trans_init due to
190 * register overflow from temporaries in the calculations.
195 * In a write transaction we can allocate a maximum of 2
196 * extents. This gives:
197 * the inode getting the new extents: inode size
198 * the inode's bmap btree: max depth * block size
199 * the agfs of the ags from which the extents are allocated: 2 * sector
200 * the superblock free block counter: sector size
201 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
202 * And the bmap_finish transaction can free bmap blocks in a join:
203 * the agfs of the ags containing the blocks: 2 * sector size
204 * the agfls of the ags containing the blocks: 2 * sector size
205 * the super block free block counter: sector size
206 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
209 xfs_calc_write_reservation(
210 struct xfs_mount
*mp
)
212 return XFS_DQUOT_LOGRES(mp
) +
213 MAX((xfs_calc_inode_res(mp
, 1) +
214 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
215 XFS_FSB_TO_B(mp
, 1)) +
216 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
217 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
218 XFS_FSB_TO_B(mp
, 1))),
219 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
220 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
221 XFS_FSB_TO_B(mp
, 1))));
225 * In truncating a file we free up to two extents at once. We can modify:
226 * the inode being truncated: inode size
227 * the inode's bmap btree: (max depth + 1) * block size
228 * And the bmap_finish transaction can free the blocks and bmap blocks:
229 * the agf for each of the ags: 4 * sector size
230 * the agfl for each of the ags: 4 * sector size
231 * the super block to reflect the freed blocks: sector size
232 * worst case split in allocation btrees per extent assuming 4 extents:
233 * 4 exts * 2 trees * (2 * max depth - 1) * block size
234 * the inode btree: max depth * blocksize
235 * the allocation btrees: 2 trees * (max depth - 1) * block size
238 xfs_calc_itruncate_reservation(
239 struct xfs_mount
*mp
)
241 return XFS_DQUOT_LOGRES(mp
) +
242 MAX((xfs_calc_inode_res(mp
, 1) +
243 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1,
244 XFS_FSB_TO_B(mp
, 1))),
245 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
246 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
247 XFS_FSB_TO_B(mp
, 1)) +
248 xfs_calc_buf_res(5, 0) +
249 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
250 XFS_FSB_TO_B(mp
, 1)) +
251 xfs_calc_buf_res(2 + mp
->m_ialloc_blks
+
252 mp
->m_in_maxlevels
, 0)));
256 * In renaming a files we can modify:
257 * the four inodes involved: 4 * inode size
258 * the two directory btrees: 2 * (max depth + v2) * dir block size
259 * the two directory bmap btrees: 2 * max depth * block size
260 * And the bmap_finish transaction can free dir and bmap blocks (two sets
261 * of bmap blocks) giving:
262 * the agf for the ags in which the blocks live: 3 * sector size
263 * the agfl for the ags in which the blocks live: 3 * sector size
264 * the superblock for the free block count: sector size
265 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
268 xfs_calc_rename_reservation(
269 struct xfs_mount
*mp
)
271 return XFS_DQUOT_LOGRES(mp
) +
272 MAX((xfs_calc_inode_res(mp
, 4) +
273 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
274 XFS_FSB_TO_B(mp
, 1))),
275 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
276 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 3),
277 XFS_FSB_TO_B(mp
, 1))));
281 * For removing an inode from unlinked list at first, we can modify:
282 * the agi hash list and counters: sector size
283 * the on disk inode before ours in the agi hash list: inode cluster size
286 xfs_calc_iunlink_remove_reservation(
287 struct xfs_mount
*mp
)
289 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
290 max_t(uint
, XFS_FSB_TO_B(mp
, 1), mp
->m_inode_cluster_size
);
294 * For creating a link to an inode:
295 * the parent directory inode: inode size
296 * the linked inode: inode size
297 * the directory btree could split: (max depth + v2) * dir block size
298 * the directory bmap btree could join or split: (max depth + v2) * blocksize
299 * And the bmap_finish transaction can free some bmap blocks giving:
300 * the agf for the ag in which the blocks live: sector size
301 * the agfl for the ag in which the blocks live: sector size
302 * the superblock for the free block count: sector size
303 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
306 xfs_calc_link_reservation(
307 struct xfs_mount
*mp
)
309 return XFS_DQUOT_LOGRES(mp
) +
310 xfs_calc_iunlink_remove_reservation(mp
) +
311 MAX((xfs_calc_inode_res(mp
, 2) +
312 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
313 XFS_FSB_TO_B(mp
, 1))),
314 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
315 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
316 XFS_FSB_TO_B(mp
, 1))));
320 * For adding an inode to unlinked list we can modify:
321 * the agi hash list: sector size
322 * the unlinked inode: inode size
325 xfs_calc_iunlink_add_reservation(xfs_mount_t
*mp
)
327 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
328 xfs_calc_inode_res(mp
, 1);
332 * For removing a directory entry we can modify:
333 * the parent directory inode: inode size
334 * the removed inode: inode size
335 * the directory btree could join: (max depth + v2) * dir block size
336 * the directory bmap btree could join or split: (max depth + v2) * blocksize
337 * And the bmap_finish transaction can free the dir and bmap blocks giving:
338 * the agf for the ag in which the blocks live: 2 * sector size
339 * the agfl for the ag in which the blocks live: 2 * sector size
340 * the superblock for the free block count: sector size
341 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
344 xfs_calc_remove_reservation(
345 struct xfs_mount
*mp
)
347 return XFS_DQUOT_LOGRES(mp
) +
348 xfs_calc_iunlink_add_reservation(mp
) +
349 MAX((xfs_calc_inode_res(mp
, 1) +
350 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
351 XFS_FSB_TO_B(mp
, 1))),
352 (xfs_calc_buf_res(4, mp
->m_sb
.sb_sectsize
) +
353 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
354 XFS_FSB_TO_B(mp
, 1))));
358 * For create, break it in to the two cases that the transaction
359 * covers. We start with the modify case - allocation done by modification
360 * of the state of existing inodes - and the allocation case.
364 * For create we can modify:
365 * the parent directory inode: inode size
366 * the new inode: inode size
367 * the inode btree entry: block size
368 * the superblock for the nlink flag: sector size
369 * the directory btree: (max depth + v2) * dir block size
370 * the directory inode's bmap btree: (max depth + v2) * block size
371 * the finobt (record modification and allocation btrees)
374 xfs_calc_create_resv_modify(
375 struct xfs_mount
*mp
)
377 return xfs_calc_inode_res(mp
, 2) +
378 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
379 (uint
)XFS_FSB_TO_B(mp
, 1) +
380 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1)) +
381 xfs_calc_finobt_res(mp
, 1, 1);
385 * For create we can allocate some inodes giving:
386 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
387 * the superblock for the nlink flag: sector size
388 * the inode blocks allocated: mp->m_ialloc_blks * blocksize
389 * the inode btree: max depth * blocksize
390 * the allocation btrees: 2 trees * (max depth - 1) * block size
393 xfs_calc_create_resv_alloc(
394 struct xfs_mount
*mp
)
396 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
397 mp
->m_sb
.sb_sectsize
+
398 xfs_calc_buf_res(mp
->m_ialloc_blks
, XFS_FSB_TO_B(mp
, 1)) +
399 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
400 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
401 XFS_FSB_TO_B(mp
, 1));
405 __xfs_calc_create_reservation(
406 struct xfs_mount
*mp
)
408 return XFS_DQUOT_LOGRES(mp
) +
409 MAX(xfs_calc_create_resv_alloc(mp
),
410 xfs_calc_create_resv_modify(mp
));
414 * For icreate we can allocate some inodes giving:
415 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
416 * the superblock for the nlink flag: sector size
417 * the inode btree: max depth * blocksize
418 * the allocation btrees: 2 trees * (max depth - 1) * block size
419 * the finobt (record insertion)
422 xfs_calc_icreate_resv_alloc(
423 struct xfs_mount
*mp
)
425 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
426 mp
->m_sb
.sb_sectsize
+
427 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
428 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
429 XFS_FSB_TO_B(mp
, 1)) +
430 xfs_calc_finobt_res(mp
, 0, 0);
434 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
436 return XFS_DQUOT_LOGRES(mp
) +
437 MAX(xfs_calc_icreate_resv_alloc(mp
),
438 xfs_calc_create_resv_modify(mp
));
442 xfs_calc_create_reservation(
443 struct xfs_mount
*mp
)
445 if (xfs_sb_version_hascrc(&mp
->m_sb
))
446 return xfs_calc_icreate_reservation(mp
);
447 return __xfs_calc_create_reservation(mp
);
452 xfs_calc_create_tmpfile_reservation(
453 struct xfs_mount
*mp
)
455 uint res
= XFS_DQUOT_LOGRES(mp
);
457 if (xfs_sb_version_hascrc(&mp
->m_sb
))
458 res
+= xfs_calc_icreate_resv_alloc(mp
);
460 res
+= xfs_calc_create_resv_alloc(mp
);
462 return res
+ xfs_calc_iunlink_add_reservation(mp
);
466 * Making a new directory is the same as creating a new file.
469 xfs_calc_mkdir_reservation(
470 struct xfs_mount
*mp
)
472 return xfs_calc_create_reservation(mp
);
477 * Making a new symplink is the same as creating a new file, but
478 * with the added blocks for remote symlink data which can be up to 1kB in
479 * length (XFS_SYMLINK_MAXLEN).
482 xfs_calc_symlink_reservation(
483 struct xfs_mount
*mp
)
485 return xfs_calc_create_reservation(mp
) +
486 xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN
);
490 * In freeing an inode we can modify:
491 * the inode being freed: inode size
492 * the super block free inode counter: sector size
493 * the agi hash list and counters: sector size
494 * the inode btree entry: block size
495 * the on disk inode before ours in the agi hash list: inode cluster size
496 * the inode btree: max depth * blocksize
497 * the allocation btrees: 2 trees * (max depth - 1) * block size
498 * the finobt (record insertion, removal or modification)
501 xfs_calc_ifree_reservation(
502 struct xfs_mount
*mp
)
504 return XFS_DQUOT_LOGRES(mp
) +
505 xfs_calc_inode_res(mp
, 1) +
506 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
507 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp
, 1)) +
508 xfs_calc_iunlink_remove_reservation(mp
) +
509 xfs_calc_buf_res(1, 0) +
510 xfs_calc_buf_res(2 + mp
->m_ialloc_blks
+
511 mp
->m_in_maxlevels
, 0) +
512 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
513 XFS_FSB_TO_B(mp
, 1)) +
514 xfs_calc_finobt_res(mp
, 0, 1);
518 * When only changing the inode we log the inode and possibly the superblock
519 * We also add a bit of slop for the transaction stuff.
522 xfs_calc_ichange_reservation(
523 struct xfs_mount
*mp
)
525 return XFS_DQUOT_LOGRES(mp
) +
526 xfs_calc_inode_res(mp
, 1) +
527 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
532 * Growing the data section of the filesystem.
538 xfs_calc_growdata_reservation(
539 struct xfs_mount
*mp
)
541 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
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 first set of transactions (ALLOC) we allocate space to the
549 * bitmap or summary files.
550 * superblock: sector size
551 * agf of the ag from which the extent is allocated: sector size
552 * bmap btree for bitmap/summary inode: max depth * blocksize
553 * bitmap/summary inode: inode size
554 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
557 xfs_calc_growrtalloc_reservation(
558 struct xfs_mount
*mp
)
560 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
561 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
562 XFS_FSB_TO_B(mp
, 1)) +
563 xfs_calc_inode_res(mp
, 1) +
564 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
565 XFS_FSB_TO_B(mp
, 1));
569 * Growing the rt section of the filesystem.
570 * In the second set of transactions (ZERO) we zero the new metadata blocks.
571 * one bitmap/summary block: blocksize
574 xfs_calc_growrtzero_reservation(
575 struct xfs_mount
*mp
)
577 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
581 * Growing the rt section of the filesystem.
582 * In the third set of transactions (FREE) we update metadata without
583 * allocating any new blocks.
584 * superblock: sector size
585 * bitmap inode: inode size
586 * summary inode: inode size
587 * one bitmap block: blocksize
588 * summary blocks: new summary size
591 xfs_calc_growrtfree_reservation(
592 struct xfs_mount
*mp
)
594 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
595 xfs_calc_inode_res(mp
, 2) +
596 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
597 xfs_calc_buf_res(1, mp
->m_rsumsize
);
601 * Logging the inode modification timestamp on a synchronous write.
605 xfs_calc_swrite_reservation(
606 struct xfs_mount
*mp
)
608 return xfs_calc_inode_res(mp
, 1);
612 * Logging the inode mode bits when writing a setuid/setgid file
616 xfs_calc_writeid_reservation(
617 struct xfs_mount
*mp
)
619 return xfs_calc_inode_res(mp
, 1);
623 * Converting the inode from non-attributed to attributed.
624 * the inode being converted: inode size
625 * agf block and superblock (for block allocation)
626 * the new block (directory sized)
627 * bmap blocks for the new directory block
631 xfs_calc_addafork_reservation(
632 struct xfs_mount
*mp
)
634 return XFS_DQUOT_LOGRES(mp
) +
635 xfs_calc_inode_res(mp
, 1) +
636 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
637 xfs_calc_buf_res(1, mp
->m_dir_geo
->blksize
) +
638 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
639 XFS_FSB_TO_B(mp
, 1)) +
640 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
641 XFS_FSB_TO_B(mp
, 1));
645 * Removing the attribute fork of a file
646 * the inode being truncated: inode size
647 * the inode's bmap btree: max depth * block size
648 * And the bmap_finish transaction can free the blocks and bmap blocks:
649 * the agf for each of the ags: 4 * sector size
650 * the agfl for each of the ags: 4 * sector size
651 * the super block to reflect the freed blocks: sector size
652 * worst case split in allocation btrees per extent assuming 4 extents:
653 * 4 exts * 2 trees * (2 * max depth - 1) * block size
656 xfs_calc_attrinval_reservation(
657 struct xfs_mount
*mp
)
659 return MAX((xfs_calc_inode_res(mp
, 1) +
660 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
661 XFS_FSB_TO_B(mp
, 1))),
662 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
663 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
664 XFS_FSB_TO_B(mp
, 1))));
668 * Setting an attribute at mount time.
669 * the inode getting the attribute
670 * the superblock for allocations
671 * the agfs extents are allocated from
672 * the attribute btree * max depth
673 * the inode allocation btree
674 * Since attribute transaction space is dependent on the size of the attribute,
675 * the calculation is done partially at mount time and partially at runtime(see
679 xfs_calc_attrsetm_reservation(
680 struct xfs_mount
*mp
)
682 return XFS_DQUOT_LOGRES(mp
) +
683 xfs_calc_inode_res(mp
, 1) +
684 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
685 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
689 * Setting an attribute at runtime, transaction space unit per block.
690 * the superblock for allocations: sector size
691 * the inode bmap btree could join or split: max depth * block size
692 * Since the runtime attribute transaction space is dependent on the total
693 * blocks needed for the 1st bmap, here we calculate out the space unit for
694 * one block so that the caller could figure out the total space according
695 * to the attibute extent length in blocks by:
696 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
699 xfs_calc_attrsetrt_reservation(
700 struct xfs_mount
*mp
)
702 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
703 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
704 XFS_FSB_TO_B(mp
, 1));
708 * Removing an attribute.
709 * the inode: inode size
710 * the attribute btree could join: max depth * block size
711 * the inode bmap btree could join or split: max depth * block size
712 * And the bmap_finish transaction can free the attr blocks freed giving:
713 * the agf for the ag in which the blocks live: 2 * sector size
714 * the agfl for the ag in which the blocks live: 2 * sector size
715 * the superblock for the free block count: sector size
716 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
719 xfs_calc_attrrm_reservation(
720 struct xfs_mount
*mp
)
722 return XFS_DQUOT_LOGRES(mp
) +
723 MAX((xfs_calc_inode_res(mp
, 1) +
724 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
725 XFS_FSB_TO_B(mp
, 1)) +
726 (uint
)XFS_FSB_TO_B(mp
,
727 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
728 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
729 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
730 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
731 XFS_FSB_TO_B(mp
, 1))));
735 * Clearing a bad agino number in an agi hash bucket.
738 xfs_calc_clear_agi_bucket_reservation(
739 struct xfs_mount
*mp
)
741 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
745 * Adjusting quota limits.
746 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
749 xfs_calc_qm_setqlim_reservation(
750 struct xfs_mount
*mp
)
752 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot
));
756 * Allocating quota on disk if needed.
757 * the write transaction log space for quota file extent allocation
758 * the unit of quota allocation: one system block size
761 xfs_calc_qm_dqalloc_reservation(
762 struct xfs_mount
*mp
)
764 return xfs_calc_write_reservation(mp
) +
766 XFS_FSB_TO_B(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
) - 1);
770 * Turning off quotas.
771 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
772 * the superblock for the quota flags: sector size
775 xfs_calc_qm_quotaoff_reservation(
776 struct xfs_mount
*mp
)
778 return sizeof(struct xfs_qoff_logitem
) * 2 +
779 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
783 * End of turning off quotas.
784 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
787 xfs_calc_qm_quotaoff_end_reservation(
788 struct xfs_mount
*mp
)
790 return sizeof(struct xfs_qoff_logitem
) * 2;
794 * Syncing the incore super block changes to disk.
795 * the super block to reflect the changes: sector size
798 xfs_calc_sb_reservation(
799 struct xfs_mount
*mp
)
801 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
806 struct xfs_mount
*mp
,
807 struct xfs_trans_resv
*resp
)
810 * The following transactions are logged in physical format and
811 * require a permanent reservation on space.
813 resp
->tr_write
.tr_logres
= xfs_calc_write_reservation(mp
);
814 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
815 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
817 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
818 resp
->tr_write
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
820 resp
->tr_itruncate
.tr_logres
= xfs_calc_itruncate_reservation(mp
);
821 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
822 resp
->tr_itruncate
.tr_logcount
=
823 XFS_ITRUNCATE_LOG_COUNT_REFLINK
;
825 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
826 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
828 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
829 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
830 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
832 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
833 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
834 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
836 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
837 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
838 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
840 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
841 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
842 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
844 resp
->tr_create
.tr_logres
= xfs_calc_create_reservation(mp
);
845 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
846 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
848 resp
->tr_create_tmpfile
.tr_logres
=
849 xfs_calc_create_tmpfile_reservation(mp
);
850 resp
->tr_create_tmpfile
.tr_logcount
= XFS_CREATE_TMPFILE_LOG_COUNT
;
851 resp
->tr_create_tmpfile
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
853 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
854 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
855 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
857 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
858 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
859 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
861 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
862 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
863 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
865 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
866 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
867 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
869 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
870 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
871 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
873 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
874 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
875 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
877 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
878 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
879 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
881 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
);
882 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
883 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
885 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
886 resp
->tr_qm_dqalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
889 * The following transactions are logged in logical format with
890 * a default log count.
892 resp
->tr_qm_setqlim
.tr_logres
= xfs_calc_qm_setqlim_reservation(mp
);
893 resp
->tr_qm_setqlim
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
895 resp
->tr_qm_quotaoff
.tr_logres
= xfs_calc_qm_quotaoff_reservation(mp
);
896 resp
->tr_qm_quotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
898 resp
->tr_qm_equotaoff
.tr_logres
=
899 xfs_calc_qm_quotaoff_end_reservation(mp
);
900 resp
->tr_qm_equotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
902 resp
->tr_sb
.tr_logres
= xfs_calc_sb_reservation(mp
);
903 resp
->tr_sb
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
905 /* The following transaction are logged in logical format */
906 resp
->tr_ichange
.tr_logres
= xfs_calc_ichange_reservation(mp
);
907 resp
->tr_growdata
.tr_logres
= xfs_calc_growdata_reservation(mp
);
908 resp
->tr_fsyncts
.tr_logres
= xfs_calc_swrite_reservation(mp
);
909 resp
->tr_writeid
.tr_logres
= xfs_calc_writeid_reservation(mp
);
910 resp
->tr_attrsetrt
.tr_logres
= xfs_calc_attrsetrt_reservation(mp
);
911 resp
->tr_clearagi
.tr_logres
= xfs_calc_clear_agi_bucket_reservation(mp
);
912 resp
->tr_growrtzero
.tr_logres
= xfs_calc_growrtzero_reservation(mp
);
913 resp
->tr_growrtfree
.tr_logres
= xfs_calc_growrtfree_reservation(mp
);