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"
40 * A buffer has a format structure overhead in the log in addition
41 * to the data, so we need to take this into account when reserving
42 * space in a transaction for a buffer. Round the space required up
43 * to a multiple of 128 bytes so that we don't change the historical
44 * reservation that has been used for this overhead.
47 xfs_buf_log_overhead(void)
49 return round_up(sizeof(struct xlog_op_header
) +
50 sizeof(struct xfs_buf_log_format
), 128);
54 * Calculate out transaction log reservation per item in bytes.
56 * The nbufs argument is used to indicate the number of items that
57 * will be changed in a transaction. size is used to tell how many
58 * bytes should be reserved per item.
65 return nbufs
* (size
+ xfs_buf_log_overhead());
69 * Per-extent log reservation for the btree changes involved in freeing or
70 * allocating an extent. In classic XFS there were two trees that will be
71 * modified (bnobt + cntbt). With rmap enabled, there are three trees
72 * (rmapbt). With reflink, there are four trees (refcountbt). The number of
73 * blocks reserved is based on the formula:
75 * num trees * ((2 blocks/level * max depth) - 1)
77 * Keep in mind that max depth is calculated separately for each type of tree.
80 xfs_allocfree_log_count(
86 blocks
= num_ops
* 2 * (2 * mp
->m_ag_maxlevels
- 1);
87 if (xfs_sb_version_hasrmapbt(&mp
->m_sb
))
88 blocks
+= num_ops
* (2 * mp
->m_rmap_maxlevels
- 1);
89 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
90 blocks
+= num_ops
* (2 * mp
->m_refc_maxlevels
- 1);
96 * Logging inodes is really tricksy. They are logged in memory format,
97 * which means that what we write into the log doesn't directly translate into
98 * the amount of space they use on disk.
100 * Case in point - btree format forks in memory format use more space than the
101 * on-disk format. In memory, the buffer contains a normal btree block header so
102 * the btree code can treat it as though it is just another generic buffer.
103 * However, when we write it to the inode fork, we don't write all of this
104 * header as it isn't needed. e.g. the root is only ever in the inode, so
105 * there's no need for sibling pointers which would waste 16 bytes of space.
107 * Hence when we have an inode with a maximally sized btree format fork, then
108 * amount of information we actually log is greater than the size of the inode
109 * on disk. Hence we need an inode reservation function that calculates all this
110 * correctly. So, we log:
112 * - 4 log op headers for object
113 * - for the ilf, the inode core and 2 forks
114 * - inode log format object
116 * - two inode forks containing bmap btree root blocks.
117 * - the btree data contained by both forks will fit into the inode size,
118 * hence when combined with the inode core above, we have a total of the
120 * - the BMBT headers need to be accounted separately, as they are
121 * additional to the records and pointers that fit inside the inode
126 struct xfs_mount
*mp
,
130 (4 * sizeof(struct xlog_op_header
) +
131 sizeof(struct xfs_inode_log_format
) +
132 mp
->m_sb
.sb_inodesize
+
133 2 * XFS_BMBT_BLOCK_LEN(mp
));
137 * Inode btree record insertion/removal modifies the inode btree and free space
138 * btrees (since the inobt does not use the agfl). This requires the following
141 * the inode btree: max depth * blocksize
142 * the allocation btrees: 2 trees * (max depth - 1) * block size
144 * The caller must account for SB and AG header modifications, etc.
148 struct xfs_mount
*mp
)
150 return xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
151 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
152 XFS_FSB_TO_B(mp
, 1));
156 * The free inode btree is a conditional feature. The behavior differs slightly
157 * from that of the traditional inode btree in that the finobt tracks records
158 * for inode chunks with at least one free inode. A record can be removed from
159 * the tree during individual inode allocation. Therefore the finobt
160 * reservation is unconditional for both the inode chunk allocation and
161 * individual inode allocation (modify) cases.
163 * Behavior aside, the reservation for finobt modification is equivalent to the
164 * traditional inobt: cover a full finobt shape change plus block allocation.
168 struct xfs_mount
*mp
)
170 if (!xfs_sb_version_hasfinobt(&mp
->m_sb
))
173 return xfs_calc_inobt_res(mp
);
177 * Calculate the reservation required to allocate or free an inode chunk. This
180 * the allocation btrees: 2 trees * (max depth - 1) * block size
181 * the inode chunk: m_ialloc_blks * N
183 * The size N of the inode chunk reservation depends on whether it is for
184 * allocation or free and which type of create transaction is in use. An inode
185 * chunk free always invalidates the buffers and only requires reservation for
186 * headers (N == 0). An inode chunk allocation requires a chunk sized
187 * reservation on v4 and older superblocks to initialize the chunk. No chunk
188 * reservation is required for allocation on v5 supers, which use ordered
189 * buffers to initialize.
192 xfs_calc_inode_chunk_res(
193 struct xfs_mount
*mp
,
198 res
= xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
199 XFS_FSB_TO_B(mp
, 1));
201 /* icreate tx uses ordered buffers */
202 if (xfs_sb_version_hascrc(&mp
->m_sb
))
204 size
= XFS_FSB_TO_B(mp
, 1);
207 res
+= xfs_calc_buf_res(mp
->m_ialloc_blks
, size
);
212 * Various log reservation values.
214 * These are based on the size of the file system block because that is what
215 * most transactions manipulate. Each adds in an additional 128 bytes per
216 * item logged to try to account for the overhead of the transaction mechanism.
218 * Note: Most of the reservations underestimate the number of allocation
219 * groups into which they could free extents in the xfs_defer_finish() call.
220 * This is because the number in the worst case is quite high and quite
221 * unusual. In order to fix this we need to change xfs_defer_finish() to free
222 * extents in only a single AG at a time. This will require changes to the
223 * EFI code as well, however, so that the EFI for the extents not freed is
224 * logged again in each transaction. See SGI PV #261917.
226 * Reservation functions here avoid a huge stack in xfs_trans_init due to
227 * register overflow from temporaries in the calculations.
232 * In a write transaction we can allocate a maximum of 2
233 * extents. This gives:
234 * the inode getting the new extents: inode size
235 * the inode's bmap btree: max depth * block size
236 * the agfs of the ags from which the extents are allocated: 2 * sector
237 * the superblock free block counter: sector size
238 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
239 * And the bmap_finish transaction can free bmap blocks in a join:
240 * the agfs of the ags containing the blocks: 2 * sector size
241 * the agfls of the ags containing the blocks: 2 * sector size
242 * the super block free block counter: sector size
243 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
246 xfs_calc_write_reservation(
247 struct xfs_mount
*mp
)
249 return XFS_DQUOT_LOGRES(mp
) +
250 MAX((xfs_calc_inode_res(mp
, 1) +
251 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
252 XFS_FSB_TO_B(mp
, 1)) +
253 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
254 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
255 XFS_FSB_TO_B(mp
, 1))),
256 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
257 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
258 XFS_FSB_TO_B(mp
, 1))));
262 * In truncating a file we free up to two extents at once. We can modify:
263 * the inode being truncated: inode size
264 * the inode's bmap btree: (max depth + 1) * block size
265 * And the bmap_finish transaction can free the blocks and bmap blocks:
266 * the agf for each of the ags: 4 * sector size
267 * the agfl for each of the ags: 4 * sector size
268 * the super block to reflect the freed blocks: sector size
269 * worst case split in allocation btrees per extent assuming 4 extents:
270 * 4 exts * 2 trees * (2 * max depth - 1) * block size
273 xfs_calc_itruncate_reservation(
274 struct xfs_mount
*mp
)
276 return XFS_DQUOT_LOGRES(mp
) +
277 MAX((xfs_calc_inode_res(mp
, 1) +
278 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1,
279 XFS_FSB_TO_B(mp
, 1))),
280 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
281 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
282 XFS_FSB_TO_B(mp
, 1))));
286 * In renaming a files we can modify:
287 * the four inodes involved: 4 * inode size
288 * the two directory btrees: 2 * (max depth + v2) * dir block size
289 * the two directory bmap btrees: 2 * max depth * block size
290 * And the bmap_finish transaction can free dir and bmap blocks (two sets
291 * of bmap blocks) giving:
292 * the agf for the ags in which the blocks live: 3 * sector size
293 * the agfl for the ags in which the blocks live: 3 * sector size
294 * the superblock for the free block count: sector size
295 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
298 xfs_calc_rename_reservation(
299 struct xfs_mount
*mp
)
301 return XFS_DQUOT_LOGRES(mp
) +
302 MAX((xfs_calc_inode_res(mp
, 4) +
303 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
304 XFS_FSB_TO_B(mp
, 1))),
305 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
306 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 3),
307 XFS_FSB_TO_B(mp
, 1))));
311 * For removing an inode from unlinked list at first, we can modify:
312 * the agi hash list and counters: sector size
313 * the on disk inode before ours in the agi hash list: inode cluster size
314 * the on disk inode in the agi hash list: inode cluster size
317 xfs_calc_iunlink_remove_reservation(
318 struct xfs_mount
*mp
)
320 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
321 2 * max_t(uint
, XFS_FSB_TO_B(mp
, 1), mp
->m_inode_cluster_size
);
325 * For creating a link to an inode:
326 * the parent directory inode: inode size
327 * the linked inode: inode size
328 * the directory btree could split: (max depth + v2) * dir block size
329 * the directory bmap btree could join or split: (max depth + v2) * blocksize
330 * And the bmap_finish transaction can free some bmap blocks giving:
331 * the agf for the ag in which the blocks live: sector size
332 * the agfl for the ag in which the blocks live: sector size
333 * the superblock for the free block count: sector size
334 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
337 xfs_calc_link_reservation(
338 struct xfs_mount
*mp
)
340 return XFS_DQUOT_LOGRES(mp
) +
341 xfs_calc_iunlink_remove_reservation(mp
) +
342 MAX((xfs_calc_inode_res(mp
, 2) +
343 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
344 XFS_FSB_TO_B(mp
, 1))),
345 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
346 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
347 XFS_FSB_TO_B(mp
, 1))));
351 * For adding an inode to unlinked list we can modify:
352 * the agi hash list: sector size
353 * the on disk inode: inode cluster size
356 xfs_calc_iunlink_add_reservation(xfs_mount_t
*mp
)
358 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
359 max_t(uint
, XFS_FSB_TO_B(mp
, 1), mp
->m_inode_cluster_size
);
363 * For removing a directory entry we can modify:
364 * the parent directory inode: inode size
365 * the removed inode: inode size
366 * the directory btree could join: (max depth + v2) * dir block size
367 * the directory bmap btree could join or split: (max depth + v2) * blocksize
368 * And the bmap_finish transaction can free the dir and bmap blocks giving:
369 * the agf for the ag in which the blocks live: 2 * sector size
370 * the agfl for the ag in which the blocks live: 2 * sector size
371 * the superblock for the free block count: sector size
372 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
375 xfs_calc_remove_reservation(
376 struct xfs_mount
*mp
)
378 return XFS_DQUOT_LOGRES(mp
) +
379 xfs_calc_iunlink_add_reservation(mp
) +
380 MAX((xfs_calc_inode_res(mp
, 1) +
381 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
382 XFS_FSB_TO_B(mp
, 1))),
383 (xfs_calc_buf_res(4, mp
->m_sb
.sb_sectsize
) +
384 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
385 XFS_FSB_TO_B(mp
, 1))));
389 * For create, break it in to the two cases that the transaction
390 * covers. We start with the modify case - allocation done by modification
391 * of the state of existing inodes - and the allocation case.
395 * For create we can modify:
396 * the parent directory inode: inode size
397 * the new inode: inode size
398 * the inode btree entry: block size
399 * the superblock for the nlink flag: sector size
400 * the directory btree: (max depth + v2) * dir block size
401 * the directory inode's bmap btree: (max depth + v2) * block size
402 * the finobt (record modification and allocation btrees)
405 xfs_calc_create_resv_modify(
406 struct xfs_mount
*mp
)
408 return xfs_calc_inode_res(mp
, 2) +
409 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
410 (uint
)XFS_FSB_TO_B(mp
, 1) +
411 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1)) +
412 xfs_calc_finobt_res(mp
);
416 * For icreate we can allocate some inodes giving:
417 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
418 * the superblock for the nlink flag: sector size
419 * the inode chunk (allocation, optional init)
420 * the inobt (record insertion)
421 * the finobt (optional, record insertion)
424 xfs_calc_icreate_resv_alloc(
425 struct xfs_mount
*mp
)
427 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
428 mp
->m_sb
.sb_sectsize
+
429 xfs_calc_inode_chunk_res(mp
, _ALLOC
) +
430 xfs_calc_inobt_res(mp
) +
431 xfs_calc_finobt_res(mp
);
435 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
437 return XFS_DQUOT_LOGRES(mp
) +
438 MAX(xfs_calc_icreate_resv_alloc(mp
),
439 xfs_calc_create_resv_modify(mp
));
443 xfs_calc_create_tmpfile_reservation(
444 struct xfs_mount
*mp
)
446 uint res
= XFS_DQUOT_LOGRES(mp
);
448 res
+= xfs_calc_icreate_resv_alloc(mp
);
449 return res
+ xfs_calc_iunlink_add_reservation(mp
);
453 * Making a new directory is the same as creating a new file.
456 xfs_calc_mkdir_reservation(
457 struct xfs_mount
*mp
)
459 return xfs_calc_icreate_reservation(mp
);
464 * Making a new symplink is the same as creating a new file, but
465 * with the added blocks for remote symlink data which can be up to 1kB in
466 * length (XFS_SYMLINK_MAXLEN).
469 xfs_calc_symlink_reservation(
470 struct xfs_mount
*mp
)
472 return xfs_calc_icreate_reservation(mp
) +
473 xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN
);
477 * In freeing an inode we can modify:
478 * the inode being freed: inode size
479 * the super block free inode counter, AGF and AGFL: sector size
480 * the on disk inode (agi unlinked list removal)
481 * the inode chunk (invalidated, headers only)
483 * the finobt (record insertion, removal or modification)
485 * Note that the inode chunk res. includes an allocfree res. for freeing of the
486 * inode chunk. This is technically extraneous because the inode chunk free is
487 * deferred (it occurs after a transaction roll). Include the extra reservation
488 * anyways since we've had reports of ifree transaction overruns due to too many
489 * agfl fixups during inode chunk frees.
492 xfs_calc_ifree_reservation(
493 struct xfs_mount
*mp
)
495 return XFS_DQUOT_LOGRES(mp
) +
496 xfs_calc_inode_res(mp
, 1) +
497 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
498 xfs_calc_iunlink_remove_reservation(mp
) +
499 xfs_calc_inode_chunk_res(mp
, _FREE
) +
500 xfs_calc_inobt_res(mp
) +
501 xfs_calc_finobt_res(mp
);
505 * When only changing the inode we log the inode and possibly the superblock
506 * We also add a bit of slop for the transaction stuff.
509 xfs_calc_ichange_reservation(
510 struct xfs_mount
*mp
)
512 return XFS_DQUOT_LOGRES(mp
) +
513 xfs_calc_inode_res(mp
, 1) +
514 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
519 * Growing the data section of the filesystem.
525 xfs_calc_growdata_reservation(
526 struct xfs_mount
*mp
)
528 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
529 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
530 XFS_FSB_TO_B(mp
, 1));
534 * Growing the rt section of the filesystem.
535 * In the first set of transactions (ALLOC) we allocate space to the
536 * bitmap or summary files.
537 * superblock: sector size
538 * agf of the ag from which the extent is allocated: sector size
539 * bmap btree for bitmap/summary inode: max depth * blocksize
540 * bitmap/summary inode: inode size
541 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
544 xfs_calc_growrtalloc_reservation(
545 struct xfs_mount
*mp
)
547 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
548 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
549 XFS_FSB_TO_B(mp
, 1)) +
550 xfs_calc_inode_res(mp
, 1) +
551 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
552 XFS_FSB_TO_B(mp
, 1));
556 * Growing the rt section of the filesystem.
557 * In the second set of transactions (ZERO) we zero the new metadata blocks.
558 * one bitmap/summary block: blocksize
561 xfs_calc_growrtzero_reservation(
562 struct xfs_mount
*mp
)
564 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
568 * Growing the rt section of the filesystem.
569 * In the third set of transactions (FREE) we update metadata without
570 * allocating any new blocks.
571 * superblock: sector size
572 * bitmap inode: inode size
573 * summary inode: inode size
574 * one bitmap block: blocksize
575 * summary blocks: new summary size
578 xfs_calc_growrtfree_reservation(
579 struct xfs_mount
*mp
)
581 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
582 xfs_calc_inode_res(mp
, 2) +
583 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
584 xfs_calc_buf_res(1, mp
->m_rsumsize
);
588 * Logging the inode modification timestamp on a synchronous write.
592 xfs_calc_swrite_reservation(
593 struct xfs_mount
*mp
)
595 return xfs_calc_inode_res(mp
, 1);
599 * Logging the inode mode bits when writing a setuid/setgid file
603 xfs_calc_writeid_reservation(
604 struct xfs_mount
*mp
)
606 return xfs_calc_inode_res(mp
, 1);
610 * Converting the inode from non-attributed to attributed.
611 * the inode being converted: inode size
612 * agf block and superblock (for block allocation)
613 * the new block (directory sized)
614 * bmap blocks for the new directory block
618 xfs_calc_addafork_reservation(
619 struct xfs_mount
*mp
)
621 return XFS_DQUOT_LOGRES(mp
) +
622 xfs_calc_inode_res(mp
, 1) +
623 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
624 xfs_calc_buf_res(1, mp
->m_dir_geo
->blksize
) +
625 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
626 XFS_FSB_TO_B(mp
, 1)) +
627 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
628 XFS_FSB_TO_B(mp
, 1));
632 * Removing the attribute fork of a file
633 * the inode being truncated: inode size
634 * the inode's bmap btree: max depth * block size
635 * And the bmap_finish transaction can free the blocks and bmap blocks:
636 * the agf for each of the ags: 4 * sector size
637 * the agfl for each of the ags: 4 * sector size
638 * the super block to reflect the freed blocks: sector size
639 * worst case split in allocation btrees per extent assuming 4 extents:
640 * 4 exts * 2 trees * (2 * max depth - 1) * block size
643 xfs_calc_attrinval_reservation(
644 struct xfs_mount
*mp
)
646 return MAX((xfs_calc_inode_res(mp
, 1) +
647 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
648 XFS_FSB_TO_B(mp
, 1))),
649 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
650 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
651 XFS_FSB_TO_B(mp
, 1))));
655 * Setting an attribute at mount time.
656 * the inode getting the attribute
657 * the superblock for allocations
658 * the agfs extents are allocated from
659 * the attribute btree * max depth
660 * the inode allocation btree
661 * Since attribute transaction space is dependent on the size of the attribute,
662 * the calculation is done partially at mount time and partially at runtime(see
666 xfs_calc_attrsetm_reservation(
667 struct xfs_mount
*mp
)
669 return XFS_DQUOT_LOGRES(mp
) +
670 xfs_calc_inode_res(mp
, 1) +
671 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
672 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
676 * Setting an attribute at runtime, transaction space unit per block.
677 * the superblock for allocations: sector size
678 * the inode bmap btree could join or split: max depth * block size
679 * Since the runtime attribute transaction space is dependent on the total
680 * blocks needed for the 1st bmap, here we calculate out the space unit for
681 * one block so that the caller could figure out the total space according
682 * to the attibute extent length in blocks by:
683 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
686 xfs_calc_attrsetrt_reservation(
687 struct xfs_mount
*mp
)
689 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
690 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
691 XFS_FSB_TO_B(mp
, 1));
695 * Removing an attribute.
696 * the inode: inode size
697 * the attribute btree could join: max depth * block size
698 * the inode bmap btree could join or split: max depth * block size
699 * And the bmap_finish transaction can free the attr blocks freed giving:
700 * the agf for the ag in which the blocks live: 2 * sector size
701 * the agfl for the ag in which the blocks live: 2 * sector size
702 * the superblock for the free block count: sector size
703 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
706 xfs_calc_attrrm_reservation(
707 struct xfs_mount
*mp
)
709 return XFS_DQUOT_LOGRES(mp
) +
710 MAX((xfs_calc_inode_res(mp
, 1) +
711 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
712 XFS_FSB_TO_B(mp
, 1)) +
713 (uint
)XFS_FSB_TO_B(mp
,
714 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
715 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
716 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
717 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
718 XFS_FSB_TO_B(mp
, 1))));
722 * Clearing a bad agino number in an agi hash bucket.
725 xfs_calc_clear_agi_bucket_reservation(
726 struct xfs_mount
*mp
)
728 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
732 * Adjusting quota limits.
733 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
736 xfs_calc_qm_setqlim_reservation(
737 struct xfs_mount
*mp
)
739 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot
));
743 * Allocating quota on disk if needed.
744 * the write transaction log space for quota file extent allocation
745 * the unit of quota allocation: one system block size
748 xfs_calc_qm_dqalloc_reservation(
749 struct xfs_mount
*mp
)
751 return xfs_calc_write_reservation(mp
) +
753 XFS_FSB_TO_B(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
) - 1);
757 * Turning off quotas.
758 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
759 * the superblock for the quota flags: sector size
762 xfs_calc_qm_quotaoff_reservation(
763 struct xfs_mount
*mp
)
765 return sizeof(struct xfs_qoff_logitem
) * 2 +
766 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
770 * End of turning off quotas.
771 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
774 xfs_calc_qm_quotaoff_end_reservation(
775 struct xfs_mount
*mp
)
777 return sizeof(struct xfs_qoff_logitem
) * 2;
781 * Syncing the incore super block changes to disk.
782 * the super block to reflect the changes: sector size
785 xfs_calc_sb_reservation(
786 struct xfs_mount
*mp
)
788 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
793 struct xfs_mount
*mp
,
794 struct xfs_trans_resv
*resp
)
797 * The following transactions are logged in physical format and
798 * require a permanent reservation on space.
800 resp
->tr_write
.tr_logres
= xfs_calc_write_reservation(mp
);
801 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
802 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
804 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
805 resp
->tr_write
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
807 resp
->tr_itruncate
.tr_logres
= xfs_calc_itruncate_reservation(mp
);
808 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
809 resp
->tr_itruncate
.tr_logcount
=
810 XFS_ITRUNCATE_LOG_COUNT_REFLINK
;
812 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
813 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
815 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
816 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
817 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
819 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
820 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
821 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
823 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
824 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
825 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
827 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
828 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
829 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
831 resp
->tr_create
.tr_logres
= xfs_calc_icreate_reservation(mp
);
832 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
833 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
835 resp
->tr_create_tmpfile
.tr_logres
=
836 xfs_calc_create_tmpfile_reservation(mp
);
837 resp
->tr_create_tmpfile
.tr_logcount
= XFS_CREATE_TMPFILE_LOG_COUNT
;
838 resp
->tr_create_tmpfile
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
840 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
841 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
842 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
844 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
845 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
846 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
848 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
849 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
850 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
852 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
853 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
854 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
856 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
857 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
858 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
860 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
861 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
862 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
864 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
865 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
866 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
868 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
);
869 if (xfs_sb_version_hasreflink(&mp
->m_sb
))
870 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT_REFLINK
;
872 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
873 resp
->tr_qm_dqalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
876 * The following transactions are logged in logical format with
877 * a default log count.
879 resp
->tr_qm_setqlim
.tr_logres
= xfs_calc_qm_setqlim_reservation(mp
);
880 resp
->tr_qm_setqlim
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
882 resp
->tr_qm_quotaoff
.tr_logres
= xfs_calc_qm_quotaoff_reservation(mp
);
883 resp
->tr_qm_quotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
885 resp
->tr_qm_equotaoff
.tr_logres
=
886 xfs_calc_qm_quotaoff_end_reservation(mp
);
887 resp
->tr_qm_equotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
889 resp
->tr_sb
.tr_logres
= xfs_calc_sb_reservation(mp
);
890 resp
->tr_sb
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
892 /* The following transaction are logged in logical format */
893 resp
->tr_ichange
.tr_logres
= xfs_calc_ichange_reservation(mp
);
894 resp
->tr_growdata
.tr_logres
= xfs_calc_growdata_reservation(mp
);
895 resp
->tr_fsyncts
.tr_logres
= xfs_calc_swrite_reservation(mp
);
896 resp
->tr_writeid
.tr_logres
= xfs_calc_writeid_reservation(mp
);
897 resp
->tr_attrsetrt
.tr_logres
= xfs_calc_attrsetrt_reservation(mp
);
898 resp
->tr_clearagi
.tr_logres
= xfs_calc_clear_agi_bucket_reservation(mp
);
899 resp
->tr_growrtzero
.tr_logres
= xfs_calc_growrtzero_reservation(mp
);
900 resp
->tr_growrtfree
.tr_logres
= xfs_calc_growrtfree_reservation(mp
);