xfs: simplify xfs_ioend_can_merge
[linux-2.6-block.git] / fs / xfs / xfs_trans.c
CommitLineData
0b61f8a4 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
7b718769 3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
e98c414f 4 * Copyright (C) 2010 Red Hat, Inc.
7b718769 5 * All Rights Reserved.
1da177e4 6 */
1da177e4 7#include "xfs.h"
a844f451 8#include "xfs_fs.h"
70a9883c 9#include "xfs_shared.h"
239880ef
DC
10#include "xfs_format.h"
11#include "xfs_log_format.h"
12#include "xfs_trans_resv.h"
1da177e4 13#include "xfs_mount.h"
efc27b52 14#include "xfs_extent_busy.h"
1da177e4 15#include "xfs_quota.h"
239880ef 16#include "xfs_trans.h"
a844f451 17#include "xfs_trans_priv.h"
239880ef 18#include "xfs_log.h"
ed3b4d6c 19#include "xfs_trace.h"
a4fbe6ab 20#include "xfs_error.h"
f8f2835a 21#include "xfs_defer.h"
1da177e4 22
8f794055 23kmem_zone_t *xfs_trans_zone;
1da177e4 24
b872af2c
DW
25#if defined(CONFIG_TRACEPOINTS)
26static void
27xfs_trans_trace_reservations(
28 struct xfs_mount *mp)
29{
30 struct xfs_trans_res resv;
31 struct xfs_trans_res *res;
32 struct xfs_trans_res *end_res;
33 int i;
34
35 res = (struct xfs_trans_res *)M_RES(mp);
36 end_res = (struct xfs_trans_res *)(M_RES(mp) + 1);
37 for (i = 0; res < end_res; i++, res++)
38 trace_xfs_trans_resv_calc(mp, i, res);
39 xfs_log_get_max_trans_res(mp, &resv);
40 trace_xfs_trans_resv_calc(mp, -1, &resv);
41}
42#else
43# define xfs_trans_trace_reservations(mp)
44#endif
45
1da177e4
LT
46/*
47 * Initialize the precomputed transaction reservation values
48 * in the mount structure.
49 */
50void
51xfs_trans_init(
025101dc 52 struct xfs_mount *mp)
1da177e4 53{
3d3c8b52 54 xfs_trans_resv_calc(mp, M_RES(mp));
b872af2c 55 xfs_trans_trace_reservations(mp);
1da177e4
LT
56}
57
b1c1b5b6
DC
58/*
59 * Free the transaction structure. If there is more clean up
60 * to do when the structure is freed, add it here.
61 */
62STATIC void
63xfs_trans_free(
ed3b4d6c 64 struct xfs_trans *tp)
b1c1b5b6 65{
4ecbfe63
DC
66 xfs_extent_busy_sort(&tp->t_busy);
67 xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false);
ed3b4d6c 68
ba18781b 69 trace_xfs_trans_free(tp, _RET_IP_);
b1c1b5b6 70 atomic_dec(&tp->t_mountp->m_active_trans);
253f4911 71 if (!(tp->t_flags & XFS_TRANS_NO_WRITECOUNT))
d9457dc0 72 sb_end_intwrite(tp->t_mountp->m_super);
b1c1b5b6
DC
73 xfs_trans_free_dqinfo(tp);
74 kmem_zone_free(xfs_trans_zone, tp);
75}
76
1da177e4
LT
77/*
78 * This is called to create a new transaction which will share the
79 * permanent log reservation of the given transaction. The remaining
80 * unused block and rt extent reservations are also inherited. This
81 * implies that the original transaction is no longer allowed to allocate
82 * blocks. Locks and log items, however, are no inherited. They must
83 * be added to the new transaction explicitly.
84 */
f8f2835a 85STATIC struct xfs_trans *
1da177e4 86xfs_trans_dup(
f8f2835a 87 struct xfs_trans *tp)
1da177e4 88{
f8f2835a 89 struct xfs_trans *ntp;
1da177e4 90
ba18781b
DC
91 trace_xfs_trans_dup(tp, _RET_IP_);
92
1da177e4
LT
93 ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP);
94
95 /*
96 * Initialize the new transaction structure.
97 */
2a3c0acc 98 ntp->t_magic = XFS_TRANS_HEADER_MAGIC;
1da177e4 99 ntp->t_mountp = tp->t_mountp;
e98c414f 100 INIT_LIST_HEAD(&ntp->t_items);
ed3b4d6c 101 INIT_LIST_HEAD(&ntp->t_busy);
9d9e6233 102 INIT_LIST_HEAD(&ntp->t_dfops);
bba59c5e 103 ntp->t_firstblock = NULLFSBLOCK;
1da177e4
LT
104
105 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
1da177e4 106 ASSERT(tp->t_ticket != NULL);
cfcbbbd0 107
d9457dc0
JK
108 ntp->t_flags = XFS_TRANS_PERM_LOG_RES |
109 (tp->t_flags & XFS_TRANS_RESERVE) |
253f4911 110 (tp->t_flags & XFS_TRANS_NO_WRITECOUNT);
d9457dc0 111 /* We gave our writer reference to the new transaction */
253f4911 112 tp->t_flags |= XFS_TRANS_NO_WRITECOUNT;
cc09c0dc 113 ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket);
3e78b9a4
BF
114
115 ASSERT(tp->t_blk_res >= tp->t_blk_res_used);
1da177e4
LT
116 ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used;
117 tp->t_blk_res = tp->t_blk_res_used;
3e78b9a4 118
1da177e4
LT
119 ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used;
120 tp->t_rtx_res = tp->t_rtx_res_used;
59c1b082 121 ntp->t_pflags = tp->t_pflags;
e021a2e5 122
9d9e6233
BF
123 /* move deferred ops over to the new tp */
124 xfs_defer_move(ntp, tp);
1da177e4 125
7d095257 126 xfs_trans_dup_dqinfo(tp, ntp);
1da177e4
LT
127
128 atomic_inc(&tp->t_mountp->m_active_trans);
129 return ntp;
130}
131
132/*
133 * This is called to reserve free disk blocks and log space for the
134 * given transaction. This must be done before allocating any resources
135 * within the transaction.
136 *
137 * This will return ENOSPC if there are not enough blocks available.
138 * It will sleep waiting for available log space.
139 * The only valid value for the flags parameter is XFS_RES_LOG_PERM, which
140 * is used by long running transactions. If any one of the reservations
141 * fails then they will all be backed out.
142 *
143 * This does not do quota reservations. That typically is done by the
144 * caller afterwards.
145 */
253f4911 146static int
1da177e4 147xfs_trans_reserve(
3d3c8b52
JL
148 struct xfs_trans *tp,
149 struct xfs_trans_res *resp,
150 uint blocks,
151 uint rtextents)
1da177e4 152{
59c1b082 153 int error = 0;
0d485ada 154 bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
1da177e4
LT
155
156 /* Mark this thread as being in a transaction */
9070733b 157 current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
1da177e4
LT
158
159 /*
160 * Attempt to reserve the needed disk blocks by decrementing
161 * the number needed from the number available. This will
162 * fail if the count would go below zero.
163 */
164 if (blocks > 0) {
0d485ada 165 error = xfs_mod_fdblocks(tp->t_mountp, -((int64_t)blocks), rsvd);
1da177e4 166 if (error != 0) {
9070733b 167 current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
2451337d 168 return -ENOSPC;
1da177e4
LT
169 }
170 tp->t_blk_res += blocks;
171 }
172
173 /*
174 * Reserve the log space needed for this transaction.
175 */
3d3c8b52 176 if (resp->tr_logres > 0) {
9006fb91
CH
177 bool permanent = false;
178
3d3c8b52
JL
179 ASSERT(tp->t_log_res == 0 ||
180 tp->t_log_res == resp->tr_logres);
181 ASSERT(tp->t_log_count == 0 ||
182 tp->t_log_count == resp->tr_logcount);
9006fb91 183
3d3c8b52 184 if (resp->tr_logflags & XFS_TRANS_PERM_LOG_RES) {
1da177e4 185 tp->t_flags |= XFS_TRANS_PERM_LOG_RES;
9006fb91 186 permanent = true;
1da177e4
LT
187 } else {
188 ASSERT(tp->t_ticket == NULL);
189 ASSERT(!(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
1da177e4
LT
190 }
191
9006fb91 192 if (tp->t_ticket != NULL) {
3d3c8b52 193 ASSERT(resp->tr_logflags & XFS_TRANS_PERM_LOG_RES);
9006fb91
CH
194 error = xfs_log_regrant(tp->t_mountp, tp->t_ticket);
195 } else {
3d3c8b52
JL
196 error = xfs_log_reserve(tp->t_mountp,
197 resp->tr_logres,
198 resp->tr_logcount,
199 &tp->t_ticket, XFS_TRANSACTION,
710b1e2c 200 permanent);
1da177e4 201 }
9006fb91
CH
202
203 if (error)
204 goto undo_blocks;
205
3d3c8b52
JL
206 tp->t_log_res = resp->tr_logres;
207 tp->t_log_count = resp->tr_logcount;
1da177e4
LT
208 }
209
210 /*
211 * Attempt to reserve the needed realtime extents by decrementing
212 * the number needed from the number available. This will
213 * fail if the count would go below zero.
214 */
215 if (rtextents > 0) {
bab98bbe 216 error = xfs_mod_frextents(tp->t_mountp, -((int64_t)rtextents));
1da177e4 217 if (error) {
2451337d 218 error = -ENOSPC;
1da177e4
LT
219 goto undo_log;
220 }
221 tp->t_rtx_res += rtextents;
222 }
223
224 return 0;
225
226 /*
227 * Error cases jump to one of these labels to undo any
228 * reservations which have already been performed.
229 */
230undo_log:
3d3c8b52 231 if (resp->tr_logres > 0) {
f78c3901 232 xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, false);
1da177e4
LT
233 tp->t_ticket = NULL;
234 tp->t_log_res = 0;
235 tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES;
236 }
237
238undo_blocks:
239 if (blocks > 0) {
a27f6ef4 240 xfs_mod_fdblocks(tp->t_mountp, (int64_t)blocks, rsvd);
1da177e4
LT
241 tp->t_blk_res = 0;
242 }
243
9070733b 244 current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
1da177e4 245
59c1b082 246 return error;
1da177e4
LT
247}
248
253f4911
CH
249int
250xfs_trans_alloc(
251 struct xfs_mount *mp,
252 struct xfs_trans_res *resp,
253 uint blocks,
254 uint rtextents,
255 uint flags,
256 struct xfs_trans **tpp)
257{
258 struct xfs_trans *tp;
259 int error;
260
8683edb7
DC
261 /*
262 * Allocate the handle before we do our freeze accounting and setting up
263 * GFP_NOFS allocation context so that we avoid lockdep false positives
264 * by doing GFP_KERNEL allocations inside sb_start_intwrite().
265 */
266 tp = kmem_zone_zalloc(xfs_trans_zone,
267 (flags & XFS_TRANS_NOFS) ? KM_NOFS : KM_SLEEP);
268
253f4911
CH
269 if (!(flags & XFS_TRANS_NO_WRITECOUNT))
270 sb_start_intwrite(mp->m_super);
271
10ee2526
DW
272 /*
273 * Zero-reservation ("empty") transactions can't modify anything, so
274 * they're allowed to run while we're frozen.
275 */
276 WARN_ON(resp->tr_logres > 0 &&
277 mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
253f4911
CH
278 atomic_inc(&mp->m_active_trans);
279
253f4911
CH
280 tp->t_magic = XFS_TRANS_HEADER_MAGIC;
281 tp->t_flags = flags;
282 tp->t_mountp = mp;
283 INIT_LIST_HEAD(&tp->t_items);
284 INIT_LIST_HEAD(&tp->t_busy);
9d9e6233 285 INIT_LIST_HEAD(&tp->t_dfops);
bba59c5e 286 tp->t_firstblock = NULLFSBLOCK;
253f4911
CH
287
288 error = xfs_trans_reserve(tp, resp, blocks, rtextents);
289 if (error) {
290 xfs_trans_cancel(tp);
291 return error;
292 }
293
ba18781b
DC
294 trace_xfs_trans_alloc(tp, _RET_IP_);
295
253f4911
CH
296 *tpp = tp;
297 return 0;
298}
299
e89c0413
DW
300/*
301 * Create an empty transaction with no reservation. This is a defensive
302 * mechanism for routines that query metadata without actually modifying
303 * them -- if the metadata being queried is somehow cross-linked (think a
304 * btree block pointer that points higher in the tree), we risk deadlock.
305 * However, blocks grabbed as part of a transaction can be re-grabbed.
306 * The verifiers will notice the corrupt block and the operation will fail
307 * back to userspace without deadlocking.
308 *
309 * Note the zero-length reservation; this transaction MUST be cancelled
310 * without any dirty data.
311 */
312int
313xfs_trans_alloc_empty(
314 struct xfs_mount *mp,
315 struct xfs_trans **tpp)
316{
317 struct xfs_trans_res resv = {0};
318
319 return xfs_trans_alloc(mp, &resv, 0, 0, XFS_TRANS_NO_WRITECOUNT, tpp);
320}
321
1da177e4
LT
322/*
323 * Record the indicated change to the given field for application
324 * to the file system's superblock when the transaction commits.
325 * For now, just store the change in the transaction structure.
326 *
327 * Mark the transaction structure to indicate that the superblock
328 * needs to be updated before committing.
92821e2b
DC
329 *
330 * Because we may not be keeping track of allocated/free inodes and
331 * used filesystem blocks in the superblock, we do not mark the
332 * superblock dirty in this transaction if we modify these fields.
333 * We still need to update the transaction deltas so that they get
334 * applied to the incore superblock, but we don't want them to
335 * cause the superblock to get locked and logged if these are the
336 * only fields in the superblock that the transaction modifies.
1da177e4
LT
337 */
338void
339xfs_trans_mod_sb(
340 xfs_trans_t *tp,
341 uint field,
20f4ebf2 342 int64_t delta)
1da177e4 343{
92821e2b
DC
344 uint32_t flags = (XFS_TRANS_DIRTY|XFS_TRANS_SB_DIRTY);
345 xfs_mount_t *mp = tp->t_mountp;
1da177e4
LT
346
347 switch (field) {
348 case XFS_TRANS_SB_ICOUNT:
349 tp->t_icount_delta += delta;
92821e2b
DC
350 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
351 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
352 break;
353 case XFS_TRANS_SB_IFREE:
354 tp->t_ifree_delta += delta;
92821e2b
DC
355 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
356 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
357 break;
358 case XFS_TRANS_SB_FDBLOCKS:
359 /*
3e78b9a4
BF
360 * Track the number of blocks allocated in the transaction.
361 * Make sure it does not exceed the number reserved. If so,
362 * shutdown as this can lead to accounting inconsistency.
1da177e4
LT
363 */
364 if (delta < 0) {
365 tp->t_blk_res_used += (uint)-delta;
3e78b9a4
BF
366 if (tp->t_blk_res_used > tp->t_blk_res)
367 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1da177e4
LT
368 }
369 tp->t_fdblocks_delta += delta;
92821e2b
DC
370 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
371 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
372 break;
373 case XFS_TRANS_SB_RES_FDBLOCKS:
374 /*
375 * The allocation has already been applied to the
376 * in-core superblock's counter. This should only
377 * be applied to the on-disk superblock.
378 */
1da177e4 379 tp->t_res_fdblocks_delta += delta;
92821e2b
DC
380 if (xfs_sb_version_haslazysbcount(&mp->m_sb))
381 flags &= ~XFS_TRANS_SB_DIRTY;
1da177e4
LT
382 break;
383 case XFS_TRANS_SB_FREXTENTS:
384 /*
385 * Track the number of blocks allocated in the
386 * transaction. Make sure it does not exceed the
387 * number reserved.
388 */
389 if (delta < 0) {
390 tp->t_rtx_res_used += (uint)-delta;
391 ASSERT(tp->t_rtx_res_used <= tp->t_rtx_res);
392 }
393 tp->t_frextents_delta += delta;
394 break;
395 case XFS_TRANS_SB_RES_FREXTENTS:
396 /*
397 * The allocation has already been applied to the
c41564b5 398 * in-core superblock's counter. This should only
1da177e4
LT
399 * be applied to the on-disk superblock.
400 */
401 ASSERT(delta < 0);
402 tp->t_res_frextents_delta += delta;
403 break;
404 case XFS_TRANS_SB_DBLOCKS:
405 ASSERT(delta > 0);
406 tp->t_dblocks_delta += delta;
407 break;
408 case XFS_TRANS_SB_AGCOUNT:
409 ASSERT(delta > 0);
410 tp->t_agcount_delta += delta;
411 break;
412 case XFS_TRANS_SB_IMAXPCT:
413 tp->t_imaxpct_delta += delta;
414 break;
415 case XFS_TRANS_SB_REXTSIZE:
416 tp->t_rextsize_delta += delta;
417 break;
418 case XFS_TRANS_SB_RBMBLOCKS:
419 tp->t_rbmblocks_delta += delta;
420 break;
421 case XFS_TRANS_SB_RBLOCKS:
422 tp->t_rblocks_delta += delta;
423 break;
424 case XFS_TRANS_SB_REXTENTS:
425 tp->t_rextents_delta += delta;
426 break;
427 case XFS_TRANS_SB_REXTSLOG:
428 tp->t_rextslog_delta += delta;
429 break;
430 default:
431 ASSERT(0);
432 return;
433 }
434
210c6f1c 435 tp->t_flags |= flags;
1da177e4
LT
436}
437
438/*
439 * xfs_trans_apply_sb_deltas() is called from the commit code
440 * to bring the superblock buffer into the current transaction
441 * and modify it as requested by earlier calls to xfs_trans_mod_sb().
442 *
443 * For now we just look at each field allowed to change and change
444 * it if necessary.
445 */
446STATIC void
447xfs_trans_apply_sb_deltas(
448 xfs_trans_t *tp)
449{
2bdf7cd0 450 xfs_dsb_t *sbp;
1da177e4
LT
451 xfs_buf_t *bp;
452 int whole = 0;
453
8c9ce2f7 454 bp = xfs_trans_getsb(tp, tp->t_mountp);
1da177e4
LT
455 sbp = XFS_BUF_TO_SBP(bp);
456
457 /*
458 * Check that superblock mods match the mods made to AGF counters.
459 */
460 ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
461 (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
462 tp->t_ag_btree_delta));
463
92821e2b
DC
464 /*
465 * Only update the superblock counters if we are logging them
466 */
467 if (!xfs_sb_version_haslazysbcount(&(tp->t_mountp->m_sb))) {
2bdf7cd0 468 if (tp->t_icount_delta)
413d57c9 469 be64_add_cpu(&sbp->sb_icount, tp->t_icount_delta);
2bdf7cd0 470 if (tp->t_ifree_delta)
413d57c9 471 be64_add_cpu(&sbp->sb_ifree, tp->t_ifree_delta);
2bdf7cd0 472 if (tp->t_fdblocks_delta)
413d57c9 473 be64_add_cpu(&sbp->sb_fdblocks, tp->t_fdblocks_delta);
2bdf7cd0 474 if (tp->t_res_fdblocks_delta)
413d57c9 475 be64_add_cpu(&sbp->sb_fdblocks, tp->t_res_fdblocks_delta);
1da177e4
LT
476 }
477
2bdf7cd0 478 if (tp->t_frextents_delta)
413d57c9 479 be64_add_cpu(&sbp->sb_frextents, tp->t_frextents_delta);
2bdf7cd0 480 if (tp->t_res_frextents_delta)
413d57c9 481 be64_add_cpu(&sbp->sb_frextents, tp->t_res_frextents_delta);
2bdf7cd0
CH
482
483 if (tp->t_dblocks_delta) {
413d57c9 484 be64_add_cpu(&sbp->sb_dblocks, tp->t_dblocks_delta);
1da177e4
LT
485 whole = 1;
486 }
2bdf7cd0 487 if (tp->t_agcount_delta) {
413d57c9 488 be32_add_cpu(&sbp->sb_agcount, tp->t_agcount_delta);
1da177e4
LT
489 whole = 1;
490 }
2bdf7cd0
CH
491 if (tp->t_imaxpct_delta) {
492 sbp->sb_imax_pct += tp->t_imaxpct_delta;
1da177e4
LT
493 whole = 1;
494 }
2bdf7cd0 495 if (tp->t_rextsize_delta) {
413d57c9 496 be32_add_cpu(&sbp->sb_rextsize, tp->t_rextsize_delta);
1da177e4
LT
497 whole = 1;
498 }
2bdf7cd0 499 if (tp->t_rbmblocks_delta) {
413d57c9 500 be32_add_cpu(&sbp->sb_rbmblocks, tp->t_rbmblocks_delta);
1da177e4
LT
501 whole = 1;
502 }
2bdf7cd0 503 if (tp->t_rblocks_delta) {
413d57c9 504 be64_add_cpu(&sbp->sb_rblocks, tp->t_rblocks_delta);
1da177e4
LT
505 whole = 1;
506 }
2bdf7cd0 507 if (tp->t_rextents_delta) {
413d57c9 508 be64_add_cpu(&sbp->sb_rextents, tp->t_rextents_delta);
1da177e4
LT
509 whole = 1;
510 }
2bdf7cd0
CH
511 if (tp->t_rextslog_delta) {
512 sbp->sb_rextslog += tp->t_rextslog_delta;
1da177e4
LT
513 whole = 1;
514 }
515
3443a3bc 516 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
1da177e4
LT
517 if (whole)
518 /*
c41564b5 519 * Log the whole thing, the fields are noncontiguous.
1da177e4 520 */
2bdf7cd0 521 xfs_trans_log_buf(tp, bp, 0, sizeof(xfs_dsb_t) - 1);
1da177e4
LT
522 else
523 /*
524 * Since all the modifiable fields are contiguous, we
525 * can get away with this.
526 */
2bdf7cd0
CH
527 xfs_trans_log_buf(tp, bp, offsetof(xfs_dsb_t, sb_icount),
528 offsetof(xfs_dsb_t, sb_frextents) +
1da177e4 529 sizeof(sbp->sb_frextents) - 1);
1da177e4
LT
530}
531
0bd5dded
DC
532STATIC int
533xfs_sb_mod8(
534 uint8_t *field,
535 int8_t delta)
536{
537 int8_t counter = *field;
538
539 counter += delta;
540 if (counter < 0) {
541 ASSERT(0);
542 return -EINVAL;
543 }
544 *field = counter;
545 return 0;
546}
547
548STATIC int
549xfs_sb_mod32(
550 uint32_t *field,
551 int32_t delta)
552{
553 int32_t counter = *field;
554
555 counter += delta;
556 if (counter < 0) {
557 ASSERT(0);
558 return -EINVAL;
559 }
560 *field = counter;
561 return 0;
562}
563
564STATIC int
565xfs_sb_mod64(
566 uint64_t *field,
567 int64_t delta)
568{
569 int64_t counter = *field;
570
571 counter += delta;
572 if (counter < 0) {
573 ASSERT(0);
574 return -EINVAL;
575 }
576 *field = counter;
577 return 0;
578}
579
1da177e4 580/*
45c34141
DC
581 * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations
582 * and apply superblock counter changes to the in-core superblock. The
583 * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT
584 * applied to the in-core superblock. The idea is that that has already been
585 * done.
1da177e4 586 *
45c34141
DC
587 * If we are not logging superblock counters, then the inode allocated/free and
588 * used block counts are not updated in the on disk superblock. In this case,
589 * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we
590 * still need to update the incore superblock with the changes.
1da177e4 591 */
71e330b5 592void
1da177e4 593xfs_trans_unreserve_and_mod_sb(
0bd5dded 594 struct xfs_trans *tp)
1da177e4 595{
0bd5dded
DC
596 struct xfs_mount *mp = tp->t_mountp;
597 bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
598 int64_t blkdelta = 0;
599 int64_t rtxdelta = 0;
600 int64_t idelta = 0;
601 int64_t ifreedelta = 0;
602 int error;
1da177e4 603
1b040712 604 /* calculate deltas */
45c34141
DC
605 if (tp->t_blk_res > 0)
606 blkdelta = tp->t_blk_res;
45c34141
DC
607 if ((tp->t_fdblocks_delta != 0) &&
608 (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
609 (tp->t_flags & XFS_TRANS_SB_DIRTY)))
610 blkdelta += tp->t_fdblocks_delta;
611
45c34141
DC
612 if (tp->t_rtx_res > 0)
613 rtxdelta = tp->t_rtx_res;
45c34141
DC
614 if ((tp->t_frextents_delta != 0) &&
615 (tp->t_flags & XFS_TRANS_SB_DIRTY))
616 rtxdelta += tp->t_frextents_delta;
617
1b040712
CH
618 if (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
619 (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
620 idelta = tp->t_icount_delta;
621 ifreedelta = tp->t_ifree_delta;
622 }
623
624 /* apply the per-cpu counters */
625 if (blkdelta) {
0d485ada 626 error = xfs_mod_fdblocks(mp, blkdelta, rsvd);
1b040712
CH
627 if (error)
628 goto out;
629 }
630
631 if (idelta) {
501ab323 632 error = xfs_mod_icount(mp, idelta);
1b040712
CH
633 if (error)
634 goto out_undo_fdblocks;
635 }
636
637 if (ifreedelta) {
e88b64ea 638 error = xfs_mod_ifree(mp, ifreedelta);
1b040712
CH
639 if (error)
640 goto out_undo_icount;
641 }
642
0bd5dded
DC
643 if (rtxdelta == 0 && !(tp->t_flags & XFS_TRANS_SB_DIRTY))
644 return;
645
1b040712 646 /* apply remaining deltas */
0bd5dded 647 spin_lock(&mp->m_sb_lock);
bab98bbe 648 if (rtxdelta) {
0bd5dded 649 error = xfs_sb_mod64(&mp->m_sb.sb_frextents, rtxdelta);
bab98bbe
DC
650 if (error)
651 goto out_undo_ifree;
1da177e4
LT
652 }
653
0bd5dded
DC
654 if (tp->t_dblocks_delta != 0) {
655 error = xfs_sb_mod64(&mp->m_sb.sb_dblocks, tp->t_dblocks_delta);
1b040712 656 if (error)
bab98bbe 657 goto out_undo_frextents;
1da177e4 658 }
0bd5dded
DC
659 if (tp->t_agcount_delta != 0) {
660 error = xfs_sb_mod32(&mp->m_sb.sb_agcount, tp->t_agcount_delta);
661 if (error)
662 goto out_undo_dblocks;
663 }
664 if (tp->t_imaxpct_delta != 0) {
665 error = xfs_sb_mod8(&mp->m_sb.sb_imax_pct, tp->t_imaxpct_delta);
666 if (error)
667 goto out_undo_agcount;
668 }
669 if (tp->t_rextsize_delta != 0) {
670 error = xfs_sb_mod32(&mp->m_sb.sb_rextsize,
671 tp->t_rextsize_delta);
672 if (error)
673 goto out_undo_imaxpct;
674 }
675 if (tp->t_rbmblocks_delta != 0) {
676 error = xfs_sb_mod32(&mp->m_sb.sb_rbmblocks,
677 tp->t_rbmblocks_delta);
678 if (error)
679 goto out_undo_rextsize;
680 }
681 if (tp->t_rblocks_delta != 0) {
682 error = xfs_sb_mod64(&mp->m_sb.sb_rblocks, tp->t_rblocks_delta);
683 if (error)
684 goto out_undo_rbmblocks;
685 }
686 if (tp->t_rextents_delta != 0) {
687 error = xfs_sb_mod64(&mp->m_sb.sb_rextents,
688 tp->t_rextents_delta);
689 if (error)
690 goto out_undo_rblocks;
691 }
692 if (tp->t_rextslog_delta != 0) {
693 error = xfs_sb_mod8(&mp->m_sb.sb_rextslog,
694 tp->t_rextslog_delta);
695 if (error)
696 goto out_undo_rextents;
697 }
698 spin_unlock(&mp->m_sb_lock);
1b040712
CH
699 return;
700
0bd5dded
DC
701out_undo_rextents:
702 if (tp->t_rextents_delta)
703 xfs_sb_mod64(&mp->m_sb.sb_rextents, -tp->t_rextents_delta);
704out_undo_rblocks:
705 if (tp->t_rblocks_delta)
706 xfs_sb_mod64(&mp->m_sb.sb_rblocks, -tp->t_rblocks_delta);
707out_undo_rbmblocks:
708 if (tp->t_rbmblocks_delta)
709 xfs_sb_mod32(&mp->m_sb.sb_rbmblocks, -tp->t_rbmblocks_delta);
710out_undo_rextsize:
711 if (tp->t_rextsize_delta)
712 xfs_sb_mod32(&mp->m_sb.sb_rextsize, -tp->t_rextsize_delta);
713out_undo_imaxpct:
714 if (tp->t_rextsize_delta)
715 xfs_sb_mod8(&mp->m_sb.sb_imax_pct, -tp->t_imaxpct_delta);
716out_undo_agcount:
717 if (tp->t_agcount_delta)
718 xfs_sb_mod32(&mp->m_sb.sb_agcount, -tp->t_agcount_delta);
719out_undo_dblocks:
720 if (tp->t_dblocks_delta)
721 xfs_sb_mod64(&mp->m_sb.sb_dblocks, -tp->t_dblocks_delta);
bab98bbe
DC
722out_undo_frextents:
723 if (rtxdelta)
0bd5dded 724 xfs_sb_mod64(&mp->m_sb.sb_frextents, -rtxdelta);
bab98bbe 725out_undo_ifree:
0bd5dded 726 spin_unlock(&mp->m_sb_lock);
1b040712 727 if (ifreedelta)
e88b64ea 728 xfs_mod_ifree(mp, -ifreedelta);
1b040712
CH
729out_undo_icount:
730 if (idelta)
501ab323 731 xfs_mod_icount(mp, -idelta);
1b040712
CH
732out_undo_fdblocks:
733 if (blkdelta)
0d485ada 734 xfs_mod_fdblocks(mp, -blkdelta, rsvd);
1b040712 735out:
1884bd83 736 ASSERT(error == 0);
1b040712 737 return;
1da177e4
LT
738}
739
e6631f85 740/* Add the given log item to the transaction's list of log items. */
e98c414f
CH
741void
742xfs_trans_add_item(
743 struct xfs_trans *tp,
744 struct xfs_log_item *lip)
745{
f65020a8
JJ
746 ASSERT(lip->li_mountp == tp->t_mountp);
747 ASSERT(lip->li_ailp == tp->t_mountp->m_ail);
e6631f85
DC
748 ASSERT(list_empty(&lip->li_trans));
749 ASSERT(!test_bit(XFS_LI_DIRTY, &lip->li_flags));
e98c414f 750
e6631f85 751 list_add_tail(&lip->li_trans, &tp->t_items);
ba18781b 752 trace_xfs_trans_add_item(tp, _RET_IP_);
e98c414f
CH
753}
754
e98c414f 755/*
e6631f85
DC
756 * Unlink the log item from the transaction. the log item is no longer
757 * considered dirty in this transaction, as the linked transaction has
758 * finished, either by abort or commit completion.
e98c414f
CH
759 */
760void
761xfs_trans_del_item(
762 struct xfs_log_item *lip)
763{
e6631f85
DC
764 clear_bit(XFS_LI_DIRTY, &lip->li_flags);
765 list_del_init(&lip->li_trans);
e98c414f
CH
766}
767
e6631f85 768/* Detach and unlock all of the items in a transaction */
195cd83d 769static void
e98c414f
CH
770xfs_trans_free_items(
771 struct xfs_trans *tp,
eacb24e7 772 bool abort)
e98c414f 773{
e6631f85 774 struct xfs_log_item *lip, *next;
e98c414f 775
ba18781b
DC
776 trace_xfs_trans_free_items(tp, _RET_IP_);
777
e6631f85
DC
778 list_for_each_entry_safe(lip, next, &tp->t_items, li_trans) {
779 xfs_trans_del_item(lip);
eacb24e7 780 if (abort)
22525c17 781 set_bit(XFS_LI_ABORTED, &lip->li_flags);
ddf92053
CH
782 if (lip->li_ops->iop_release)
783 lip->li_ops->iop_release(lip);
e98c414f
CH
784 }
785}
786
0e57f6a3
DC
787static inline void
788xfs_log_item_batch_insert(
789 struct xfs_ail *ailp,
1d8c95a3 790 struct xfs_ail_cursor *cur,
0e57f6a3
DC
791 struct xfs_log_item **log_items,
792 int nr_items,
793 xfs_lsn_t commit_lsn)
794{
795 int i;
796
57e80956
MW
797 spin_lock(&ailp->ail_lock);
798 /* xfs_trans_ail_update_bulk drops ailp->ail_lock */
1d8c95a3 799 xfs_trans_ail_update_bulk(ailp, cur, log_items, nr_items, commit_lsn);
0e57f6a3 800
904c17e6
DC
801 for (i = 0; i < nr_items; i++) {
802 struct xfs_log_item *lip = log_items[i];
803
e8b78db7
CH
804 if (lip->li_ops->iop_unpin)
805 lip->li_ops->iop_unpin(lip, 0);
904c17e6 806 }
0e57f6a3
DC
807}
808
809/*
810 * Bulk operation version of xfs_trans_committed that takes a log vector of
811 * items to insert into the AIL. This uses bulk AIL insertion techniques to
812 * minimise lock traffic.
e34a314c
DC
813 *
814 * If we are called with the aborted flag set, it is because a log write during
815 * a CIL checkpoint commit has failed. In this case, all the items in the
ddf92053 816 * checkpoint have already gone through iop_committed and iop_committing, which
e34a314c
DC
817 * means that checkpoint commit abort handling is treated exactly the same
818 * as an iclog write error even though we haven't started any IO yet. Hence in
904c17e6
DC
819 * this case all we need to do is iop_committed processing, followed by an
820 * iop_unpin(aborted) call.
1d8c95a3
DC
821 *
822 * The AIL cursor is used to optimise the insert process. If commit_lsn is not
823 * at the end of the AIL, the insert cursor avoids the need to walk
824 * the AIL to find the insertion point on every xfs_log_item_batch_insert()
825 * call. This saves a lot of needless list walking and is a net win, even
826 * though it slightly increases that amount of AIL lock traffic to set it up
827 * and tear it down.
0e57f6a3
DC
828 */
829void
830xfs_trans_committed_bulk(
831 struct xfs_ail *ailp,
832 struct xfs_log_vec *log_vector,
833 xfs_lsn_t commit_lsn,
d15cbf2f 834 bool aborted)
0e57f6a3
DC
835{
836#define LOG_ITEM_BATCH_SIZE 32
837 struct xfs_log_item *log_items[LOG_ITEM_BATCH_SIZE];
838 struct xfs_log_vec *lv;
1d8c95a3 839 struct xfs_ail_cursor cur;
0e57f6a3
DC
840 int i = 0;
841
57e80956 842 spin_lock(&ailp->ail_lock);
1d8c95a3 843 xfs_trans_ail_cursor_last(ailp, &cur, commit_lsn);
57e80956 844 spin_unlock(&ailp->ail_lock);
1d8c95a3 845
0e57f6a3
DC
846 /* unpin all the log items */
847 for (lv = log_vector; lv; lv = lv->lv_next ) {
848 struct xfs_log_item *lip = lv->lv_item;
849 xfs_lsn_t item_lsn;
850
851 if (aborted)
22525c17 852 set_bit(XFS_LI_ABORTED, &lip->li_flags);
9ce632a2
CH
853
854 if (lip->li_ops->flags & XFS_ITEM_RELEASE_WHEN_COMMITTED) {
855 lip->li_ops->iop_release(lip);
856 continue;
857 }
858
e8b78db7
CH
859 if (lip->li_ops->iop_committed)
860 item_lsn = lip->li_ops->iop_committed(lip, commit_lsn);
861 else
862 item_lsn = commit_lsn;
0e57f6a3 863
1316d4da 864 /* item_lsn of -1 means the item needs no further processing */
0e57f6a3
DC
865 if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0)
866 continue;
867
e34a314c
DC
868 /*
869 * if we are aborting the operation, no point in inserting the
870 * object into the AIL as we are in a shutdown situation.
871 */
872 if (aborted) {
57e80956 873 ASSERT(XFS_FORCED_SHUTDOWN(ailp->ail_mount));
e8b78db7
CH
874 if (lip->li_ops->iop_unpin)
875 lip->li_ops->iop_unpin(lip, 1);
e34a314c
DC
876 continue;
877 }
878
0e57f6a3
DC
879 if (item_lsn != commit_lsn) {
880
881 /*
882 * Not a bulk update option due to unusual item_lsn.
883 * Push into AIL immediately, rechecking the lsn once
1d8c95a3
DC
884 * we have the ail lock. Then unpin the item. This does
885 * not affect the AIL cursor the bulk insert path is
886 * using.
0e57f6a3 887 */
57e80956 888 spin_lock(&ailp->ail_lock);
0e57f6a3
DC
889 if (XFS_LSN_CMP(item_lsn, lip->li_lsn) > 0)
890 xfs_trans_ail_update(ailp, lip, item_lsn);
891 else
57e80956 892 spin_unlock(&ailp->ail_lock);
e8b78db7
CH
893 if (lip->li_ops->iop_unpin)
894 lip->li_ops->iop_unpin(lip, 0);
0e57f6a3
DC
895 continue;
896 }
897
898 /* Item is a candidate for bulk AIL insert. */
899 log_items[i++] = lv->lv_item;
900 if (i >= LOG_ITEM_BATCH_SIZE) {
1d8c95a3 901 xfs_log_item_batch_insert(ailp, &cur, log_items,
0e57f6a3
DC
902 LOG_ITEM_BATCH_SIZE, commit_lsn);
903 i = 0;
904 }
905 }
906
907 /* make sure we insert the remainder! */
908 if (i)
1d8c95a3
DC
909 xfs_log_item_batch_insert(ailp, &cur, log_items, i, commit_lsn);
910
57e80956 911 spin_lock(&ailp->ail_lock);
e4a1e29c 912 xfs_trans_ail_cursor_done(&cur);
57e80956 913 spin_unlock(&ailp->ail_lock);
0e57f6a3
DC
914}
915
0924378a 916/*
b1037058 917 * Commit the given transaction to the log.
0924378a
DC
918 *
919 * XFS disk error handling mechanism is not based on a typical
920 * transaction abort mechanism. Logically after the filesystem
921 * gets marked 'SHUTDOWN', we can't let any new transactions
922 * be durable - ie. committed to disk - because some metadata might
923 * be inconsistent. In such cases, this returns an error, and the
924 * caller may assume that all locked objects joined to the transaction
925 * have already been unlocked as if the commit had succeeded.
926 * Do not reference the transaction structure after this call.
927 */
70393313
CH
928static int
929__xfs_trans_commit(
a3ccd2ca 930 struct xfs_trans *tp,
70393313 931 bool regrant)
0924378a 932{
a3ccd2ca 933 struct xfs_mount *mp = tp->t_mountp;
0924378a 934 xfs_lsn_t commit_lsn = -1;
a3ccd2ca 935 int error = 0;
0924378a 936 int sync = tp->t_flags & XFS_TRANS_SYNC;
0924378a 937
ba18781b
DC
938 trace_xfs_trans_commit(tp, _RET_IP_);
939
98719051
BF
940 /*
941 * Finish deferred items on final commit. Only permanent transactions
942 * should ever have deferred ops.
943 */
9d9e6233 944 WARN_ON_ONCE(!list_empty(&tp->t_dfops) &&
98719051
BF
945 !(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
946 if (!regrant && (tp->t_flags & XFS_TRANS_PERM_LOG_RES)) {
b277c37f 947 error = xfs_defer_finish_noroll(&tp);
9b1f4e98 948 if (error)
e021a2e5 949 goto out_unreserve;
e021a2e5
BF
950 }
951
0924378a
DC
952 /*
953 * If there is nothing to be logged by the transaction,
954 * then unlock all of the items associated with the
955 * transaction and free the transaction structure.
956 * Also make sure to return any reserved blocks to
957 * the free pool.
958 */
a3ccd2ca
CH
959 if (!(tp->t_flags & XFS_TRANS_DIRTY))
960 goto out_unreserve;
961
962 if (XFS_FORCED_SHUTDOWN(mp)) {
2451337d 963 error = -EIO;
a3ccd2ca 964 goto out_unreserve;
0924378a 965 }
a3ccd2ca 966
0924378a
DC
967 ASSERT(tp->t_ticket != NULL);
968
969 /*
970 * If we need to update the superblock, then do it now.
971 */
972 if (tp->t_flags & XFS_TRANS_SB_DIRTY)
973 xfs_trans_apply_sb_deltas(tp);
974 xfs_trans_apply_dquot_deltas(tp);
975
70393313 976 xfs_log_commit_cil(mp, tp, &commit_lsn, regrant);
1da177e4 977
9070733b 978 current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
0244b960
CH
979 xfs_trans_free(tp);
980
1da177e4
LT
981 /*
982 * If the transaction needs to be synchronous, then force the
983 * log out now and wait for it.
984 */
985 if (sync) {
656de4ff 986 error = xfs_log_force_lsn(mp, commit_lsn, XFS_LOG_SYNC, NULL);
ff6d6af2 987 XFS_STATS_INC(mp, xs_trans_sync);
1da177e4 988 } else {
ff6d6af2 989 XFS_STATS_INC(mp, xs_trans_async);
1da177e4
LT
990 }
991
a3ccd2ca
CH
992 return error;
993
994out_unreserve:
995 xfs_trans_unreserve_and_mod_sb(tp);
996
997 /*
998 * It is indeed possible for the transaction to be not dirty but
999 * the dqinfo portion to be. All that means is that we have some
1000 * (non-persistent) quota reservations that need to be unreserved.
1001 */
1002 xfs_trans_unreserve_and_mod_dquots(tp);
1003 if (tp->t_ticket) {
f78c3901 1004 commit_lsn = xfs_log_done(mp, tp->t_ticket, NULL, regrant);
a3ccd2ca 1005 if (commit_lsn == -1 && !error)
2451337d 1006 error = -EIO;
ba18781b 1007 tp->t_ticket = NULL;
a3ccd2ca 1008 }
9070733b 1009 current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
195cd83d 1010 xfs_trans_free_items(tp, !!error);
a3ccd2ca
CH
1011 xfs_trans_free(tp);
1012
ff6d6af2 1013 XFS_STATS_INC(mp, xs_trans_empty);
a3ccd2ca 1014 return error;
1da177e4
LT
1015}
1016
70393313
CH
1017int
1018xfs_trans_commit(
1019 struct xfs_trans *tp)
1020{
1021 return __xfs_trans_commit(tp, false);
1022}
1023
1da177e4
LT
1024/*
1025 * Unlock all of the transaction's items and free the transaction.
1026 * The transaction must not have modified any of its items, because
1027 * there is no way to restore them to their previous state.
1028 *
1029 * If the transaction has made a log reservation, make sure to release
1030 * it as well.
1031 */
1032void
1033xfs_trans_cancel(
4906e215 1034 struct xfs_trans *tp)
1da177e4 1035{
4906e215
CH
1036 struct xfs_mount *mp = tp->t_mountp;
1037 bool dirty = (tp->t_flags & XFS_TRANS_DIRTY);
1da177e4 1038
ba18781b
DC
1039 trace_xfs_trans_cancel(tp, _RET_IP_);
1040
98719051 1041 if (tp->t_flags & XFS_TRANS_PERM_LOG_RES)
9e28a242 1042 xfs_defer_cancel(tp);
e021a2e5 1043
1da177e4
LT
1044 /*
1045 * See if the caller is relying on us to shut down the
1046 * filesystem. This happens in paths where we detect
1047 * corruption and decide to give up.
1048 */
4906e215 1049 if (dirty && !XFS_FORCED_SHUTDOWN(mp)) {
0733af21 1050 XFS_ERROR_REPORT("xfs_trans_cancel", XFS_ERRLEVEL_LOW, mp);
7d04a335 1051 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
60a204f0 1052 }
1da177e4 1053#ifdef DEBUG
4906e215 1054 if (!dirty && !XFS_FORCED_SHUTDOWN(mp)) {
e6631f85 1055 struct xfs_log_item *lip;
e98c414f 1056
e6631f85
DC
1057 list_for_each_entry(lip, &tp->t_items, li_trans)
1058 ASSERT(!(lip->li_type == XFS_LI_EFD));
1da177e4
LT
1059 }
1060#endif
1061 xfs_trans_unreserve_and_mod_sb(tp);
7d095257 1062 xfs_trans_unreserve_and_mod_dquots(tp);
1da177e4 1063
ba18781b 1064 if (tp->t_ticket) {
f78c3901 1065 xfs_log_done(mp, tp->t_ticket, NULL, false);
ba18781b
DC
1066 tp->t_ticket = NULL;
1067 }
1da177e4
LT
1068
1069 /* mark this thread as no longer being in a transaction */
9070733b 1070 current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
1da177e4 1071
195cd83d 1072 xfs_trans_free_items(tp, dirty);
1da177e4
LT
1073 xfs_trans_free(tp);
1074}
1075
322ff6b8
NS
1076/*
1077 * Roll from one trans in the sequence of PERMANENT transactions to
1078 * the next: permanent transactions are only flushed out when
70393313 1079 * committed with xfs_trans_commit(), but we still want as soon
322ff6b8
NS
1080 * as possible to let chunks of it go to the log. So we commit the
1081 * chunk we've been working on and get a new transaction to continue.
1082 */
1083int
254133f5 1084xfs_trans_roll(
411350df 1085 struct xfs_trans **tpp)
322ff6b8 1086{
411350df 1087 struct xfs_trans *trans = *tpp;
3d3c8b52 1088 struct xfs_trans_res tres;
322ff6b8
NS
1089 int error;
1090
ba18781b
DC
1091 trace_xfs_trans_roll(trans, _RET_IP_);
1092
322ff6b8
NS
1093 /*
1094 * Copy the critical parameters from one trans to the next.
1095 */
3d3c8b52
JL
1096 tres.tr_logres = trans->t_log_res;
1097 tres.tr_logcount = trans->t_log_count;
411350df 1098
322ff6b8
NS
1099 *tpp = xfs_trans_dup(trans);
1100
1101 /*
1102 * Commit the current transaction.
1103 * If this commit failed, then it'd just unlock those items that
1104 * are not marked ihold. That also means that a filesystem shutdown
1105 * is in progress. The caller takes the responsibility to cancel
1106 * the duplicate transaction that gets returned.
1107 */
70393313 1108 error = __xfs_trans_commit(trans, true);
322ff6b8 1109 if (error)
d99831ff 1110 return error;
322ff6b8 1111
322ff6b8 1112 /*
411350df 1113 * Reserve space in the log for the next transaction.
322ff6b8
NS
1114 * This also pushes items in the "AIL", the list of logged items,
1115 * out to disk if they are taking up space at the tail of the log
1116 * that we want to use. This requires that either nothing be locked
1117 * across this call, or that anything that is locked be logged in
1118 * the prior and the next transactions.
1119 */
3d3c8b52 1120 tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
411350df 1121 return xfs_trans_reserve(*tpp, &tres, 0, 0);
322ff6b8 1122}