xfs: calculate XFS_TRANS_QM_DQALLOC space log reservation at mount time
[deliverable/linux.git] / fs / xfs / xfs_trans.c
CommitLineData
1da177e4 1/*
7b718769 2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
e98c414f 3 * Copyright (C) 2010 Red Hat, Inc.
7b718769 4 * All Rights Reserved.
1da177e4 5 *
7b718769
NS
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
1da177e4
LT
8 * published by the Free Software Foundation.
9 *
7b718769
NS
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.
1da177e4 14 *
7b718769
NS
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
1da177e4 18 */
1da177e4 19#include "xfs.h"
a844f451 20#include "xfs_fs.h"
1da177e4 21#include "xfs_types.h"
1da177e4
LT
22#include "xfs_log.h"
23#include "xfs_trans.h"
24#include "xfs_sb.h"
25#include "xfs_ag.h"
1da177e4
LT
26#include "xfs_mount.h"
27#include "xfs_error.h"
a844f451 28#include "xfs_da_btree.h"
1da177e4 29#include "xfs_bmap_btree.h"
a844f451 30#include "xfs_alloc_btree.h"
1da177e4 31#include "xfs_ialloc_btree.h"
1da177e4
LT
32#include "xfs_dinode.h"
33#include "xfs_inode.h"
a844f451
NS
34#include "xfs_btree.h"
35#include "xfs_ialloc.h"
36#include "xfs_alloc.h"
efc27b52 37#include "xfs_extent_busy.h"
1da177e4 38#include "xfs_bmap.h"
1da177e4 39#include "xfs_quota.h"
4f3b5783 40#include "xfs_qm.h"
a844f451 41#include "xfs_trans_priv.h"
1da177e4 42#include "xfs_trans_space.h"
322ff6b8 43#include "xfs_inode_item.h"
4f3b5783
JL
44#include "xfs_log_priv.h"
45#include "xfs_buf_item.h"
ed3b4d6c 46#include "xfs_trace.h"
1da177e4 47
8f794055 48kmem_zone_t *xfs_trans_zone;
e98c414f 49kmem_zone_t *xfs_log_item_desc_zone;
1da177e4 50
4f3b5783
JL
51/*
52 * A buffer has a format structure overhead in the log in addition
53 * to the data, so we need to take this into account when reserving
54 * space in a transaction for a buffer. Round the space required up
55 * to a multiple of 128 bytes so that we don't change the historical
56 * reservation that has been used for this overhead.
57 */
58STATIC uint
59xfs_buf_log_overhead(void)
60{
61 return round_up(sizeof(struct xlog_op_header) +
62 sizeof(struct xfs_buf_log_format), 128);
63}
64
65/*
66 * Calculate out transaction log reservation per item in bytes.
67 *
68 * The nbufs argument is used to indicate the number of items that
69 * will be changed in a transaction. size is used to tell how many
70 * bytes should be reserved per item.
71 */
72STATIC uint
73xfs_calc_buf_res(
74 uint nbufs,
75 uint size)
76{
77 return nbufs * (size + xfs_buf_log_overhead());
78}
025101dc 79
8f794055 80/*
025101dc
CH
81 * Various log reservation values.
82 *
83 * These are based on the size of the file system block because that is what
84 * most transactions manipulate. Each adds in an additional 128 bytes per
85 * item logged to try to account for the overhead of the transaction mechanism.
86 *
87 * Note: Most of the reservations underestimate the number of allocation
88 * groups into which they could free extents in the xfs_bmap_finish() call.
89 * This is because the number in the worst case is quite high and quite
90 * unusual. In order to fix this we need to change xfs_bmap_finish() to free
91 * extents in only a single AG at a time. This will require changes to the
92 * EFI code as well, however, so that the EFI for the extents not freed is
93 * logged again in each transaction. See SGI PV #261917.
94 *
95 * Reservation functions here avoid a huge stack in xfs_trans_init due to
96 * register overflow from temporaries in the calculations.
97 */
98
99
100/*
101 * In a write transaction we can allocate a maximum of 2
102 * extents. This gives:
103 * the inode getting the new extents: inode size
104 * the inode's bmap btree: max depth * block size
105 * the agfs of the ags from which the extents are allocated: 2 * sector
106 * the superblock free block counter: sector size
107 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
108 * And the bmap_finish transaction can free bmap blocks in a join:
109 * the agfs of the ags containing the blocks: 2 * sector size
110 * the agfls of the ags containing the blocks: 2 * sector size
111 * the super block free block counter: sector size
112 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
8f794055 113 */
8f794055 114STATIC uint
025101dc
CH
115xfs_calc_write_reservation(
116 struct xfs_mount *mp)
8f794055 117{
025101dc 118 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
119 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
120 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
121 XFS_FSB_TO_B(mp, 1)) +
122 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
123 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
124 XFS_FSB_TO_B(mp, 1))),
125 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
126 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
127 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
128}
129
025101dc
CH
130/*
131 * In truncating a file we free up to two extents at once. We can modify:
132 * the inode being truncated: inode size
133 * the inode's bmap btree: (max depth + 1) * block size
134 * And the bmap_finish transaction can free the blocks and bmap blocks:
135 * the agf for each of the ags: 4 * sector size
136 * the agfl for each of the ags: 4 * sector size
137 * the super block to reflect the freed blocks: sector size
138 * worst case split in allocation btrees per extent assuming 4 extents:
139 * 4 exts * 2 trees * (2 * max depth - 1) * block size
140 * the inode btree: max depth * blocksize
141 * the allocation btrees: 2 trees * (max depth - 1) * block size
142 */
8f794055 143STATIC uint
025101dc
CH
144xfs_calc_itruncate_reservation(
145 struct xfs_mount *mp)
8f794055 146{
025101dc 147 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
148 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
149 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
150 XFS_FSB_TO_B(mp, 1))),
151 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
152 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
153 XFS_FSB_TO_B(mp, 1)) +
154 xfs_calc_buf_res(5, 0) +
155 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
156 XFS_FSB_TO_B(mp, 1)) +
157 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
158 mp->m_in_maxlevels, 0)));
8f794055
NS
159}
160
025101dc
CH
161/*
162 * In renaming a files we can modify:
163 * the four inodes involved: 4 * inode size
164 * the two directory btrees: 2 * (max depth + v2) * dir block size
165 * the two directory bmap btrees: 2 * max depth * block size
166 * And the bmap_finish transaction can free dir and bmap blocks (two sets
167 * of bmap blocks) giving:
168 * the agf for the ags in which the blocks live: 3 * sector size
169 * the agfl for the ags in which the blocks live: 3 * sector size
170 * the superblock for the free block count: sector size
171 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
172 */
8f794055 173STATIC uint
025101dc
CH
174xfs_calc_rename_reservation(
175 struct xfs_mount *mp)
8f794055 176{
025101dc 177 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
178 MAX((xfs_calc_buf_res(4, mp->m_sb.sb_inodesize) +
179 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
180 XFS_FSB_TO_B(mp, 1))),
181 (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
182 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3),
183 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
184}
185
025101dc
CH
186/*
187 * For creating a link to an inode:
188 * the parent directory inode: inode size
189 * the linked inode: inode size
190 * the directory btree could split: (max depth + v2) * dir block size
191 * the directory bmap btree could join or split: (max depth + v2) * blocksize
192 * And the bmap_finish transaction can free some bmap blocks giving:
193 * the agf for the ag in which the blocks live: sector size
194 * the agfl for the ag in which the blocks live: sector size
195 * the superblock for the free block count: sector size
196 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
197 */
8f794055 198STATIC uint
025101dc
CH
199xfs_calc_link_reservation(
200 struct xfs_mount *mp)
8f794055 201{
025101dc 202 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
203 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
204 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
205 XFS_FSB_TO_B(mp, 1))),
206 (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
207 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
208 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
209}
210
025101dc
CH
211/*
212 * For removing a directory entry we can modify:
213 * the parent directory inode: inode size
214 * the removed inode: inode size
215 * the directory btree could join: (max depth + v2) * dir block size
216 * the directory bmap btree could join or split: (max depth + v2) * blocksize
217 * And the bmap_finish transaction can free the dir and bmap blocks giving:
218 * the agf for the ag in which the blocks live: 2 * sector size
219 * the agfl for the ag in which the blocks live: 2 * sector size
220 * the superblock for the free block count: sector size
221 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
222 */
8f794055 223STATIC uint
025101dc
CH
224xfs_calc_remove_reservation(
225 struct xfs_mount *mp)
8f794055 226{
025101dc 227 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
228 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
229 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
230 XFS_FSB_TO_B(mp, 1))),
231 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
232 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
233 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
234}
235
025101dc
CH
236/*
237 * For symlink we can modify:
238 * the parent directory inode: inode size
239 * the new inode: inode size
240 * the inode btree entry: 1 block
241 * the directory btree: (max depth + v2) * dir block size
242 * the directory inode's bmap btree: (max depth + v2) * block size
243 * the blocks for the symlink: 1 kB
244 * Or in the first xact we allocate some inodes giving:
245 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
246 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
247 * the inode btree: max depth * blocksize
248 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
249 */
8f794055 250STATIC uint
025101dc
CH
251xfs_calc_symlink_reservation(
252 struct xfs_mount *mp)
8f794055 253{
025101dc 254 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
255 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
256 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
257 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
258 XFS_FSB_TO_B(mp, 1)) +
259 xfs_calc_buf_res(1, 1024)),
260 (xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
261 xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp),
262 XFS_FSB_TO_B(mp, 1)) +
263 xfs_calc_buf_res(mp->m_in_maxlevels,
264 XFS_FSB_TO_B(mp, 1)) +
265 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
266 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
267}
268
025101dc
CH
269/*
270 * For create we can modify:
271 * the parent directory inode: inode size
272 * the new inode: inode size
273 * the inode btree entry: block size
274 * the superblock for the nlink flag: sector size
275 * the directory btree: (max depth + v2) * dir block size
276 * the directory inode's bmap btree: (max depth + v2) * block size
277 * Or in the first xact we allocate some inodes giving:
278 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
279 * the superblock for the nlink flag: sector size
280 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
281 * the inode btree: max depth * blocksize
282 * the allocation btrees: 2 trees * (max depth - 1) * block size
283 */
8f794055 284STATIC uint
025101dc
CH
285xfs_calc_create_reservation(
286 struct xfs_mount *mp)
8f794055 287{
025101dc 288 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
289 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
290 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
291 (uint)XFS_FSB_TO_B(mp, 1) +
292 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
293 XFS_FSB_TO_B(mp, 1))),
294 (xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
025101dc 295 mp->m_sb.sb_sectsize +
5b292ae3
JL
296 xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp),
297 XFS_FSB_TO_B(mp, 1)) +
298 xfs_calc_buf_res(mp->m_in_maxlevels,
299 XFS_FSB_TO_B(mp, 1)) +
300 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
301 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
302}
303
025101dc
CH
304/*
305 * Making a new directory is the same as creating a new file.
306 */
8f794055 307STATIC uint
025101dc
CH
308xfs_calc_mkdir_reservation(
309 struct xfs_mount *mp)
8f794055 310{
025101dc 311 return xfs_calc_create_reservation(mp);
8f794055
NS
312}
313
025101dc
CH
314/*
315 * In freeing an inode we can modify:
316 * the inode being freed: inode size
317 * the super block free inode counter: sector size
318 * the agi hash list and counters: sector size
319 * the inode btree entry: block size
320 * the on disk inode before ours in the agi hash list: inode cluster size
321 * the inode btree: max depth * blocksize
322 * the allocation btrees: 2 trees * (max depth - 1) * block size
323 */
8f794055 324STATIC uint
025101dc
CH
325xfs_calc_ifree_reservation(
326 struct xfs_mount *mp)
8f794055 327{
025101dc 328 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
329 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
330 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
331 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
025101dc
CH
332 MAX((__uint16_t)XFS_FSB_TO_B(mp, 1),
333 XFS_INODE_CLUSTER_SIZE(mp)) +
5b292ae3
JL
334 xfs_calc_buf_res(1, 0) +
335 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
336 mp->m_in_maxlevels, 0) +
337 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
338 XFS_FSB_TO_B(mp, 1));
8f794055
NS
339}
340
025101dc
CH
341/*
342 * When only changing the inode we log the inode and possibly the superblock
343 * We also add a bit of slop for the transaction stuff.
344 */
8f794055 345STATIC uint
025101dc
CH
346xfs_calc_ichange_reservation(
347 struct xfs_mount *mp)
8f794055 348{
025101dc
CH
349 return XFS_DQUOT_LOGRES(mp) +
350 mp->m_sb.sb_inodesize +
351 mp->m_sb.sb_sectsize +
352 512;
353
8f794055
NS
354}
355
025101dc
CH
356/*
357 * Growing the data section of the filesystem.
358 * superblock
359 * agi and agf
360 * allocation btrees
361 */
8f794055 362STATIC uint
025101dc
CH
363xfs_calc_growdata_reservation(
364 struct xfs_mount *mp)
8f794055 365{
5b292ae3
JL
366 return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
367 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
368 XFS_FSB_TO_B(mp, 1));
8f794055
NS
369}
370
025101dc
CH
371/*
372 * Growing the rt section of the filesystem.
373 * In the first set of transactions (ALLOC) we allocate space to the
374 * bitmap or summary files.
375 * superblock: sector size
376 * agf of the ag from which the extent is allocated: sector size
377 * bmap btree for bitmap/summary inode: max depth * blocksize
378 * bitmap/summary inode: inode size
379 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
380 */
8f794055 381STATIC uint
025101dc
CH
382xfs_calc_growrtalloc_reservation(
383 struct xfs_mount *mp)
8f794055 384{
5b292ae3
JL
385 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
386 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
387 XFS_FSB_TO_B(mp, 1)) +
388 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
389 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
390 XFS_FSB_TO_B(mp, 1));
8f794055
NS
391}
392
025101dc
CH
393/*
394 * Growing the rt section of the filesystem.
395 * In the second set of transactions (ZERO) we zero the new metadata blocks.
396 * one bitmap/summary block: blocksize
397 */
8f794055 398STATIC uint
025101dc
CH
399xfs_calc_growrtzero_reservation(
400 struct xfs_mount *mp)
8f794055 401{
5b292ae3 402 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
8f794055
NS
403}
404
025101dc
CH
405/*
406 * Growing the rt section of the filesystem.
407 * In the third set of transactions (FREE) we update metadata without
408 * allocating any new blocks.
409 * superblock: sector size
410 * bitmap inode: inode size
411 * summary inode: inode size
412 * one bitmap block: blocksize
413 * summary blocks: new summary size
414 */
8f794055 415STATIC uint
025101dc
CH
416xfs_calc_growrtfree_reservation(
417 struct xfs_mount *mp)
8f794055 418{
5b292ae3
JL
419 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
420 xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
421 xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
422 xfs_calc_buf_res(1, mp->m_rsumsize);
8f794055
NS
423}
424
025101dc
CH
425/*
426 * Logging the inode modification timestamp on a synchronous write.
427 * inode
428 */
8f794055 429STATIC uint
025101dc
CH
430xfs_calc_swrite_reservation(
431 struct xfs_mount *mp)
8f794055 432{
5b292ae3 433 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
8f794055
NS
434}
435
025101dc
CH
436/*
437 * Logging the inode mode bits when writing a setuid/setgid file
438 * inode
439 */
8f794055
NS
440STATIC uint
441xfs_calc_writeid_reservation(xfs_mount_t *mp)
442{
5b292ae3 443 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
8f794055
NS
444}
445
025101dc
CH
446/*
447 * Converting the inode from non-attributed to attributed.
448 * the inode being converted: inode size
449 * agf block and superblock (for block allocation)
450 * the new block (directory sized)
451 * bmap blocks for the new directory block
452 * allocation btrees
453 */
8f794055 454STATIC uint
025101dc
CH
455xfs_calc_addafork_reservation(
456 struct xfs_mount *mp)
8f794055 457{
025101dc 458 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
459 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
460 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
461 xfs_calc_buf_res(1, mp->m_dirblksize) +
462 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
463 XFS_FSB_TO_B(mp, 1)) +
464 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
465 XFS_FSB_TO_B(mp, 1));
8f794055
NS
466}
467
025101dc
CH
468/*
469 * Removing the attribute fork of a file
470 * the inode being truncated: inode size
471 * the inode's bmap btree: max depth * block size
472 * And the bmap_finish transaction can free the blocks and bmap blocks:
473 * the agf for each of the ags: 4 * sector size
474 * the agfl for each of the ags: 4 * sector size
475 * the super block to reflect the freed blocks: sector size
476 * worst case split in allocation btrees per extent assuming 4 extents:
477 * 4 exts * 2 trees * (2 * max depth - 1) * block size
478 */
8f794055 479STATIC uint
025101dc
CH
480xfs_calc_attrinval_reservation(
481 struct xfs_mount *mp)
8f794055 482{
5b292ae3
JL
483 return MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
484 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
485 XFS_FSB_TO_B(mp, 1))),
486 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
487 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
488 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
489}
490
025101dc
CH
491/*
492 * Setting an attribute.
493 * the inode getting the attribute
494 * the superblock for allocations
495 * the agfs extents are allocated from
496 * the attribute btree * max depth
497 * the inode allocation btree
498 * Since attribute transaction space is dependent on the size of the attribute,
499 * the calculation is done partially at mount time and partially at runtime.
500 */
8f794055 501STATIC uint
025101dc
CH
502xfs_calc_attrset_reservation(
503 struct xfs_mount *mp)
8f794055 504{
025101dc 505 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
506 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
507 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
508 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1));
8f794055
NS
509}
510
025101dc
CH
511/*
512 * Removing an attribute.
513 * the inode: inode size
514 * the attribute btree could join: max depth * block size
515 * the inode bmap btree could join or split: max depth * block size
516 * And the bmap_finish transaction can free the attr blocks freed giving:
517 * the agf for the ag in which the blocks live: 2 * sector size
518 * the agfl for the ag in which the blocks live: 2 * sector size
519 * the superblock for the free block count: sector size
520 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
521 */
8f794055 522STATIC uint
025101dc
CH
523xfs_calc_attrrm_reservation(
524 struct xfs_mount *mp)
8f794055 525{
025101dc 526 return XFS_DQUOT_LOGRES(mp) +
5b292ae3
JL
527 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
528 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH,
529 XFS_FSB_TO_B(mp, 1)) +
530 (uint)XFS_FSB_TO_B(mp,
531 XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
532 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
533 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
534 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
535 XFS_FSB_TO_B(mp, 1))));
8f794055
NS
536}
537
025101dc
CH
538/*
539 * Clearing a bad agino number in an agi hash bucket.
540 */
8f794055 541STATIC uint
025101dc
CH
542xfs_calc_clear_agi_bucket_reservation(
543 struct xfs_mount *mp)
8f794055 544{
5b292ae3 545 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
8f794055
NS
546}
547
b0c10b98
JL
548/*
549 * Clearing the quotaflags in the superblock.
550 * the super block for changing quota flags: sector size
551 */
552STATIC uint
553xfs_calc_qm_sbchange_reservation(
554 struct xfs_mount *mp)
555{
556 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
557}
558
f0f2df94
JL
559/*
560 * Adjusting quota limits.
561 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
562 */
563STATIC uint
564xfs_calc_qm_setqlim_reservation(
565 struct xfs_mount *mp)
566{
567 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
568}
569
48001044
JL
570/*
571 * Allocating quota on disk if needed.
572 * the write transaction log space: XFS_WRITE_LOG_RES(mp)
573 * the unit of quota allocation: one system block size
574 */
575STATIC uint
576xfs_calc_qm_dqalloc_reservation(
577 struct xfs_mount *mp)
578{
579 return XFS_WRITE_LOG_RES(mp) +
580 xfs_calc_buf_res(1,
581 XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
582}
583
1da177e4
LT
584/*
585 * Initialize the precomputed transaction reservation values
586 * in the mount structure.
587 */
588void
589xfs_trans_init(
025101dc 590 struct xfs_mount *mp)
1da177e4 591{
025101dc 592 struct xfs_trans_reservations *resp = &mp->m_reservations;
1da177e4 593
8f794055
NS
594 resp->tr_write = xfs_calc_write_reservation(mp);
595 resp->tr_itruncate = xfs_calc_itruncate_reservation(mp);
596 resp->tr_rename = xfs_calc_rename_reservation(mp);
597 resp->tr_link = xfs_calc_link_reservation(mp);
598 resp->tr_remove = xfs_calc_remove_reservation(mp);
599 resp->tr_symlink = xfs_calc_symlink_reservation(mp);
600 resp->tr_create = xfs_calc_create_reservation(mp);
601 resp->tr_mkdir = xfs_calc_mkdir_reservation(mp);
602 resp->tr_ifree = xfs_calc_ifree_reservation(mp);
603 resp->tr_ichange = xfs_calc_ichange_reservation(mp);
604 resp->tr_growdata = xfs_calc_growdata_reservation(mp);
605 resp->tr_swrite = xfs_calc_swrite_reservation(mp);
606 resp->tr_writeid = xfs_calc_writeid_reservation(mp);
607 resp->tr_addafork = xfs_calc_addafork_reservation(mp);
608 resp->tr_attrinval = xfs_calc_attrinval_reservation(mp);
609 resp->tr_attrset = xfs_calc_attrset_reservation(mp);
610 resp->tr_attrrm = xfs_calc_attrrm_reservation(mp);
611 resp->tr_clearagi = xfs_calc_clear_agi_bucket_reservation(mp);
612 resp->tr_growrtalloc = xfs_calc_growrtalloc_reservation(mp);
613 resp->tr_growrtzero = xfs_calc_growrtzero_reservation(mp);
614 resp->tr_growrtfree = xfs_calc_growrtfree_reservation(mp);
b0c10b98 615 resp->tr_qm_sbchange = xfs_calc_qm_sbchange_reservation(mp);
f0f2df94 616 resp->tr_qm_setqlim = xfs_calc_qm_setqlim_reservation(mp);
48001044 617 resp->tr_qm_dqalloc = xfs_calc_qm_dqalloc_reservation(mp);
1da177e4
LT
618}
619
620/*
621 * This routine is called to allocate a transaction structure.
622 * The type parameter indicates the type of the transaction. These
623 * are enumerated in xfs_trans.h.
b2ce3974
AE
624 *
625 * Dynamically allocate the transaction structure from the transaction
626 * zone, initialize it, and return it to the caller.
1da177e4 627 */
b2ce3974
AE
628xfs_trans_t *
629xfs_trans_alloc(
630 xfs_mount_t *mp,
631 uint type)
632{
d9457dc0
JK
633 xfs_trans_t *tp;
634
635 sb_start_intwrite(mp->m_super);
636 tp = _xfs_trans_alloc(mp, type, KM_SLEEP);
637 tp->t_flags |= XFS_TRANS_FREEZE_PROT;
638 return tp;
b2ce3974
AE
639}
640
641xfs_trans_t *
1da177e4 642_xfs_trans_alloc(
b2ce3974
AE
643 xfs_mount_t *mp,
644 uint type,
77ba7877 645 xfs_km_flags_t memflags)
1da177e4 646{
b2ce3974 647 xfs_trans_t *tp;
1da177e4 648
d9457dc0 649 WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
34327e13 650 atomic_inc(&mp->m_active_trans);
1da177e4 651
80641dc6 652 tp = kmem_zone_zalloc(xfs_trans_zone, memflags);
1da177e4
LT
653 tp->t_magic = XFS_TRANS_MAGIC;
654 tp->t_type = type;
655 tp->t_mountp = mp;
e98c414f 656 INIT_LIST_HEAD(&tp->t_items);
ed3b4d6c 657 INIT_LIST_HEAD(&tp->t_busy);
34327e13 658 return tp;
1da177e4
LT
659}
660
b1c1b5b6
DC
661/*
662 * Free the transaction structure. If there is more clean up
663 * to do when the structure is freed, add it here.
664 */
665STATIC void
666xfs_trans_free(
ed3b4d6c 667 struct xfs_trans *tp)
b1c1b5b6 668{
4ecbfe63
DC
669 xfs_extent_busy_sort(&tp->t_busy);
670 xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false);
ed3b4d6c 671
b1c1b5b6 672 atomic_dec(&tp->t_mountp->m_active_trans);
d9457dc0
JK
673 if (tp->t_flags & XFS_TRANS_FREEZE_PROT)
674 sb_end_intwrite(tp->t_mountp->m_super);
b1c1b5b6
DC
675 xfs_trans_free_dqinfo(tp);
676 kmem_zone_free(xfs_trans_zone, tp);
677}
678
1da177e4
LT
679/*
680 * This is called to create a new transaction which will share the
681 * permanent log reservation of the given transaction. The remaining
682 * unused block and rt extent reservations are also inherited. This
683 * implies that the original transaction is no longer allowed to allocate
684 * blocks. Locks and log items, however, are no inherited. They must
685 * be added to the new transaction explicitly.
686 */
687xfs_trans_t *
688xfs_trans_dup(
689 xfs_trans_t *tp)
690{
691 xfs_trans_t *ntp;
692
693 ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP);
694
695 /*
696 * Initialize the new transaction structure.
697 */
698 ntp->t_magic = XFS_TRANS_MAGIC;
699 ntp->t_type = tp->t_type;
700 ntp->t_mountp = tp->t_mountp;
e98c414f 701 INIT_LIST_HEAD(&ntp->t_items);
ed3b4d6c 702 INIT_LIST_HEAD(&ntp->t_busy);
1da177e4
LT
703
704 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
1da177e4 705 ASSERT(tp->t_ticket != NULL);
cfcbbbd0 706
d9457dc0
JK
707 ntp->t_flags = XFS_TRANS_PERM_LOG_RES |
708 (tp->t_flags & XFS_TRANS_RESERVE) |
709 (tp->t_flags & XFS_TRANS_FREEZE_PROT);
710 /* We gave our writer reference to the new transaction */
711 tp->t_flags &= ~XFS_TRANS_FREEZE_PROT;
cc09c0dc 712 ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket);
1da177e4
LT
713 ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used;
714 tp->t_blk_res = tp->t_blk_res_used;
715 ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used;
716 tp->t_rtx_res = tp->t_rtx_res_used;
59c1b082 717 ntp->t_pflags = tp->t_pflags;
1da177e4 718
7d095257 719 xfs_trans_dup_dqinfo(tp, ntp);
1da177e4
LT
720
721 atomic_inc(&tp->t_mountp->m_active_trans);
722 return ntp;
723}
724
725/*
726 * This is called to reserve free disk blocks and log space for the
727 * given transaction. This must be done before allocating any resources
728 * within the transaction.
729 *
730 * This will return ENOSPC if there are not enough blocks available.
731 * It will sleep waiting for available log space.
732 * The only valid value for the flags parameter is XFS_RES_LOG_PERM, which
733 * is used by long running transactions. If any one of the reservations
734 * fails then they will all be backed out.
735 *
736 * This does not do quota reservations. That typically is done by the
737 * caller afterwards.
738 */
739int
740xfs_trans_reserve(
741 xfs_trans_t *tp,
742 uint blocks,
743 uint logspace,
744 uint rtextents,
745 uint flags,
746 uint logcount)
747{
59c1b082
NS
748 int error = 0;
749 int rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
1da177e4
LT
750
751 /* Mark this thread as being in a transaction */
59c1b082 752 current_set_flags_nested(&tp->t_pflags, PF_FSTRANS);
1da177e4
LT
753
754 /*
755 * Attempt to reserve the needed disk blocks by decrementing
756 * the number needed from the number available. This will
757 * fail if the count would go below zero.
758 */
759 if (blocks > 0) {
96540c78 760 error = xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
20f4ebf2 761 -((int64_t)blocks), rsvd);
1da177e4 762 if (error != 0) {
59c1b082 763 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
1da177e4
LT
764 return (XFS_ERROR(ENOSPC));
765 }
766 tp->t_blk_res += blocks;
767 }
768
769 /*
770 * Reserve the log space needed for this transaction.
771 */
772 if (logspace > 0) {
9006fb91
CH
773 bool permanent = false;
774
775 ASSERT(tp->t_log_res == 0 || tp->t_log_res == logspace);
776 ASSERT(tp->t_log_count == 0 || tp->t_log_count == logcount);
777
1da177e4 778 if (flags & XFS_TRANS_PERM_LOG_RES) {
1da177e4 779 tp->t_flags |= XFS_TRANS_PERM_LOG_RES;
9006fb91 780 permanent = true;
1da177e4
LT
781 } else {
782 ASSERT(tp->t_ticket == NULL);
783 ASSERT(!(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
1da177e4
LT
784 }
785
9006fb91
CH
786 if (tp->t_ticket != NULL) {
787 ASSERT(flags & XFS_TRANS_PERM_LOG_RES);
788 error = xfs_log_regrant(tp->t_mountp, tp->t_ticket);
789 } else {
790 error = xfs_log_reserve(tp->t_mountp, logspace,
791 logcount, &tp->t_ticket,
792 XFS_TRANSACTION, permanent,
793 tp->t_type);
1da177e4 794 }
9006fb91
CH
795
796 if (error)
797 goto undo_blocks;
798
1da177e4
LT
799 tp->t_log_res = logspace;
800 tp->t_log_count = logcount;
801 }
802
803 /*
804 * Attempt to reserve the needed realtime extents by decrementing
805 * the number needed from the number available. This will
806 * fail if the count would go below zero.
807 */
808 if (rtextents > 0) {
809 error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS,
20f4ebf2 810 -((int64_t)rtextents), rsvd);
1da177e4
LT
811 if (error) {
812 error = XFS_ERROR(ENOSPC);
813 goto undo_log;
814 }
815 tp->t_rtx_res += rtextents;
816 }
817
818 return 0;
819
820 /*
821 * Error cases jump to one of these labels to undo any
822 * reservations which have already been performed.
823 */
824undo_log:
825 if (logspace > 0) {
9006fb91
CH
826 int log_flags;
827
1da177e4
LT
828 if (flags & XFS_TRANS_PERM_LOG_RES) {
829 log_flags = XFS_LOG_REL_PERM_RESERV;
830 } else {
831 log_flags = 0;
832 }
833 xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, log_flags);
834 tp->t_ticket = NULL;
835 tp->t_log_res = 0;
836 tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES;
837 }
838
839undo_blocks:
840 if (blocks > 0) {
96540c78 841 xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
20f4ebf2 842 (int64_t)blocks, rsvd);
1da177e4
LT
843 tp->t_blk_res = 0;
844 }
845
59c1b082 846 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
1da177e4 847
59c1b082 848 return error;
1da177e4
LT
849}
850
1da177e4
LT
851/*
852 * Record the indicated change to the given field for application
853 * to the file system's superblock when the transaction commits.
854 * For now, just store the change in the transaction structure.
855 *
856 * Mark the transaction structure to indicate that the superblock
857 * needs to be updated before committing.
92821e2b
DC
858 *
859 * Because we may not be keeping track of allocated/free inodes and
860 * used filesystem blocks in the superblock, we do not mark the
861 * superblock dirty in this transaction if we modify these fields.
862 * We still need to update the transaction deltas so that they get
863 * applied to the incore superblock, but we don't want them to
864 * cause the superblock to get locked and logged if these are the
865 * only fields in the superblock that the transaction modifies.
1da177e4
LT
866 */
867void
868xfs_trans_mod_sb(
869 xfs_trans_t *tp,
870 uint field,
20f4ebf2 871 int64_t delta)
1da177e4 872{
92821e2b
DC
873 uint32_t flags = (XFS_TRANS_DIRTY|XFS_TRANS_SB_DIRTY);
874 xfs_mount_t *mp = tp->t_mountp;
1da177e4
LT
875
876 switch (field) {
877 case XFS_TRANS_SB_ICOUNT:
878 tp->t_icount_delta += delta;
92821e2b
DC
879 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
880 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
881 break;
882 case XFS_TRANS_SB_IFREE:
883 tp->t_ifree_delta += delta;
92821e2b
DC
884 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
885 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
886 break;
887 case XFS_TRANS_SB_FDBLOCKS:
888 /*
889 * Track the number of blocks allocated in the
890 * transaction. Make sure it does not exceed the
891 * number reserved.
892 */
893 if (delta < 0) {
894 tp->t_blk_res_used += (uint)-delta;
895 ASSERT(tp->t_blk_res_used <= tp->t_blk_res);
896 }
897 tp->t_fdblocks_delta += delta;
92821e2b
DC
898 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
899 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
900 break;
901 case XFS_TRANS_SB_RES_FDBLOCKS:
902 /*
903 * The allocation has already been applied to the
904 * in-core superblock's counter. This should only
905 * be applied to the on-disk superblock.
906 */
907 ASSERT(delta < 0);
908 tp->t_res_fdblocks_delta += delta;
92821e2b
DC
909 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
910 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
911 break;
912 case XFS_TRANS_SB_FREXTENTS:
913 /*
914 * Track the number of blocks allocated in the
915 * transaction. Make sure it does not exceed the
916 * number reserved.
917 */
918 if (delta < 0) {
919 tp->t_rtx_res_used += (uint)-delta;
920 ASSERT(tp->t_rtx_res_used <= tp->t_rtx_res);
921 }
922 tp->t_frextents_delta += delta;
923 break;
924 case XFS_TRANS_SB_RES_FREXTENTS:
925 /*
926 * The allocation has already been applied to the
c41564b5 927 * in-core superblock's counter. This should only
1da177e4
LT
928 * be applied to the on-disk superblock.
929 */
930 ASSERT(delta < 0);
931 tp->t_res_frextents_delta += delta;
932 break;
933 case XFS_TRANS_SB_DBLOCKS:
934 ASSERT(delta > 0);
935 tp->t_dblocks_delta += delta;
936 break;
937 case XFS_TRANS_SB_AGCOUNT:
938 ASSERT(delta > 0);
939 tp->t_agcount_delta += delta;
940 break;
941 case XFS_TRANS_SB_IMAXPCT:
942 tp->t_imaxpct_delta += delta;
943 break;
944 case XFS_TRANS_SB_REXTSIZE:
945 tp->t_rextsize_delta += delta;
946 break;
947 case XFS_TRANS_SB_RBMBLOCKS:
948 tp->t_rbmblocks_delta += delta;
949 break;
950 case XFS_TRANS_SB_RBLOCKS:
951 tp->t_rblocks_delta += delta;
952 break;
953 case XFS_TRANS_SB_REXTENTS:
954 tp->t_rextents_delta += delta;
955 break;
956 case XFS_TRANS_SB_REXTSLOG:
957 tp->t_rextslog_delta += delta;
958 break;
959 default:
960 ASSERT(0);
961 return;
962 }
963
210c6f1c 964 tp->t_flags |= flags;
1da177e4
LT
965}
966
967/*
968 * xfs_trans_apply_sb_deltas() is called from the commit code
969 * to bring the superblock buffer into the current transaction
970 * and modify it as requested by earlier calls to xfs_trans_mod_sb().
971 *
972 * For now we just look at each field allowed to change and change
973 * it if necessary.
974 */
975STATIC void
976xfs_trans_apply_sb_deltas(
977 xfs_trans_t *tp)
978{
2bdf7cd0 979 xfs_dsb_t *sbp;
1da177e4
LT
980 xfs_buf_t *bp;
981 int whole = 0;
982
983 bp = xfs_trans_getsb(tp, tp->t_mountp, 0);
984 sbp = XFS_BUF_TO_SBP(bp);
985
986 /*
987 * Check that superblock mods match the mods made to AGF counters.
988 */
989 ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
990 (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
991 tp->t_ag_btree_delta));
992
92821e2b
DC
993 /*
994 * Only update the superblock counters if we are logging them
995 */
996 if (!xfs_sb_version_haslazysbcount(&(tp->t_mountp->m_sb))) {
2bdf7cd0 997 if (tp->t_icount_delta)
413d57c9 998 be64_add_cpu(&sbp->sb_icount, tp->t_icount_delta);
2bdf7cd0 999 if (tp->t_ifree_delta)
413d57c9 1000 be64_add_cpu(&sbp->sb_ifree, tp->t_ifree_delta);
2bdf7cd0 1001 if (tp->t_fdblocks_delta)
413d57c9 1002 be64_add_cpu(&sbp->sb_fdblocks, tp->t_fdblocks_delta);
2bdf7cd0 1003 if (tp->t_res_fdblocks_delta)
413d57c9 1004 be64_add_cpu(&sbp->sb_fdblocks, tp->t_res_fdblocks_delta);
1da177e4
LT
1005 }
1006
2bdf7cd0 1007 if (tp->t_frextents_delta)
413d57c9 1008 be64_add_cpu(&sbp->sb_frextents, tp->t_frextents_delta);
2bdf7cd0 1009 if (tp->t_res_frextents_delta)
413d57c9 1010 be64_add_cpu(&sbp->sb_frextents, tp->t_res_frextents_delta);
2bdf7cd0
CH
1011
1012 if (tp->t_dblocks_delta) {
413d57c9 1013 be64_add_cpu(&sbp->sb_dblocks, tp->t_dblocks_delta);
1da177e4
LT
1014 whole = 1;
1015 }
2bdf7cd0 1016 if (tp->t_agcount_delta) {
413d57c9 1017 be32_add_cpu(&sbp->sb_agcount, tp->t_agcount_delta);
1da177e4
LT
1018 whole = 1;
1019 }
2bdf7cd0
CH
1020 if (tp->t_imaxpct_delta) {
1021 sbp->sb_imax_pct += tp->t_imaxpct_delta;
1da177e4
LT
1022 whole = 1;
1023 }
2bdf7cd0 1024 if (tp->t_rextsize_delta) {
413d57c9 1025 be32_add_cpu(&sbp->sb_rextsize, tp->t_rextsize_delta);
1da177e4
LT
1026 whole = 1;
1027 }
2bdf7cd0 1028 if (tp->t_rbmblocks_delta) {
413d57c9 1029 be32_add_cpu(&sbp->sb_rbmblocks, tp->t_rbmblocks_delta);
1da177e4
LT
1030 whole = 1;
1031 }
2bdf7cd0 1032 if (tp->t_rblocks_delta) {
413d57c9 1033 be64_add_cpu(&sbp->sb_rblocks, tp->t_rblocks_delta);
1da177e4
LT
1034 whole = 1;
1035 }
2bdf7cd0 1036 if (tp->t_rextents_delta) {
413d57c9 1037 be64_add_cpu(&sbp->sb_rextents, tp->t_rextents_delta);
1da177e4
LT
1038 whole = 1;
1039 }
2bdf7cd0
CH
1040 if (tp->t_rextslog_delta) {
1041 sbp->sb_rextslog += tp->t_rextslog_delta;
1da177e4
LT
1042 whole = 1;
1043 }
1044
1045 if (whole)
1046 /*
c41564b5 1047 * Log the whole thing, the fields are noncontiguous.
1da177e4 1048 */
2bdf7cd0 1049 xfs_trans_log_buf(tp, bp, 0, sizeof(xfs_dsb_t) - 1);
1da177e4
LT
1050 else
1051 /*
1052 * Since all the modifiable fields are contiguous, we
1053 * can get away with this.
1054 */
2bdf7cd0
CH
1055 xfs_trans_log_buf(tp, bp, offsetof(xfs_dsb_t, sb_icount),
1056 offsetof(xfs_dsb_t, sb_frextents) +
1da177e4 1057 sizeof(sbp->sb_frextents) - 1);
1da177e4
LT
1058}
1059
1060/*
45c34141
DC
1061 * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations
1062 * and apply superblock counter changes to the in-core superblock. The
1063 * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT
1064 * applied to the in-core superblock. The idea is that that has already been
1065 * done.
1da177e4
LT
1066 *
1067 * This is done efficiently with a single call to xfs_mod_incore_sb_batch().
45c34141
DC
1068 * However, we have to ensure that we only modify each superblock field only
1069 * once because the application of the delta values may not be atomic. That can
1070 * lead to ENOSPC races occurring if we have two separate modifcations of the
1071 * free space counter to put back the entire reservation and then take away
1072 * what we used.
1073 *
1074 * If we are not logging superblock counters, then the inode allocated/free and
1075 * used block counts are not updated in the on disk superblock. In this case,
1076 * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we
1077 * still need to update the incore superblock with the changes.
1da177e4 1078 */
71e330b5 1079void
1da177e4
LT
1080xfs_trans_unreserve_and_mod_sb(
1081 xfs_trans_t *tp)
1082{
1b040712 1083 xfs_mod_sb_t msb[9]; /* If you add cases, add entries */
1da177e4 1084 xfs_mod_sb_t *msbp;
92821e2b 1085 xfs_mount_t *mp = tp->t_mountp;
1da177e4
LT
1086 /* REFERENCED */
1087 int error;
1088 int rsvd;
45c34141
DC
1089 int64_t blkdelta = 0;
1090 int64_t rtxdelta = 0;
1b040712
CH
1091 int64_t idelta = 0;
1092 int64_t ifreedelta = 0;
1da177e4
LT
1093
1094 msbp = msb;
1095 rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
1096
1b040712 1097 /* calculate deltas */
45c34141
DC
1098 if (tp->t_blk_res > 0)
1099 blkdelta = tp->t_blk_res;
45c34141
DC
1100 if ((tp->t_fdblocks_delta != 0) &&
1101 (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
1102 (tp->t_flags & XFS_TRANS_SB_DIRTY)))
1103 blkdelta += tp->t_fdblocks_delta;
1104
45c34141
DC
1105 if (tp->t_rtx_res > 0)
1106 rtxdelta = tp->t_rtx_res;
45c34141
DC
1107 if ((tp->t_frextents_delta != 0) &&
1108 (tp->t_flags & XFS_TRANS_SB_DIRTY))
1109 rtxdelta += tp->t_frextents_delta;
1110
1b040712
CH
1111 if (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
1112 (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
1113 idelta = tp->t_icount_delta;
1114 ifreedelta = tp->t_ifree_delta;
1115 }
1116
1117 /* apply the per-cpu counters */
1118 if (blkdelta) {
1119 error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS,
1120 blkdelta, rsvd);
1121 if (error)
1122 goto out;
1123 }
1124
1125 if (idelta) {
1126 error = xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT,
1127 idelta, rsvd);
1128 if (error)
1129 goto out_undo_fdblocks;
1130 }
1131
1132 if (ifreedelta) {
1133 error = xfs_icsb_modify_counters(mp, XFS_SBS_IFREE,
1134 ifreedelta, rsvd);
1135 if (error)
1136 goto out_undo_icount;
1137 }
1138
1139 /* apply remaining deltas */
45c34141 1140 if (rtxdelta != 0) {
1da177e4 1141 msbp->msb_field = XFS_SBS_FREXTENTS;
45c34141 1142 msbp->msb_delta = rtxdelta;
1da177e4
LT
1143 msbp++;
1144 }
1145
92821e2b 1146 if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
1da177e4
LT
1147 if (tp->t_dblocks_delta != 0) {
1148 msbp->msb_field = XFS_SBS_DBLOCKS;
20f4ebf2 1149 msbp->msb_delta = tp->t_dblocks_delta;
1da177e4
LT
1150 msbp++;
1151 }
1152 if (tp->t_agcount_delta != 0) {
1153 msbp->msb_field = XFS_SBS_AGCOUNT;
20f4ebf2 1154 msbp->msb_delta = tp->t_agcount_delta;
1da177e4
LT
1155 msbp++;
1156 }
1157 if (tp->t_imaxpct_delta != 0) {
1158 msbp->msb_field = XFS_SBS_IMAX_PCT;
20f4ebf2 1159 msbp->msb_delta = tp->t_imaxpct_delta;
1da177e4
LT
1160 msbp++;
1161 }
1162 if (tp->t_rextsize_delta != 0) {
1163 msbp->msb_field = XFS_SBS_REXTSIZE;
20f4ebf2 1164 msbp->msb_delta = tp->t_rextsize_delta;
1da177e4
LT
1165 msbp++;
1166 }
1167 if (tp->t_rbmblocks_delta != 0) {
1168 msbp->msb_field = XFS_SBS_RBMBLOCKS;
20f4ebf2 1169 msbp->msb_delta = tp->t_rbmblocks_delta;
1da177e4
LT
1170 msbp++;
1171 }
1172 if (tp->t_rblocks_delta != 0) {
1173 msbp->msb_field = XFS_SBS_RBLOCKS;
20f4ebf2 1174 msbp->msb_delta = tp->t_rblocks_delta;
1da177e4
LT
1175 msbp++;
1176 }
1177 if (tp->t_rextents_delta != 0) {
1178 msbp->msb_field = XFS_SBS_REXTENTS;
20f4ebf2 1179 msbp->msb_delta = tp->t_rextents_delta;
1da177e4
LT
1180 msbp++;
1181 }
1182 if (tp->t_rextslog_delta != 0) {
1183 msbp->msb_field = XFS_SBS_REXTSLOG;
20f4ebf2 1184 msbp->msb_delta = tp->t_rextslog_delta;
1da177e4
LT
1185 msbp++;
1186 }
1187 }
1188
1189 /*
1190 * If we need to change anything, do it.
1191 */
1192 if (msbp > msb) {
1193 error = xfs_mod_incore_sb_batch(tp->t_mountp, msb,
1194 (uint)(msbp - msb), rsvd);
1b040712
CH
1195 if (error)
1196 goto out_undo_ifreecount;
1da177e4 1197 }
1b040712
CH
1198
1199 return;
1200
1201out_undo_ifreecount:
1202 if (ifreedelta)
1203 xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, -ifreedelta, rsvd);
1204out_undo_icount:
1205 if (idelta)
1206 xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, -idelta, rsvd);
1207out_undo_fdblocks:
1208 if (blkdelta)
1209 xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd);
1210out:
1884bd83 1211 ASSERT(error == 0);
1b040712 1212 return;
1da177e4
LT
1213}
1214
e98c414f
CH
1215/*
1216 * Add the given log item to the transaction's list of log items.
1217 *
1218 * The log item will now point to its new descriptor with its li_desc field.
1219 */
1220void
1221xfs_trans_add_item(
1222 struct xfs_trans *tp,
1223 struct xfs_log_item *lip)
1224{
1225 struct xfs_log_item_desc *lidp;
1226
f65020a8
JJ
1227 ASSERT(lip->li_mountp == tp->t_mountp);
1228 ASSERT(lip->li_ailp == tp->t_mountp->m_ail);
e98c414f 1229
43869706 1230 lidp = kmem_zone_zalloc(xfs_log_item_desc_zone, KM_SLEEP | KM_NOFS);
e98c414f
CH
1231
1232 lidp->lid_item = lip;
1233 lidp->lid_flags = 0;
e98c414f
CH
1234 list_add_tail(&lidp->lid_trans, &tp->t_items);
1235
1236 lip->li_desc = lidp;
1237}
1238
1239STATIC void
1240xfs_trans_free_item_desc(
1241 struct xfs_log_item_desc *lidp)
1242{
1243 list_del_init(&lidp->lid_trans);
1244 kmem_zone_free(xfs_log_item_desc_zone, lidp);
1245}
1246
1247/*
1248 * Unlink and free the given descriptor.
1249 */
1250void
1251xfs_trans_del_item(
1252 struct xfs_log_item *lip)
1253{
1254 xfs_trans_free_item_desc(lip->li_desc);
1255 lip->li_desc = NULL;
1256}
1257
1258/*
1259 * Unlock all of the items of a transaction and free all the descriptors
1260 * of that transaction.
1261 */
d17c701c 1262void
e98c414f
CH
1263xfs_trans_free_items(
1264 struct xfs_trans *tp,
1265 xfs_lsn_t commit_lsn,
1266 int flags)
1267{
1268 struct xfs_log_item_desc *lidp, *next;
1269
1270 list_for_each_entry_safe(lidp, next, &tp->t_items, lid_trans) {
1271 struct xfs_log_item *lip = lidp->lid_item;
1272
1273 lip->li_desc = NULL;
1274
1275 if (commit_lsn != NULLCOMMITLSN)
1276 IOP_COMMITTING(lip, commit_lsn);
1277 if (flags & XFS_TRANS_ABORT)
1278 lip->li_flags |= XFS_LI_ABORTED;
1279 IOP_UNLOCK(lip);
1280
1281 xfs_trans_free_item_desc(lidp);
1282 }
1283}
1284
0e57f6a3
DC
1285static inline void
1286xfs_log_item_batch_insert(
1287 struct xfs_ail *ailp,
1d8c95a3 1288 struct xfs_ail_cursor *cur,
0e57f6a3
DC
1289 struct xfs_log_item **log_items,
1290 int nr_items,
1291 xfs_lsn_t commit_lsn)
1292{
1293 int i;
1294
1295 spin_lock(&ailp->xa_lock);
1296 /* xfs_trans_ail_update_bulk drops ailp->xa_lock */
1d8c95a3 1297 xfs_trans_ail_update_bulk(ailp, cur, log_items, nr_items, commit_lsn);
0e57f6a3
DC
1298
1299 for (i = 0; i < nr_items; i++)
1300 IOP_UNPIN(log_items[i], 0);
1301}
1302
1303/*
1304 * Bulk operation version of xfs_trans_committed that takes a log vector of
1305 * items to insert into the AIL. This uses bulk AIL insertion techniques to
1306 * minimise lock traffic.
e34a314c
DC
1307 *
1308 * If we are called with the aborted flag set, it is because a log write during
1309 * a CIL checkpoint commit has failed. In this case, all the items in the
1310 * checkpoint have already gone through IOP_COMMITED and IOP_UNLOCK, which
1311 * means that checkpoint commit abort handling is treated exactly the same
1312 * as an iclog write error even though we haven't started any IO yet. Hence in
1313 * this case all we need to do is IOP_COMMITTED processing, followed by an
1314 * IOP_UNPIN(aborted) call.
1d8c95a3
DC
1315 *
1316 * The AIL cursor is used to optimise the insert process. If commit_lsn is not
1317 * at the end of the AIL, the insert cursor avoids the need to walk
1318 * the AIL to find the insertion point on every xfs_log_item_batch_insert()
1319 * call. This saves a lot of needless list walking and is a net win, even
1320 * though it slightly increases that amount of AIL lock traffic to set it up
1321 * and tear it down.
0e57f6a3
DC
1322 */
1323void
1324xfs_trans_committed_bulk(
1325 struct xfs_ail *ailp,
1326 struct xfs_log_vec *log_vector,
1327 xfs_lsn_t commit_lsn,
1328 int aborted)
1329{
1330#define LOG_ITEM_BATCH_SIZE 32
1331 struct xfs_log_item *log_items[LOG_ITEM_BATCH_SIZE];
1332 struct xfs_log_vec *lv;
1d8c95a3 1333 struct xfs_ail_cursor cur;
0e57f6a3
DC
1334 int i = 0;
1335
1d8c95a3
DC
1336 spin_lock(&ailp->xa_lock);
1337 xfs_trans_ail_cursor_last(ailp, &cur, commit_lsn);
1338 spin_unlock(&ailp->xa_lock);
1339
0e57f6a3
DC
1340 /* unpin all the log items */
1341 for (lv = log_vector; lv; lv = lv->lv_next ) {
1342 struct xfs_log_item *lip = lv->lv_item;
1343 xfs_lsn_t item_lsn;
1344
1345 if (aborted)
1346 lip->li_flags |= XFS_LI_ABORTED;
1347 item_lsn = IOP_COMMITTED(lip, commit_lsn);
1348
1316d4da 1349 /* item_lsn of -1 means the item needs no further processing */
0e57f6a3
DC
1350 if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0)
1351 continue;
1352
e34a314c
DC
1353 /*
1354 * if we are aborting the operation, no point in inserting the
1355 * object into the AIL as we are in a shutdown situation.
1356 */
1357 if (aborted) {
1358 ASSERT(XFS_FORCED_SHUTDOWN(ailp->xa_mount));
1359 IOP_UNPIN(lip, 1);
1360 continue;
1361 }
1362
0e57f6a3
DC
1363 if (item_lsn != commit_lsn) {
1364
1365 /*
1366 * Not a bulk update option due to unusual item_lsn.
1367 * Push into AIL immediately, rechecking the lsn once
1d8c95a3
DC
1368 * we have the ail lock. Then unpin the item. This does
1369 * not affect the AIL cursor the bulk insert path is
1370 * using.
0e57f6a3
DC
1371 */
1372 spin_lock(&ailp->xa_lock);
1373 if (XFS_LSN_CMP(item_lsn, lip->li_lsn) > 0)
1374 xfs_trans_ail_update(ailp, lip, item_lsn);
1375 else
1376 spin_unlock(&ailp->xa_lock);
1377 IOP_UNPIN(lip, 0);
1378 continue;
1379 }
1380
1381 /* Item is a candidate for bulk AIL insert. */
1382 log_items[i++] = lv->lv_item;
1383 if (i >= LOG_ITEM_BATCH_SIZE) {
1d8c95a3 1384 xfs_log_item_batch_insert(ailp, &cur, log_items,
0e57f6a3
DC
1385 LOG_ITEM_BATCH_SIZE, commit_lsn);
1386 i = 0;
1387 }
1388 }
1389
1390 /* make sure we insert the remainder! */
1391 if (i)
1d8c95a3
DC
1392 xfs_log_item_batch_insert(ailp, &cur, log_items, i, commit_lsn);
1393
1394 spin_lock(&ailp->xa_lock);
1395 xfs_trans_ail_cursor_done(ailp, &cur);
1396 spin_unlock(&ailp->xa_lock);
0e57f6a3
DC
1397}
1398
0924378a 1399/*
b1037058 1400 * Commit the given transaction to the log.
0924378a
DC
1401 *
1402 * XFS disk error handling mechanism is not based on a typical
1403 * transaction abort mechanism. Logically after the filesystem
1404 * gets marked 'SHUTDOWN', we can't let any new transactions
1405 * be durable - ie. committed to disk - because some metadata might
1406 * be inconsistent. In such cases, this returns an error, and the
1407 * caller may assume that all locked objects joined to the transaction
1408 * have already been unlocked as if the commit had succeeded.
1409 * Do not reference the transaction structure after this call.
1410 */
0924378a 1411int
b1037058 1412xfs_trans_commit(
a3ccd2ca 1413 struct xfs_trans *tp,
b1037058 1414 uint flags)
0924378a 1415{
a3ccd2ca 1416 struct xfs_mount *mp = tp->t_mountp;
0924378a 1417 xfs_lsn_t commit_lsn = -1;
a3ccd2ca 1418 int error = 0;
0924378a
DC
1419 int log_flags = 0;
1420 int sync = tp->t_flags & XFS_TRANS_SYNC;
0924378a
DC
1421
1422 /*
1423 * Determine whether this commit is releasing a permanent
1424 * log reservation or not.
1425 */
1426 if (flags & XFS_TRANS_RELEASE_LOG_RES) {
1427 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
1428 log_flags = XFS_LOG_REL_PERM_RESERV;
1429 }
1430
1431 /*
1432 * If there is nothing to be logged by the transaction,
1433 * then unlock all of the items associated with the
1434 * transaction and free the transaction structure.
1435 * Also make sure to return any reserved blocks to
1436 * the free pool.
1437 */
a3ccd2ca
CH
1438 if (!(tp->t_flags & XFS_TRANS_DIRTY))
1439 goto out_unreserve;
1440
1441 if (XFS_FORCED_SHUTDOWN(mp)) {
1442 error = XFS_ERROR(EIO);
1443 goto out_unreserve;
0924378a 1444 }
a3ccd2ca 1445
0924378a
DC
1446 ASSERT(tp->t_ticket != NULL);
1447
1448 /*
1449 * If we need to update the superblock, then do it now.
1450 */
1451 if (tp->t_flags & XFS_TRANS_SB_DIRTY)
1452 xfs_trans_apply_sb_deltas(tp);
1453 xfs_trans_apply_dquot_deltas(tp);
1454
0244b960 1455 error = xfs_log_commit_cil(mp, tp, &commit_lsn, flags);
0924378a
DC
1456 if (error == ENOMEM) {
1457 xfs_force_shutdown(mp, SHUTDOWN_LOG_IO_ERROR);
a3ccd2ca
CH
1458 error = XFS_ERROR(EIO);
1459 goto out_unreserve;
0924378a 1460 }
1da177e4 1461
0244b960
CH
1462 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
1463 xfs_trans_free(tp);
1464
1da177e4
LT
1465 /*
1466 * If the transaction needs to be synchronous, then force the
1467 * log out now and wait for it.
1468 */
1469 if (sync) {
f538d4da 1470 if (!error) {
a14a348b 1471 error = _xfs_log_force_lsn(mp, commit_lsn,
b1037058 1472 XFS_LOG_SYNC, NULL);
f538d4da 1473 }
1da177e4
LT
1474 XFS_STATS_INC(xs_trans_sync);
1475 } else {
1476 XFS_STATS_INC(xs_trans_async);
1477 }
1478
a3ccd2ca
CH
1479 return error;
1480
1481out_unreserve:
1482 xfs_trans_unreserve_and_mod_sb(tp);
1483
1484 /*
1485 * It is indeed possible for the transaction to be not dirty but
1486 * the dqinfo portion to be. All that means is that we have some
1487 * (non-persistent) quota reservations that need to be unreserved.
1488 */
1489 xfs_trans_unreserve_and_mod_dquots(tp);
1490 if (tp->t_ticket) {
1491 commit_lsn = xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
1492 if (commit_lsn == -1 && !error)
1493 error = XFS_ERROR(EIO);
1494 }
1495 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
71e330b5 1496 xfs_trans_free_items(tp, NULLCOMMITLSN, error ? XFS_TRANS_ABORT : 0);
a3ccd2ca
CH
1497 xfs_trans_free(tp);
1498
1499 XFS_STATS_INC(xs_trans_empty);
1500 return error;
1da177e4
LT
1501}
1502
1da177e4
LT
1503/*
1504 * Unlock all of the transaction's items and free the transaction.
1505 * The transaction must not have modified any of its items, because
1506 * there is no way to restore them to their previous state.
1507 *
1508 * If the transaction has made a log reservation, make sure to release
1509 * it as well.
1510 */
1511void
1512xfs_trans_cancel(
1513 xfs_trans_t *tp,
1514 int flags)
1515{
1516 int log_flags;
0733af21 1517 xfs_mount_t *mp = tp->t_mountp;
1da177e4
LT
1518
1519 /*
1520 * See if the caller is being too lazy to figure out if
1521 * the transaction really needs an abort.
1522 */
1523 if ((flags & XFS_TRANS_ABORT) && !(tp->t_flags & XFS_TRANS_DIRTY))
1524 flags &= ~XFS_TRANS_ABORT;
1525 /*
1526 * See if the caller is relying on us to shut down the
1527 * filesystem. This happens in paths where we detect
1528 * corruption and decide to give up.
1529 */
60a204f0 1530 if ((tp->t_flags & XFS_TRANS_DIRTY) && !XFS_FORCED_SHUTDOWN(mp)) {
0733af21 1531 XFS_ERROR_REPORT("xfs_trans_cancel", XFS_ERRLEVEL_LOW, mp);
7d04a335 1532 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
60a204f0 1533 }
1da177e4 1534#ifdef DEBUG
e98c414f
CH
1535 if (!(flags & XFS_TRANS_ABORT) && !XFS_FORCED_SHUTDOWN(mp)) {
1536 struct xfs_log_item_desc *lidp;
1537
1538 list_for_each_entry(lidp, &tp->t_items, lid_trans)
1539 ASSERT(!(lidp->lid_item->li_type == XFS_LI_EFD));
1da177e4
LT
1540 }
1541#endif
1542 xfs_trans_unreserve_and_mod_sb(tp);
7d095257 1543 xfs_trans_unreserve_and_mod_dquots(tp);
1da177e4
LT
1544
1545 if (tp->t_ticket) {
1546 if (flags & XFS_TRANS_RELEASE_LOG_RES) {
1547 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
1548 log_flags = XFS_LOG_REL_PERM_RESERV;
1549 } else {
1550 log_flags = 0;
1551 }
0733af21 1552 xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
1da177e4
LT
1553 }
1554
1555 /* mark this thread as no longer being in a transaction */
59c1b082 1556 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
1da177e4 1557
71e330b5 1558 xfs_trans_free_items(tp, NULLCOMMITLSN, flags);
1da177e4
LT
1559 xfs_trans_free(tp);
1560}
1561
322ff6b8
NS
1562/*
1563 * Roll from one trans in the sequence of PERMANENT transactions to
1564 * the next: permanent transactions are only flushed out when
1565 * committed with XFS_TRANS_RELEASE_LOG_RES, but we still want as soon
1566 * as possible to let chunks of it go to the log. So we commit the
1567 * chunk we've been working on and get a new transaction to continue.
1568 */
1569int
1570xfs_trans_roll(
1571 struct xfs_trans **tpp,
1572 struct xfs_inode *dp)
1573{
1574 struct xfs_trans *trans;
1575 unsigned int logres, count;
1576 int error;
1577
1578 /*
1579 * Ensure that the inode is always logged.
1580 */
1581 trans = *tpp;
1582 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
1583
1584 /*
1585 * Copy the critical parameters from one trans to the next.
1586 */
1587 logres = trans->t_log_res;
1588 count = trans->t_log_count;
1589 *tpp = xfs_trans_dup(trans);
1590
1591 /*
1592 * Commit the current transaction.
1593 * If this commit failed, then it'd just unlock those items that
1594 * are not marked ihold. That also means that a filesystem shutdown
1595 * is in progress. The caller takes the responsibility to cancel
1596 * the duplicate transaction that gets returned.
1597 */
1598 error = xfs_trans_commit(trans, 0);
1599 if (error)
1600 return (error);
1601
1602 trans = *tpp;
1603
cc09c0dc
DC
1604 /*
1605 * transaction commit worked ok so we can drop the extra ticket
1606 * reference that we gained in xfs_trans_dup()
1607 */
1608 xfs_log_ticket_put(trans->t_ticket);
1609
1610
322ff6b8
NS
1611 /*
1612 * Reserve space in the log for th next transaction.
1613 * This also pushes items in the "AIL", the list of logged items,
1614 * out to disk if they are taking up space at the tail of the log
1615 * that we want to use. This requires that either nothing be locked
1616 * across this call, or that anything that is locked be logged in
1617 * the prior and the next transactions.
1618 */
1619 error = xfs_trans_reserve(trans, 0, logres, 0,
1620 XFS_TRANS_PERM_LOG_RES, count);
1621 /*
1622 * Ensure that the inode is in the new transaction and locked.
1623 */
1624 if (error)
1625 return error;
1626
ddc3415a 1627 xfs_trans_ijoin(trans, dp, 0);
322ff6b8
NS
1628 return 0;
1629}
This page took 1.097241 seconds and 5 git commands to generate.