2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * Copyright (C) 2010 Red Hat, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "xfs_types.h"
23 #include "xfs_trans.h"
26 #include "xfs_mount.h"
27 #include "xfs_error.h"
28 #include "xfs_da_btree.h"
29 #include "xfs_bmap_btree.h"
30 #include "xfs_alloc_btree.h"
31 #include "xfs_ialloc_btree.h"
32 #include "xfs_dinode.h"
33 #include "xfs_inode.h"
34 #include "xfs_btree.h"
35 #include "xfs_ialloc.h"
36 #include "xfs_alloc.h"
37 #include "xfs_extent_busy.h"
39 #include "xfs_quota.h"
41 #include "xfs_trans_priv.h"
42 #include "xfs_trans_space.h"
43 #include "xfs_inode_item.h"
44 #include "xfs_log_priv.h"
45 #include "xfs_buf_item.h"
46 #include "xfs_trace.h"
48 kmem_zone_t *xfs_trans_zone;
49 kmem_zone_t *xfs_log_item_desc_zone;
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.
59 xfs_buf_log_overhead(void)
61 return round_up(sizeof(struct xlog_op_header) +
62 sizeof(struct xfs_buf_log_format), 128);
66 * Calculate out transaction log reservation per item in bytes.
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.
77 return nbufs * (size + xfs_buf_log_overhead());
81 * Various log reservation values.
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.
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.
95 * Reservation functions here avoid a huge stack in xfs_trans_init due to
96 * register overflow from temporaries in the calculations.
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
115 xfs_calc_write_reservation(
116 struct xfs_mount *mp)
118 return XFS_DQUOT_LOGRES(mp) +
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))));
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
144 xfs_calc_itruncate_reservation(
145 struct xfs_mount *mp)
147 return XFS_DQUOT_LOGRES(mp) +
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)));
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
174 xfs_calc_rename_reservation(
175 struct xfs_mount *mp)
177 return XFS_DQUOT_LOGRES(mp) +
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))));
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
199 xfs_calc_link_reservation(
200 struct xfs_mount *mp)
202 return XFS_DQUOT_LOGRES(mp) +
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))));
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
224 xfs_calc_remove_reservation(
225 struct xfs_mount *mp)
227 return XFS_DQUOT_LOGRES(mp) +
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))));
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
251 xfs_calc_symlink_reservation(
252 struct xfs_mount *mp)
254 return XFS_DQUOT_LOGRES(mp) +
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))));
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
285 xfs_calc_create_reservation(
286 struct xfs_mount *mp)
288 return XFS_DQUOT_LOGRES(mp) +
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) +
295 mp->m_sb.sb_sectsize +
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))));
305 * Making a new directory is the same as creating a new file.
308 xfs_calc_mkdir_reservation(
309 struct xfs_mount *mp)
311 return xfs_calc_create_reservation(mp);
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
325 xfs_calc_ifree_reservation(
326 struct xfs_mount *mp)
328 return XFS_DQUOT_LOGRES(mp) +
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)) +
332 MAX((__uint16_t)XFS_FSB_TO_B(mp, 1),
333 XFS_INODE_CLUSTER_SIZE(mp)) +
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));
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.
346 xfs_calc_ichange_reservation(
347 struct xfs_mount *mp)
349 return XFS_DQUOT_LOGRES(mp) +
350 mp->m_sb.sb_inodesize +
351 mp->m_sb.sb_sectsize +
357 * Growing the data section of the filesystem.
363 xfs_calc_growdata_reservation(
364 struct xfs_mount *mp)
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));
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
382 xfs_calc_growrtalloc_reservation(
383 struct xfs_mount *mp)
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));
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
399 xfs_calc_growrtzero_reservation(
400 struct xfs_mount *mp)
402 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
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
416 xfs_calc_growrtfree_reservation(
417 struct xfs_mount *mp)
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);
426 * Logging the inode modification timestamp on a synchronous write.
430 xfs_calc_swrite_reservation(
431 struct xfs_mount *mp)
433 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
437 * Logging the inode mode bits when writing a setuid/setgid file
441 xfs_calc_writeid_reservation(xfs_mount_t *mp)
443 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
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
455 xfs_calc_addafork_reservation(
456 struct xfs_mount *mp)
458 return XFS_DQUOT_LOGRES(mp) +
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));
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
480 xfs_calc_attrinval_reservation(
481 struct xfs_mount *mp)
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))));
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.
502 xfs_calc_attrset_reservation(
503 struct xfs_mount *mp)
505 return XFS_DQUOT_LOGRES(mp) +
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));
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
523 xfs_calc_attrrm_reservation(
524 struct xfs_mount *mp)
526 return XFS_DQUOT_LOGRES(mp) +
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))));
539 * Clearing a bad agino number in an agi hash bucket.
542 xfs_calc_clear_agi_bucket_reservation(
543 struct xfs_mount *mp)
545 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
549 * Initialize the precomputed transaction reservation values
550 * in the mount structure.
554 struct xfs_mount *mp)
556 struct xfs_trans_reservations *resp = &mp->m_reservations;
558 resp->tr_write = xfs_calc_write_reservation(mp);
559 resp->tr_itruncate = xfs_calc_itruncate_reservation(mp);
560 resp->tr_rename = xfs_calc_rename_reservation(mp);
561 resp->tr_link = xfs_calc_link_reservation(mp);
562 resp->tr_remove = xfs_calc_remove_reservation(mp);
563 resp->tr_symlink = xfs_calc_symlink_reservation(mp);
564 resp->tr_create = xfs_calc_create_reservation(mp);
565 resp->tr_mkdir = xfs_calc_mkdir_reservation(mp);
566 resp->tr_ifree = xfs_calc_ifree_reservation(mp);
567 resp->tr_ichange = xfs_calc_ichange_reservation(mp);
568 resp->tr_growdata = xfs_calc_growdata_reservation(mp);
569 resp->tr_swrite = xfs_calc_swrite_reservation(mp);
570 resp->tr_writeid = xfs_calc_writeid_reservation(mp);
571 resp->tr_addafork = xfs_calc_addafork_reservation(mp);
572 resp->tr_attrinval = xfs_calc_attrinval_reservation(mp);
573 resp->tr_attrset = xfs_calc_attrset_reservation(mp);
574 resp->tr_attrrm = xfs_calc_attrrm_reservation(mp);
575 resp->tr_clearagi = xfs_calc_clear_agi_bucket_reservation(mp);
576 resp->tr_growrtalloc = xfs_calc_growrtalloc_reservation(mp);
577 resp->tr_growrtzero = xfs_calc_growrtzero_reservation(mp);
578 resp->tr_growrtfree = xfs_calc_growrtfree_reservation(mp);
582 * This routine is called to allocate a transaction structure.
583 * The type parameter indicates the type of the transaction. These
584 * are enumerated in xfs_trans.h.
586 * Dynamically allocate the transaction structure from the transaction
587 * zone, initialize it, and return it to the caller.
596 sb_start_intwrite(mp->m_super);
597 tp = _xfs_trans_alloc(mp, type, KM_SLEEP);
598 tp->t_flags |= XFS_TRANS_FREEZE_PROT;
606 xfs_km_flags_t memflags)
610 WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
611 atomic_inc(&mp->m_active_trans);
613 tp = kmem_zone_zalloc(xfs_trans_zone, memflags);
614 tp->t_magic = XFS_TRANS_MAGIC;
617 INIT_LIST_HEAD(&tp->t_items);
618 INIT_LIST_HEAD(&tp->t_busy);
623 * Free the transaction structure. If there is more clean up
624 * to do when the structure is freed, add it here.
628 struct xfs_trans *tp)
630 xfs_extent_busy_sort(&tp->t_busy);
631 xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false);
633 atomic_dec(&tp->t_mountp->m_active_trans);
634 if (tp->t_flags & XFS_TRANS_FREEZE_PROT)
635 sb_end_intwrite(tp->t_mountp->m_super);
636 xfs_trans_free_dqinfo(tp);
637 kmem_zone_free(xfs_trans_zone, tp);
641 * This is called to create a new transaction which will share the
642 * permanent log reservation of the given transaction. The remaining
643 * unused block and rt extent reservations are also inherited. This
644 * implies that the original transaction is no longer allowed to allocate
645 * blocks. Locks and log items, however, are no inherited. They must
646 * be added to the new transaction explicitly.
654 ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP);
657 * Initialize the new transaction structure.
659 ntp->t_magic = XFS_TRANS_MAGIC;
660 ntp->t_type = tp->t_type;
661 ntp->t_mountp = tp->t_mountp;
662 INIT_LIST_HEAD(&ntp->t_items);
663 INIT_LIST_HEAD(&ntp->t_busy);
665 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
666 ASSERT(tp->t_ticket != NULL);
668 ntp->t_flags = XFS_TRANS_PERM_LOG_RES |
669 (tp->t_flags & XFS_TRANS_RESERVE) |
670 (tp->t_flags & XFS_TRANS_FREEZE_PROT);
671 /* We gave our writer reference to the new transaction */
672 tp->t_flags &= ~XFS_TRANS_FREEZE_PROT;
673 ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket);
674 ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used;
675 tp->t_blk_res = tp->t_blk_res_used;
676 ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used;
677 tp->t_rtx_res = tp->t_rtx_res_used;
678 ntp->t_pflags = tp->t_pflags;
680 xfs_trans_dup_dqinfo(tp, ntp);
682 atomic_inc(&tp->t_mountp->m_active_trans);
687 * This is called to reserve free disk blocks and log space for the
688 * given transaction. This must be done before allocating any resources
689 * within the transaction.
691 * This will return ENOSPC if there are not enough blocks available.
692 * It will sleep waiting for available log space.
693 * The only valid value for the flags parameter is XFS_RES_LOG_PERM, which
694 * is used by long running transactions. If any one of the reservations
695 * fails then they will all be backed out.
697 * This does not do quota reservations. That typically is done by the
710 int rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
712 /* Mark this thread as being in a transaction */
713 current_set_flags_nested(&tp->t_pflags, PF_FSTRANS);
716 * Attempt to reserve the needed disk blocks by decrementing
717 * the number needed from the number available. This will
718 * fail if the count would go below zero.
721 error = xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
722 -((int64_t)blocks), rsvd);
724 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
725 return (XFS_ERROR(ENOSPC));
727 tp->t_blk_res += blocks;
731 * Reserve the log space needed for this transaction.
734 bool permanent = false;
736 ASSERT(tp->t_log_res == 0 || tp->t_log_res == logspace);
737 ASSERT(tp->t_log_count == 0 || tp->t_log_count == logcount);
739 if (flags & XFS_TRANS_PERM_LOG_RES) {
740 tp->t_flags |= XFS_TRANS_PERM_LOG_RES;
743 ASSERT(tp->t_ticket == NULL);
744 ASSERT(!(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
747 if (tp->t_ticket != NULL) {
748 ASSERT(flags & XFS_TRANS_PERM_LOG_RES);
749 error = xfs_log_regrant(tp->t_mountp, tp->t_ticket);
751 error = xfs_log_reserve(tp->t_mountp, logspace,
752 logcount, &tp->t_ticket,
753 XFS_TRANSACTION, permanent,
760 tp->t_log_res = logspace;
761 tp->t_log_count = logcount;
765 * Attempt to reserve the needed realtime extents by decrementing
766 * the number needed from the number available. This will
767 * fail if the count would go below zero.
770 error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS,
771 -((int64_t)rtextents), rsvd);
773 error = XFS_ERROR(ENOSPC);
776 tp->t_rtx_res += rtextents;
782 * Error cases jump to one of these labels to undo any
783 * reservations which have already been performed.
789 if (flags & XFS_TRANS_PERM_LOG_RES) {
790 log_flags = XFS_LOG_REL_PERM_RESERV;
794 xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, log_flags);
797 tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES;
802 xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
803 (int64_t)blocks, rsvd);
807 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
813 * Record the indicated change to the given field for application
814 * to the file system's superblock when the transaction commits.
815 * For now, just store the change in the transaction structure.
817 * Mark the transaction structure to indicate that the superblock
818 * needs to be updated before committing.
820 * Because we may not be keeping track of allocated/free inodes and
821 * used filesystem blocks in the superblock, we do not mark the
822 * superblock dirty in this transaction if we modify these fields.
823 * We still need to update the transaction deltas so that they get
824 * applied to the incore superblock, but we don't want them to
825 * cause the superblock to get locked and logged if these are the
826 * only fields in the superblock that the transaction modifies.
834 uint32_t flags = (XFS_TRANS_DIRTY|XFS_TRANS_SB_DIRTY);
835 xfs_mount_t *mp = tp->t_mountp;
838 case XFS_TRANS_SB_ICOUNT:
839 tp->t_icount_delta += delta;
840 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
841 flags &= ~XFS_TRANS_SB_DIRTY;
843 case XFS_TRANS_SB_IFREE:
844 tp->t_ifree_delta += delta;
845 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
846 flags &= ~XFS_TRANS_SB_DIRTY;
848 case XFS_TRANS_SB_FDBLOCKS:
850 * Track the number of blocks allocated in the
851 * transaction. Make sure it does not exceed the
855 tp->t_blk_res_used += (uint)-delta;
856 ASSERT(tp->t_blk_res_used <= tp->t_blk_res);
858 tp->t_fdblocks_delta += delta;
859 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
860 flags &= ~XFS_TRANS_SB_DIRTY;
862 case XFS_TRANS_SB_RES_FDBLOCKS:
864 * The allocation has already been applied to the
865 * in-core superblock's counter. This should only
866 * be applied to the on-disk superblock.
869 tp->t_res_fdblocks_delta += delta;
870 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
871 flags &= ~XFS_TRANS_SB_DIRTY;
873 case XFS_TRANS_SB_FREXTENTS:
875 * Track the number of blocks allocated in the
876 * transaction. Make sure it does not exceed the
880 tp->t_rtx_res_used += (uint)-delta;
881 ASSERT(tp->t_rtx_res_used <= tp->t_rtx_res);
883 tp->t_frextents_delta += delta;
885 case XFS_TRANS_SB_RES_FREXTENTS:
887 * The allocation has already been applied to the
888 * in-core superblock's counter. This should only
889 * be applied to the on-disk superblock.
892 tp->t_res_frextents_delta += delta;
894 case XFS_TRANS_SB_DBLOCKS:
896 tp->t_dblocks_delta += delta;
898 case XFS_TRANS_SB_AGCOUNT:
900 tp->t_agcount_delta += delta;
902 case XFS_TRANS_SB_IMAXPCT:
903 tp->t_imaxpct_delta += delta;
905 case XFS_TRANS_SB_REXTSIZE:
906 tp->t_rextsize_delta += delta;
908 case XFS_TRANS_SB_RBMBLOCKS:
909 tp->t_rbmblocks_delta += delta;
911 case XFS_TRANS_SB_RBLOCKS:
912 tp->t_rblocks_delta += delta;
914 case XFS_TRANS_SB_REXTENTS:
915 tp->t_rextents_delta += delta;
917 case XFS_TRANS_SB_REXTSLOG:
918 tp->t_rextslog_delta += delta;
925 tp->t_flags |= flags;
929 * xfs_trans_apply_sb_deltas() is called from the commit code
930 * to bring the superblock buffer into the current transaction
931 * and modify it as requested by earlier calls to xfs_trans_mod_sb().
933 * For now we just look at each field allowed to change and change
937 xfs_trans_apply_sb_deltas(
944 bp = xfs_trans_getsb(tp, tp->t_mountp, 0);
945 sbp = XFS_BUF_TO_SBP(bp);
948 * Check that superblock mods match the mods made to AGF counters.
950 ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
951 (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
952 tp->t_ag_btree_delta));
955 * Only update the superblock counters if we are logging them
957 if (!xfs_sb_version_haslazysbcount(&(tp->t_mountp->m_sb))) {
958 if (tp->t_icount_delta)
959 be64_add_cpu(&sbp->sb_icount, tp->t_icount_delta);
960 if (tp->t_ifree_delta)
961 be64_add_cpu(&sbp->sb_ifree, tp->t_ifree_delta);
962 if (tp->t_fdblocks_delta)
963 be64_add_cpu(&sbp->sb_fdblocks, tp->t_fdblocks_delta);
964 if (tp->t_res_fdblocks_delta)
965 be64_add_cpu(&sbp->sb_fdblocks, tp->t_res_fdblocks_delta);
968 if (tp->t_frextents_delta)
969 be64_add_cpu(&sbp->sb_frextents, tp->t_frextents_delta);
970 if (tp->t_res_frextents_delta)
971 be64_add_cpu(&sbp->sb_frextents, tp->t_res_frextents_delta);
973 if (tp->t_dblocks_delta) {
974 be64_add_cpu(&sbp->sb_dblocks, tp->t_dblocks_delta);
977 if (tp->t_agcount_delta) {
978 be32_add_cpu(&sbp->sb_agcount, tp->t_agcount_delta);
981 if (tp->t_imaxpct_delta) {
982 sbp->sb_imax_pct += tp->t_imaxpct_delta;
985 if (tp->t_rextsize_delta) {
986 be32_add_cpu(&sbp->sb_rextsize, tp->t_rextsize_delta);
989 if (tp->t_rbmblocks_delta) {
990 be32_add_cpu(&sbp->sb_rbmblocks, tp->t_rbmblocks_delta);
993 if (tp->t_rblocks_delta) {
994 be64_add_cpu(&sbp->sb_rblocks, tp->t_rblocks_delta);
997 if (tp->t_rextents_delta) {
998 be64_add_cpu(&sbp->sb_rextents, tp->t_rextents_delta);
1001 if (tp->t_rextslog_delta) {
1002 sbp->sb_rextslog += tp->t_rextslog_delta;
1008 * Log the whole thing, the fields are noncontiguous.
1010 xfs_trans_log_buf(tp, bp, 0, sizeof(xfs_dsb_t) - 1);
1013 * Since all the modifiable fields are contiguous, we
1014 * can get away with this.
1016 xfs_trans_log_buf(tp, bp, offsetof(xfs_dsb_t, sb_icount),
1017 offsetof(xfs_dsb_t, sb_frextents) +
1018 sizeof(sbp->sb_frextents) - 1);
1022 * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations
1023 * and apply superblock counter changes to the in-core superblock. The
1024 * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT
1025 * applied to the in-core superblock. The idea is that that has already been
1028 * This is done efficiently with a single call to xfs_mod_incore_sb_batch().
1029 * However, we have to ensure that we only modify each superblock field only
1030 * once because the application of the delta values may not be atomic. That can
1031 * lead to ENOSPC races occurring if we have two separate modifcations of the
1032 * free space counter to put back the entire reservation and then take away
1035 * If we are not logging superblock counters, then the inode allocated/free and
1036 * used block counts are not updated in the on disk superblock. In this case,
1037 * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we
1038 * still need to update the incore superblock with the changes.
1041 xfs_trans_unreserve_and_mod_sb(
1044 xfs_mod_sb_t msb[9]; /* If you add cases, add entries */
1046 xfs_mount_t *mp = tp->t_mountp;
1050 int64_t blkdelta = 0;
1051 int64_t rtxdelta = 0;
1053 int64_t ifreedelta = 0;
1056 rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
1058 /* calculate deltas */
1059 if (tp->t_blk_res > 0)
1060 blkdelta = tp->t_blk_res;
1061 if ((tp->t_fdblocks_delta != 0) &&
1062 (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
1063 (tp->t_flags & XFS_TRANS_SB_DIRTY)))
1064 blkdelta += tp->t_fdblocks_delta;
1066 if (tp->t_rtx_res > 0)
1067 rtxdelta = tp->t_rtx_res;
1068 if ((tp->t_frextents_delta != 0) &&
1069 (tp->t_flags & XFS_TRANS_SB_DIRTY))
1070 rtxdelta += tp->t_frextents_delta;
1072 if (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
1073 (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
1074 idelta = tp->t_icount_delta;
1075 ifreedelta = tp->t_ifree_delta;
1078 /* apply the per-cpu counters */
1080 error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS,
1087 error = xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT,
1090 goto out_undo_fdblocks;
1094 error = xfs_icsb_modify_counters(mp, XFS_SBS_IFREE,
1097 goto out_undo_icount;
1100 /* apply remaining deltas */
1101 if (rtxdelta != 0) {
1102 msbp->msb_field = XFS_SBS_FREXTENTS;
1103 msbp->msb_delta = rtxdelta;
1107 if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
1108 if (tp->t_dblocks_delta != 0) {
1109 msbp->msb_field = XFS_SBS_DBLOCKS;
1110 msbp->msb_delta = tp->t_dblocks_delta;
1113 if (tp->t_agcount_delta != 0) {
1114 msbp->msb_field = XFS_SBS_AGCOUNT;
1115 msbp->msb_delta = tp->t_agcount_delta;
1118 if (tp->t_imaxpct_delta != 0) {
1119 msbp->msb_field = XFS_SBS_IMAX_PCT;
1120 msbp->msb_delta = tp->t_imaxpct_delta;
1123 if (tp->t_rextsize_delta != 0) {
1124 msbp->msb_field = XFS_SBS_REXTSIZE;
1125 msbp->msb_delta = tp->t_rextsize_delta;
1128 if (tp->t_rbmblocks_delta != 0) {
1129 msbp->msb_field = XFS_SBS_RBMBLOCKS;
1130 msbp->msb_delta = tp->t_rbmblocks_delta;
1133 if (tp->t_rblocks_delta != 0) {
1134 msbp->msb_field = XFS_SBS_RBLOCKS;
1135 msbp->msb_delta = tp->t_rblocks_delta;
1138 if (tp->t_rextents_delta != 0) {
1139 msbp->msb_field = XFS_SBS_REXTENTS;
1140 msbp->msb_delta = tp->t_rextents_delta;
1143 if (tp->t_rextslog_delta != 0) {
1144 msbp->msb_field = XFS_SBS_REXTSLOG;
1145 msbp->msb_delta = tp->t_rextslog_delta;
1151 * If we need to change anything, do it.
1154 error = xfs_mod_incore_sb_batch(tp->t_mountp, msb,
1155 (uint)(msbp - msb), rsvd);
1157 goto out_undo_ifreecount;
1162 out_undo_ifreecount:
1164 xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, -ifreedelta, rsvd);
1167 xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, -idelta, rsvd);
1170 xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd);
1177 * Add the given log item to the transaction's list of log items.
1179 * The log item will now point to its new descriptor with its li_desc field.
1183 struct xfs_trans *tp,
1184 struct xfs_log_item *lip)
1186 struct xfs_log_item_desc *lidp;
1188 ASSERT(lip->li_mountp == tp->t_mountp);
1189 ASSERT(lip->li_ailp == tp->t_mountp->m_ail);
1191 lidp = kmem_zone_zalloc(xfs_log_item_desc_zone, KM_SLEEP | KM_NOFS);
1193 lidp->lid_item = lip;
1194 lidp->lid_flags = 0;
1195 list_add_tail(&lidp->lid_trans, &tp->t_items);
1197 lip->li_desc = lidp;
1201 xfs_trans_free_item_desc(
1202 struct xfs_log_item_desc *lidp)
1204 list_del_init(&lidp->lid_trans);
1205 kmem_zone_free(xfs_log_item_desc_zone, lidp);
1209 * Unlink and free the given descriptor.
1213 struct xfs_log_item *lip)
1215 xfs_trans_free_item_desc(lip->li_desc);
1216 lip->li_desc = NULL;
1220 * Unlock all of the items of a transaction and free all the descriptors
1221 * of that transaction.
1224 xfs_trans_free_items(
1225 struct xfs_trans *tp,
1226 xfs_lsn_t commit_lsn,
1229 struct xfs_log_item_desc *lidp, *next;
1231 list_for_each_entry_safe(lidp, next, &tp->t_items, lid_trans) {
1232 struct xfs_log_item *lip = lidp->lid_item;
1234 lip->li_desc = NULL;
1236 if (commit_lsn != NULLCOMMITLSN)
1237 IOP_COMMITTING(lip, commit_lsn);
1238 if (flags & XFS_TRANS_ABORT)
1239 lip->li_flags |= XFS_LI_ABORTED;
1242 xfs_trans_free_item_desc(lidp);
1247 xfs_log_item_batch_insert(
1248 struct xfs_ail *ailp,
1249 struct xfs_ail_cursor *cur,
1250 struct xfs_log_item **log_items,
1252 xfs_lsn_t commit_lsn)
1256 spin_lock(&ailp->xa_lock);
1257 /* xfs_trans_ail_update_bulk drops ailp->xa_lock */
1258 xfs_trans_ail_update_bulk(ailp, cur, log_items, nr_items, commit_lsn);
1260 for (i = 0; i < nr_items; i++)
1261 IOP_UNPIN(log_items[i], 0);
1265 * Bulk operation version of xfs_trans_committed that takes a log vector of
1266 * items to insert into the AIL. This uses bulk AIL insertion techniques to
1267 * minimise lock traffic.
1269 * If we are called with the aborted flag set, it is because a log write during
1270 * a CIL checkpoint commit has failed. In this case, all the items in the
1271 * checkpoint have already gone through IOP_COMMITED and IOP_UNLOCK, which
1272 * means that checkpoint commit abort handling is treated exactly the same
1273 * as an iclog write error even though we haven't started any IO yet. Hence in
1274 * this case all we need to do is IOP_COMMITTED processing, followed by an
1275 * IOP_UNPIN(aborted) call.
1277 * The AIL cursor is used to optimise the insert process. If commit_lsn is not
1278 * at the end of the AIL, the insert cursor avoids the need to walk
1279 * the AIL to find the insertion point on every xfs_log_item_batch_insert()
1280 * call. This saves a lot of needless list walking and is a net win, even
1281 * though it slightly increases that amount of AIL lock traffic to set it up
1285 xfs_trans_committed_bulk(
1286 struct xfs_ail *ailp,
1287 struct xfs_log_vec *log_vector,
1288 xfs_lsn_t commit_lsn,
1291 #define LOG_ITEM_BATCH_SIZE 32
1292 struct xfs_log_item *log_items[LOG_ITEM_BATCH_SIZE];
1293 struct xfs_log_vec *lv;
1294 struct xfs_ail_cursor cur;
1297 spin_lock(&ailp->xa_lock);
1298 xfs_trans_ail_cursor_last(ailp, &cur, commit_lsn);
1299 spin_unlock(&ailp->xa_lock);
1301 /* unpin all the log items */
1302 for (lv = log_vector; lv; lv = lv->lv_next ) {
1303 struct xfs_log_item *lip = lv->lv_item;
1307 lip->li_flags |= XFS_LI_ABORTED;
1308 item_lsn = IOP_COMMITTED(lip, commit_lsn);
1310 /* item_lsn of -1 means the item needs no further processing */
1311 if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0)
1315 * if we are aborting the operation, no point in inserting the
1316 * object into the AIL as we are in a shutdown situation.
1319 ASSERT(XFS_FORCED_SHUTDOWN(ailp->xa_mount));
1324 if (item_lsn != commit_lsn) {
1327 * Not a bulk update option due to unusual item_lsn.
1328 * Push into AIL immediately, rechecking the lsn once
1329 * we have the ail lock. Then unpin the item. This does
1330 * not affect the AIL cursor the bulk insert path is
1333 spin_lock(&ailp->xa_lock);
1334 if (XFS_LSN_CMP(item_lsn, lip->li_lsn) > 0)
1335 xfs_trans_ail_update(ailp, lip, item_lsn);
1337 spin_unlock(&ailp->xa_lock);
1342 /* Item is a candidate for bulk AIL insert. */
1343 log_items[i++] = lv->lv_item;
1344 if (i >= LOG_ITEM_BATCH_SIZE) {
1345 xfs_log_item_batch_insert(ailp, &cur, log_items,
1346 LOG_ITEM_BATCH_SIZE, commit_lsn);
1351 /* make sure we insert the remainder! */
1353 xfs_log_item_batch_insert(ailp, &cur, log_items, i, commit_lsn);
1355 spin_lock(&ailp->xa_lock);
1356 xfs_trans_ail_cursor_done(ailp, &cur);
1357 spin_unlock(&ailp->xa_lock);
1361 * Commit the given transaction to the log.
1363 * XFS disk error handling mechanism is not based on a typical
1364 * transaction abort mechanism. Logically after the filesystem
1365 * gets marked 'SHUTDOWN', we can't let any new transactions
1366 * be durable - ie. committed to disk - because some metadata might
1367 * be inconsistent. In such cases, this returns an error, and the
1368 * caller may assume that all locked objects joined to the transaction
1369 * have already been unlocked as if the commit had succeeded.
1370 * Do not reference the transaction structure after this call.
1374 struct xfs_trans *tp,
1377 struct xfs_mount *mp = tp->t_mountp;
1378 xfs_lsn_t commit_lsn = -1;
1381 int sync = tp->t_flags & XFS_TRANS_SYNC;
1384 * Determine whether this commit is releasing a permanent
1385 * log reservation or not.
1387 if (flags & XFS_TRANS_RELEASE_LOG_RES) {
1388 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
1389 log_flags = XFS_LOG_REL_PERM_RESERV;
1393 * If there is nothing to be logged by the transaction,
1394 * then unlock all of the items associated with the
1395 * transaction and free the transaction structure.
1396 * Also make sure to return any reserved blocks to
1399 if (!(tp->t_flags & XFS_TRANS_DIRTY))
1402 if (XFS_FORCED_SHUTDOWN(mp)) {
1403 error = XFS_ERROR(EIO);
1407 ASSERT(tp->t_ticket != NULL);
1410 * If we need to update the superblock, then do it now.
1412 if (tp->t_flags & XFS_TRANS_SB_DIRTY)
1413 xfs_trans_apply_sb_deltas(tp);
1414 xfs_trans_apply_dquot_deltas(tp);
1416 error = xfs_log_commit_cil(mp, tp, &commit_lsn, flags);
1417 if (error == ENOMEM) {
1418 xfs_force_shutdown(mp, SHUTDOWN_LOG_IO_ERROR);
1419 error = XFS_ERROR(EIO);
1423 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
1427 * If the transaction needs to be synchronous, then force the
1428 * log out now and wait for it.
1432 error = _xfs_log_force_lsn(mp, commit_lsn,
1433 XFS_LOG_SYNC, NULL);
1435 XFS_STATS_INC(xs_trans_sync);
1437 XFS_STATS_INC(xs_trans_async);
1443 xfs_trans_unreserve_and_mod_sb(tp);
1446 * It is indeed possible for the transaction to be not dirty but
1447 * the dqinfo portion to be. All that means is that we have some
1448 * (non-persistent) quota reservations that need to be unreserved.
1450 xfs_trans_unreserve_and_mod_dquots(tp);
1452 commit_lsn = xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
1453 if (commit_lsn == -1 && !error)
1454 error = XFS_ERROR(EIO);
1456 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
1457 xfs_trans_free_items(tp, NULLCOMMITLSN, error ? XFS_TRANS_ABORT : 0);
1460 XFS_STATS_INC(xs_trans_empty);
1465 * Unlock all of the transaction's items and free the transaction.
1466 * The transaction must not have modified any of its items, because
1467 * there is no way to restore them to their previous state.
1469 * If the transaction has made a log reservation, make sure to release
1478 xfs_mount_t *mp = tp->t_mountp;
1481 * See if the caller is being too lazy to figure out if
1482 * the transaction really needs an abort.
1484 if ((flags & XFS_TRANS_ABORT) && !(tp->t_flags & XFS_TRANS_DIRTY))
1485 flags &= ~XFS_TRANS_ABORT;
1487 * See if the caller is relying on us to shut down the
1488 * filesystem. This happens in paths where we detect
1489 * corruption and decide to give up.
1491 if ((tp->t_flags & XFS_TRANS_DIRTY) && !XFS_FORCED_SHUTDOWN(mp)) {
1492 XFS_ERROR_REPORT("xfs_trans_cancel", XFS_ERRLEVEL_LOW, mp);
1493 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1496 if (!(flags & XFS_TRANS_ABORT) && !XFS_FORCED_SHUTDOWN(mp)) {
1497 struct xfs_log_item_desc *lidp;
1499 list_for_each_entry(lidp, &tp->t_items, lid_trans)
1500 ASSERT(!(lidp->lid_item->li_type == XFS_LI_EFD));
1503 xfs_trans_unreserve_and_mod_sb(tp);
1504 xfs_trans_unreserve_and_mod_dquots(tp);
1507 if (flags & XFS_TRANS_RELEASE_LOG_RES) {
1508 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
1509 log_flags = XFS_LOG_REL_PERM_RESERV;
1513 xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
1516 /* mark this thread as no longer being in a transaction */
1517 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
1519 xfs_trans_free_items(tp, NULLCOMMITLSN, flags);
1524 * Roll from one trans in the sequence of PERMANENT transactions to
1525 * the next: permanent transactions are only flushed out when
1526 * committed with XFS_TRANS_RELEASE_LOG_RES, but we still want as soon
1527 * as possible to let chunks of it go to the log. So we commit the
1528 * chunk we've been working on and get a new transaction to continue.
1532 struct xfs_trans **tpp,
1533 struct xfs_inode *dp)
1535 struct xfs_trans *trans;
1536 unsigned int logres, count;
1540 * Ensure that the inode is always logged.
1543 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
1546 * Copy the critical parameters from one trans to the next.
1548 logres = trans->t_log_res;
1549 count = trans->t_log_count;
1550 *tpp = xfs_trans_dup(trans);
1553 * Commit the current transaction.
1554 * If this commit failed, then it'd just unlock those items that
1555 * are not marked ihold. That also means that a filesystem shutdown
1556 * is in progress. The caller takes the responsibility to cancel
1557 * the duplicate transaction that gets returned.
1559 error = xfs_trans_commit(trans, 0);
1566 * transaction commit worked ok so we can drop the extra ticket
1567 * reference that we gained in xfs_trans_dup()
1569 xfs_log_ticket_put(trans->t_ticket);
1573 * Reserve space in the log for th next transaction.
1574 * This also pushes items in the "AIL", the list of logged items,
1575 * out to disk if they are taking up space at the tail of the log
1576 * that we want to use. This requires that either nothing be locked
1577 * across this call, or that anything that is locked be logged in
1578 * the prior and the next transactions.
1580 error = xfs_trans_reserve(trans, 0, logres, 0,
1581 XFS_TRANS_PERM_LOG_RES, count);
1583 * Ensure that the inode is in the new transaction and locked.
1588 xfs_trans_ijoin(trans, dp, 0);