xfs: unify directory/attribute format definitions
[deliverable/linux.git] / fs / xfs / xfs_trans_resv.c
1 /*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * Copyright (C) 2010 Red Hat, Inc.
4 * All Rights Reserved.
5 *
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.
9 *
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.
14 *
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
18 */
19 #include "xfs.h"
20 #include "xfs_fs.h"
21 #include "xfs_format.h"
22 #include "xfs_shared.h"
23 #include "xfs_log.h"
24 #include "xfs_trans_resv.h"
25 #include "xfs_trans.h"
26 #include "xfs_sb.h"
27 #include "xfs_ag.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"
41 #include "xfs_bmap.h"
42 #include "xfs_bmap_util.h"
43 #include "xfs_quota.h"
44 #include "xfs_qm.h"
45 #include "xfs_trans_space.h"
46 #include "xfs_trace.h"
47
48 /*
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.
54 */
55 STATIC uint
56 xfs_buf_log_overhead(void)
57 {
58 return round_up(sizeof(struct xlog_op_header) +
59 sizeof(struct xfs_buf_log_format), 128);
60 }
61
62 /*
63 * Calculate out transaction log reservation per item in bytes.
64 *
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.
68 */
69 STATIC uint
70 xfs_calc_buf_res(
71 uint nbufs,
72 uint size)
73 {
74 return nbufs * (size + xfs_buf_log_overhead());
75 }
76
77 /*
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.
81 *
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.
88 *
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:
93 *
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
98 */
99 STATIC uint
100 xfs_calc_inode_res(
101 struct xfs_mount *mp,
102 uint ninodes)
103 {
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));
108 }
109
110 /*
111 * Various log reservation values.
112 *
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.
116 *
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.
124 *
125 * Reservation functions here avoid a huge stack in xfs_trans_init due to
126 * register overflow from temporaries in the calculations.
127 */
128
129
130 /*
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
143 */
144 STATIC uint
145 xfs_calc_write_reservation(
146 struct xfs_mount *mp)
147 {
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))));
158 }
159
160 /*
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
172 */
173 STATIC uint
174 xfs_calc_itruncate_reservation(
175 struct xfs_mount *mp)
176 {
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)));
189 }
190
191 /*
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
202 */
203 STATIC uint
204 xfs_calc_rename_reservation(
205 struct xfs_mount *mp)
206 {
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))));
214 }
215
216 /*
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
227 */
228 STATIC uint
229 xfs_calc_link_reservation(
230 struct xfs_mount *mp)
231 {
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))));
239 }
240
241 /*
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
252 */
253 STATIC uint
254 xfs_calc_remove_reservation(
255 struct xfs_mount *mp)
256 {
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))));
264 }
265
266 /*
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.
270 */
271
272 /*
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
280 */
281 STATIC uint
282 xfs_calc_create_resv_modify(
283 struct xfs_mount *mp)
284 {
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));
289 }
290
291 /*
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
298 */
299 STATIC uint
300 xfs_calc_create_resv_alloc(
301 struct xfs_mount *mp)
302 {
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));
309 }
310
311 STATIC uint
312 __xfs_calc_create_reservation(
313 struct xfs_mount *mp)
314 {
315 return XFS_DQUOT_LOGRES(mp) +
316 MAX(xfs_calc_create_resv_alloc(mp),
317 xfs_calc_create_resv_modify(mp));
318 }
319
320 /*
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
326 */
327 STATIC uint
328 xfs_calc_icreate_resv_alloc(
329 struct xfs_mount *mp)
330 {
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));
336 }
337
338 STATIC uint
339 xfs_calc_icreate_reservation(xfs_mount_t *mp)
340 {
341 return XFS_DQUOT_LOGRES(mp) +
342 MAX(xfs_calc_icreate_resv_alloc(mp),
343 xfs_calc_create_resv_modify(mp));
344 }
345
346 STATIC uint
347 xfs_calc_create_reservation(
348 struct xfs_mount *mp)
349 {
350 if (xfs_sb_version_hascrc(&mp->m_sb))
351 return xfs_calc_icreate_reservation(mp);
352 return __xfs_calc_create_reservation(mp);
353
354 }
355
356 /*
357 * Making a new directory is the same as creating a new file.
358 */
359 STATIC uint
360 xfs_calc_mkdir_reservation(
361 struct xfs_mount *mp)
362 {
363 return xfs_calc_create_reservation(mp);
364 }
365
366
367 /*
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).
371 */
372 STATIC uint
373 xfs_calc_symlink_reservation(
374 struct xfs_mount *mp)
375 {
376 return xfs_calc_create_reservation(mp) +
377 xfs_calc_buf_res(1, MAXPATHLEN);
378 }
379
380 /*
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
389 */
390 STATIC uint
391 xfs_calc_ifree_reservation(
392 struct xfs_mount *mp)
393 {
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));
405 }
406
407 /*
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.
410 */
411 STATIC uint
412 xfs_calc_ichange_reservation(
413 struct xfs_mount *mp)
414 {
415 return XFS_DQUOT_LOGRES(mp) +
416 xfs_calc_inode_res(mp, 1) +
417 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
418
419 }
420
421 /*
422 * Growing the data section of the filesystem.
423 * superblock
424 * agi and agf
425 * allocation btrees
426 */
427 STATIC uint
428 xfs_calc_growdata_reservation(
429 struct xfs_mount *mp)
430 {
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));
434 }
435
436 /*
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
445 */
446 STATIC uint
447 xfs_calc_growrtalloc_reservation(
448 struct xfs_mount *mp)
449 {
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));
456 }
457
458 /*
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
462 */
463 STATIC uint
464 xfs_calc_growrtzero_reservation(
465 struct xfs_mount *mp)
466 {
467 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
468 }
469
470 /*
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
479 */
480 STATIC uint
481 xfs_calc_growrtfree_reservation(
482 struct xfs_mount *mp)
483 {
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);
488 }
489
490 /*
491 * Logging the inode modification timestamp on a synchronous write.
492 * inode
493 */
494 STATIC uint
495 xfs_calc_swrite_reservation(
496 struct xfs_mount *mp)
497 {
498 return xfs_calc_inode_res(mp, 1);
499 }
500
501 /*
502 * Logging the inode mode bits when writing a setuid/setgid file
503 * inode
504 */
505 STATIC uint
506 xfs_calc_writeid_reservation(
507 struct xfs_mount *mp)
508 {
509 return xfs_calc_inode_res(mp, 1);
510 }
511
512 /*
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
518 * allocation btrees
519 */
520 STATIC uint
521 xfs_calc_addafork_reservation(
522 struct xfs_mount *mp)
523 {
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));
532 }
533
534 /*
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
544 */
545 STATIC uint
546 xfs_calc_attrinval_reservation(
547 struct xfs_mount *mp)
548 {
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))));
555 }
556
557 /*
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
566 * below).
567 */
568 STATIC uint
569 xfs_calc_attrsetm_reservation(
570 struct xfs_mount *mp)
571 {
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));
576 }
577
578 /*
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
587 */
588 STATIC uint
589 xfs_calc_attrsetrt_reservation(
590 struct xfs_mount *mp)
591 {
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));
595 }
596
597 /*
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
607 */
608 STATIC uint
609 xfs_calc_attrrm_reservation(
610 struct xfs_mount *mp)
611 {
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))));
622 }
623
624 /*
625 * Clearing a bad agino number in an agi hash bucket.
626 */
627 STATIC uint
628 xfs_calc_clear_agi_bucket_reservation(
629 struct xfs_mount *mp)
630 {
631 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
632 }
633
634 /*
635 * Clearing the quotaflags in the superblock.
636 * the super block for changing quota flags: sector size
637 */
638 STATIC uint
639 xfs_calc_qm_sbchange_reservation(
640 struct xfs_mount *mp)
641 {
642 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
643 }
644
645 /*
646 * Adjusting quota limits.
647 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
648 */
649 STATIC uint
650 xfs_calc_qm_setqlim_reservation(
651 struct xfs_mount *mp)
652 {
653 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
654 }
655
656 /*
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
660 */
661 STATIC uint
662 xfs_calc_qm_dqalloc_reservation(
663 struct xfs_mount *mp)
664 {
665 ASSERT(M_RES(mp)->tr_write.tr_logres);
666 return M_RES(mp)->tr_write.tr_logres +
667 xfs_calc_buf_res(1,
668 XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
669 }
670
671 /*
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
675 */
676 STATIC uint
677 xfs_calc_qm_quotaoff_reservation(
678 struct xfs_mount *mp)
679 {
680 return sizeof(struct xfs_qoff_logitem) * 2 +
681 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
682 }
683
684 /*
685 * End of turning off quotas.
686 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
687 */
688 STATIC uint
689 xfs_calc_qm_quotaoff_end_reservation(
690 struct xfs_mount *mp)
691 {
692 return sizeof(struct xfs_qoff_logitem) * 2;
693 }
694
695 /*
696 * Syncing the incore super block changes to disk.
697 * the super block to reflect the changes: sector size
698 */
699 STATIC uint
700 xfs_calc_sb_reservation(
701 struct xfs_mount *mp)
702 {
703 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
704 }
705
706 void
707 xfs_trans_resv_calc(
708 struct xfs_mount *mp,
709 struct xfs_trans_resv *resp)
710 {
711 /*
712 * The following transactions are logged in physical format and
713 * require a permanent reservation on space.
714 */
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;
718
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;
722
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;
726
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;
730
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;
734
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;
738
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;
742
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;
746
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;
750
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;
754
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;
758
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;
762
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;
766
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;
770
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;
774
775 /*
776 * The following transactions are logged in logical format with
777 * a default log count.
778 */
779 resp->tr_qm_sbchange.tr_logres = xfs_calc_qm_sbchange_reservation(mp);
780 resp->tr_qm_sbchange.tr_logcount = XFS_DEFAULT_LOG_COUNT;
781
782 resp->tr_qm_setqlim.tr_logres = xfs_calc_qm_setqlim_reservation(mp);
783 resp->tr_qm_setqlim.tr_logcount = XFS_DEFAULT_LOG_COUNT;
784
785 resp->tr_qm_quotaoff.tr_logres = xfs_calc_qm_quotaoff_reservation(mp);
786 resp->tr_qm_quotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT;
787
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;
791
792 resp->tr_sb.tr_logres = xfs_calc_sb_reservation(mp);
793 resp->tr_sb.tr_logcount = XFS_DEFAULT_LOG_COUNT;
794
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);
805 }
This page took 0.055305 seconds and 5 git commands to generate.