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"
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_quota.h"
32 #include "xfs_trans.h"
34 #include "xfs_trans_space.h"
35 #include "xfs_trace.h"
38 * A buffer has a format structure overhead in the log in addition
39 * to the data, so we need to take this into account when reserving
40 * space in a transaction for a buffer. Round the space required up
41 * to a multiple of 128 bytes so that we don't change the historical
42 * reservation that has been used for this overhead.
45 xfs_buf_log_overhead(void)
47 return round_up(sizeof(struct xlog_op_header
) +
48 sizeof(struct xfs_buf_log_format
), 128);
52 * Calculate out transaction log reservation per item in bytes.
54 * The nbufs argument is used to indicate the number of items that
55 * will be changed in a transaction. size is used to tell how many
56 * bytes should be reserved per item.
63 return nbufs
* (size
+ xfs_buf_log_overhead());
67 * Per-extent log reservation for the btree changes involved in freeing or
68 * allocating an extent. In classic XFS there were two trees that will be
69 * modified (bnobt + cntbt). With rmap enabled, there are three trees
70 * (rmapbt). With reflink, there are four trees (refcountbt). The number of
71 * blocks reserved is based on the formula:
73 * num trees * ((2 blocks/level * max depth) - 1)
75 * Keep in mind that max depth is calculated separately for each type of tree.
78 xfs_allocfree_log_count(
84 blocks
= num_ops
* 2 * (2 * mp
->m_ag_maxlevels
- 1);
85 if (xfs_sb_version_hasrmapbt(&mp
->m_sb
))
86 blocks
+= num_ops
* (2 * mp
->m_rmap_maxlevels
- 1);
87 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
88 blocks
+= num_ops
* (2 * mp
->m_refc_maxlevels
- 1);
94 * Logging inodes is really tricksy. They are logged in memory format,
95 * which means that what we write into the log doesn't directly translate into
96 * the amount of space they use on disk.
98 * Case in point - btree format forks in memory format use more space than the
99 * on-disk format. In memory, the buffer contains a normal btree block header so
100 * the btree code can treat it as though it is just another generic buffer.
101 * However, when we write it to the inode fork, we don't write all of this
102 * header as it isn't needed. e.g. the root is only ever in the inode, so
103 * there's no need for sibling pointers which would waste 16 bytes of space.
105 * Hence when we have an inode with a maximally sized btree format fork, then
106 * amount of information we actually log is greater than the size of the inode
107 * on disk. Hence we need an inode reservation function that calculates all this
108 * correctly. So, we log:
110 * - 4 log op headers for object
111 * - for the ilf, the inode core and 2 forks
112 * - inode log format object
114 * - two inode forks containing bmap btree root blocks.
115 * - the btree data contained by both forks will fit into the inode size,
116 * hence when combined with the inode core above, we have a total of the
118 * - the BMBT headers need to be accounted separately, as they are
119 * additional to the records and pointers that fit inside the inode
124 struct xfs_mount
*mp
,
128 (4 * sizeof(struct xlog_op_header
) +
129 sizeof(struct xfs_inode_log_format
) +
130 mp
->m_sb
.sb_inodesize
+
131 2 * XFS_BMBT_BLOCK_LEN(mp
));
135 * The free inode btree is a conditional feature and the log reservation
136 * requirements differ slightly from that of the traditional inode allocation
137 * btree. The finobt tracks records for inode chunks with at least one free
138 * inode. A record can be removed from the tree for an inode allocation
139 * or free and thus the finobt reservation is unconditional across:
143 * - inode chunk allocation
145 * The 'modify' param indicates to include the record modification scenario. The
146 * 'alloc' param indicates to include the reservation for free space btree
147 * modifications on behalf of finobt modifications. This is required only for
148 * transactions that do not already account for free space btree modifications.
150 * the free inode btree: max depth * block size
151 * the allocation btrees: 2 trees * (max depth - 1) * block size
152 * the free inode btree entry: block size
156 struct xfs_mount
*mp
,
162 if (!xfs_sb_version_hasfinobt(&mp
->m_sb
))
165 res
= xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1));
167 res
+= xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
168 XFS_FSB_TO_B(mp
, 1));
170 res
+= (uint
)XFS_FSB_TO_B(mp
, 1);
176 * Various log reservation values.
178 * These are based on the size of the file system block because that is what
179 * most transactions manipulate. Each adds in an additional 128 bytes per
180 * item logged to try to account for the overhead of the transaction mechanism.
182 * Note: Most of the reservations underestimate the number of allocation
183 * groups into which they could free extents in the xfs_defer_finish() call.
184 * This is because the number in the worst case is quite high and quite
185 * unusual. In order to fix this we need to change xfs_defer_finish() to free
186 * extents in only a single AG at a time. This will require changes to the
187 * EFI code as well, however, so that the EFI for the extents not freed is
188 * logged again in each transaction. See SGI PV #261917.
190 * Reservation functions here avoid a huge stack in xfs_trans_init due to
191 * register overflow from temporaries in the calculations.
196 * In a write transaction we can allocate a maximum of 2
197 * extents. This gives:
198 * the inode getting the new extents: inode size
199 * the inode's bmap btree: max depth * block size
200 * the agfs of the ags from which the extents are allocated: 2 * sector
201 * the superblock free block counter: sector size
202 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
203 * And the bmap_finish transaction can free bmap blocks in a join:
204 * the agfs of the ags containing the blocks: 2 * sector size
205 * the agfls of the ags containing the blocks: 2 * sector size
206 * the super block free block counter: sector size
207 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
210 xfs_calc_write_reservation(
211 struct xfs_mount
*mp
)
213 return XFS_DQUOT_LOGRES(mp
) +
214 MAX((xfs_calc_inode_res(mp
, 1) +
215 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
216 XFS_FSB_TO_B(mp
, 1)) +
217 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
218 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
219 XFS_FSB_TO_B(mp
, 1))),
220 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
221 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
222 XFS_FSB_TO_B(mp
, 1))));
226 * In truncating a file we free up to two extents at once. We can modify:
227 * the inode being truncated: inode size
228 * the inode's bmap btree: (max depth + 1) * block size
229 * And the bmap_finish transaction can free the blocks and bmap blocks:
230 * the agf for each of the ags: 4 * sector size
231 * the agfl for each of the ags: 4 * sector size
232 * the super block to reflect the freed blocks: sector size
233 * worst case split in allocation btrees per extent assuming 4 extents:
234 * 4 exts * 2 trees * (2 * max depth - 1) * block size
237 xfs_calc_itruncate_reservation(
238 struct xfs_mount
*mp
)
240 return XFS_DQUOT_LOGRES(mp
) +
241 MAX((xfs_calc_inode_res(mp
, 1) +
242 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1,
243 XFS_FSB_TO_B(mp
, 1))),
244 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
245 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
246 XFS_FSB_TO_B(mp
, 1))));
250 * In renaming a files we can modify:
251 * the four inodes involved: 4 * inode size
252 * the two directory btrees: 2 * (max depth + v2) * dir block size
253 * the two directory bmap btrees: 2 * max depth * block size
254 * And the bmap_finish transaction can free dir and bmap blocks (two sets
255 * of bmap blocks) giving:
256 * the agf for the ags in which the blocks live: 3 * sector size
257 * the agfl for the ags in which the blocks live: 3 * sector size
258 * the superblock for the free block count: sector size
259 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
262 xfs_calc_rename_reservation(
263 struct xfs_mount
*mp
)
265 return XFS_DQUOT_LOGRES(mp
) +
266 MAX((xfs_calc_inode_res(mp
, 4) +
267 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
268 XFS_FSB_TO_B(mp
, 1))),
269 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
270 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 3),
271 XFS_FSB_TO_B(mp
, 1))));
275 * For removing an inode from unlinked list at first, we can modify:
276 * the agi hash list and counters: sector size
277 * the on disk inode before ours in the agi hash list: inode cluster size
280 xfs_calc_iunlink_remove_reservation(
281 struct xfs_mount
*mp
)
283 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
284 max_t(uint
, XFS_FSB_TO_B(mp
, 1), mp
->m_inode_cluster_size
);
288 * For creating a link to an inode:
289 * the parent directory inode: inode size
290 * the linked inode: inode size
291 * the directory btree could split: (max depth + v2) * dir block size
292 * the directory bmap btree could join or split: (max depth + v2) * blocksize
293 * And the bmap_finish transaction can free some bmap blocks giving:
294 * the agf for the ag in which the blocks live: sector size
295 * the agfl for the ag in which the blocks live: sector size
296 * the superblock for the free block count: sector size
297 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
300 xfs_calc_link_reservation(
301 struct xfs_mount
*mp
)
303 return XFS_DQUOT_LOGRES(mp
) +
304 xfs_calc_iunlink_remove_reservation(mp
) +
305 MAX((xfs_calc_inode_res(mp
, 2) +
306 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
307 XFS_FSB_TO_B(mp
, 1))),
308 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
309 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
310 XFS_FSB_TO_B(mp
, 1))));
314 * For adding an inode to unlinked list we can modify:
315 * the agi hash list: sector size
316 * the unlinked inode: inode size
319 xfs_calc_iunlink_add_reservation(xfs_mount_t
*mp
)
321 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
322 xfs_calc_inode_res(mp
, 1);
326 * For removing a directory entry we can modify:
327 * the parent directory inode: inode size
328 * the removed inode: inode size
329 * the directory btree could join: (max depth + v2) * dir block size
330 * the directory bmap btree could join or split: (max depth + v2) * blocksize
331 * And the bmap_finish transaction can free the dir and bmap blocks giving:
332 * the agf for the ag in which the blocks live: 2 * sector size
333 * the agfl for the ag in which the blocks live: 2 * sector size
334 * the superblock for the free block count: sector size
335 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
338 xfs_calc_remove_reservation(
339 struct xfs_mount
*mp
)
341 return XFS_DQUOT_LOGRES(mp
) +
342 xfs_calc_iunlink_add_reservation(mp
) +
343 MAX((xfs_calc_inode_res(mp
, 1) +
344 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
345 XFS_FSB_TO_B(mp
, 1))),
346 (xfs_calc_buf_res(4, mp
->m_sb
.sb_sectsize
) +
347 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
348 XFS_FSB_TO_B(mp
, 1))));
352 * For create, break it in to the two cases that the transaction
353 * covers. We start with the modify case - allocation done by modification
354 * of the state of existing inodes - and the allocation case.
358 * For create we can modify:
359 * the parent directory inode: inode size
360 * the new inode: inode size
361 * the inode btree entry: block size
362 * the superblock for the nlink flag: sector size
363 * the directory btree: (max depth + v2) * dir block size
364 * the directory inode's bmap btree: (max depth + v2) * block size
365 * the finobt (record modification and allocation btrees)
368 xfs_calc_create_resv_modify(
369 struct xfs_mount
*mp
)
371 return xfs_calc_inode_res(mp
, 2) +
372 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
373 (uint
)XFS_FSB_TO_B(mp
, 1) +
374 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1)) +
375 xfs_calc_finobt_res(mp
, 1, 1);
379 * For create we can allocate some inodes giving:
380 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
381 * the superblock for the nlink flag: sector size
382 * the inode blocks allocated: mp->m_ialloc_blks * blocksize
383 * the inode btree: max depth * blocksize
384 * the allocation btrees: 2 trees * (max depth - 1) * block size
387 xfs_calc_create_resv_alloc(
388 struct xfs_mount
*mp
)
390 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
391 mp
->m_sb
.sb_sectsize
+
392 xfs_calc_buf_res(mp
->m_ialloc_blks
, XFS_FSB_TO_B(mp
, 1)) +
393 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
394 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
395 XFS_FSB_TO_B(mp
, 1));
399 __xfs_calc_create_reservation(
400 struct xfs_mount
*mp
)
402 return XFS_DQUOT_LOGRES(mp
) +
403 MAX(xfs_calc_create_resv_alloc(mp
),
404 xfs_calc_create_resv_modify(mp
));
408 * For icreate we can allocate some inodes giving:
409 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
410 * the superblock for the nlink flag: sector size
411 * the inode btree: max depth * blocksize
412 * the allocation btrees: 2 trees * (max depth - 1) * block size
413 * the finobt (record insertion)
416 xfs_calc_icreate_resv_alloc(
417 struct xfs_mount
*mp
)
419 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
420 mp
->m_sb
.sb_sectsize
+
421 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
422 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
423 XFS_FSB_TO_B(mp
, 1)) +
424 xfs_calc_finobt_res(mp
, 0, 0);
428 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
430 return XFS_DQUOT_LOGRES(mp
) +
431 MAX(xfs_calc_icreate_resv_alloc(mp
),
432 xfs_calc_create_resv_modify(mp
));
436 xfs_calc_create_reservation(
437 struct xfs_mount
*mp
)
439 if (xfs_sb_version_hascrc(&mp
->m_sb
))
440 return xfs_calc_icreate_reservation(mp
);
441 return __xfs_calc_create_reservation(mp
);
446 xfs_calc_create_tmpfile_reservation(
447 struct xfs_mount
*mp
)
449 uint res
= XFS_DQUOT_LOGRES(mp
);
451 if (xfs_sb_version_hascrc(&mp
->m_sb
))
452 res
+= xfs_calc_icreate_resv_alloc(mp
);
454 res
+= xfs_calc_create_resv_alloc(mp
);
456 return res
+ xfs_calc_iunlink_add_reservation(mp
);
460 * Making a new directory is the same as creating a new file.
463 xfs_calc_mkdir_reservation(
464 struct xfs_mount
*mp
)
466 return xfs_calc_create_reservation(mp
);
471 * Making a new symplink is the same as creating a new file, but
472 * with the added blocks for remote symlink data which can be up to 1kB in
473 * length (XFS_SYMLINK_MAXLEN).
476 xfs_calc_symlink_reservation(
477 struct xfs_mount
*mp
)
479 return xfs_calc_create_reservation(mp
) +
480 xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN
);
484 * In freeing an inode we can modify:
485 * the inode being freed: inode size
486 * the super block free inode counter: sector size
487 * the agi hash list and counters: sector size
488 * the inode btree entry: block size
489 * the on disk inode before ours in the agi hash list: inode cluster size
490 * the inode btree: max depth * blocksize
491 * the allocation btrees: 2 trees * (max depth - 1) * block size
492 * the finobt (record insertion, removal or modification)
495 xfs_calc_ifree_reservation(
496 struct xfs_mount
*mp
)
498 return XFS_DQUOT_LOGRES(mp
) +
499 xfs_calc_inode_res(mp
, 1) +
500 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
501 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp
, 1)) +
502 xfs_calc_iunlink_remove_reservation(mp
) +
503 xfs_calc_buf_res(1, 0) +
504 xfs_calc_buf_res(2 + mp
->m_ialloc_blks
+
505 mp
->m_in_maxlevels
, 0) +
506 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
507 XFS_FSB_TO_B(mp
, 1)) +
508 xfs_calc_finobt_res(mp
, 0, 1);
512 * When only changing the inode we log the inode and possibly the superblock
513 * We also add a bit of slop for the transaction stuff.
516 xfs_calc_ichange_reservation(
517 struct xfs_mount
*mp
)
519 return XFS_DQUOT_LOGRES(mp
) +
520 xfs_calc_inode_res(mp
, 1) +
521 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
526 * Growing the data section of the filesystem.
532 xfs_calc_growdata_reservation(
533 struct xfs_mount
*mp
)
535 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
536 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
537 XFS_FSB_TO_B(mp
, 1));
541 * Growing the rt section of the filesystem.
542 * In the first set of transactions (ALLOC) we allocate space to the
543 * bitmap or summary files.
544 * superblock: sector size
545 * agf of the ag from which the extent is allocated: sector size
546 * bmap btree for bitmap/summary inode: max depth * blocksize
547 * bitmap/summary inode: inode size
548 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
551 xfs_calc_growrtalloc_reservation(
552 struct xfs_mount
*mp
)
554 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
555 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
556 XFS_FSB_TO_B(mp
, 1)) +
557 xfs_calc_inode_res(mp
, 1) +
558 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
559 XFS_FSB_TO_B(mp
, 1));
563 * Growing the rt section of the filesystem.
564 * In the second set of transactions (ZERO) we zero the new metadata blocks.
565 * one bitmap/summary block: blocksize
568 xfs_calc_growrtzero_reservation(
569 struct xfs_mount
*mp
)
571 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
575 * Growing the rt section of the filesystem.
576 * In the third set of transactions (FREE) we update metadata without
577 * allocating any new blocks.
578 * superblock: sector size
579 * bitmap inode: inode size
580 * summary inode: inode size
581 * one bitmap block: blocksize
582 * summary blocks: new summary size
585 xfs_calc_growrtfree_reservation(
586 struct xfs_mount
*mp
)
588 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
589 xfs_calc_inode_res(mp
, 2) +
590 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
591 xfs_calc_buf_res(1, mp
->m_rsumsize
);
595 * Logging the inode modification timestamp on a synchronous write.
599 xfs_calc_swrite_reservation(
600 struct xfs_mount
*mp
)
602 return xfs_calc_inode_res(mp
, 1);
606 * Logging the inode mode bits when writing a setuid/setgid file
610 xfs_calc_writeid_reservation(
611 struct xfs_mount
*mp
)
613 return xfs_calc_inode_res(mp
, 1);
617 * Converting the inode from non-attributed to attributed.
618 * the inode being converted: inode size
619 * agf block and superblock (for block allocation)
620 * the new block (directory sized)
621 * bmap blocks for the new directory block
625 xfs_calc_addafork_reservation(
626 struct xfs_mount
*mp
)
628 return XFS_DQUOT_LOGRES(mp
) +
629 xfs_calc_inode_res(mp
, 1) +
630 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
631 xfs_calc_buf_res(1, mp
->m_dir_geo
->blksize
) +
632 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
633 XFS_FSB_TO_B(mp
, 1)) +
634 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
635 XFS_FSB_TO_B(mp
, 1));
639 * Removing the attribute fork of a file
640 * the inode being truncated: inode size
641 * the inode's bmap btree: max depth * block size
642 * And the bmap_finish transaction can free the blocks and bmap blocks:
643 * the agf for each of the ags: 4 * sector size
644 * the agfl for each of the ags: 4 * sector size
645 * the super block to reflect the freed blocks: sector size
646 * worst case split in allocation btrees per extent assuming 4 extents:
647 * 4 exts * 2 trees * (2 * max depth - 1) * block size
650 xfs_calc_attrinval_reservation(
651 struct xfs_mount
*mp
)
653 return MAX((xfs_calc_inode_res(mp
, 1) +
654 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
655 XFS_FSB_TO_B(mp
, 1))),
656 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
657 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
658 XFS_FSB_TO_B(mp
, 1))));
662 * Setting an attribute at mount time.
663 * the inode getting the attribute
664 * the superblock for allocations
665 * the agfs extents are allocated from
666 * the attribute btree * max depth
667 * the inode allocation btree
668 * Since attribute transaction space is dependent on the size of the attribute,
669 * the calculation is done partially at mount time and partially at runtime(see
673 xfs_calc_attrsetm_reservation(
674 struct xfs_mount
*mp
)
676 return XFS_DQUOT_LOGRES(mp
) +
677 xfs_calc_inode_res(mp
, 1) +
678 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
679 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
683 * Setting an attribute at runtime, transaction space unit per block.
684 * the superblock for allocations: sector size
685 * the inode bmap btree could join or split: max depth * block size
686 * Since the runtime attribute transaction space is dependent on the total
687 * blocks needed for the 1st bmap, here we calculate out the space unit for
688 * one block so that the caller could figure out the total space according
689 * to the attibute extent length in blocks by:
690 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
693 xfs_calc_attrsetrt_reservation(
694 struct xfs_mount
*mp
)
696 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
697 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
698 XFS_FSB_TO_B(mp
, 1));
702 * Removing an attribute.
703 * the inode: inode size
704 * the attribute btree could join: max depth * block size
705 * the inode bmap btree could join or split: max depth * block size
706 * And the bmap_finish transaction can free the attr blocks freed giving:
707 * the agf for the ag in which the blocks live: 2 * sector size
708 * the agfl for the ag in which the blocks live: 2 * sector size
709 * the superblock for the free block count: sector size
710 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
713 xfs_calc_attrrm_reservation(
714 struct xfs_mount
*mp
)
716 return XFS_DQUOT_LOGRES(mp
) +
717 MAX((xfs_calc_inode_res(mp
, 1) +
718 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
719 XFS_FSB_TO_B(mp
, 1)) +
720 (uint
)XFS_FSB_TO_B(mp
,
721 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
722 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
723 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
724 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
725 XFS_FSB_TO_B(mp
, 1))));
729 * Clearing a bad agino number in an agi hash bucket.
732 xfs_calc_clear_agi_bucket_reservation(
733 struct xfs_mount
*mp
)
735 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
739 * Adjusting quota limits.
740 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
743 xfs_calc_qm_setqlim_reservation(
744 struct xfs_mount
*mp
)
746 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot
));
750 * Allocating quota on disk if needed.
751 * the write transaction log space for quota file extent allocation
752 * the unit of quota allocation: one system block size
755 xfs_calc_qm_dqalloc_reservation(
756 struct xfs_mount
*mp
)
758 return xfs_calc_write_reservation(mp
) +
760 XFS_FSB_TO_B(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
) - 1);
764 * Turning off quotas.
765 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
766 * the superblock for the quota flags: sector size
769 xfs_calc_qm_quotaoff_reservation(
770 struct xfs_mount
*mp
)
772 return sizeof(struct xfs_qoff_logitem
) * 2 +
773 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
777 * End of turning off quotas.
778 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
781 xfs_calc_qm_quotaoff_end_reservation(
782 struct xfs_mount
*mp
)
784 return sizeof(struct xfs_qoff_logitem
) * 2;
788 * Syncing the incore super block changes to disk.
789 * the super block to reflect the changes: sector size
792 xfs_calc_sb_reservation(
793 struct xfs_mount
*mp
)
795 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
800 struct xfs_mount
*mp
,
801 struct xfs_trans_resv
*resp
)
804 * The following transactions are logged in physical format and
805 * require a permanent reservation on space.
807 resp
->tr_write
.tr_logres
= xfs_calc_write_reservation(mp
);
808 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
809 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
811 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
812 resp
->tr_write
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
814 resp
->tr_itruncate
.tr_logres
= xfs_calc_itruncate_reservation(mp
);
815 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
816 resp
->tr_itruncate
.tr_logcount
=
817 XFS_ITRUNCATE_LOG_COUNT_REFLINK
;
819 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
820 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
822 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
823 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
824 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
826 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
827 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
828 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
830 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
831 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
832 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
834 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
835 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
836 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
838 resp
->tr_create
.tr_logres
= xfs_calc_create_reservation(mp
);
839 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
840 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
842 resp
->tr_create_tmpfile
.tr_logres
=
843 xfs_calc_create_tmpfile_reservation(mp
);
844 resp
->tr_create_tmpfile
.tr_logcount
= XFS_CREATE_TMPFILE_LOG_COUNT
;
845 resp
->tr_create_tmpfile
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
847 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
848 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
849 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
851 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
852 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
853 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
855 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
856 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
857 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
859 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
860 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
861 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
863 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
864 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
865 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
867 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
868 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
869 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
871 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
872 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
873 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
875 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
);
876 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
877 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
879 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
880 resp
->tr_qm_dqalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
883 * The following transactions are logged in logical format with
884 * a default log count.
886 resp
->tr_qm_setqlim
.tr_logres
= xfs_calc_qm_setqlim_reservation(mp
);
887 resp
->tr_qm_setqlim
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
889 resp
->tr_qm_quotaoff
.tr_logres
= xfs_calc_qm_quotaoff_reservation(mp
);
890 resp
->tr_qm_quotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
892 resp
->tr_qm_equotaoff
.tr_logres
=
893 xfs_calc_qm_quotaoff_end_reservation(mp
);
894 resp
->tr_qm_equotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
896 resp
->tr_sb
.tr_logres
= xfs_calc_sb_reservation(mp
);
897 resp
->tr_sb
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
899 /* The following transaction are logged in logical format */
900 resp
->tr_ichange
.tr_logres
= xfs_calc_ichange_reservation(mp
);
901 resp
->tr_growdata
.tr_logres
= xfs_calc_growdata_reservation(mp
);
902 resp
->tr_fsyncts
.tr_logres
= xfs_calc_swrite_reservation(mp
);
903 resp
->tr_writeid
.tr_logres
= xfs_calc_writeid_reservation(mp
);
904 resp
->tr_attrsetrt
.tr_logres
= xfs_calc_attrsetrt_reservation(mp
);
905 resp
->tr_clearagi
.tr_logres
= xfs_calc_clear_agi_bucket_reservation(mp
);
906 resp
->tr_growrtzero
.tr_logres
= xfs_calc_growrtzero_reservation(mp
);
907 resp
->tr_growrtfree
.tr_logres
= xfs_calc_growrtfree_reservation(mp
);