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_format.h"
22 #include "xfs_shared.h"
24 #include "xfs_trans_resv.h"
25 #include "xfs_trans.h"
28 #include "xfs_mount.h"
29 #include "xfs_da_format.h"
30 #include "xfs_error.h"
31 #include "xfs_da_btree.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_btree.h"
38 #include "xfs_ialloc.h"
39 #include "xfs_alloc.h"
40 #include "xfs_extent_busy.h"
42 #include "xfs_bmap_util.h"
43 #include "xfs_quota.h"
45 #include "xfs_trans_space.h"
46 #include "xfs_trace.h"
49 * A buffer has a format structure overhead in the log in addition
50 * to the data, so we need to take this into account when reserving
51 * space in a transaction for a buffer. Round the space required up
52 * to a multiple of 128 bytes so that we don't change the historical
53 * reservation that has been used for this overhead.
56 xfs_buf_log_overhead(void)
58 return round_up(sizeof(struct xlog_op_header
) +
59 sizeof(struct xfs_buf_log_format
), 128);
63 * Calculate out transaction log reservation per item in bytes.
65 * The nbufs argument is used to indicate the number of items that
66 * will be changed in a transaction. size is used to tell how many
67 * bytes should be reserved per item.
74 return nbufs
* (size
+ xfs_buf_log_overhead());
78 * Logging inodes is really tricksy. They are logged in memory format,
79 * which means that what we write into the log doesn't directly translate into
80 * the amount of space they use on disk.
82 * Case in point - btree format forks in memory format use more space than the
83 * on-disk format. In memory, the buffer contains a normal btree block header so
84 * the btree code can treat it as though it is just another generic buffer.
85 * However, when we write it to the inode fork, we don't write all of this
86 * header as it isn't needed. e.g. the root is only ever in the inode, so
87 * there's no need for sibling pointers which would waste 16 bytes of space.
89 * Hence when we have an inode with a maximally sized btree format fork, then
90 * amount of information we actually log is greater than the size of the inode
91 * on disk. Hence we need an inode reservation function that calculates all this
92 * correctly. So, we log:
94 * - log op headers for object
95 * - inode log format object
96 * - the entire inode contents (core + 2 forks)
97 * - two bmap btree block headers
101 struct xfs_mount
*mp
,
104 return ninodes
* (sizeof(struct xlog_op_header
) +
105 sizeof(struct xfs_inode_log_format
) +
106 mp
->m_sb
.sb_inodesize
+
107 2 * XFS_BMBT_BLOCK_LEN(mp
));
111 * Various log reservation values.
113 * These are based on the size of the file system block because that is what
114 * most transactions manipulate. Each adds in an additional 128 bytes per
115 * item logged to try to account for the overhead of the transaction mechanism.
117 * Note: Most of the reservations underestimate the number of allocation
118 * groups into which they could free extents in the xfs_bmap_finish() call.
119 * This is because the number in the worst case is quite high and quite
120 * unusual. In order to fix this we need to change xfs_bmap_finish() to free
121 * extents in only a single AG at a time. This will require changes to the
122 * EFI code as well, however, so that the EFI for the extents not freed is
123 * logged again in each transaction. See SGI PV #261917.
125 * Reservation functions here avoid a huge stack in xfs_trans_init due to
126 * register overflow from temporaries in the calculations.
131 * In a write transaction we can allocate a maximum of 2
132 * extents. This gives:
133 * the inode getting the new extents: inode size
134 * the inode's bmap btree: max depth * block size
135 * the agfs of the ags from which the extents are allocated: 2 * sector
136 * the superblock free block counter: sector size
137 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
138 * And the bmap_finish transaction can free bmap blocks in a join:
139 * the agfs of the ags containing the blocks: 2 * sector size
140 * the agfls of the ags containing the blocks: 2 * sector size
141 * the super block free block counter: sector size
142 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
145 xfs_calc_write_reservation(
146 struct xfs_mount
*mp
)
148 return XFS_DQUOT_LOGRES(mp
) +
149 MAX((xfs_calc_inode_res(mp
, 1) +
150 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
151 XFS_FSB_TO_B(mp
, 1)) +
152 xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
153 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
154 XFS_FSB_TO_B(mp
, 1))),
155 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
156 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
157 XFS_FSB_TO_B(mp
, 1))));
161 * In truncating a file we free up to two extents at once. We can modify:
162 * the inode being truncated: inode size
163 * the inode's bmap btree: (max depth + 1) * block size
164 * And the bmap_finish transaction can free the blocks and bmap blocks:
165 * the agf for each of the ags: 4 * sector size
166 * the agfl for each of the ags: 4 * sector size
167 * the super block to reflect the freed blocks: sector size
168 * worst case split in allocation btrees per extent assuming 4 extents:
169 * 4 exts * 2 trees * (2 * max depth - 1) * block size
170 * the inode btree: max depth * blocksize
171 * the allocation btrees: 2 trees * (max depth - 1) * block size
174 xfs_calc_itruncate_reservation(
175 struct xfs_mount
*mp
)
177 return XFS_DQUOT_LOGRES(mp
) +
178 MAX((xfs_calc_inode_res(mp
, 1) +
179 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) + 1,
180 XFS_FSB_TO_B(mp
, 1))),
181 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
182 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 4),
183 XFS_FSB_TO_B(mp
, 1)) +
184 xfs_calc_buf_res(5, 0) +
185 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
186 XFS_FSB_TO_B(mp
, 1)) +
187 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp
) +
188 mp
->m_in_maxlevels
, 0)));
192 * In renaming a files we can modify:
193 * the four inodes involved: 4 * inode size
194 * the two directory btrees: 2 * (max depth + v2) * dir block size
195 * the two directory bmap btrees: 2 * max depth * block size
196 * And the bmap_finish transaction can free dir and bmap blocks (two sets
197 * of bmap blocks) giving:
198 * the agf for the ags in which the blocks live: 3 * sector size
199 * the agfl for the ags in which the blocks live: 3 * sector size
200 * the superblock for the free block count: sector size
201 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
204 xfs_calc_rename_reservation(
205 struct xfs_mount
*mp
)
207 return XFS_DQUOT_LOGRES(mp
) +
208 MAX((xfs_calc_inode_res(mp
, 4) +
209 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp
),
210 XFS_FSB_TO_B(mp
, 1))),
211 (xfs_calc_buf_res(7, mp
->m_sb
.sb_sectsize
) +
212 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 3),
213 XFS_FSB_TO_B(mp
, 1))));
217 * For creating a link to an inode:
218 * the parent directory inode: inode size
219 * the linked inode: inode size
220 * the directory btree could split: (max depth + v2) * dir block size
221 * the directory bmap btree could join or split: (max depth + v2) * blocksize
222 * And the bmap_finish transaction can free some bmap blocks giving:
223 * the agf for the ag in which the blocks live: sector size
224 * the agfl for the ag in which the blocks live: sector size
225 * the superblock for the free block count: sector size
226 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
229 xfs_calc_link_reservation(
230 struct xfs_mount
*mp
)
232 return XFS_DQUOT_LOGRES(mp
) +
233 MAX((xfs_calc_inode_res(mp
, 2) +
234 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
235 XFS_FSB_TO_B(mp
, 1))),
236 (xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
237 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
238 XFS_FSB_TO_B(mp
, 1))));
242 * For removing a directory entry we can modify:
243 * the parent directory inode: inode size
244 * the removed inode: inode size
245 * the directory btree could join: (max depth + v2) * dir block size
246 * the directory bmap btree could join or split: (max depth + v2) * blocksize
247 * And the bmap_finish transaction can free the dir and bmap blocks giving:
248 * the agf for the ag in which the blocks live: 2 * sector size
249 * the agfl for the ag in which the blocks live: 2 * sector size
250 * the superblock for the free block count: sector size
251 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
254 xfs_calc_remove_reservation(
255 struct xfs_mount
*mp
)
257 return XFS_DQUOT_LOGRES(mp
) +
258 MAX((xfs_calc_inode_res(mp
, 2) +
259 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
),
260 XFS_FSB_TO_B(mp
, 1))),
261 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
262 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
263 XFS_FSB_TO_B(mp
, 1))));
267 * For create, break it in to the two cases that the transaction
268 * covers. We start with the modify case - allocation done by modification
269 * of the state of existing inodes - and the allocation case.
273 * For create we can modify:
274 * the parent directory inode: inode size
275 * the new inode: inode size
276 * the inode btree entry: block size
277 * the superblock for the nlink flag: sector size
278 * the directory btree: (max depth + v2) * dir block size
279 * the directory inode's bmap btree: (max depth + v2) * block size
282 xfs_calc_create_resv_modify(
283 struct xfs_mount
*mp
)
285 return xfs_calc_inode_res(mp
, 2) +
286 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
287 (uint
)XFS_FSB_TO_B(mp
, 1) +
288 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp
), XFS_FSB_TO_B(mp
, 1));
292 * For create we can allocate some inodes giving:
293 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
294 * the superblock for the nlink flag: sector size
295 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
296 * the inode btree: max depth * blocksize
297 * the allocation btrees: 2 trees * (max depth - 1) * block size
300 xfs_calc_create_resv_alloc(
301 struct xfs_mount
*mp
)
303 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
304 mp
->m_sb
.sb_sectsize
+
305 xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp
), XFS_FSB_TO_B(mp
, 1)) +
306 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
307 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
308 XFS_FSB_TO_B(mp
, 1));
312 __xfs_calc_create_reservation(
313 struct xfs_mount
*mp
)
315 return XFS_DQUOT_LOGRES(mp
) +
316 MAX(xfs_calc_create_resv_alloc(mp
),
317 xfs_calc_create_resv_modify(mp
));
321 * For icreate we can allocate some inodes giving:
322 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
323 * the superblock for the nlink flag: sector size
324 * the inode btree: max depth * blocksize
325 * the allocation btrees: 2 trees * (max depth - 1) * block size
328 xfs_calc_icreate_resv_alloc(
329 struct xfs_mount
*mp
)
331 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
332 mp
->m_sb
.sb_sectsize
+
333 xfs_calc_buf_res(mp
->m_in_maxlevels
, XFS_FSB_TO_B(mp
, 1)) +
334 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
335 XFS_FSB_TO_B(mp
, 1));
339 xfs_calc_icreate_reservation(xfs_mount_t
*mp
)
341 return XFS_DQUOT_LOGRES(mp
) +
342 MAX(xfs_calc_icreate_resv_alloc(mp
),
343 xfs_calc_create_resv_modify(mp
));
347 xfs_calc_create_reservation(
348 struct xfs_mount
*mp
)
350 if (xfs_sb_version_hascrc(&mp
->m_sb
))
351 return xfs_calc_icreate_reservation(mp
);
352 return __xfs_calc_create_reservation(mp
);
357 * Making a new directory is the same as creating a new file.
360 xfs_calc_mkdir_reservation(
361 struct xfs_mount
*mp
)
363 return xfs_calc_create_reservation(mp
);
368 * Making a new symplink is the same as creating a new file, but
369 * with the added blocks for remote symlink data which can be up to 1kB in
370 * length (MAXPATHLEN).
373 xfs_calc_symlink_reservation(
374 struct xfs_mount
*mp
)
376 return xfs_calc_create_reservation(mp
) +
377 xfs_calc_buf_res(1, MAXPATHLEN
);
381 * In freeing an inode we can modify:
382 * the inode being freed: inode size
383 * the super block free inode counter: sector size
384 * the agi hash list and counters: sector size
385 * the inode btree entry: block size
386 * the on disk inode before ours in the agi hash list: inode cluster size
387 * the inode btree: max depth * blocksize
388 * the allocation btrees: 2 trees * (max depth - 1) * block size
391 xfs_calc_ifree_reservation(
392 struct xfs_mount
*mp
)
394 return XFS_DQUOT_LOGRES(mp
) +
395 xfs_calc_inode_res(mp
, 1) +
396 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
397 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp
, 1)) +
398 MAX((__uint16_t
)XFS_FSB_TO_B(mp
, 1),
399 XFS_INODE_CLUSTER_SIZE(mp
)) +
400 xfs_calc_buf_res(1, 0) +
401 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp
) +
402 mp
->m_in_maxlevels
, 0) +
403 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
404 XFS_FSB_TO_B(mp
, 1));
408 * When only changing the inode we log the inode and possibly the superblock
409 * We also add a bit of slop for the transaction stuff.
412 xfs_calc_ichange_reservation(
413 struct xfs_mount
*mp
)
415 return XFS_DQUOT_LOGRES(mp
) +
416 xfs_calc_inode_res(mp
, 1) +
417 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
422 * Growing the data section of the filesystem.
428 xfs_calc_growdata_reservation(
429 struct xfs_mount
*mp
)
431 return xfs_calc_buf_res(3, mp
->m_sb
.sb_sectsize
) +
432 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
433 XFS_FSB_TO_B(mp
, 1));
437 * Growing the rt section of the filesystem.
438 * In the first set of transactions (ALLOC) we allocate space to the
439 * bitmap or summary files.
440 * superblock: sector size
441 * agf of the ag from which the extent is allocated: sector size
442 * bmap btree for bitmap/summary inode: max depth * blocksize
443 * bitmap/summary inode: inode size
444 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
447 xfs_calc_growrtalloc_reservation(
448 struct xfs_mount
*mp
)
450 return xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
451 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
),
452 XFS_FSB_TO_B(mp
, 1)) +
453 xfs_calc_inode_res(mp
, 1) +
454 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
455 XFS_FSB_TO_B(mp
, 1));
459 * Growing the rt section of the filesystem.
460 * In the second set of transactions (ZERO) we zero the new metadata blocks.
461 * one bitmap/summary block: blocksize
464 xfs_calc_growrtzero_reservation(
465 struct xfs_mount
*mp
)
467 return xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
);
471 * Growing the rt section of the filesystem.
472 * In the third set of transactions (FREE) we update metadata without
473 * allocating any new blocks.
474 * superblock: sector size
475 * bitmap inode: inode size
476 * summary inode: inode size
477 * one bitmap block: blocksize
478 * summary blocks: new summary size
481 xfs_calc_growrtfree_reservation(
482 struct xfs_mount
*mp
)
484 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
485 xfs_calc_inode_res(mp
, 2) +
486 xfs_calc_buf_res(1, mp
->m_sb
.sb_blocksize
) +
487 xfs_calc_buf_res(1, mp
->m_rsumsize
);
491 * Logging the inode modification timestamp on a synchronous write.
495 xfs_calc_swrite_reservation(
496 struct xfs_mount
*mp
)
498 return xfs_calc_inode_res(mp
, 1);
502 * Logging the inode mode bits when writing a setuid/setgid file
506 xfs_calc_writeid_reservation(
507 struct xfs_mount
*mp
)
509 return xfs_calc_inode_res(mp
, 1);
513 * Converting the inode from non-attributed to attributed.
514 * the inode being converted: inode size
515 * agf block and superblock (for block allocation)
516 * the new block (directory sized)
517 * bmap blocks for the new directory block
521 xfs_calc_addafork_reservation(
522 struct xfs_mount
*mp
)
524 return XFS_DQUOT_LOGRES(mp
) +
525 xfs_calc_inode_res(mp
, 1) +
526 xfs_calc_buf_res(2, mp
->m_sb
.sb_sectsize
) +
527 xfs_calc_buf_res(1, mp
->m_dirblksize
) +
528 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp
, XFS_DATA_FORK
) + 1,
529 XFS_FSB_TO_B(mp
, 1)) +
530 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 1),
531 XFS_FSB_TO_B(mp
, 1));
535 * Removing the attribute fork of a file
536 * the inode being truncated: inode size
537 * the inode's bmap btree: max depth * block size
538 * And the bmap_finish transaction can free the blocks and bmap blocks:
539 * the agf for each of the ags: 4 * sector size
540 * the agfl for each of the ags: 4 * sector size
541 * the super block to reflect the freed blocks: sector size
542 * worst case split in allocation btrees per extent assuming 4 extents:
543 * 4 exts * 2 trees * (2 * max depth - 1) * block size
546 xfs_calc_attrinval_reservation(
547 struct xfs_mount
*mp
)
549 return MAX((xfs_calc_inode_res(mp
, 1) +
550 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
551 XFS_FSB_TO_B(mp
, 1))),
552 (xfs_calc_buf_res(9, mp
->m_sb
.sb_sectsize
) +
553 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 4),
554 XFS_FSB_TO_B(mp
, 1))));
558 * Setting an attribute at mount time.
559 * the inode getting the attribute
560 * the superblock for allocations
561 * the agfs extents are allocated from
562 * the attribute btree * max depth
563 * the inode allocation btree
564 * Since attribute transaction space is dependent on the size of the attribute,
565 * the calculation is done partially at mount time and partially at runtime(see
569 xfs_calc_attrsetm_reservation(
570 struct xfs_mount
*mp
)
572 return XFS_DQUOT_LOGRES(mp
) +
573 xfs_calc_inode_res(mp
, 1) +
574 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
575 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
, XFS_FSB_TO_B(mp
, 1));
579 * Setting an attribute at runtime, transaction space unit per block.
580 * the superblock for allocations: sector size
581 * the inode bmap btree could join or split: max depth * block size
582 * Since the runtime attribute transaction space is dependent on the total
583 * blocks needed for the 1st bmap, here we calculate out the space unit for
584 * one block so that the caller could figure out the total space according
585 * to the attibute extent length in blocks by:
586 * ext * M_RES(mp)->tr_attrsetrt.tr_logres
589 xfs_calc_attrsetrt_reservation(
590 struct xfs_mount
*mp
)
592 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
) +
593 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
),
594 XFS_FSB_TO_B(mp
, 1));
598 * Removing an attribute.
599 * the inode: inode size
600 * the attribute btree could join: max depth * block size
601 * the inode bmap btree could join or split: max depth * block size
602 * And the bmap_finish transaction can free the attr blocks freed giving:
603 * the agf for the ag in which the blocks live: 2 * sector size
604 * the agfl for the ag in which the blocks live: 2 * sector size
605 * the superblock for the free block count: sector size
606 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
609 xfs_calc_attrrm_reservation(
610 struct xfs_mount
*mp
)
612 return XFS_DQUOT_LOGRES(mp
) +
613 MAX((xfs_calc_inode_res(mp
, 1) +
614 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH
,
615 XFS_FSB_TO_B(mp
, 1)) +
616 (uint
)XFS_FSB_TO_B(mp
,
617 XFS_BM_MAXLEVELS(mp
, XFS_ATTR_FORK
)) +
618 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
), 0)),
619 (xfs_calc_buf_res(5, mp
->m_sb
.sb_sectsize
) +
620 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp
, 2),
621 XFS_FSB_TO_B(mp
, 1))));
625 * Clearing a bad agino number in an agi hash bucket.
628 xfs_calc_clear_agi_bucket_reservation(
629 struct xfs_mount
*mp
)
631 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
635 * Clearing the quotaflags in the superblock.
636 * the super block for changing quota flags: sector size
639 xfs_calc_qm_sbchange_reservation(
640 struct xfs_mount
*mp
)
642 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
646 * Adjusting quota limits.
647 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
650 xfs_calc_qm_setqlim_reservation(
651 struct xfs_mount
*mp
)
653 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot
));
657 * Allocating quota on disk if needed.
658 * the write transaction log space: M_RES(mp)->tr_write.tr_logres
659 * the unit of quota allocation: one system block size
662 xfs_calc_qm_dqalloc_reservation(
663 struct xfs_mount
*mp
)
665 ASSERT(M_RES(mp
)->tr_write
.tr_logres
);
666 return M_RES(mp
)->tr_write
.tr_logres
+
668 XFS_FSB_TO_B(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
) - 1);
672 * Turning off quotas.
673 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
674 * the superblock for the quota flags: sector size
677 xfs_calc_qm_quotaoff_reservation(
678 struct xfs_mount
*mp
)
680 return sizeof(struct xfs_qoff_logitem
) * 2 +
681 xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
685 * End of turning off quotas.
686 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
689 xfs_calc_qm_quotaoff_end_reservation(
690 struct xfs_mount
*mp
)
692 return sizeof(struct xfs_qoff_logitem
) * 2;
696 * Syncing the incore super block changes to disk.
697 * the super block to reflect the changes: sector size
700 xfs_calc_sb_reservation(
701 struct xfs_mount
*mp
)
703 return xfs_calc_buf_res(1, mp
->m_sb
.sb_sectsize
);
708 struct xfs_mount
*mp
,
709 struct xfs_trans_resv
*resp
)
712 * The following transactions are logged in physical format and
713 * require a permanent reservation on space.
715 resp
->tr_write
.tr_logres
= xfs_calc_write_reservation(mp
);
716 resp
->tr_write
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
717 resp
->tr_write
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
719 resp
->tr_itruncate
.tr_logres
= xfs_calc_itruncate_reservation(mp
);
720 resp
->tr_itruncate
.tr_logcount
= XFS_ITRUNCATE_LOG_COUNT
;
721 resp
->tr_itruncate
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
723 resp
->tr_rename
.tr_logres
= xfs_calc_rename_reservation(mp
);
724 resp
->tr_rename
.tr_logcount
= XFS_RENAME_LOG_COUNT
;
725 resp
->tr_rename
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
727 resp
->tr_link
.tr_logres
= xfs_calc_link_reservation(mp
);
728 resp
->tr_link
.tr_logcount
= XFS_LINK_LOG_COUNT
;
729 resp
->tr_link
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
731 resp
->tr_remove
.tr_logres
= xfs_calc_remove_reservation(mp
);
732 resp
->tr_remove
.tr_logcount
= XFS_REMOVE_LOG_COUNT
;
733 resp
->tr_remove
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
735 resp
->tr_symlink
.tr_logres
= xfs_calc_symlink_reservation(mp
);
736 resp
->tr_symlink
.tr_logcount
= XFS_SYMLINK_LOG_COUNT
;
737 resp
->tr_symlink
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
739 resp
->tr_create
.tr_logres
= xfs_calc_create_reservation(mp
);
740 resp
->tr_create
.tr_logcount
= XFS_CREATE_LOG_COUNT
;
741 resp
->tr_create
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
743 resp
->tr_mkdir
.tr_logres
= xfs_calc_mkdir_reservation(mp
);
744 resp
->tr_mkdir
.tr_logcount
= XFS_MKDIR_LOG_COUNT
;
745 resp
->tr_mkdir
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
747 resp
->tr_ifree
.tr_logres
= xfs_calc_ifree_reservation(mp
);
748 resp
->tr_ifree
.tr_logcount
= XFS_INACTIVE_LOG_COUNT
;
749 resp
->tr_ifree
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
751 resp
->tr_addafork
.tr_logres
= xfs_calc_addafork_reservation(mp
);
752 resp
->tr_addafork
.tr_logcount
= XFS_ADDAFORK_LOG_COUNT
;
753 resp
->tr_addafork
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
755 resp
->tr_attrinval
.tr_logres
= xfs_calc_attrinval_reservation(mp
);
756 resp
->tr_attrinval
.tr_logcount
= XFS_ATTRINVAL_LOG_COUNT
;
757 resp
->tr_attrinval
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
759 resp
->tr_attrsetm
.tr_logres
= xfs_calc_attrsetm_reservation(mp
);
760 resp
->tr_attrsetm
.tr_logcount
= XFS_ATTRSET_LOG_COUNT
;
761 resp
->tr_attrsetm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
763 resp
->tr_attrrm
.tr_logres
= xfs_calc_attrrm_reservation(mp
);
764 resp
->tr_attrrm
.tr_logcount
= XFS_ATTRRM_LOG_COUNT
;
765 resp
->tr_attrrm
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
767 resp
->tr_growrtalloc
.tr_logres
= xfs_calc_growrtalloc_reservation(mp
);
768 resp
->tr_growrtalloc
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
769 resp
->tr_growrtalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
771 resp
->tr_qm_dqalloc
.tr_logres
= xfs_calc_qm_dqalloc_reservation(mp
);
772 resp
->tr_qm_dqalloc
.tr_logcount
= XFS_WRITE_LOG_COUNT
;
773 resp
->tr_qm_dqalloc
.tr_logflags
|= XFS_TRANS_PERM_LOG_RES
;
776 * The following transactions are logged in logical format with
777 * a default log count.
779 resp
->tr_qm_sbchange
.tr_logres
= xfs_calc_qm_sbchange_reservation(mp
);
780 resp
->tr_qm_sbchange
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
782 resp
->tr_qm_setqlim
.tr_logres
= xfs_calc_qm_setqlim_reservation(mp
);
783 resp
->tr_qm_setqlim
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
785 resp
->tr_qm_quotaoff
.tr_logres
= xfs_calc_qm_quotaoff_reservation(mp
);
786 resp
->tr_qm_quotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
788 resp
->tr_qm_equotaoff
.tr_logres
=
789 xfs_calc_qm_quotaoff_end_reservation(mp
);
790 resp
->tr_qm_equotaoff
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
792 resp
->tr_sb
.tr_logres
= xfs_calc_sb_reservation(mp
);
793 resp
->tr_sb
.tr_logcount
= XFS_DEFAULT_LOG_COUNT
;
795 /* The following transaction are logged in logical format */
796 resp
->tr_ichange
.tr_logres
= xfs_calc_ichange_reservation(mp
);
797 resp
->tr_growdata
.tr_logres
= xfs_calc_growdata_reservation(mp
);
798 resp
->tr_swrite
.tr_logres
= xfs_calc_swrite_reservation(mp
);
799 resp
->tr_fsyncts
.tr_logres
= xfs_calc_swrite_reservation(mp
);
800 resp
->tr_writeid
.tr_logres
= xfs_calc_writeid_reservation(mp
);
801 resp
->tr_attrsetrt
.tr_logres
= xfs_calc_attrsetrt_reservation(mp
);
802 resp
->tr_clearagi
.tr_logres
= xfs_calc_clear_agi_bucket_reservation(mp
);
803 resp
->tr_growrtzero
.tr_logres
= xfs_calc_growrtzero_reservation(mp
);
804 resp
->tr_growrtfree
.tr_logres
= xfs_calc_growrtfree_reservation(mp
);