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"
27 #include "xfs_mount.h"
28 #include "xfs_da_format.h"
29 #include "xfs_da_btree.h"
30 #include "xfs_inode.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_ialloc.h"
33 #include "xfs_quota.h"
34 #include "xfs_trans.h"
36 #include "xfs_trans_space.h"
37 #include "xfs_trace.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 * Logging inodes is really tricksy. They are logged in memory format,
70 * which means that what we write into the log doesn't directly translate into
71 * the amount of space they use on disk.
73 * Case in point - btree format forks in memory format use more space than the
74 * on-disk format. In memory, the buffer contains a normal btree block header so
75 * the btree code can treat it as though it is just another generic buffer.
76 * However, when we write it to the inode fork, we don't write all of this
77 * header as it isn't needed. e.g. the root is only ever in the inode, so
78 * there's no need for sibling pointers which would waste 16 bytes of space.
80 * Hence when we have an inode with a maximally sized btree format fork, then
81 * amount of information we actually log is greater than the size of the inode
82 * on disk. Hence we need an inode reservation function that calculates all this
83 * correctly. So, we log:
85 * - 4 log op headers for object
86 * - for the ilf, the inode core and 2 forks
87 * - inode log format object
89 * - two inode forks containing bmap btree root blocks.
90 * - the btree data contained by both forks will fit into the inode size,
91 * hence when combined with the inode core above, we have a total of the
93 * - the BMBT headers need to be accounted separately, as they are
94 * additional to the records and pointers that fit inside the inode
103 (4 * 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 * The free inode btree is a conditional feature and the log reservation
111 * requirements differ slightly from that of the traditional inode allocation
112 * btree. The finobt tracks records for inode chunks with at least one free
113 * inode. A record can be removed from the tree for an inode allocation
114 * or free and thus the finobt reservation is unconditional across:
118 * - inode chunk allocation
120 * The 'modify' param indicates to include the record modification scenario. The
121 * 'alloc' param indicates to include the reservation for free space btree
122 * modifications on behalf of finobt modifications. This is required only for
123 * transactions that do not already account for free space btree modifications.
125 * the free inode btree: max depth * block size
126 * the allocation btrees: 2 trees * (max depth - 1) * block size
127 * the free inode btree entry: block size
131 struct xfs_mount
*mp
,
137 if (!xfs_sb_version_hasfinobt(&mp
->m_sb
))
140 res
= xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1));
142 res
+= xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
143 XFS_FSB_TO_B(mp
, 1));
145 res
+= (uint
)XFS_FSB_TO_B(mp
, 1);
151 * Various log reservation values.
153 * These are based on the size of the file system block because that is what
154 * most transactions manipulate. Each adds in an additional 128 bytes per
155 * item logged to try to account for the overhead of the transaction mechanism.
157 * Note: Most of the reservations underestimate the number of allocation
158 * groups into which they could free extents in the xfs_bmap_finish() call.
159 * This is because the number in the worst case is quite high and quite
160 * unusual. In order to fix this we need to change xfs_bmap_finish() to free
161 * extents in only a single AG at a time. This will require changes to the
162 * EFI code as well, however, so that the EFI for the extents not freed is
163 * logged again in each transaction. See SGI PV #261917.
165 * Reservation functions here avoid a huge stack in xfs_trans_init due to
166 * register overflow from temporaries in the calculations.
171 * In a write transaction we can allocate a maximum of 2
172 * extents. This gives:
173 * the inode getting the new extents: inode size
174 * the inode's bmap btree: max depth * block size
175 * the agfs of the ags from which the extents are allocated: 2 * sector
176 * the superblock free block counter: sector size
177 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
178 * And the bmap_finish transaction can free bmap blocks in a join:
179 * the agfs of the ags containing the blocks: 2 * sector size
180 * the agfls of the ags containing the blocks: 2 * sector size
181 * the super block free block counter: sector size
182 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
185 xfs_calc_write_reservation(
186 struct xfs_mount
*mp
)
188 return XFS_DQUOT_LOGRES(mp
) +
189 MAX((xfs_calc_inode_res(mp
, 1) +
190 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
191 XFS_FSB_TO_B(mp
, 1)) +
192 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
193 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
194 XFS_FSB_TO_B(mp
, 1))),
195 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
196 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
197 XFS_FSB_TO_B(mp
, 1))));
201 * In truncating a file we free up to two extents at once. We can modify:
202 * the inode being truncated: inode size
203 * the inode's bmap btree: (max depth + 1) * block size
204 * And the bmap_finish transaction can free the blocks and bmap blocks:
205 * the agf for each of the ags: 4 * sector size
206 * the agfl for each of the ags: 4 * sector size
207 * the super block to reflect the freed blocks: sector size
208 * worst case split in allocation btrees per extent assuming 4 extents:
209 * 4 exts * 2 trees * (2 * max depth - 1) * block size
210 * the inode btree: max depth * blocksize
211 * the allocation btrees: 2 trees * (max depth - 1) * block size
214 xfs_calc_itruncate_reservation(
215 struct xfs_mount
*mp
)
217 return XFS_DQUOT_LOGRES(mp
) +
218 MAX((xfs_calc_inode_res(mp
, 1) +
219 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1,
220 XFS_FSB_TO_B(mp
, 1))),
221 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
222 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 4),
223 XFS_FSB_TO_B(mp
, 1)) +
224 xfs_calc_buf_res(5, 0) +
225 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
226 XFS_FSB_TO_B(mp
, 1)) +
227 xfs_calc_buf_res(2 + mp
->m_ialloc_blks
+
228 mp
->m_in_maxlevels
, 0)));
232 * In renaming a files we can modify:
233 * the four inodes involved: 4 * inode size
234 * the two directory btrees: 2 * (max depth + v2) * dir block size
235 * the two directory bmap btrees: 2 * max depth * block size
236 * And the bmap_finish transaction can free dir and bmap blocks (two sets
237 * of bmap blocks) giving:
238 * the agf for the ags in which the blocks live: 3 * sector size
239 * the agfl for the ags in which the blocks live: 3 * sector size
240 * the superblock for the free block count: sector size
241 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
244 xfs_calc_rename_reservation(
245 struct xfs_mount
*mp
)
247 return XFS_DQUOT_LOGRES(mp
) +
248 MAX((xfs_calc_inode_res(mp
, 4) +
249 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
250 XFS_FSB_TO_B(mp
, 1))),
251 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
252 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 3),
253 XFS_FSB_TO_B(mp
, 1))));
257 * For removing an inode from unlinked list at first, we can modify:
258 * the agi hash list and counters: sector size
259 * the on disk inode before ours in the agi hash list: inode cluster size
262 xfs_calc_iunlink_remove_reservation(
263 struct xfs_mount
*mp
)
265 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
266 max_t(uint
, XFS_FSB_TO_B(mp
, 1), mp
->m_inode_cluster_size
);
270 * For creating a link to an inode:
271 * the parent directory inode: inode size
272 * the linked inode: inode size
273 * the directory btree could split: (max depth + v2) * dir block size
274 * the directory bmap btree could join or split: (max depth + v2) * blocksize
275 * And the bmap_finish transaction can free some bmap blocks giving:
276 * the agf for the ag in which the blocks live: sector size
277 * the agfl for the ag in which the blocks live: sector size
278 * the superblock for the free block count: sector size
279 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
282 xfs_calc_link_reservation(
283 struct xfs_mount
*mp
)
285 return XFS_DQUOT_LOGRES(mp
) +
286 xfs_calc_iunlink_remove_reservation(mp
) +
287 MAX((xfs_calc_inode_res(mp
, 2) +
288 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
289 XFS_FSB_TO_B(mp
, 1))),
290 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
291 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
292 XFS_FSB_TO_B(mp
, 1))));
296 * For adding an inode to unlinked list we can modify:
297 * the agi hash list: sector size
298 * the unlinked inode: inode size
301 xfs_calc_iunlink_add_reservation(xfs_mount_t
*mp
)
303 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
304 xfs_calc_inode_res(mp
, 1);
308 * For removing a directory entry we can modify:
309 * the parent directory inode: inode size
310 * the removed inode: inode size
311 * the directory btree could join: (max depth + v2) * dir block size
312 * the directory bmap btree could join or split: (max depth + v2) * blocksize
313 * And the bmap_finish transaction can free the dir and bmap blocks giving:
314 * the agf for the ag in which the blocks live: 2 * sector size
315 * the agfl for the ag in which the blocks live: 2 * sector size
316 * the superblock for the free block count: sector size
317 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
320 xfs_calc_remove_reservation(
321 struct xfs_mount
*mp
)
323 return XFS_DQUOT_LOGRES(mp
) +
324 xfs_calc_iunlink_add_reservation(mp
) +
325 MAX((xfs_calc_inode_res(mp
, 1) +
326 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
327 XFS_FSB_TO_B(mp
, 1))),
328 (xfs_calc_buf_res(4, mp
->m_sb
.sb_sectsize
) +
329 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
330 XFS_FSB_TO_B(mp
, 1))));
334 * For create, break it in to the two cases that the transaction
335 * covers. We start with the modify case - allocation done by modification
336 * of the state of existing inodes - and the allocation case.
340 * For create we can modify:
341 * the parent directory inode: inode size
342 * the new inode: inode size
343 * the inode btree entry: block size
344 * the superblock for the nlink flag: sector size
345 * the directory btree: (max depth + v2) * dir block size
346 * the directory inode's bmap btree: (max depth + v2) * block size
347 * the finobt (record modification and allocation btrees)
350 xfs_calc_create_resv_modify(
351 struct xfs_mount
*mp
)
353 return xfs_calc_inode_res(mp
, 2) +
354 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
355 (uint
)XFS_FSB_TO_B(mp
, 1) +
356 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1)) +
357 xfs_calc_finobt_res(mp
, 1, 1);
361 * For create we can allocate some inodes giving:
362 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
363 * the superblock for the nlink flag: sector size
364 * the inode blocks allocated: mp->m_ialloc_blks * blocksize
365 * the inode btree: max depth * blocksize
366 * the allocation btrees: 2 trees * (max depth - 1) * block size
369 xfs_calc_create_resv_alloc(
370 struct xfs_mount
*mp
)
372 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
373 mp
->m_sb
.sb_sectsize
+
374 xfs_calc_buf_res(mp
->m_ialloc_blks
, XFS_FSB_TO_B(mp
, 1)) +
375 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
376 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
377 XFS_FSB_TO_B(mp
, 1));
381 __xfs_calc_create_reservation(
382 struct xfs_mount
*mp
)
384 return XFS_DQUOT_LOGRES(mp
) +
385 MAX(xfs_calc_create_resv_alloc(mp
),
386 xfs_calc_create_resv_modify(mp
));
390 * For icreate we can allocate some inodes giving:
391 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
392 * the superblock for the nlink flag: sector size
393 * the inode btree: max depth * blocksize
394 * the allocation btrees: 2 trees * (max depth - 1) * block size
395 * the finobt (record insertion)
398 xfs_calc_icreate_resv_alloc(
399 struct xfs_mount
*mp
)
401 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
402 mp
->m_sb
.sb_sectsize
+
403 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
404 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
405 XFS_FSB_TO_B(mp
, 1)) +
406 xfs_calc_finobt_res(mp
, 0, 0);
410 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
412 return XFS_DQUOT_LOGRES(mp
) +
413 MAX(xfs_calc_icreate_resv_alloc(mp
),
414 xfs_calc_create_resv_modify(mp
));
418 xfs_calc_create_reservation(
419 struct xfs_mount
*mp
)
421 if (xfs_sb_version_hascrc(&mp
->m_sb
))
422 return xfs_calc_icreate_reservation(mp
);
423 return __xfs_calc_create_reservation(mp
);
428 xfs_calc_create_tmpfile_reservation(
429 struct xfs_mount
*mp
)
431 uint res
= XFS_DQUOT_LOGRES(mp
);
433 if (xfs_sb_version_hascrc(&mp
->m_sb
))
434 res
+= xfs_calc_icreate_resv_alloc(mp
);
436 res
+= xfs_calc_create_resv_alloc(mp
);
438 return res
+ xfs_calc_iunlink_add_reservation(mp
);
442 * Making a new directory is the same as creating a new file.
445 xfs_calc_mkdir_reservation(
446 struct xfs_mount
*mp
)
448 return xfs_calc_create_reservation(mp
);
453 * Making a new symplink is the same as creating a new file, but
454 * with the added blocks for remote symlink data which can be up to 1kB in
455 * length (MAXPATHLEN).
458 xfs_calc_symlink_reservation(
459 struct xfs_mount
*mp
)
461 return xfs_calc_create_reservation(mp
) +
462 xfs_calc_buf_res(1, MAXPATHLEN
);
466 * In freeing an inode we can modify:
467 * the inode being freed: inode size
468 * the super block free inode counter: sector size
469 * the agi hash list and counters: sector size
470 * the inode btree entry: block size
471 * the on disk inode before ours in the agi hash list: inode cluster size
472 * the inode btree: max depth * blocksize
473 * the allocation btrees: 2 trees * (max depth - 1) * block size
474 * the finobt (record insertion, removal or modification)
477 xfs_calc_ifree_reservation(
478 struct xfs_mount
*mp
)
480 return XFS_DQUOT_LOGRES(mp
) +
481 xfs_calc_inode_res(mp
, 1) +
482 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
483 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp
, 1)) +
484 xfs_calc_iunlink_remove_reservation(mp
) +
485 xfs_calc_buf_res(1, 0) +
486 xfs_calc_buf_res(2 + mp
->m_ialloc_blks
+
487 mp
->m_in_maxlevels
, 0) +
488 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
489 XFS_FSB_TO_B(mp
, 1)) +
490 xfs_calc_finobt_res(mp
, 0, 1);
494 * When only changing the inode we log the inode and possibly the superblock
495 * We also add a bit of slop for the transaction stuff.
498 xfs_calc_ichange_reservation(
499 struct xfs_mount
*mp
)
501 return XFS_DQUOT_LOGRES(mp
) +
502 xfs_calc_inode_res(mp
, 1) +
503 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
508 * Growing the data section of the filesystem.
514 xfs_calc_growdata_reservation(
515 struct xfs_mount
*mp
)
517 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
518 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
519 XFS_FSB_TO_B(mp
, 1));
523 * Growing the rt section of the filesystem.
524 * In the first set of transactions (ALLOC) we allocate space to the
525 * bitmap or summary files.
526 * superblock: sector size
527 * agf of the ag from which the extent is allocated: sector size
528 * bmap btree for bitmap/summary inode: max depth * blocksize
529 * bitmap/summary inode: inode size
530 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
533 xfs_calc_growrtalloc_reservation(
534 struct xfs_mount
*mp
)
536 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
537 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
538 XFS_FSB_TO_B(mp
, 1)) +
539 xfs_calc_inode_res(mp
, 1) +
540 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
541 XFS_FSB_TO_B(mp
, 1));
545 * Growing the rt section of the filesystem.
546 * In the second set of transactions (ZERO) we zero the new metadata blocks.
547 * one bitmap/summary block: blocksize
550 xfs_calc_growrtzero_reservation(
551 struct xfs_mount
*mp
)
553 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
557 * Growing the rt section of the filesystem.
558 * In the third set of transactions (FREE) we update metadata without
559 * allocating any new blocks.
560 * superblock: sector size
561 * bitmap inode: inode size
562 * summary inode: inode size
563 * one bitmap block: blocksize
564 * summary blocks: new summary size
567 xfs_calc_growrtfree_reservation(
568 struct xfs_mount
*mp
)
570 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
571 xfs_calc_inode_res(mp
, 2) +
572 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
573 xfs_calc_buf_res(1, mp
->m_rsumsize
);
577 * Logging the inode modification timestamp on a synchronous write.
581 xfs_calc_swrite_reservation(
582 struct xfs_mount
*mp
)
584 return xfs_calc_inode_res(mp
, 1);
588 * Logging the inode mode bits when writing a setuid/setgid file
592 xfs_calc_writeid_reservation(
593 struct xfs_mount
*mp
)
595 return xfs_calc_inode_res(mp
, 1);
599 * Converting the inode from non-attributed to attributed.
600 * the inode being converted: inode size
601 * agf block and superblock (for block allocation)
602 * the new block (directory sized)
603 * bmap blocks for the new directory block
607 xfs_calc_addafork_reservation(
608 struct xfs_mount
*mp
)
610 return XFS_DQUOT_LOGRES(mp
) +
611 xfs_calc_inode_res(mp
, 1) +
612 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
613 xfs_calc_buf_res(1, mp
->m_dir_geo
->blksize
) +
614 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
615 XFS_FSB_TO_B(mp
, 1)) +
616 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
617 XFS_FSB_TO_B(mp
, 1));
621 * Removing the attribute fork of a file
622 * the inode being truncated: inode size
623 * the inode's bmap btree: max depth * block size
624 * And the bmap_finish transaction can free the blocks and bmap blocks:
625 * the agf for each of the ags: 4 * sector size
626 * the agfl for each of the ags: 4 * sector size
627 * the super block to reflect the freed blocks: sector size
628 * worst case split in allocation btrees per extent assuming 4 extents:
629 * 4 exts * 2 trees * (2 * max depth - 1) * block size
632 xfs_calc_attrinval_reservation(
633 struct xfs_mount
*mp
)
635 return MAX((xfs_calc_inode_res(mp
, 1) +
636 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
637 XFS_FSB_TO_B(mp
, 1))),
638 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
639 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 4),
640 XFS_FSB_TO_B(mp
, 1))));
644 * Setting an attribute at mount time.
645 * the inode getting the attribute
646 * the superblock for allocations
647 * the agfs extents are allocated from
648 * the attribute btree * max depth
649 * the inode allocation btree
650 * Since attribute transaction space is dependent on the size of the attribute,
651 * the calculation is done partially at mount time and partially at runtime(see
655 xfs_calc_attrsetm_reservation(
656 struct xfs_mount
*mp
)
658 return XFS_DQUOT_LOGRES(mp
) +
659 xfs_calc_inode_res(mp
, 1) +
660 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
661 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
665 * Setting an attribute at runtime, transaction space unit per block.
666 * the superblock for allocations: sector size
667 * the inode bmap btree could join or split: max depth * block size
668 * Since the runtime attribute transaction space is dependent on the total
669 * blocks needed for the 1st bmap, here we calculate out the space unit for
670 * one block so that the caller could figure out the total space according
671 * to the attibute extent length in blocks by:
672 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
675 xfs_calc_attrsetrt_reservation(
676 struct xfs_mount
*mp
)
678 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
679 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
680 XFS_FSB_TO_B(mp
, 1));
684 * Removing an attribute.
685 * the inode: inode size
686 * the attribute btree could join: max depth * block size
687 * the inode bmap btree could join or split: max depth * block size
688 * And the bmap_finish transaction can free the attr blocks freed giving:
689 * the agf for the ag in which the blocks live: 2 * sector size
690 * the agfl for the ag in which the blocks live: 2 * sector size
691 * the superblock for the free block count: sector size
692 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
695 xfs_calc_attrrm_reservation(
696 struct xfs_mount
*mp
)
698 return XFS_DQUOT_LOGRES(mp
) +
699 MAX((xfs_calc_inode_res(mp
, 1) +
700 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
701 XFS_FSB_TO_B(mp
, 1)) +
702 (uint
)XFS_FSB_TO_B(mp
,
703 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
704 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
705 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
706 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
707 XFS_FSB_TO_B(mp
, 1))));
711 * Clearing a bad agino number in an agi hash bucket.
714 xfs_calc_clear_agi_bucket_reservation(
715 struct xfs_mount
*mp
)
717 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
721 * Clearing the quotaflags in the superblock.
722 * the super block for changing quota flags: sector size
725 xfs_calc_qm_sbchange_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 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
802 resp
->tr_write
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
804 resp
->tr_itruncate
.tr_logres
= xfs_calc_itruncate_reservation(mp
);
805 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
806 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
808 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
809 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
810 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
812 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
813 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
814 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
816 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
817 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
818 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
820 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
821 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
822 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
824 resp
->tr_create
.tr_logres
= xfs_calc_create_reservation(mp
);
825 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
826 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
828 resp
->tr_create_tmpfile
.tr_logres
=
829 xfs_calc_create_tmpfile_reservation(mp
);
830 resp
->tr_create_tmpfile
.tr_logcount
= XFS_CREATE_TMPFILE_LOG_COUNT
;
831 resp
->tr_create_tmpfile
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
833 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
834 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
835 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
837 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
838 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
839 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
841 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
842 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
843 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
845 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
846 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
847 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
849 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
850 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
851 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
853 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
854 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
855 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
857 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
858 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
859 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
861 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
);
862 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
863 resp
->tr_qm_dqalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
866 * The following transactions are logged in logical format with
867 * a default log count.
869 resp
->tr_qm_sbchange
.tr_logres
= xfs_calc_qm_sbchange_reservation(mp
);
870 resp
->tr_qm_sbchange
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
872 resp
->tr_qm_setqlim
.tr_logres
= xfs_calc_qm_setqlim_reservation(mp
);
873 resp
->tr_qm_setqlim
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
875 resp
->tr_qm_quotaoff
.tr_logres
= xfs_calc_qm_quotaoff_reservation(mp
);
876 resp
->tr_qm_quotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
878 resp
->tr_qm_equotaoff
.tr_logres
=
879 xfs_calc_qm_quotaoff_end_reservation(mp
);
880 resp
->tr_qm_equotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
882 resp
->tr_sb
.tr_logres
= xfs_calc_sb_reservation(mp
);
883 resp
->tr_sb
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
885 /* The following transaction are logged in logical format */
886 resp
->tr_ichange
.tr_logres
= xfs_calc_ichange_reservation(mp
);
887 resp
->tr_growdata
.tr_logres
= xfs_calc_growdata_reservation(mp
);
888 resp
->tr_fsyncts
.tr_logres
= xfs_calc_swrite_reservation(mp
);
889 resp
->tr_writeid
.tr_logres
= xfs_calc_writeid_reservation(mp
);
890 resp
->tr_attrsetrt
.tr_logres
= xfs_calc_attrsetrt_reservation(mp
);
891 resp
->tr_clearagi
.tr_logres
= xfs_calc_clear_agi_bucket_reservation(mp
);
892 resp
->tr_growrtzero
.tr_logres
= xfs_calc_growrtzero_reservation(mp
);
893 resp
->tr_growrtfree
.tr_logres
= xfs_calc_growrtfree_reservation(mp
);