]>
Commit | Line | Data |
---|---|---|
364e85ec DC |
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 | */ | |
9c799827 | 19 | #include "libxfs_priv.h" |
b626fb59 DC |
20 | #include "xfs_fs.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" | |
364e85ec DC |
35 | |
36 | /* | |
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. | |
42 | */ | |
43 | STATIC uint | |
44 | xfs_buf_log_overhead(void) | |
45 | { | |
46 | return round_up(sizeof(struct xlog_op_header) + | |
47 | sizeof(struct xfs_buf_log_format), 128); | |
48 | } | |
49 | ||
50 | /* | |
51 | * Calculate out transaction log reservation per item in bytes. | |
52 | * | |
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. | |
56 | */ | |
57 | STATIC uint | |
58 | xfs_calc_buf_res( | |
59 | uint nbufs, | |
60 | uint size) | |
61 | { | |
62 | return nbufs * (size + xfs_buf_log_overhead()); | |
63 | } | |
64 | ||
546abaa4 DC |
65 | /* |
66 | * Logging inodes is really tricksy. They are logged in memory format, | |
e6d77a21 | 67 | * which means that what we write into the log doesn't directly translate into |
546abaa4 DC |
68 | * the amount of space they use on disk. |
69 | * | |
70 | * Case in point - btree format forks in memory format use more space than the | |
71 | * on-disk format. In memory, the buffer contains a normal btree block header so | |
72 | * the btree code can treat it as though it is just another generic buffer. | |
73 | * However, when we write it to the inode fork, we don't write all of this | |
74 | * header as it isn't needed. e.g. the root is only ever in the inode, so | |
75 | * there's no need for sibling pointers which would waste 16 bytes of space. | |
76 | * | |
77 | * Hence when we have an inode with a maximally sized btree format fork, then | |
78 | * amount of information we actually log is greater than the size of the inode | |
79 | * on disk. Hence we need an inode reservation function that calculates all this | |
80 | * correctly. So, we log: | |
81 | * | |
ff105f75 DC |
82 | * - 4 log op headers for object |
83 | * - for the ilf, the inode core and 2 forks | |
546abaa4 | 84 | * - inode log format object |
ff105f75 DC |
85 | * - the inode core |
86 | * - two inode forks containing bmap btree root blocks. | |
87 | * - the btree data contained by both forks will fit into the inode size, | |
88 | * hence when combined with the inode core above, we have a total of the | |
89 | * actual inode size. | |
90 | * - the BMBT headers need to be accounted separately, as they are | |
91 | * additional to the records and pointers that fit inside the inode | |
92 | * forks. | |
546abaa4 DC |
93 | */ |
94 | STATIC uint | |
95 | xfs_calc_inode_res( | |
96 | struct xfs_mount *mp, | |
97 | uint ninodes) | |
98 | { | |
ff105f75 DC |
99 | return ninodes * |
100 | (4 * sizeof(struct xlog_op_header) + | |
101 | sizeof(struct xfs_inode_log_format) + | |
102 | mp->m_sb.sb_inodesize + | |
103 | 2 * XFS_BMBT_BLOCK_LEN(mp)); | |
546abaa4 DC |
104 | } |
105 | ||
0f88d64a BF |
106 | /* |
107 | * The free inode btree is a conditional feature and the log reservation | |
108 | * requirements differ slightly from that of the traditional inode allocation | |
ff105f75 DC |
109 | * btree. The finobt tracks records for inode chunks with at least one free |
110 | * inode. A record can be removed from the tree for an inode allocation | |
111 | * or free and thus the finobt reservation is unconditional across: | |
112 | * | |
113 | * - inode allocation | |
114 | * - inode free | |
115 | * - inode chunk allocation | |
116 | * | |
117 | * The 'modify' param indicates to include the record modification scenario. The | |
118 | * 'alloc' param indicates to include the reservation for free space btree | |
119 | * modifications on behalf of finobt modifications. This is required only for | |
120 | * transactions that do not already account for free space btree modifications. | |
0f88d64a BF |
121 | * |
122 | * the free inode btree: max depth * block size | |
ff105f75 | 123 | * the allocation btrees: 2 trees * (max depth - 1) * block size |
0f88d64a | 124 | * the free inode btree entry: block size |
0f88d64a BF |
125 | */ |
126 | STATIC uint | |
127 | xfs_calc_finobt_res( | |
128 | struct xfs_mount *mp, | |
ff105f75 | 129 | int alloc, |
0f88d64a BF |
130 | int modify) |
131 | { | |
132 | uint res; | |
133 | ||
134 | if (!xfs_sb_version_hasfinobt(&mp->m_sb)) | |
135 | return 0; | |
136 | ||
137 | res = xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)); | |
ff105f75 | 138 | if (alloc) |
f8149110 | 139 | res += xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
ff105f75 | 140 | XFS_FSB_TO_B(mp, 1)); |
0f88d64a BF |
141 | if (modify) |
142 | res += (uint)XFS_FSB_TO_B(mp, 1); | |
143 | ||
144 | return res; | |
145 | } | |
146 | ||
364e85ec DC |
147 | /* |
148 | * Various log reservation values. | |
149 | * | |
150 | * These are based on the size of the file system block because that is what | |
151 | * most transactions manipulate. Each adds in an additional 128 bytes per | |
152 | * item logged to try to account for the overhead of the transaction mechanism. | |
153 | * | |
154 | * Note: Most of the reservations underestimate the number of allocation | |
6f530e9a | 155 | * groups into which they could free extents in the xfs_defer_finish() call. |
364e85ec | 156 | * This is because the number in the worst case is quite high and quite |
6f530e9a | 157 | * unusual. In order to fix this we need to change xfs_defer_finish() to free |
364e85ec DC |
158 | * extents in only a single AG at a time. This will require changes to the |
159 | * EFI code as well, however, so that the EFI for the extents not freed is | |
160 | * logged again in each transaction. See SGI PV #261917. | |
161 | * | |
162 | * Reservation functions here avoid a huge stack in xfs_trans_init due to | |
163 | * register overflow from temporaries in the calculations. | |
164 | */ | |
165 | ||
166 | ||
167 | /* | |
168 | * In a write transaction we can allocate a maximum of 2 | |
169 | * extents. This gives: | |
170 | * the inode getting the new extents: inode size | |
171 | * the inode's bmap btree: max depth * block size | |
172 | * the agfs of the ags from which the extents are allocated: 2 * sector | |
173 | * the superblock free block counter: sector size | |
174 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
175 | * And the bmap_finish transaction can free bmap blocks in a join: | |
176 | * the agfs of the ags containing the blocks: 2 * sector size | |
177 | * the agfls of the ags containing the blocks: 2 * sector size | |
178 | * the super block free block counter: sector size | |
179 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
180 | */ | |
181 | STATIC uint | |
182 | xfs_calc_write_reservation( | |
183 | struct xfs_mount *mp) | |
184 | { | |
185 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 | 186 | MAX((xfs_calc_inode_res(mp, 1) + |
364e85ec DC |
187 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), |
188 | XFS_FSB_TO_B(mp, 1)) + | |
189 | xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + | |
190 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), | |
191 | XFS_FSB_TO_B(mp, 1))), | |
192 | (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + | |
193 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), | |
194 | XFS_FSB_TO_B(mp, 1)))); | |
195 | } | |
196 | ||
197 | /* | |
198 | * In truncating a file we free up to two extents at once. We can modify: | |
199 | * the inode being truncated: inode size | |
200 | * the inode's bmap btree: (max depth + 1) * block size | |
201 | * And the bmap_finish transaction can free the blocks and bmap blocks: | |
202 | * the agf for each of the ags: 4 * sector size | |
203 | * the agfl for each of the ags: 4 * sector size | |
204 | * the super block to reflect the freed blocks: sector size | |
205 | * worst case split in allocation btrees per extent assuming 4 extents: | |
206 | * 4 exts * 2 trees * (2 * max depth - 1) * block size | |
207 | * the inode btree: max depth * blocksize | |
208 | * the allocation btrees: 2 trees * (max depth - 1) * block size | |
209 | */ | |
210 | STATIC uint | |
211 | xfs_calc_itruncate_reservation( | |
212 | struct xfs_mount *mp) | |
213 | { | |
214 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 | 215 | MAX((xfs_calc_inode_res(mp, 1) + |
364e85ec DC |
216 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1, |
217 | XFS_FSB_TO_B(mp, 1))), | |
218 | (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) + | |
219 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4), | |
220 | XFS_FSB_TO_B(mp, 1)) + | |
221 | xfs_calc_buf_res(5, 0) + | |
222 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), | |
223 | XFS_FSB_TO_B(mp, 1)) + | |
ff105f75 | 224 | xfs_calc_buf_res(2 + mp->m_ialloc_blks + |
364e85ec DC |
225 | mp->m_in_maxlevels, 0))); |
226 | } | |
227 | ||
228 | /* | |
229 | * In renaming a files we can modify: | |
230 | * the four inodes involved: 4 * inode size | |
231 | * the two directory btrees: 2 * (max depth + v2) * dir block size | |
232 | * the two directory bmap btrees: 2 * max depth * block size | |
233 | * And the bmap_finish transaction can free dir and bmap blocks (two sets | |
234 | * of bmap blocks) giving: | |
235 | * the agf for the ags in which the blocks live: 3 * sector size | |
236 | * the agfl for the ags in which the blocks live: 3 * sector size | |
237 | * the superblock for the free block count: sector size | |
238 | * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size | |
239 | */ | |
240 | STATIC uint | |
241 | xfs_calc_rename_reservation( | |
242 | struct xfs_mount *mp) | |
243 | { | |
244 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 | 245 | MAX((xfs_calc_inode_res(mp, 4) + |
364e85ec DC |
246 | xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), |
247 | XFS_FSB_TO_B(mp, 1))), | |
248 | (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + | |
249 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3), | |
250 | XFS_FSB_TO_B(mp, 1)))); | |
251 | } | |
252 | ||
ff105f75 DC |
253 | /* |
254 | * For removing an inode from unlinked list at first, we can modify: | |
255 | * the agi hash list and counters: sector size | |
256 | * the on disk inode before ours in the agi hash list: inode cluster size | |
257 | */ | |
258 | STATIC uint | |
259 | xfs_calc_iunlink_remove_reservation( | |
260 | struct xfs_mount *mp) | |
261 | { | |
262 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + | |
263 | max_t(uint, XFS_FSB_TO_B(mp, 1), mp->m_inode_cluster_size); | |
264 | } | |
265 | ||
364e85ec DC |
266 | /* |
267 | * For creating a link to an inode: | |
268 | * the parent directory inode: inode size | |
269 | * the linked inode: inode size | |
270 | * the directory btree could split: (max depth + v2) * dir block size | |
271 | * the directory bmap btree could join or split: (max depth + v2) * blocksize | |
272 | * And the bmap_finish transaction can free some bmap blocks giving: | |
273 | * the agf for the ag in which the blocks live: sector size | |
274 | * the agfl for the ag in which the blocks live: sector size | |
275 | * the superblock for the free block count: sector size | |
276 | * the allocation btrees: 2 trees * (2 * max depth - 1) * block size | |
277 | */ | |
278 | STATIC uint | |
279 | xfs_calc_link_reservation( | |
280 | struct xfs_mount *mp) | |
281 | { | |
282 | return XFS_DQUOT_LOGRES(mp) + | |
ff105f75 | 283 | xfs_calc_iunlink_remove_reservation(mp) + |
546abaa4 | 284 | MAX((xfs_calc_inode_res(mp, 2) + |
364e85ec DC |
285 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
286 | XFS_FSB_TO_B(mp, 1))), | |
287 | (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + | |
288 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), | |
289 | XFS_FSB_TO_B(mp, 1)))); | |
290 | } | |
291 | ||
ff105f75 DC |
292 | /* |
293 | * For adding an inode to unlinked list we can modify: | |
294 | * the agi hash list: sector size | |
295 | * the unlinked inode: inode size | |
296 | */ | |
297 | STATIC uint | |
298 | xfs_calc_iunlink_add_reservation(xfs_mount_t *mp) | |
299 | { | |
300 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + | |
301 | xfs_calc_inode_res(mp, 1); | |
302 | } | |
303 | ||
364e85ec DC |
304 | /* |
305 | * For removing a directory entry we can modify: | |
306 | * the parent directory inode: inode size | |
307 | * the removed inode: inode size | |
308 | * the directory btree could join: (max depth + v2) * dir block size | |
309 | * the directory bmap btree could join or split: (max depth + v2) * blocksize | |
310 | * And the bmap_finish transaction can free the dir and bmap blocks giving: | |
311 | * the agf for the ag in which the blocks live: 2 * sector size | |
312 | * the agfl for the ag in which the blocks live: 2 * sector size | |
313 | * the superblock for the free block count: sector size | |
314 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
315 | */ | |
316 | STATIC uint | |
317 | xfs_calc_remove_reservation( | |
318 | struct xfs_mount *mp) | |
319 | { | |
320 | return XFS_DQUOT_LOGRES(mp) + | |
ff105f75 DC |
321 | xfs_calc_iunlink_add_reservation(mp) + |
322 | MAX((xfs_calc_inode_res(mp, 1) + | |
364e85ec DC |
323 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
324 | XFS_FSB_TO_B(mp, 1))), | |
ff105f75 | 325 | (xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) + |
364e85ec DC |
326 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), |
327 | XFS_FSB_TO_B(mp, 1)))); | |
328 | } | |
329 | ||
330 | /* | |
331 | * For create, break it in to the two cases that the transaction | |
332 | * covers. We start with the modify case - allocation done by modification | |
333 | * of the state of existing inodes - and the allocation case. | |
334 | */ | |
335 | ||
336 | /* | |
337 | * For create we can modify: | |
338 | * the parent directory inode: inode size | |
339 | * the new inode: inode size | |
340 | * the inode btree entry: block size | |
341 | * the superblock for the nlink flag: sector size | |
342 | * the directory btree: (max depth + v2) * dir block size | |
343 | * the directory inode's bmap btree: (max depth + v2) * block size | |
ff105f75 | 344 | * the finobt (record modification and allocation btrees) |
364e85ec DC |
345 | */ |
346 | STATIC uint | |
347 | xfs_calc_create_resv_modify( | |
348 | struct xfs_mount *mp) | |
349 | { | |
546abaa4 | 350 | return xfs_calc_inode_res(mp, 2) + |
364e85ec DC |
351 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
352 | (uint)XFS_FSB_TO_B(mp, 1) + | |
0f88d64a | 353 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)) + |
ff105f75 | 354 | xfs_calc_finobt_res(mp, 1, 1); |
364e85ec DC |
355 | } |
356 | ||
357 | /* | |
358 | * For create we can allocate some inodes giving: | |
359 | * the agi and agf of the ag getting the new inodes: 2 * sectorsize | |
360 | * the superblock for the nlink flag: sector size | |
ff105f75 | 361 | * the inode blocks allocated: mp->m_ialloc_blks * blocksize |
364e85ec DC |
362 | * the inode btree: max depth * blocksize |
363 | * the allocation btrees: 2 trees * (max depth - 1) * block size | |
364 | */ | |
365 | STATIC uint | |
366 | xfs_calc_create_resv_alloc( | |
367 | struct xfs_mount *mp) | |
368 | { | |
369 | return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + | |
370 | mp->m_sb.sb_sectsize + | |
ff105f75 | 371 | xfs_calc_buf_res(mp->m_ialloc_blks, XFS_FSB_TO_B(mp, 1)) + |
364e85ec DC |
372 | xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) + |
373 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), | |
ff105f75 | 374 | XFS_FSB_TO_B(mp, 1)); |
364e85ec DC |
375 | } |
376 | ||
377 | STATIC uint | |
378 | __xfs_calc_create_reservation( | |
379 | struct xfs_mount *mp) | |
380 | { | |
381 | return XFS_DQUOT_LOGRES(mp) + | |
382 | MAX(xfs_calc_create_resv_alloc(mp), | |
383 | xfs_calc_create_resv_modify(mp)); | |
384 | } | |
385 | ||
386 | /* | |
387 | * For icreate we can allocate some inodes giving: | |
388 | * the agi and agf of the ag getting the new inodes: 2 * sectorsize | |
389 | * the superblock for the nlink flag: sector size | |
390 | * the inode btree: max depth * blocksize | |
391 | * the allocation btrees: 2 trees * (max depth - 1) * block size | |
ff105f75 | 392 | * the finobt (record insertion) |
364e85ec DC |
393 | */ |
394 | STATIC uint | |
395 | xfs_calc_icreate_resv_alloc( | |
396 | struct xfs_mount *mp) | |
397 | { | |
398 | return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + | |
399 | mp->m_sb.sb_sectsize + | |
400 | xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) + | |
401 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), | |
0f88d64a | 402 | XFS_FSB_TO_B(mp, 1)) + |
ff105f75 | 403 | xfs_calc_finobt_res(mp, 0, 0); |
364e85ec DC |
404 | } |
405 | ||
406 | STATIC uint | |
407 | xfs_calc_icreate_reservation(xfs_mount_t *mp) | |
408 | { | |
409 | return XFS_DQUOT_LOGRES(mp) + | |
410 | MAX(xfs_calc_icreate_resv_alloc(mp), | |
411 | xfs_calc_create_resv_modify(mp)); | |
412 | } | |
413 | ||
414 | STATIC uint | |
415 | xfs_calc_create_reservation( | |
416 | struct xfs_mount *mp) | |
417 | { | |
418 | if (xfs_sb_version_hascrc(&mp->m_sb)) | |
419 | return xfs_calc_icreate_reservation(mp); | |
420 | return __xfs_calc_create_reservation(mp); | |
421 | ||
422 | } | |
423 | ||
ff105f75 DC |
424 | STATIC uint |
425 | xfs_calc_create_tmpfile_reservation( | |
426 | struct xfs_mount *mp) | |
427 | { | |
428 | uint res = XFS_DQUOT_LOGRES(mp); | |
429 | ||
430 | if (xfs_sb_version_hascrc(&mp->m_sb)) | |
431 | res += xfs_calc_icreate_resv_alloc(mp); | |
432 | else | |
433 | res += xfs_calc_create_resv_alloc(mp); | |
434 | ||
435 | return res + xfs_calc_iunlink_add_reservation(mp); | |
436 | } | |
437 | ||
364e85ec DC |
438 | /* |
439 | * Making a new directory is the same as creating a new file. | |
440 | */ | |
441 | STATIC uint | |
442 | xfs_calc_mkdir_reservation( | |
443 | struct xfs_mount *mp) | |
444 | { | |
445 | return xfs_calc_create_reservation(mp); | |
446 | } | |
447 | ||
448 | ||
449 | /* | |
450 | * Making a new symplink is the same as creating a new file, but | |
451 | * with the added blocks for remote symlink data which can be up to 1kB in | |
452 | * length (MAXPATHLEN). | |
453 | */ | |
454 | STATIC uint | |
455 | xfs_calc_symlink_reservation( | |
456 | struct xfs_mount *mp) | |
457 | { | |
458 | return xfs_calc_create_reservation(mp) + | |
459 | xfs_calc_buf_res(1, MAXPATHLEN); | |
460 | } | |
461 | ||
462 | /* | |
463 | * In freeing an inode we can modify: | |
464 | * the inode being freed: inode size | |
465 | * the super block free inode counter: sector size | |
466 | * the agi hash list and counters: sector size | |
467 | * the inode btree entry: block size | |
468 | * the on disk inode before ours in the agi hash list: inode cluster size | |
469 | * the inode btree: max depth * blocksize | |
470 | * the allocation btrees: 2 trees * (max depth - 1) * block size | |
ff105f75 | 471 | * the finobt (record insertion, removal or modification) |
364e85ec DC |
472 | */ |
473 | STATIC uint | |
474 | xfs_calc_ifree_reservation( | |
475 | struct xfs_mount *mp) | |
476 | { | |
477 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 | 478 | xfs_calc_inode_res(mp, 1) + |
ff105f75 | 479 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
364e85ec | 480 | xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) + |
ff105f75 | 481 | xfs_calc_iunlink_remove_reservation(mp) + |
364e85ec | 482 | xfs_calc_buf_res(1, 0) + |
ff105f75 | 483 | xfs_calc_buf_res(2 + mp->m_ialloc_blks + |
364e85ec DC |
484 | mp->m_in_maxlevels, 0) + |
485 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), | |
0f88d64a | 486 | XFS_FSB_TO_B(mp, 1)) + |
ff105f75 | 487 | xfs_calc_finobt_res(mp, 0, 1); |
364e85ec DC |
488 | } |
489 | ||
490 | /* | |
491 | * When only changing the inode we log the inode and possibly the superblock | |
492 | * We also add a bit of slop for the transaction stuff. | |
493 | */ | |
494 | STATIC uint | |
495 | xfs_calc_ichange_reservation( | |
496 | struct xfs_mount *mp) | |
497 | { | |
498 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 DC |
499 | xfs_calc_inode_res(mp, 1) + |
500 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); | |
364e85ec DC |
501 | |
502 | } | |
503 | ||
504 | /* | |
505 | * Growing the data section of the filesystem. | |
506 | * superblock | |
507 | * agi and agf | |
508 | * allocation btrees | |
509 | */ | |
510 | STATIC uint | |
511 | xfs_calc_growdata_reservation( | |
512 | struct xfs_mount *mp) | |
513 | { | |
514 | return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + | |
515 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), | |
516 | XFS_FSB_TO_B(mp, 1)); | |
517 | } | |
518 | ||
519 | /* | |
520 | * Growing the rt section of the filesystem. | |
521 | * In the first set of transactions (ALLOC) we allocate space to the | |
522 | * bitmap or summary files. | |
523 | * superblock: sector size | |
524 | * agf of the ag from which the extent is allocated: sector size | |
525 | * bmap btree for bitmap/summary inode: max depth * blocksize | |
526 | * bitmap/summary inode: inode size | |
527 | * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize | |
528 | */ | |
529 | STATIC uint | |
530 | xfs_calc_growrtalloc_reservation( | |
531 | struct xfs_mount *mp) | |
532 | { | |
533 | return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + | |
534 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), | |
535 | XFS_FSB_TO_B(mp, 1)) + | |
546abaa4 | 536 | xfs_calc_inode_res(mp, 1) + |
364e85ec DC |
537 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
538 | XFS_FSB_TO_B(mp, 1)); | |
539 | } | |
540 | ||
541 | /* | |
542 | * Growing the rt section of the filesystem. | |
543 | * In the second set of transactions (ZERO) we zero the new metadata blocks. | |
544 | * one bitmap/summary block: blocksize | |
545 | */ | |
546 | STATIC uint | |
547 | xfs_calc_growrtzero_reservation( | |
548 | struct xfs_mount *mp) | |
549 | { | |
550 | return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize); | |
551 | } | |
552 | ||
553 | /* | |
554 | * Growing the rt section of the filesystem. | |
555 | * In the third set of transactions (FREE) we update metadata without | |
556 | * allocating any new blocks. | |
557 | * superblock: sector size | |
558 | * bitmap inode: inode size | |
559 | * summary inode: inode size | |
560 | * one bitmap block: blocksize | |
561 | * summary blocks: new summary size | |
562 | */ | |
563 | STATIC uint | |
564 | xfs_calc_growrtfree_reservation( | |
565 | struct xfs_mount *mp) | |
566 | { | |
567 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + | |
546abaa4 | 568 | xfs_calc_inode_res(mp, 2) + |
364e85ec DC |
569 | xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) + |
570 | xfs_calc_buf_res(1, mp->m_rsumsize); | |
571 | } | |
572 | ||
573 | /* | |
574 | * Logging the inode modification timestamp on a synchronous write. | |
575 | * inode | |
576 | */ | |
577 | STATIC uint | |
578 | xfs_calc_swrite_reservation( | |
579 | struct xfs_mount *mp) | |
580 | { | |
546abaa4 | 581 | return xfs_calc_inode_res(mp, 1); |
364e85ec DC |
582 | } |
583 | ||
584 | /* | |
585 | * Logging the inode mode bits when writing a setuid/setgid file | |
586 | * inode | |
587 | */ | |
588 | STATIC uint | |
546abaa4 DC |
589 | xfs_calc_writeid_reservation( |
590 | struct xfs_mount *mp) | |
364e85ec | 591 | { |
546abaa4 | 592 | return xfs_calc_inode_res(mp, 1); |
364e85ec DC |
593 | } |
594 | ||
595 | /* | |
596 | * Converting the inode from non-attributed to attributed. | |
597 | * the inode being converted: inode size | |
598 | * agf block and superblock (for block allocation) | |
599 | * the new block (directory sized) | |
600 | * bmap blocks for the new directory block | |
601 | * allocation btrees | |
602 | */ | |
603 | STATIC uint | |
604 | xfs_calc_addafork_reservation( | |
605 | struct xfs_mount *mp) | |
606 | { | |
607 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 | 608 | xfs_calc_inode_res(mp, 1) + |
364e85ec | 609 | xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
ff105f75 | 610 | xfs_calc_buf_res(1, mp->m_dir_geo->blksize) + |
364e85ec DC |
611 | xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1, |
612 | XFS_FSB_TO_B(mp, 1)) + | |
613 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), | |
614 | XFS_FSB_TO_B(mp, 1)); | |
615 | } | |
616 | ||
617 | /* | |
618 | * Removing the attribute fork of a file | |
619 | * the inode being truncated: inode size | |
620 | * the inode's bmap btree: max depth * block size | |
621 | * And the bmap_finish transaction can free the blocks and bmap blocks: | |
622 | * the agf for each of the ags: 4 * sector size | |
623 | * the agfl for each of the ags: 4 * sector size | |
624 | * the super block to reflect the freed blocks: sector size | |
625 | * worst case split in allocation btrees per extent assuming 4 extents: | |
626 | * 4 exts * 2 trees * (2 * max depth - 1) * block size | |
627 | */ | |
628 | STATIC uint | |
629 | xfs_calc_attrinval_reservation( | |
630 | struct xfs_mount *mp) | |
631 | { | |
546abaa4 | 632 | return MAX((xfs_calc_inode_res(mp, 1) + |
364e85ec DC |
633 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK), |
634 | XFS_FSB_TO_B(mp, 1))), | |
635 | (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) + | |
636 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4), | |
637 | XFS_FSB_TO_B(mp, 1)))); | |
638 | } | |
639 | ||
640 | /* | |
641 | * Setting an attribute at mount time. | |
642 | * the inode getting the attribute | |
643 | * the superblock for allocations | |
644 | * the agfs extents are allocated from | |
645 | * the attribute btree * max depth | |
646 | * the inode allocation btree | |
647 | * Since attribute transaction space is dependent on the size of the attribute, | |
648 | * the calculation is done partially at mount time and partially at runtime(see | |
649 | * below). | |
650 | */ | |
651 | STATIC uint | |
652 | xfs_calc_attrsetm_reservation( | |
653 | struct xfs_mount *mp) | |
654 | { | |
655 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 | 656 | xfs_calc_inode_res(mp, 1) + |
364e85ec DC |
657 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
658 | xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1)); | |
659 | } | |
660 | ||
661 | /* | |
662 | * Setting an attribute at runtime, transaction space unit per block. | |
663 | * the superblock for allocations: sector size | |
664 | * the inode bmap btree could join or split: max depth * block size | |
665 | * Since the runtime attribute transaction space is dependent on the total | |
666 | * blocks needed for the 1st bmap, here we calculate out the space unit for | |
667 | * one block so that the caller could figure out the total space according | |
48ea6cb9 DC |
668 | * to the attibute extent length in blocks by: |
669 | * ext * M_RES(mp)->tr_attrsetrt.tr_logres | |
364e85ec DC |
670 | */ |
671 | STATIC uint | |
672 | xfs_calc_attrsetrt_reservation( | |
673 | struct xfs_mount *mp) | |
674 | { | |
675 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + | |
676 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK), | |
677 | XFS_FSB_TO_B(mp, 1)); | |
678 | } | |
679 | ||
680 | /* | |
681 | * Removing an attribute. | |
682 | * the inode: inode size | |
683 | * the attribute btree could join: max depth * block size | |
684 | * the inode bmap btree could join or split: max depth * block size | |
685 | * And the bmap_finish transaction can free the attr blocks freed giving: | |
686 | * the agf for the ag in which the blocks live: 2 * sector size | |
687 | * the agfl for the ag in which the blocks live: 2 * sector size | |
688 | * the superblock for the free block count: sector size | |
689 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size | |
690 | */ | |
691 | STATIC uint | |
692 | xfs_calc_attrrm_reservation( | |
693 | struct xfs_mount *mp) | |
694 | { | |
695 | return XFS_DQUOT_LOGRES(mp) + | |
546abaa4 | 696 | MAX((xfs_calc_inode_res(mp, 1) + |
364e85ec DC |
697 | xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, |
698 | XFS_FSB_TO_B(mp, 1)) + | |
699 | (uint)XFS_FSB_TO_B(mp, | |
700 | XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + | |
701 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)), | |
702 | (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + | |
703 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), | |
704 | XFS_FSB_TO_B(mp, 1)))); | |
705 | } | |
706 | ||
707 | /* | |
708 | * Clearing a bad agino number in an agi hash bucket. | |
709 | */ | |
710 | STATIC uint | |
711 | xfs_calc_clear_agi_bucket_reservation( | |
712 | struct xfs_mount *mp) | |
713 | { | |
714 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); | |
715 | } | |
716 | ||
364e85ec DC |
717 | /* |
718 | * Adjusting quota limits. | |
719 | * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot) | |
720 | */ | |
721 | STATIC uint | |
722 | xfs_calc_qm_setqlim_reservation( | |
723 | struct xfs_mount *mp) | |
724 | { | |
725 | return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot)); | |
726 | } | |
727 | ||
728 | /* | |
729 | * Allocating quota on disk if needed. | |
ff105f75 | 730 | * the write transaction log space for quota file extent allocation |
364e85ec DC |
731 | * the unit of quota allocation: one system block size |
732 | */ | |
733 | STATIC uint | |
734 | xfs_calc_qm_dqalloc_reservation( | |
735 | struct xfs_mount *mp) | |
736 | { | |
ff105f75 | 737 | return xfs_calc_write_reservation(mp) + |
364e85ec DC |
738 | xfs_calc_buf_res(1, |
739 | XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1); | |
740 | } | |
741 | ||
742 | /* | |
743 | * Turning off quotas. | |
744 | * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2 | |
745 | * the superblock for the quota flags: sector size | |
746 | */ | |
747 | STATIC uint | |
748 | xfs_calc_qm_quotaoff_reservation( | |
749 | struct xfs_mount *mp) | |
750 | { | |
751 | return sizeof(struct xfs_qoff_logitem) * 2 + | |
752 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); | |
753 | } | |
754 | ||
755 | /* | |
756 | * End of turning off quotas. | |
757 | * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2 | |
758 | */ | |
759 | STATIC uint | |
760 | xfs_calc_qm_quotaoff_end_reservation( | |
761 | struct xfs_mount *mp) | |
762 | { | |
763 | return sizeof(struct xfs_qoff_logitem) * 2; | |
764 | } | |
765 | ||
766 | /* | |
767 | * Syncing the incore super block changes to disk. | |
768 | * the super block to reflect the changes: sector size | |
769 | */ | |
770 | STATIC uint | |
771 | xfs_calc_sb_reservation( | |
772 | struct xfs_mount *mp) | |
773 | { | |
774 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); | |
775 | } | |
776 | ||
777 | void | |
778 | xfs_trans_resv_calc( | |
779 | struct xfs_mount *mp, | |
780 | struct xfs_trans_resv *resp) | |
781 | { | |
cf52c730 DC |
782 | /* |
783 | * The following transactions are logged in physical format and | |
784 | * require a permanent reservation on space. | |
785 | */ | |
786 | resp->tr_write.tr_logres = xfs_calc_write_reservation(mp); | |
787 | resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; | |
788 | resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
789 | ||
790 | resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp); | |
791 | resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; | |
792 | resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
793 | ||
794 | resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); | |
795 | resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT; | |
796 | resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
797 | ||
798 | resp->tr_link.tr_logres = xfs_calc_link_reservation(mp); | |
799 | resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT; | |
800 | resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
801 | ||
802 | resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp); | |
803 | resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT; | |
804 | resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
805 | ||
806 | resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp); | |
807 | resp->tr_symlink.tr_logcount = XFS_SYMLINK_LOG_COUNT; | |
808 | resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
809 | ||
810 | resp->tr_create.tr_logres = xfs_calc_create_reservation(mp); | |
811 | resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT; | |
812 | resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
813 | ||
ff105f75 DC |
814 | resp->tr_create_tmpfile.tr_logres = |
815 | xfs_calc_create_tmpfile_reservation(mp); | |
816 | resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; | |
817 | resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
818 | ||
cf52c730 DC |
819 | resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); |
820 | resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; | |
821 | resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
822 | ||
823 | resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); | |
824 | resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; | |
825 | resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
826 | ||
827 | resp->tr_addafork.tr_logres = xfs_calc_addafork_reservation(mp); | |
828 | resp->tr_addafork.tr_logcount = XFS_ADDAFORK_LOG_COUNT; | |
829 | resp->tr_addafork.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
830 | ||
831 | resp->tr_attrinval.tr_logres = xfs_calc_attrinval_reservation(mp); | |
832 | resp->tr_attrinval.tr_logcount = XFS_ATTRINVAL_LOG_COUNT; | |
833 | resp->tr_attrinval.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
834 | ||
835 | resp->tr_attrsetm.tr_logres = xfs_calc_attrsetm_reservation(mp); | |
836 | resp->tr_attrsetm.tr_logcount = XFS_ATTRSET_LOG_COUNT; | |
837 | resp->tr_attrsetm.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
838 | ||
839 | resp->tr_attrrm.tr_logres = xfs_calc_attrrm_reservation(mp); | |
840 | resp->tr_attrrm.tr_logcount = XFS_ATTRRM_LOG_COUNT; | |
841 | resp->tr_attrrm.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
842 | ||
843 | resp->tr_growrtalloc.tr_logres = xfs_calc_growrtalloc_reservation(mp); | |
844 | resp->tr_growrtalloc.tr_logcount = XFS_DEFAULT_PERM_LOG_COUNT; | |
845 | resp->tr_growrtalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
846 | ||
847 | resp->tr_qm_dqalloc.tr_logres = xfs_calc_qm_dqalloc_reservation(mp); | |
848 | resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT; | |
849 | resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES; | |
850 | ||
851 | /* | |
852 | * The following transactions are logged in logical format with | |
853 | * a default log count. | |
854 | */ | |
cf52c730 DC |
855 | resp->tr_qm_setqlim.tr_logres = xfs_calc_qm_setqlim_reservation(mp); |
856 | resp->tr_qm_setqlim.tr_logcount = XFS_DEFAULT_LOG_COUNT; | |
857 | ||
858 | resp->tr_qm_quotaoff.tr_logres = xfs_calc_qm_quotaoff_reservation(mp); | |
859 | resp->tr_qm_quotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT; | |
860 | ||
861 | resp->tr_qm_equotaoff.tr_logres = | |
862 | xfs_calc_qm_quotaoff_end_reservation(mp); | |
863 | resp->tr_qm_equotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT; | |
864 | ||
865 | resp->tr_sb.tr_logres = xfs_calc_sb_reservation(mp); | |
866 | resp->tr_sb.tr_logcount = XFS_DEFAULT_LOG_COUNT; | |
867 | ||
868 | /* The following transaction are logged in logical format */ | |
869 | resp->tr_ichange.tr_logres = xfs_calc_ichange_reservation(mp); | |
870 | resp->tr_growdata.tr_logres = xfs_calc_growdata_reservation(mp); | |
60295fb3 | 871 | resp->tr_fsyncts.tr_logres = xfs_calc_swrite_reservation(mp); |
cf52c730 DC |
872 | resp->tr_writeid.tr_logres = xfs_calc_writeid_reservation(mp); |
873 | resp->tr_attrsetrt.tr_logres = xfs_calc_attrsetrt_reservation(mp); | |
874 | resp->tr_clearagi.tr_logres = xfs_calc_clear_agi_bucket_reservation(mp); | |
875 | resp->tr_growrtzero.tr_logres = xfs_calc_growrtzero_reservation(mp); | |
876 | resp->tr_growrtfree.tr_logres = xfs_calc_growrtfree_reservation(mp); | |
364e85ec | 877 | } |