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). The number of blocks reserved is based on the formula:
71 * num trees * ((2 blocks/level * max depth) - 1)
73 * Keep in mind that max depth is calculated separately for each type of tree.
76 xfs_allocfree_log_count(
82 blocks
= num_ops
* 2 * (2 * mp
->m_ag_maxlevels
- 1);
83 if (xfs_sb_version_hasrmapbt(&mp
->m_sb
))
84 blocks
+= num_ops
* (2 * mp
->m_rmap_maxlevels
- 1);
90 * Logging inodes is really tricksy. They are logged in memory format,
91 * which means that what we write into the log doesn't directly translate into
92 * the amount of space they use on disk.
94 * Case in point - btree format forks in memory format use more space than the
95 * on-disk format. In memory, the buffer contains a normal btree block header so
96 * the btree code can treat it as though it is just another generic buffer.
97 * However, when we write it to the inode fork, we don't write all of this
98 * header as it isn't needed. e.g. the root is only ever in the inode, so
99 * there's no need for sibling pointers which would waste 16 bytes of space.
101 * Hence when we have an inode with a maximally sized btree format fork, then
102 * amount of information we actually log is greater than the size of the inode
103 * on disk. Hence we need an inode reservation function that calculates all this
104 * correctly. So, we log:
106 * - 4 log op headers for object
107 * - for the ilf, the inode core and 2 forks
108 * - inode log format object
110 * - two inode forks containing bmap btree root blocks.
111 * - the btree data contained by both forks will fit into the inode size,
112 * hence when combined with the inode core above, we have a total of the
114 * - the BMBT headers need to be accounted separately, as they are
115 * additional to the records and pointers that fit inside the inode
120 struct xfs_mount
*mp
,
124 (4 * sizeof(struct xlog_op_header
) +
125 sizeof(struct xfs_inode_log_format
) +
126 mp
->m_sb
.sb_inodesize
+
127 2 * XFS_BMBT_BLOCK_LEN(mp
));
131 * The free inode btree is a conditional feature and the log reservation
132 * requirements differ slightly from that of the traditional inode allocation
133 * btree. The finobt tracks records for inode chunks with at least one free
134 * inode. A record can be removed from the tree for an inode allocation
135 * or free and thus the finobt reservation is unconditional across:
139 * - inode chunk allocation
141 * The 'modify' param indicates to include the record modification scenario. The
142 * 'alloc' param indicates to include the reservation for free space btree
143 * modifications on behalf of finobt modifications. This is required only for
144 * transactions that do not already account for free space btree modifications.
146 * the free inode btree: max depth * block size
147 * the allocation btrees: 2 trees * (max depth - 1) * block size
148 * the free inode btree entry: block size
152 struct xfs_mount
*mp
,
158 if (!xfs_sb_version_hasfinobt(&mp
->m_sb
))
161 res
= xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1));
163 res
+= xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
164 XFS_FSB_TO_B(mp
, 1));
166 res
+= (uint
)XFS_FSB_TO_B(mp
, 1);
172 * Various log reservation values.
174 * These are based on the size of the file system block because that is what
175 * most transactions manipulate. Each adds in an additional 128 bytes per
176 * item logged to try to account for the overhead of the transaction mechanism.
178 * Note: Most of the reservations underestimate the number of allocation
179 * groups into which they could free extents in the xfs_defer_finish() call.
180 * This is because the number in the worst case is quite high and quite
181 * unusual. In order to fix this we need to change xfs_defer_finish() to free
182 * extents in only a single AG at a time. This will require changes to the
183 * EFI code as well, however, so that the EFI for the extents not freed is
184 * logged again in each transaction. See SGI PV #261917.
186 * Reservation functions here avoid a huge stack in xfs_trans_init due to
187 * register overflow from temporaries in the calculations.
192 * In a write transaction we can allocate a maximum of 2
193 * extents. This gives:
194 * the inode getting the new extents: inode size
195 * the inode's bmap btree: max depth * block size
196 * the agfs of the ags from which the extents are allocated: 2 * sector
197 * the superblock free block counter: sector size
198 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
199 * And the bmap_finish transaction can free bmap blocks in a join:
200 * the agfs of the ags containing the blocks: 2 * sector size
201 * the agfls of the ags containing the blocks: 2 * sector size
202 * the super block free block counter: sector size
203 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
206 xfs_calc_write_reservation(
207 struct xfs_mount
*mp
)
209 return XFS_DQUOT_LOGRES(mp
) +
210 MAX((xfs_calc_inode_res(mp
, 1) +
211 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
212 XFS_FSB_TO_B(mp
, 1)) +
213 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
214 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
215 XFS_FSB_TO_B(mp
, 1))),
216 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
217 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
218 XFS_FSB_TO_B(mp
, 1))));
222 * In truncating a file we free up to two extents at once. We can modify:
223 * the inode being truncated: inode size
224 * the inode's bmap btree: (max depth + 1) * block size
225 * And the bmap_finish transaction can free the blocks and bmap blocks:
226 * the agf for each of the ags: 4 * sector size
227 * the agfl for each of the ags: 4 * sector size
228 * the super block to reflect the freed blocks: sector size
229 * worst case split in allocation btrees per extent assuming 4 extents:
230 * 4 exts * 2 trees * (2 * max depth - 1) * block size
231 * the inode btree: max depth * blocksize
232 * the allocation btrees: 2 trees * (max depth - 1) * block size
235 xfs_calc_itruncate_reservation(
236 struct xfs_mount
*mp
)
238 return XFS_DQUOT_LOGRES(mp
) +
239 MAX((xfs_calc_inode_res(mp
, 1) +
240 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1,
241 XFS_FSB_TO_B(mp
, 1))),
242 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
243 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
244 XFS_FSB_TO_B(mp
, 1)) +
245 xfs_calc_buf_res(5, 0) +
246 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
247 XFS_FSB_TO_B(mp
, 1)) +
248 xfs_calc_buf_res(2 + mp
->m_ialloc_blks
+
249 mp
->m_in_maxlevels
, 0)));
253 * In renaming a files we can modify:
254 * the four inodes involved: 4 * inode size
255 * the two directory btrees: 2 * (max depth + v2) * dir block size
256 * the two directory bmap btrees: 2 * max depth * block size
257 * And the bmap_finish transaction can free dir and bmap blocks (two sets
258 * of bmap blocks) giving:
259 * the agf for the ags in which the blocks live: 3 * sector size
260 * the agfl for the ags in which the blocks live: 3 * sector size
261 * the superblock for the free block count: sector size
262 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
265 xfs_calc_rename_reservation(
266 struct xfs_mount
*mp
)
268 return XFS_DQUOT_LOGRES(mp
) +
269 MAX((xfs_calc_inode_res(mp
, 4) +
270 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
271 XFS_FSB_TO_B(mp
, 1))),
272 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
273 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 3),
274 XFS_FSB_TO_B(mp
, 1))));
278 * For removing an inode from unlinked list at first, we can modify:
279 * the agi hash list and counters: sector size
280 * the on disk inode before ours in the agi hash list: inode cluster size
283 xfs_calc_iunlink_remove_reservation(
284 struct xfs_mount
*mp
)
286 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
287 max_t(uint
, XFS_FSB_TO_B(mp
, 1), mp
->m_inode_cluster_size
);
291 * For creating a link to an inode:
292 * the parent directory inode: inode size
293 * the linked inode: inode size
294 * the directory btree could split: (max depth + v2) * dir block size
295 * the directory bmap btree could join or split: (max depth + v2) * blocksize
296 * And the bmap_finish transaction can free some bmap blocks giving:
297 * the agf for the ag in which the blocks live: sector size
298 * the agfl for the ag in which the blocks live: sector size
299 * the superblock for the free block count: sector size
300 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
303 xfs_calc_link_reservation(
304 struct xfs_mount
*mp
)
306 return XFS_DQUOT_LOGRES(mp
) +
307 xfs_calc_iunlink_remove_reservation(mp
) +
308 MAX((xfs_calc_inode_res(mp
, 2) +
309 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
310 XFS_FSB_TO_B(mp
, 1))),
311 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
312 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
313 XFS_FSB_TO_B(mp
, 1))));
317 * For adding an inode to unlinked list we can modify:
318 * the agi hash list: sector size
319 * the unlinked inode: inode size
322 xfs_calc_iunlink_add_reservation(xfs_mount_t
*mp
)
324 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
325 xfs_calc_inode_res(mp
, 1);
329 * For removing a directory entry we can modify:
330 * the parent directory inode: inode size
331 * the removed inode: inode size
332 * the directory btree could join: (max depth + v2) * dir block size
333 * the directory bmap btree could join or split: (max depth + v2) * blocksize
334 * And the bmap_finish transaction can free the dir and bmap blocks giving:
335 * the agf for the ag in which the blocks live: 2 * sector size
336 * the agfl for the ag in which the blocks live: 2 * sector size
337 * the superblock for the free block count: sector size
338 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
341 xfs_calc_remove_reservation(
342 struct xfs_mount
*mp
)
344 return XFS_DQUOT_LOGRES(mp
) +
345 xfs_calc_iunlink_add_reservation(mp
) +
346 MAX((xfs_calc_inode_res(mp
, 1) +
347 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
348 XFS_FSB_TO_B(mp
, 1))),
349 (xfs_calc_buf_res(4, mp
->m_sb
.sb_sectsize
) +
350 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
351 XFS_FSB_TO_B(mp
, 1))));
355 * For create, break it in to the two cases that the transaction
356 * covers. We start with the modify case - allocation done by modification
357 * of the state of existing inodes - and the allocation case.
361 * For create we can modify:
362 * the parent directory inode: inode size
363 * the new inode: inode size
364 * the inode btree entry: block size
365 * the superblock for the nlink flag: sector size
366 * the directory btree: (max depth + v2) * dir block size
367 * the directory inode's bmap btree: (max depth + v2) * block size
368 * the finobt (record modification and allocation btrees)
371 xfs_calc_create_resv_modify(
372 struct xfs_mount
*mp
)
374 return xfs_calc_inode_res(mp
, 2) +
375 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
376 (uint
)XFS_FSB_TO_B(mp
, 1) +
377 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1)) +
378 xfs_calc_finobt_res(mp
, 1, 1);
382 * For create we can allocate some inodes giving:
383 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
384 * the superblock for the nlink flag: sector size
385 * the inode blocks allocated: mp->m_ialloc_blks * blocksize
386 * the inode btree: max depth * blocksize
387 * the allocation btrees: 2 trees * (max depth - 1) * block size
390 xfs_calc_create_resv_alloc(
391 struct xfs_mount
*mp
)
393 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
394 mp
->m_sb
.sb_sectsize
+
395 xfs_calc_buf_res(mp
->m_ialloc_blks
, XFS_FSB_TO_B(mp
, 1)) +
396 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
397 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
398 XFS_FSB_TO_B(mp
, 1));
402 __xfs_calc_create_reservation(
403 struct xfs_mount
*mp
)
405 return XFS_DQUOT_LOGRES(mp
) +
406 MAX(xfs_calc_create_resv_alloc(mp
),
407 xfs_calc_create_resv_modify(mp
));
411 * For icreate we can allocate some inodes giving:
412 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
413 * the superblock for the nlink flag: sector size
414 * the inode btree: max depth * blocksize
415 * the allocation btrees: 2 trees * (max depth - 1) * block size
416 * the finobt (record insertion)
419 xfs_calc_icreate_resv_alloc(
420 struct xfs_mount
*mp
)
422 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
423 mp
->m_sb
.sb_sectsize
+
424 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
425 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
426 XFS_FSB_TO_B(mp
, 1)) +
427 xfs_calc_finobt_res(mp
, 0, 0);
431 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
433 return XFS_DQUOT_LOGRES(mp
) +
434 MAX(xfs_calc_icreate_resv_alloc(mp
),
435 xfs_calc_create_resv_modify(mp
));
439 xfs_calc_create_reservation(
440 struct xfs_mount
*mp
)
442 if (xfs_sb_version_hascrc(&mp
->m_sb
))
443 return xfs_calc_icreate_reservation(mp
);
444 return __xfs_calc_create_reservation(mp
);
449 xfs_calc_create_tmpfile_reservation(
450 struct xfs_mount
*mp
)
452 uint res
= XFS_DQUOT_LOGRES(mp
);
454 if (xfs_sb_version_hascrc(&mp
->m_sb
))
455 res
+= xfs_calc_icreate_resv_alloc(mp
);
457 res
+= xfs_calc_create_resv_alloc(mp
);
459 return res
+ xfs_calc_iunlink_add_reservation(mp
);
463 * Making a new directory is the same as creating a new file.
466 xfs_calc_mkdir_reservation(
467 struct xfs_mount
*mp
)
469 return xfs_calc_create_reservation(mp
);
474 * Making a new symplink is the same as creating a new file, but
475 * with the added blocks for remote symlink data which can be up to 1kB in
476 * length (MAXPATHLEN).
479 xfs_calc_symlink_reservation(
480 struct xfs_mount
*mp
)
482 return xfs_calc_create_reservation(mp
) +
483 xfs_calc_buf_res(1, MAXPATHLEN
);
487 * In freeing an inode we can modify:
488 * the inode being freed: inode size
489 * the super block free inode counter: sector size
490 * the agi hash list and counters: sector size
491 * the inode btree entry: block size
492 * the on disk inode before ours in the agi hash list: inode cluster size
493 * the inode btree: max depth * blocksize
494 * the allocation btrees: 2 trees * (max depth - 1) * block size
495 * the finobt (record insertion, removal or modification)
498 xfs_calc_ifree_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
) +
504 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp
, 1)) +
505 xfs_calc_iunlink_remove_reservation(mp
) +
506 xfs_calc_buf_res(1, 0) +
507 xfs_calc_buf_res(2 + mp
->m_ialloc_blks
+
508 mp
->m_in_maxlevels
, 0) +
509 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
510 XFS_FSB_TO_B(mp
, 1)) +
511 xfs_calc_finobt_res(mp
, 0, 1);
515 * When only changing the inode we log the inode and possibly the superblock
516 * We also add a bit of slop for the transaction stuff.
519 xfs_calc_ichange_reservation(
520 struct xfs_mount
*mp
)
522 return XFS_DQUOT_LOGRES(mp
) +
523 xfs_calc_inode_res(mp
, 1) +
524 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
529 * Growing the data section of the filesystem.
535 xfs_calc_growdata_reservation(
536 struct xfs_mount
*mp
)
538 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
539 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
540 XFS_FSB_TO_B(mp
, 1));
544 * Growing the rt section of the filesystem.
545 * In the first set of transactions (ALLOC) we allocate space to the
546 * bitmap or summary files.
547 * superblock: sector size
548 * agf of the ag from which the extent is allocated: sector size
549 * bmap btree for bitmap/summary inode: max depth * blocksize
550 * bitmap/summary inode: inode size
551 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
554 xfs_calc_growrtalloc_reservation(
555 struct xfs_mount
*mp
)
557 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
558 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
559 XFS_FSB_TO_B(mp
, 1)) +
560 xfs_calc_inode_res(mp
, 1) +
561 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
562 XFS_FSB_TO_B(mp
, 1));
566 * Growing the rt section of the filesystem.
567 * In the second set of transactions (ZERO) we zero the new metadata blocks.
568 * one bitmap/summary block: blocksize
571 xfs_calc_growrtzero_reservation(
572 struct xfs_mount
*mp
)
574 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
578 * Growing the rt section of the filesystem.
579 * In the third set of transactions (FREE) we update metadata without
580 * allocating any new blocks.
581 * superblock: sector size
582 * bitmap inode: inode size
583 * summary inode: inode size
584 * one bitmap block: blocksize
585 * summary blocks: new summary size
588 xfs_calc_growrtfree_reservation(
589 struct xfs_mount
*mp
)
591 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
592 xfs_calc_inode_res(mp
, 2) +
593 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
594 xfs_calc_buf_res(1, mp
->m_rsumsize
);
598 * Logging the inode modification timestamp on a synchronous write.
602 xfs_calc_swrite_reservation(
603 struct xfs_mount
*mp
)
605 return xfs_calc_inode_res(mp
, 1);
609 * Logging the inode mode bits when writing a setuid/setgid file
613 xfs_calc_writeid_reservation(
614 struct xfs_mount
*mp
)
616 return xfs_calc_inode_res(mp
, 1);
620 * Converting the inode from non-attributed to attributed.
621 * the inode being converted: inode size
622 * agf block and superblock (for block allocation)
623 * the new block (directory sized)
624 * bmap blocks for the new directory block
628 xfs_calc_addafork_reservation(
629 struct xfs_mount
*mp
)
631 return XFS_DQUOT_LOGRES(mp
) +
632 xfs_calc_inode_res(mp
, 1) +
633 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
634 xfs_calc_buf_res(1, mp
->m_dir_geo
->blksize
) +
635 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
636 XFS_FSB_TO_B(mp
, 1)) +
637 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 1),
638 XFS_FSB_TO_B(mp
, 1));
642 * Removing the attribute fork of a file
643 * the inode being truncated: inode size
644 * the inode's bmap btree: max depth * block size
645 * And the bmap_finish transaction can free the blocks and bmap blocks:
646 * the agf for each of the ags: 4 * sector size
647 * the agfl for each of the ags: 4 * sector size
648 * the super block to reflect the freed blocks: sector size
649 * worst case split in allocation btrees per extent assuming 4 extents:
650 * 4 exts * 2 trees * (2 * max depth - 1) * block size
653 xfs_calc_attrinval_reservation(
654 struct xfs_mount
*mp
)
656 return MAX((xfs_calc_inode_res(mp
, 1) +
657 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
658 XFS_FSB_TO_B(mp
, 1))),
659 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
660 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 4),
661 XFS_FSB_TO_B(mp
, 1))));
665 * Setting an attribute at mount time.
666 * the inode getting the attribute
667 * the superblock for allocations
668 * the agfs extents are allocated from
669 * the attribute btree * max depth
670 * the inode allocation btree
671 * Since attribute transaction space is dependent on the size of the attribute,
672 * the calculation is done partially at mount time and partially at runtime(see
676 xfs_calc_attrsetm_reservation(
677 struct xfs_mount
*mp
)
679 return XFS_DQUOT_LOGRES(mp
) +
680 xfs_calc_inode_res(mp
, 1) +
681 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
682 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
686 * Setting an attribute at runtime, transaction space unit per block.
687 * the superblock for allocations: sector size
688 * the inode bmap btree could join or split: max depth * block size
689 * Since the runtime attribute transaction space is dependent on the total
690 * blocks needed for the 1st bmap, here we calculate out the space unit for
691 * one block so that the caller could figure out the total space according
692 * to the attibute extent length in blocks by:
693 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
696 xfs_calc_attrsetrt_reservation(
697 struct xfs_mount
*mp
)
699 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
700 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
701 XFS_FSB_TO_B(mp
, 1));
705 * Removing an attribute.
706 * the inode: inode size
707 * the attribute btree could join: max depth * block size
708 * the inode bmap btree could join or split: max depth * block size
709 * And the bmap_finish transaction can free the attr blocks freed giving:
710 * the agf for the ag in which the blocks live: 2 * sector size
711 * the agfl for the ag in which the blocks live: 2 * sector size
712 * the superblock for the free block count: sector size
713 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
716 xfs_calc_attrrm_reservation(
717 struct xfs_mount
*mp
)
719 return XFS_DQUOT_LOGRES(mp
) +
720 MAX((xfs_calc_inode_res(mp
, 1) +
721 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
722 XFS_FSB_TO_B(mp
, 1)) +
723 (uint
)XFS_FSB_TO_B(mp
,
724 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
725 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
726 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
727 xfs_calc_buf_res(xfs_allocfree_log_count(mp
, 2),
728 XFS_FSB_TO_B(mp
, 1))));
732 * Clearing a bad agino number in an agi hash bucket.
735 xfs_calc_clear_agi_bucket_reservation(
736 struct xfs_mount
*mp
)
738 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
742 * Adjusting quota limits.
743 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
746 xfs_calc_qm_setqlim_reservation(
747 struct xfs_mount
*mp
)
749 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot
));
753 * Allocating quota on disk if needed.
754 * the write transaction log space for quota file extent allocation
755 * the unit of quota allocation: one system block size
758 xfs_calc_qm_dqalloc_reservation(
759 struct xfs_mount
*mp
)
761 return xfs_calc_write_reservation(mp
) +
763 XFS_FSB_TO_B(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
) - 1);
767 * Turning off quotas.
768 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
769 * the superblock for the quota flags: sector size
772 xfs_calc_qm_quotaoff_reservation(
773 struct xfs_mount
*mp
)
775 return sizeof(struct xfs_qoff_logitem
) * 2 +
776 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
780 * End of turning off quotas.
781 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
784 xfs_calc_qm_quotaoff_end_reservation(
785 struct xfs_mount
*mp
)
787 return sizeof(struct xfs_qoff_logitem
) * 2;
791 * Syncing the incore super block changes to disk.
792 * the super block to reflect the changes: sector size
795 xfs_calc_sb_reservation(
796 struct xfs_mount
*mp
)
798 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
803 struct xfs_mount
*mp
,
804 struct xfs_trans_resv
*resp
)
807 * The following transactions are logged in physical format and
808 * require a permanent reservation on space.
810 resp
->tr_write
.tr_logres
= xfs_calc_write_reservation(mp
);
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 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
816 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
818 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
819 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
820 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
822 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
823 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
824 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
826 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
827 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
828 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
830 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
831 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
832 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
834 resp
->tr_create
.tr_logres
= xfs_calc_create_reservation(mp
);
835 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
836 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
838 resp
->tr_create_tmpfile
.tr_logres
=
839 xfs_calc_create_tmpfile_reservation(mp
);
840 resp
->tr_create_tmpfile
.tr_logcount
= XFS_CREATE_TMPFILE_LOG_COUNT
;
841 resp
->tr_create_tmpfile
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
843 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
844 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
845 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
847 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
848 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
849 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
851 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
852 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
853 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
855 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
856 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
857 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
859 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
860 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
861 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
863 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
864 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
865 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
867 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
868 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
869 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
871 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
);
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
);