[XFS] Remove xfs_macros.c, xfs_macros.h, rework headers a whole lot.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / xfs / xfs_trans.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
1da177e4 32#include "xfs.h"
a844f451 33#include "xfs_fs.h"
1da177e4 34#include "xfs_types.h"
a844f451 35#include "xfs_bit.h"
1da177e4 36#include "xfs_log.h"
a844f451 37#include "xfs_inum.h"
1da177e4
LT
38#include "xfs_trans.h"
39#include "xfs_sb.h"
40#include "xfs_ag.h"
41#include "xfs_dir.h"
42#include "xfs_dir2.h"
43#include "xfs_dmapi.h"
44#include "xfs_mount.h"
45#include "xfs_error.h"
a844f451 46#include "xfs_da_btree.h"
1da177e4 47#include "xfs_bmap_btree.h"
a844f451 48#include "xfs_alloc_btree.h"
1da177e4 49#include "xfs_ialloc_btree.h"
1da177e4
LT
50#include "xfs_dir_sf.h"
51#include "xfs_dir2_sf.h"
a844f451 52#include "xfs_attr_sf.h"
1da177e4
LT
53#include "xfs_dinode.h"
54#include "xfs_inode.h"
a844f451
NS
55#include "xfs_btree.h"
56#include "xfs_ialloc.h"
57#include "xfs_alloc.h"
1da177e4 58#include "xfs_bmap.h"
1da177e4 59#include "xfs_quota.h"
a844f451 60#include "xfs_trans_priv.h"
1da177e4
LT
61#include "xfs_trans_space.h"
62
63
64STATIC void xfs_trans_apply_sb_deltas(xfs_trans_t *);
65STATIC uint xfs_trans_count_vecs(xfs_trans_t *);
66STATIC void xfs_trans_fill_vecs(xfs_trans_t *, xfs_log_iovec_t *);
67STATIC void xfs_trans_uncommit(xfs_trans_t *, uint);
68STATIC void xfs_trans_committed(xfs_trans_t *, int);
69STATIC void xfs_trans_chunk_committed(xfs_log_item_chunk_t *, xfs_lsn_t, int);
70STATIC void xfs_trans_free(xfs_trans_t *);
71
72kmem_zone_t *xfs_trans_zone;
73
74
75/*
76 * Initialize the precomputed transaction reservation values
77 * in the mount structure.
78 */
79void
80xfs_trans_init(
81 xfs_mount_t *mp)
82{
83 xfs_trans_reservations_t *resp;
84
85 resp = &(mp->m_reservations);
86 resp->tr_write =
87 (uint)(XFS_CALC_WRITE_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
88 resp->tr_itruncate =
89 (uint)(XFS_CALC_ITRUNCATE_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
90 resp->tr_rename =
91 (uint)(XFS_CALC_RENAME_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
92 resp->tr_link = (uint)XFS_CALC_LINK_LOG_RES(mp);
93 resp->tr_remove =
94 (uint)(XFS_CALC_REMOVE_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
95 resp->tr_symlink =
96 (uint)(XFS_CALC_SYMLINK_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
97 resp->tr_create =
98 (uint)(XFS_CALC_CREATE_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
99 resp->tr_mkdir =
100 (uint)(XFS_CALC_MKDIR_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
101 resp->tr_ifree =
102 (uint)(XFS_CALC_IFREE_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
103 resp->tr_ichange =
104 (uint)(XFS_CALC_ICHANGE_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
105 resp->tr_growdata = (uint)XFS_CALC_GROWDATA_LOG_RES(mp);
106 resp->tr_swrite = (uint)XFS_CALC_SWRITE_LOG_RES(mp);
107 resp->tr_writeid = (uint)XFS_CALC_WRITEID_LOG_RES(mp);
108 resp->tr_addafork =
109 (uint)(XFS_CALC_ADDAFORK_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
110 resp->tr_attrinval = (uint)XFS_CALC_ATTRINVAL_LOG_RES(mp);
111 resp->tr_attrset =
112 (uint)(XFS_CALC_ATTRSET_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
113 resp->tr_attrrm =
114 (uint)(XFS_CALC_ATTRRM_LOG_RES(mp) + XFS_DQUOT_LOGRES(mp));
115 resp->tr_clearagi = (uint)XFS_CALC_CLEAR_AGI_BUCKET_LOG_RES(mp);
116 resp->tr_growrtalloc = (uint)XFS_CALC_GROWRTALLOC_LOG_RES(mp);
117 resp->tr_growrtzero = (uint)XFS_CALC_GROWRTZERO_LOG_RES(mp);
118 resp->tr_growrtfree = (uint)XFS_CALC_GROWRTFREE_LOG_RES(mp);
119}
120
121/*
122 * This routine is called to allocate a transaction structure.
123 * The type parameter indicates the type of the transaction. These
124 * are enumerated in xfs_trans.h.
125 *
126 * Dynamically allocate the transaction structure from the transaction
127 * zone, initialize it, and return it to the caller.
128 */
129xfs_trans_t *
130xfs_trans_alloc(
131 xfs_mount_t *mp,
132 uint type)
133{
134 fs_check_frozen(XFS_MTOVFS(mp), SB_FREEZE_TRANS);
135 atomic_inc(&mp->m_active_trans);
136
137 return (_xfs_trans_alloc(mp, type));
138
139}
140
141xfs_trans_t *
142_xfs_trans_alloc(
143 xfs_mount_t *mp,
144 uint type)
145{
146 xfs_trans_t *tp;
147
148 ASSERT(xfs_trans_zone != NULL);
149 tp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP);
150
151 /*
152 * Initialize the transaction structure.
153 */
154 tp->t_magic = XFS_TRANS_MAGIC;
155 tp->t_type = type;
156 tp->t_mountp = mp;
157 tp->t_items_free = XFS_LIC_NUM_SLOTS;
158 tp->t_busy_free = XFS_LBC_NUM_SLOTS;
159 XFS_LIC_INIT(&(tp->t_items));
160 XFS_LBC_INIT(&(tp->t_busy));
161
162 return (tp);
163}
164
165/*
166 * This is called to create a new transaction which will share the
167 * permanent log reservation of the given transaction. The remaining
168 * unused block and rt extent reservations are also inherited. This
169 * implies that the original transaction is no longer allowed to allocate
170 * blocks. Locks and log items, however, are no inherited. They must
171 * be added to the new transaction explicitly.
172 */
173xfs_trans_t *
174xfs_trans_dup(
175 xfs_trans_t *tp)
176{
177 xfs_trans_t *ntp;
178
179 ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP);
180
181 /*
182 * Initialize the new transaction structure.
183 */
184 ntp->t_magic = XFS_TRANS_MAGIC;
185 ntp->t_type = tp->t_type;
186 ntp->t_mountp = tp->t_mountp;
187 ntp->t_items_free = XFS_LIC_NUM_SLOTS;
188 ntp->t_busy_free = XFS_LBC_NUM_SLOTS;
189 XFS_LIC_INIT(&(ntp->t_items));
190 XFS_LBC_INIT(&(ntp->t_busy));
191
192 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
193
194#if defined(XLOG_NOLOG) || defined(DEBUG)
195 ASSERT(!xlog_debug || tp->t_ticket != NULL);
196#else
197 ASSERT(tp->t_ticket != NULL);
198#endif
199 ntp->t_flags = XFS_TRANS_PERM_LOG_RES | (tp->t_flags & XFS_TRANS_RESERVE);
200 ntp->t_ticket = tp->t_ticket;
201 ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used;
202 tp->t_blk_res = tp->t_blk_res_used;
203 ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used;
204 tp->t_rtx_res = tp->t_rtx_res_used;
205 PFLAGS_DUP(&tp->t_pflags, &ntp->t_pflags);
206
207 XFS_TRANS_DUP_DQINFO(tp->t_mountp, tp, ntp);
208
209 atomic_inc(&tp->t_mountp->m_active_trans);
210 return ntp;
211}
212
213/*
214 * This is called to reserve free disk blocks and log space for the
215 * given transaction. This must be done before allocating any resources
216 * within the transaction.
217 *
218 * This will return ENOSPC if there are not enough blocks available.
219 * It will sleep waiting for available log space.
220 * The only valid value for the flags parameter is XFS_RES_LOG_PERM, which
221 * is used by long running transactions. If any one of the reservations
222 * fails then they will all be backed out.
223 *
224 * This does not do quota reservations. That typically is done by the
225 * caller afterwards.
226 */
227int
228xfs_trans_reserve(
229 xfs_trans_t *tp,
230 uint blocks,
231 uint logspace,
232 uint rtextents,
233 uint flags,
234 uint logcount)
235{
236 int log_flags;
237 int error;
238 int rsvd;
239
240 error = 0;
241 rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
242
243 /* Mark this thread as being in a transaction */
244 PFLAGS_SET_FSTRANS(&tp->t_pflags);
245
246 /*
247 * Attempt to reserve the needed disk blocks by decrementing
248 * the number needed from the number available. This will
249 * fail if the count would go below zero.
250 */
251 if (blocks > 0) {
252 error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FDBLOCKS,
253 -blocks, rsvd);
254 if (error != 0) {
255 PFLAGS_RESTORE_FSTRANS(&tp->t_pflags);
256 return (XFS_ERROR(ENOSPC));
257 }
258 tp->t_blk_res += blocks;
259 }
260
261 /*
262 * Reserve the log space needed for this transaction.
263 */
264 if (logspace > 0) {
265 ASSERT((tp->t_log_res == 0) || (tp->t_log_res == logspace));
266 ASSERT((tp->t_log_count == 0) ||
267 (tp->t_log_count == logcount));
268 if (flags & XFS_TRANS_PERM_LOG_RES) {
269 log_flags = XFS_LOG_PERM_RESERV;
270 tp->t_flags |= XFS_TRANS_PERM_LOG_RES;
271 } else {
272 ASSERT(tp->t_ticket == NULL);
273 ASSERT(!(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
274 log_flags = 0;
275 }
276
277 error = xfs_log_reserve(tp->t_mountp, logspace, logcount,
278 &tp->t_ticket,
7e9c6396 279 XFS_TRANSACTION, log_flags, tp->t_type);
1da177e4
LT
280 if (error) {
281 goto undo_blocks;
282 }
283 tp->t_log_res = logspace;
284 tp->t_log_count = logcount;
285 }
286
287 /*
288 * Attempt to reserve the needed realtime extents by decrementing
289 * the number needed from the number available. This will
290 * fail if the count would go below zero.
291 */
292 if (rtextents > 0) {
293 error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS,
294 -rtextents, rsvd);
295 if (error) {
296 error = XFS_ERROR(ENOSPC);
297 goto undo_log;
298 }
299 tp->t_rtx_res += rtextents;
300 }
301
302 return 0;
303
304 /*
305 * Error cases jump to one of these labels to undo any
306 * reservations which have already been performed.
307 */
308undo_log:
309 if (logspace > 0) {
310 if (flags & XFS_TRANS_PERM_LOG_RES) {
311 log_flags = XFS_LOG_REL_PERM_RESERV;
312 } else {
313 log_flags = 0;
314 }
315 xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, log_flags);
316 tp->t_ticket = NULL;
317 tp->t_log_res = 0;
318 tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES;
319 }
320
321undo_blocks:
322 if (blocks > 0) {
323 (void) xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FDBLOCKS,
324 blocks, rsvd);
325 tp->t_blk_res = 0;
326 }
327
328 PFLAGS_RESTORE_FSTRANS(&tp->t_pflags);
329
330 return (error);
331}
332
333
1da177e4
LT
334/*
335 * Record the indicated change to the given field for application
336 * to the file system's superblock when the transaction commits.
337 * For now, just store the change in the transaction structure.
338 *
339 * Mark the transaction structure to indicate that the superblock
340 * needs to be updated before committing.
341 */
342void
343xfs_trans_mod_sb(
344 xfs_trans_t *tp,
345 uint field,
346 long delta)
347{
348
349 switch (field) {
350 case XFS_TRANS_SB_ICOUNT:
351 tp->t_icount_delta += delta;
352 break;
353 case XFS_TRANS_SB_IFREE:
354 tp->t_ifree_delta += delta;
355 break;
356 case XFS_TRANS_SB_FDBLOCKS:
357 /*
358 * Track the number of blocks allocated in the
359 * transaction. Make sure it does not exceed the
360 * number reserved.
361 */
362 if (delta < 0) {
363 tp->t_blk_res_used += (uint)-delta;
364 ASSERT(tp->t_blk_res_used <= tp->t_blk_res);
365 }
366 tp->t_fdblocks_delta += delta;
367 break;
368 case XFS_TRANS_SB_RES_FDBLOCKS:
369 /*
370 * The allocation has already been applied to the
371 * in-core superblock's counter. This should only
372 * be applied to the on-disk superblock.
373 */
374 ASSERT(delta < 0);
375 tp->t_res_fdblocks_delta += delta;
376 break;
377 case XFS_TRANS_SB_FREXTENTS:
378 /*
379 * Track the number of blocks allocated in the
380 * transaction. Make sure it does not exceed the
381 * number reserved.
382 */
383 if (delta < 0) {
384 tp->t_rtx_res_used += (uint)-delta;
385 ASSERT(tp->t_rtx_res_used <= tp->t_rtx_res);
386 }
387 tp->t_frextents_delta += delta;
388 break;
389 case XFS_TRANS_SB_RES_FREXTENTS:
390 /*
391 * The allocation has already been applied to the
392 * in-core superblocks's counter. This should only
393 * be applied to the on-disk superblock.
394 */
395 ASSERT(delta < 0);
396 tp->t_res_frextents_delta += delta;
397 break;
398 case XFS_TRANS_SB_DBLOCKS:
399 ASSERT(delta > 0);
400 tp->t_dblocks_delta += delta;
401 break;
402 case XFS_TRANS_SB_AGCOUNT:
403 ASSERT(delta > 0);
404 tp->t_agcount_delta += delta;
405 break;
406 case XFS_TRANS_SB_IMAXPCT:
407 tp->t_imaxpct_delta += delta;
408 break;
409 case XFS_TRANS_SB_REXTSIZE:
410 tp->t_rextsize_delta += delta;
411 break;
412 case XFS_TRANS_SB_RBMBLOCKS:
413 tp->t_rbmblocks_delta += delta;
414 break;
415 case XFS_TRANS_SB_RBLOCKS:
416 tp->t_rblocks_delta += delta;
417 break;
418 case XFS_TRANS_SB_REXTENTS:
419 tp->t_rextents_delta += delta;
420 break;
421 case XFS_TRANS_SB_REXTSLOG:
422 tp->t_rextslog_delta += delta;
423 break;
424 default:
425 ASSERT(0);
426 return;
427 }
428
429 tp->t_flags |= (XFS_TRANS_SB_DIRTY | XFS_TRANS_DIRTY);
430}
431
432/*
433 * xfs_trans_apply_sb_deltas() is called from the commit code
434 * to bring the superblock buffer into the current transaction
435 * and modify it as requested by earlier calls to xfs_trans_mod_sb().
436 *
437 * For now we just look at each field allowed to change and change
438 * it if necessary.
439 */
440STATIC void
441xfs_trans_apply_sb_deltas(
442 xfs_trans_t *tp)
443{
444 xfs_sb_t *sbp;
445 xfs_buf_t *bp;
446 int whole = 0;
447
448 bp = xfs_trans_getsb(tp, tp->t_mountp, 0);
449 sbp = XFS_BUF_TO_SBP(bp);
450
451 /*
452 * Check that superblock mods match the mods made to AGF counters.
453 */
454 ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
455 (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
456 tp->t_ag_btree_delta));
457
458 if (tp->t_icount_delta != 0) {
459 INT_MOD(sbp->sb_icount, ARCH_CONVERT, tp->t_icount_delta);
460 }
461 if (tp->t_ifree_delta != 0) {
462 INT_MOD(sbp->sb_ifree, ARCH_CONVERT, tp->t_ifree_delta);
463 }
464
465 if (tp->t_fdblocks_delta != 0) {
466 INT_MOD(sbp->sb_fdblocks, ARCH_CONVERT, tp->t_fdblocks_delta);
467 }
468 if (tp->t_res_fdblocks_delta != 0) {
469 INT_MOD(sbp->sb_fdblocks, ARCH_CONVERT, tp->t_res_fdblocks_delta);
470 }
471
472 if (tp->t_frextents_delta != 0) {
473 INT_MOD(sbp->sb_frextents, ARCH_CONVERT, tp->t_frextents_delta);
474 }
475 if (tp->t_res_frextents_delta != 0) {
476 INT_MOD(sbp->sb_frextents, ARCH_CONVERT, tp->t_res_frextents_delta);
477 }
478 if (tp->t_dblocks_delta != 0) {
479 INT_MOD(sbp->sb_dblocks, ARCH_CONVERT, tp->t_dblocks_delta);
480 whole = 1;
481 }
482 if (tp->t_agcount_delta != 0) {
483 INT_MOD(sbp->sb_agcount, ARCH_CONVERT, tp->t_agcount_delta);
484 whole = 1;
485 }
486 if (tp->t_imaxpct_delta != 0) {
487 INT_MOD(sbp->sb_imax_pct, ARCH_CONVERT, tp->t_imaxpct_delta);
488 whole = 1;
489 }
490 if (tp->t_rextsize_delta != 0) {
491 INT_MOD(sbp->sb_rextsize, ARCH_CONVERT, tp->t_rextsize_delta);
492 whole = 1;
493 }
494 if (tp->t_rbmblocks_delta != 0) {
495 INT_MOD(sbp->sb_rbmblocks, ARCH_CONVERT, tp->t_rbmblocks_delta);
496 whole = 1;
497 }
498 if (tp->t_rblocks_delta != 0) {
499 INT_MOD(sbp->sb_rblocks, ARCH_CONVERT, tp->t_rblocks_delta);
500 whole = 1;
501 }
502 if (tp->t_rextents_delta != 0) {
503 INT_MOD(sbp->sb_rextents, ARCH_CONVERT, tp->t_rextents_delta);
504 whole = 1;
505 }
506 if (tp->t_rextslog_delta != 0) {
507 INT_MOD(sbp->sb_rextslog, ARCH_CONVERT, tp->t_rextslog_delta);
508 whole = 1;
509 }
510
511 if (whole)
512 /*
513 * Log the whole thing, the fields are discontiguous.
514 */
515 xfs_trans_log_buf(tp, bp, 0, sizeof(xfs_sb_t) - 1);
516 else
517 /*
518 * Since all the modifiable fields are contiguous, we
519 * can get away with this.
520 */
521 xfs_trans_log_buf(tp, bp, offsetof(xfs_sb_t, sb_icount),
522 offsetof(xfs_sb_t, sb_frextents) +
523 sizeof(sbp->sb_frextents) - 1);
524
525 XFS_MTOVFS(tp->t_mountp)->vfs_super->s_dirt = 1;
526}
527
528/*
529 * xfs_trans_unreserve_and_mod_sb() is called to release unused
530 * reservations and apply superblock counter changes to the in-core
531 * superblock.
532 *
533 * This is done efficiently with a single call to xfs_mod_incore_sb_batch().
534 */
ba0f32d4 535STATIC void
1da177e4
LT
536xfs_trans_unreserve_and_mod_sb(
537 xfs_trans_t *tp)
538{
539 xfs_mod_sb_t msb[14]; /* If you add cases, add entries */
540 xfs_mod_sb_t *msbp;
541 /* REFERENCED */
542 int error;
543 int rsvd;
544
545 msbp = msb;
546 rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
547
548 /*
549 * Release any reserved blocks. Any that were allocated
550 * will be taken back again by fdblocks_delta below.
551 */
552 if (tp->t_blk_res > 0) {
553 msbp->msb_field = XFS_SBS_FDBLOCKS;
554 msbp->msb_delta = tp->t_blk_res;
555 msbp++;
556 }
557
558 /*
559 * Release any reserved real time extents . Any that were
560 * allocated will be taken back again by frextents_delta below.
561 */
562 if (tp->t_rtx_res > 0) {
563 msbp->msb_field = XFS_SBS_FREXTENTS;
564 msbp->msb_delta = tp->t_rtx_res;
565 msbp++;
566 }
567
568 /*
569 * Apply any superblock modifications to the in-core version.
570 * The t_res_fdblocks_delta and t_res_frextents_delta fields are
571 * explicity NOT applied to the in-core superblock.
572 * The idea is that that has already been done.
573 */
574 if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
575 if (tp->t_icount_delta != 0) {
576 msbp->msb_field = XFS_SBS_ICOUNT;
577 msbp->msb_delta = (int)tp->t_icount_delta;
578 msbp++;
579 }
580 if (tp->t_ifree_delta != 0) {
581 msbp->msb_field = XFS_SBS_IFREE;
582 msbp->msb_delta = (int)tp->t_ifree_delta;
583 msbp++;
584 }
585 if (tp->t_fdblocks_delta != 0) {
586 msbp->msb_field = XFS_SBS_FDBLOCKS;
587 msbp->msb_delta = (int)tp->t_fdblocks_delta;
588 msbp++;
589 }
590 if (tp->t_frextents_delta != 0) {
591 msbp->msb_field = XFS_SBS_FREXTENTS;
592 msbp->msb_delta = (int)tp->t_frextents_delta;
593 msbp++;
594 }
595 if (tp->t_dblocks_delta != 0) {
596 msbp->msb_field = XFS_SBS_DBLOCKS;
597 msbp->msb_delta = (int)tp->t_dblocks_delta;
598 msbp++;
599 }
600 if (tp->t_agcount_delta != 0) {
601 msbp->msb_field = XFS_SBS_AGCOUNT;
602 msbp->msb_delta = (int)tp->t_agcount_delta;
603 msbp++;
604 }
605 if (tp->t_imaxpct_delta != 0) {
606 msbp->msb_field = XFS_SBS_IMAX_PCT;
607 msbp->msb_delta = (int)tp->t_imaxpct_delta;
608 msbp++;
609 }
610 if (tp->t_rextsize_delta != 0) {
611 msbp->msb_field = XFS_SBS_REXTSIZE;
612 msbp->msb_delta = (int)tp->t_rextsize_delta;
613 msbp++;
614 }
615 if (tp->t_rbmblocks_delta != 0) {
616 msbp->msb_field = XFS_SBS_RBMBLOCKS;
617 msbp->msb_delta = (int)tp->t_rbmblocks_delta;
618 msbp++;
619 }
620 if (tp->t_rblocks_delta != 0) {
621 msbp->msb_field = XFS_SBS_RBLOCKS;
622 msbp->msb_delta = (int)tp->t_rblocks_delta;
623 msbp++;
624 }
625 if (tp->t_rextents_delta != 0) {
626 msbp->msb_field = XFS_SBS_REXTENTS;
627 msbp->msb_delta = (int)tp->t_rextents_delta;
628 msbp++;
629 }
630 if (tp->t_rextslog_delta != 0) {
631 msbp->msb_field = XFS_SBS_REXTSLOG;
632 msbp->msb_delta = (int)tp->t_rextslog_delta;
633 msbp++;
634 }
635 }
636
637 /*
638 * If we need to change anything, do it.
639 */
640 if (msbp > msb) {
641 error = xfs_mod_incore_sb_batch(tp->t_mountp, msb,
642 (uint)(msbp - msb), rsvd);
643 ASSERT(error == 0);
644 }
645}
646
647
648/*
649 * xfs_trans_commit
650 *
651 * Commit the given transaction to the log a/synchronously.
652 *
653 * XFS disk error handling mechanism is not based on a typical
654 * transaction abort mechanism. Logically after the filesystem
655 * gets marked 'SHUTDOWN', we can't let any new transactions
656 * be durable - ie. committed to disk - because some metadata might
657 * be inconsistent. In such cases, this returns an error, and the
658 * caller may assume that all locked objects joined to the transaction
659 * have already been unlocked as if the commit had succeeded.
660 * Do not reference the transaction structure after this call.
661 */
662 /*ARGSUSED*/
663int
f538d4da 664_xfs_trans_commit(
1da177e4
LT
665 xfs_trans_t *tp,
666 uint flags,
f538d4da
CH
667 xfs_lsn_t *commit_lsn_p,
668 int *log_flushed)
1da177e4
LT
669{
670 xfs_log_iovec_t *log_vector;
671 int nvec;
672 xfs_mount_t *mp;
673 xfs_lsn_t commit_lsn;
674 /* REFERENCED */
675 int error;
676 int log_flags;
677 int sync;
678#define XFS_TRANS_LOGVEC_COUNT 16
679 xfs_log_iovec_t log_vector_fast[XFS_TRANS_LOGVEC_COUNT];
680#if defined(XLOG_NOLOG) || defined(DEBUG)
681 static xfs_lsn_t trans_lsn = 1;
682#endif
683 void *commit_iclog;
684 int shutdown;
685
686 commit_lsn = -1;
687
688 /*
689 * Determine whether this commit is releasing a permanent
690 * log reservation or not.
691 */
692 if (flags & XFS_TRANS_RELEASE_LOG_RES) {
693 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
694 log_flags = XFS_LOG_REL_PERM_RESERV;
695 } else {
696 log_flags = 0;
697 }
698 mp = tp->t_mountp;
699
700 /*
701 * If there is nothing to be logged by the transaction,
702 * then unlock all of the items associated with the
703 * transaction and free the transaction structure.
704 * Also make sure to return any reserved blocks to
705 * the free pool.
706 */
707shut_us_down:
708 shutdown = XFS_FORCED_SHUTDOWN(mp) ? EIO : 0;
709 if (!(tp->t_flags & XFS_TRANS_DIRTY) || shutdown) {
710 xfs_trans_unreserve_and_mod_sb(tp);
711 /*
712 * It is indeed possible for the transaction to be
713 * not dirty but the dqinfo portion to be. All that
714 * means is that we have some (non-persistent) quota
715 * reservations that need to be unreserved.
716 */
717 XFS_TRANS_UNRESERVE_AND_MOD_DQUOTS(mp, tp);
718 if (tp->t_ticket) {
719 commit_lsn = xfs_log_done(mp, tp->t_ticket,
720 NULL, log_flags);
721 if (commit_lsn == -1 && !shutdown)
722 shutdown = XFS_ERROR(EIO);
723 }
724 PFLAGS_RESTORE_FSTRANS(&tp->t_pflags);
725 xfs_trans_free_items(tp, shutdown? XFS_TRANS_ABORT : 0);
726 xfs_trans_free_busy(tp);
727 xfs_trans_free(tp);
728 XFS_STATS_INC(xs_trans_empty);
729 if (commit_lsn_p)
730 *commit_lsn_p = commit_lsn;
731 return (shutdown);
732 }
733#if defined(XLOG_NOLOG) || defined(DEBUG)
734 ASSERT(!xlog_debug || tp->t_ticket != NULL);
735#else
736 ASSERT(tp->t_ticket != NULL);
737#endif
738
739 /*
740 * If we need to update the superblock, then do it now.
741 */
742 if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
743 xfs_trans_apply_sb_deltas(tp);
744 }
745 XFS_TRANS_APPLY_DQUOT_DELTAS(mp, tp);
746
747 /*
748 * Ask each log item how many log_vector entries it will
749 * need so we can figure out how many to allocate.
750 * Try to avoid the kmem_alloc() call in the common case
751 * by using a vector from the stack when it fits.
752 */
753 nvec = xfs_trans_count_vecs(tp);
754
755 if (nvec == 0) {
756 xfs_force_shutdown(mp, XFS_LOG_IO_ERROR);
757 goto shut_us_down;
758 }
759
760
761 if (nvec <= XFS_TRANS_LOGVEC_COUNT) {
762 log_vector = log_vector_fast;
763 } else {
764 log_vector = (xfs_log_iovec_t *)kmem_alloc(nvec *
765 sizeof(xfs_log_iovec_t),
766 KM_SLEEP);
767 }
768
769 /*
770 * Fill in the log_vector and pin the logged items, and
771 * then write the transaction to the log.
772 */
773 xfs_trans_fill_vecs(tp, log_vector);
774
775 /*
776 * Ignore errors here. xfs_log_done would do the right thing.
777 * We need to put the ticket, etc. away.
778 */
779 error = xfs_log_write(mp, log_vector, nvec, tp->t_ticket,
780 &(tp->t_lsn));
781
782#if defined(XLOG_NOLOG) || defined(DEBUG)
783 if (xlog_debug) {
784 commit_lsn = xfs_log_done(mp, tp->t_ticket,
785 &commit_iclog, log_flags);
786 } else {
787 commit_lsn = 0;
788 tp->t_lsn = trans_lsn++;
789 }
790#else
791 /*
792 * This is the regular case. At this point (after the call finishes),
793 * the transaction is committed incore and could go out to disk at
794 * any time. However, all the items associated with the transaction
795 * are still locked and pinned in memory.
796 */
797 commit_lsn = xfs_log_done(mp, tp->t_ticket, &commit_iclog, log_flags);
798#endif
799
800 tp->t_commit_lsn = commit_lsn;
801 if (nvec > XFS_TRANS_LOGVEC_COUNT) {
802 kmem_free(log_vector, nvec * sizeof(xfs_log_iovec_t));
803 }
804
805 if (commit_lsn_p)
806 *commit_lsn_p = commit_lsn;
807
808 /*
809 * If we got a log write error. Unpin the logitems that we
810 * had pinned, clean up, free trans structure, and return error.
811 */
812 if (error || commit_lsn == -1) {
813 PFLAGS_RESTORE_FSTRANS(&tp->t_pflags);
814 xfs_trans_uncommit(tp, flags|XFS_TRANS_ABORT);
815 return XFS_ERROR(EIO);
816 }
817
818 /*
819 * Once the transaction has committed, unused
820 * reservations need to be released and changes to
821 * the superblock need to be reflected in the in-core
822 * version. Do that now.
823 */
824 xfs_trans_unreserve_and_mod_sb(tp);
825
826 sync = tp->t_flags & XFS_TRANS_SYNC;
827
828 /*
829 * Tell the LM to call the transaction completion routine
830 * when the log write with LSN commit_lsn completes (e.g.
831 * when the transaction commit really hits the on-disk log).
832 * After this call we cannot reference tp, because the call
833 * can happen at any time and the call will free the transaction
834 * structure pointed to by tp. The only case where we call
835 * the completion routine (xfs_trans_committed) directly is
836 * if the log is turned off on a debug kernel or we're
837 * running in simulation mode (the log is explicitly turned
838 * off).
839 */
840 tp->t_logcb.cb_func = (void(*)(void*, int))xfs_trans_committed;
841 tp->t_logcb.cb_arg = tp;
842
843 /*
844 * We need to pass the iclog buffer which was used for the
845 * transaction commit record into this function, and attach
846 * the callback to it. The callback must be attached before
847 * the items are unlocked to avoid racing with other threads
848 * waiting for an item to unlock.
849 */
850 shutdown = xfs_log_notify(mp, commit_iclog, &(tp->t_logcb));
851
852 /*
853 * Mark this thread as no longer being in a transaction
854 */
855 PFLAGS_RESTORE_FSTRANS(&tp->t_pflags);
856
857 /*
858 * Once all the items of the transaction have been copied
859 * to the in core log and the callback is attached, the
860 * items can be unlocked.
861 *
862 * This will free descriptors pointing to items which were
863 * not logged since there is nothing more to do with them.
864 * For items which were logged, we will keep pointers to them
865 * so they can be unpinned after the transaction commits to disk.
866 * This will also stamp each modified meta-data item with
867 * the commit lsn of this transaction for dependency tracking
868 * purposes.
869 */
870 xfs_trans_unlock_items(tp, commit_lsn);
871
872 /*
873 * If we detected a log error earlier, finish committing
874 * the transaction now (unpin log items, etc).
875 *
876 * Order is critical here, to avoid using the transaction
877 * pointer after its been freed (by xfs_trans_committed
878 * either here now, or as a callback). We cannot do this
879 * step inside xfs_log_notify as was done earlier because
880 * of this issue.
881 */
882 if (shutdown)
883 xfs_trans_committed(tp, XFS_LI_ABORTED);
884
885 /*
886 * Now that the xfs_trans_committed callback has been attached,
887 * and the items are released we can finally allow the iclog to
888 * go to disk.
889 */
890 error = xfs_log_release_iclog(mp, commit_iclog);
891
892 /*
893 * If the transaction needs to be synchronous, then force the
894 * log out now and wait for it.
895 */
896 if (sync) {
f538d4da
CH
897 if (!error) {
898 error = _xfs_log_force(mp, commit_lsn,
899 XFS_LOG_FORCE | XFS_LOG_SYNC,
900 log_flushed);
901 }
1da177e4
LT
902 XFS_STATS_INC(xs_trans_sync);
903 } else {
904 XFS_STATS_INC(xs_trans_async);
905 }
906
907 return (error);
908}
909
910
911/*
912 * Total up the number of log iovecs needed to commit this
913 * transaction. The transaction itself needs one for the
914 * transaction header. Ask each dirty item in turn how many
915 * it needs to get the total.
916 */
917STATIC uint
918xfs_trans_count_vecs(
919 xfs_trans_t *tp)
920{
921 int nvecs;
922 xfs_log_item_desc_t *lidp;
923
924 nvecs = 1;
925 lidp = xfs_trans_first_item(tp);
926 ASSERT(lidp != NULL);
927
928 /* In the non-debug case we need to start bailing out if we
929 * didn't find a log_item here, return zero and let trans_commit
930 * deal with it.
931 */
932 if (lidp == NULL)
933 return 0;
934
935 while (lidp != NULL) {
936 /*
937 * Skip items which aren't dirty in this transaction.
938 */
939 if (!(lidp->lid_flags & XFS_LID_DIRTY)) {
940 lidp = xfs_trans_next_item(tp, lidp);
941 continue;
942 }
943 lidp->lid_size = IOP_SIZE(lidp->lid_item);
944 nvecs += lidp->lid_size;
945 lidp = xfs_trans_next_item(tp, lidp);
946 }
947
948 return nvecs;
949}
950
951/*
952 * Called from the trans_commit code when we notice that
953 * the filesystem is in the middle of a forced shutdown.
954 */
955STATIC void
956xfs_trans_uncommit(
957 xfs_trans_t *tp,
958 uint flags)
959{
960 xfs_log_item_desc_t *lidp;
961
962 for (lidp = xfs_trans_first_item(tp);
963 lidp != NULL;
964 lidp = xfs_trans_next_item(tp, lidp)) {
965 /*
966 * Unpin all but those that aren't dirty.
967 */
968 if (lidp->lid_flags & XFS_LID_DIRTY)
969 IOP_UNPIN_REMOVE(lidp->lid_item, tp);
970 }
971
972 xfs_trans_unreserve_and_mod_sb(tp);
973 XFS_TRANS_UNRESERVE_AND_MOD_DQUOTS(tp->t_mountp, tp);
974
975 xfs_trans_free_items(tp, flags);
976 xfs_trans_free_busy(tp);
977 xfs_trans_free(tp);
978}
979
980/*
981 * Fill in the vector with pointers to data to be logged
982 * by this transaction. The transaction header takes
983 * the first vector, and then each dirty item takes the
984 * number of vectors it indicated it needed in xfs_trans_count_vecs().
985 *
986 * As each item fills in the entries it needs, also pin the item
987 * so that it cannot be flushed out until the log write completes.
988 */
989STATIC void
990xfs_trans_fill_vecs(
991 xfs_trans_t *tp,
992 xfs_log_iovec_t *log_vector)
993{
994 xfs_log_item_desc_t *lidp;
995 xfs_log_iovec_t *vecp;
996 uint nitems;
997
998 /*
999 * Skip over the entry for the transaction header, we'll
1000 * fill that in at the end.
1001 */
1002 vecp = log_vector + 1; /* pointer arithmetic */
1003
1004 nitems = 0;
1005 lidp = xfs_trans_first_item(tp);
1006 ASSERT(lidp != NULL);
1007 while (lidp != NULL) {
1008 /*
1009 * Skip items which aren't dirty in this transaction.
1010 */
1011 if (!(lidp->lid_flags & XFS_LID_DIRTY)) {
1012 lidp = xfs_trans_next_item(tp, lidp);
1013 continue;
1014 }
1015 /*
1016 * The item may be marked dirty but not log anything.
1017 * This can be used to get called when a transaction
1018 * is committed.
1019 */
1020 if (lidp->lid_size) {
1021 nitems++;
1022 }
1023 IOP_FORMAT(lidp->lid_item, vecp);
1024 vecp += lidp->lid_size; /* pointer arithmetic */
1025 IOP_PIN(lidp->lid_item);
1026 lidp = xfs_trans_next_item(tp, lidp);
1027 }
1028
1029 /*
1030 * Now that we've counted the number of items in this
1031 * transaction, fill in the transaction header.
1032 */
1033 tp->t_header.th_magic = XFS_TRANS_HEADER_MAGIC;
1034 tp->t_header.th_type = tp->t_type;
1035 tp->t_header.th_num_items = nitems;
1036 log_vector->i_addr = (xfs_caddr_t)&tp->t_header;
1037 log_vector->i_len = sizeof(xfs_trans_header_t);
7e9c6396 1038 XLOG_VEC_SET_TYPE(log_vector, XLOG_REG_TYPE_TRANSHDR);
1da177e4
LT
1039}
1040
1041
1042/*
1043 * Unlock all of the transaction's items and free the transaction.
1044 * The transaction must not have modified any of its items, because
1045 * there is no way to restore them to their previous state.
1046 *
1047 * If the transaction has made a log reservation, make sure to release
1048 * it as well.
1049 */
1050void
1051xfs_trans_cancel(
1052 xfs_trans_t *tp,
1053 int flags)
1054{
1055 int log_flags;
1056#ifdef DEBUG
1057 xfs_log_item_chunk_t *licp;
1058 xfs_log_item_desc_t *lidp;
1059 xfs_log_item_t *lip;
1060 int i;
1061#endif
1062
1063 /*
1064 * See if the caller is being too lazy to figure out if
1065 * the transaction really needs an abort.
1066 */
1067 if ((flags & XFS_TRANS_ABORT) && !(tp->t_flags & XFS_TRANS_DIRTY))
1068 flags &= ~XFS_TRANS_ABORT;
1069 /*
1070 * See if the caller is relying on us to shut down the
1071 * filesystem. This happens in paths where we detect
1072 * corruption and decide to give up.
1073 */
1074 if ((tp->t_flags & XFS_TRANS_DIRTY) &&
1075 !XFS_FORCED_SHUTDOWN(tp->t_mountp))
1076 xfs_force_shutdown(tp->t_mountp, XFS_CORRUPT_INCORE);
1077#ifdef DEBUG
1078 if (!(flags & XFS_TRANS_ABORT)) {
1079 licp = &(tp->t_items);
1080 while (licp != NULL) {
1081 lidp = licp->lic_descs;
1082 for (i = 0; i < licp->lic_unused; i++, lidp++) {
1083 if (XFS_LIC_ISFREE(licp, i)) {
1084 continue;
1085 }
1086
1087 lip = lidp->lid_item;
1088 if (!XFS_FORCED_SHUTDOWN(tp->t_mountp))
1089 ASSERT(!(lip->li_type == XFS_LI_EFD));
1090 }
1091 licp = licp->lic_next;
1092 }
1093 }
1094#endif
1095 xfs_trans_unreserve_and_mod_sb(tp);
1096 XFS_TRANS_UNRESERVE_AND_MOD_DQUOTS(tp->t_mountp, tp);
1097
1098 if (tp->t_ticket) {
1099 if (flags & XFS_TRANS_RELEASE_LOG_RES) {
1100 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
1101 log_flags = XFS_LOG_REL_PERM_RESERV;
1102 } else {
1103 log_flags = 0;
1104 }
1105 xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, log_flags);
1106 }
1107
1108 /* mark this thread as no longer being in a transaction */
1109 PFLAGS_RESTORE_FSTRANS(&tp->t_pflags);
1110
1111 xfs_trans_free_items(tp, flags);
1112 xfs_trans_free_busy(tp);
1113 xfs_trans_free(tp);
1114}
1115
1116
1117/*
1118 * Free the transaction structure. If there is more clean up
1119 * to do when the structure is freed, add it here.
1120 */
1121STATIC void
1122xfs_trans_free(
1123 xfs_trans_t *tp)
1124{
1125 atomic_dec(&tp->t_mountp->m_active_trans);
1126 XFS_TRANS_FREE_DQINFO(tp->t_mountp, tp);
1127 kmem_zone_free(xfs_trans_zone, tp);
1128}
1129
1130
1131/*
1132 * THIS SHOULD BE REWRITTEN TO USE xfs_trans_next_item().
1133 *
1134 * This is typically called by the LM when a transaction has been fully
1135 * committed to disk. It needs to unpin the items which have
1136 * been logged by the transaction and update their positions
1137 * in the AIL if necessary.
1138 * This also gets called when the transactions didn't get written out
1139 * because of an I/O error. Abortflag & XFS_LI_ABORTED is set then.
1140 *
1141 * Call xfs_trans_chunk_committed() to process the items in
1142 * each chunk.
1143 */
1144STATIC void
1145xfs_trans_committed(
1146 xfs_trans_t *tp,
1147 int abortflag)
1148{
1149 xfs_log_item_chunk_t *licp;
1150 xfs_log_item_chunk_t *next_licp;
1151 xfs_log_busy_chunk_t *lbcp;
1152 xfs_log_busy_slot_t *lbsp;
1153 int i;
1154
1155 /*
1156 * Call the transaction's completion callback if there
1157 * is one.
1158 */
1159 if (tp->t_callback != NULL) {
1160 tp->t_callback(tp, tp->t_callarg);
1161 }
1162
1163 /*
1164 * Special case the chunk embedded in the transaction.
1165 */
1166 licp = &(tp->t_items);
1167 if (!(XFS_LIC_ARE_ALL_FREE(licp))) {
1168 xfs_trans_chunk_committed(licp, tp->t_lsn, abortflag);
1169 }
1170
1171 /*
1172 * Process the items in each chunk in turn.
1173 */
1174 licp = licp->lic_next;
1175 while (licp != NULL) {
1176 ASSERT(!XFS_LIC_ARE_ALL_FREE(licp));
1177 xfs_trans_chunk_committed(licp, tp->t_lsn, abortflag);
1178 next_licp = licp->lic_next;
1179 kmem_free(licp, sizeof(xfs_log_item_chunk_t));
1180 licp = next_licp;
1181 }
1182
1183 /*
1184 * Clear all the per-AG busy list items listed in this transaction
1185 */
1186 lbcp = &tp->t_busy;
1187 while (lbcp != NULL) {
1188 for (i = 0, lbsp = lbcp->lbc_busy; i < lbcp->lbc_unused; i++, lbsp++) {
1189 if (!XFS_LBC_ISFREE(lbcp, i)) {
1190 xfs_alloc_clear_busy(tp, lbsp->lbc_ag,
1191 lbsp->lbc_idx);
1192 }
1193 }
1194 lbcp = lbcp->lbc_next;
1195 }
1196 xfs_trans_free_busy(tp);
1197
1198 /*
1199 * That's it for the transaction structure. Free it.
1200 */
1201 xfs_trans_free(tp);
1202}
1203
1204/*
1205 * This is called to perform the commit processing for each
1206 * item described by the given chunk.
1207 *
1208 * The commit processing consists of unlocking items which were
1209 * held locked with the SYNC_UNLOCK attribute, calling the committed
1210 * routine of each logged item, updating the item's position in the AIL
1211 * if necessary, and unpinning each item. If the committed routine
1212 * returns -1, then do nothing further with the item because it
1213 * may have been freed.
1214 *
1215 * Since items are unlocked when they are copied to the incore
1216 * log, it is possible for two transactions to be completing
1217 * and manipulating the same item simultaneously. The AIL lock
1218 * will protect the lsn field of each item. The value of this
1219 * field can never go backwards.
1220 *
1221 * We unpin the items after repositioning them in the AIL, because
1222 * otherwise they could be immediately flushed and we'd have to race
1223 * with the flusher trying to pull the item from the AIL as we add it.
1224 */
1225STATIC void
1226xfs_trans_chunk_committed(
1227 xfs_log_item_chunk_t *licp,
1228 xfs_lsn_t lsn,
1229 int aborted)
1230{
1231 xfs_log_item_desc_t *lidp;
1232 xfs_log_item_t *lip;
1233 xfs_lsn_t item_lsn;
1234 struct xfs_mount *mp;
1235 int i;
1236 SPLDECL(s);
1237
1238 lidp = licp->lic_descs;
1239 for (i = 0; i < licp->lic_unused; i++, lidp++) {
1240 if (XFS_LIC_ISFREE(licp, i)) {
1241 continue;
1242 }
1243
1244 lip = lidp->lid_item;
1245 if (aborted)
1246 lip->li_flags |= XFS_LI_ABORTED;
1247
1248 /*
1249 * Send in the ABORTED flag to the COMMITTED routine
1250 * so that it knows whether the transaction was aborted
1251 * or not.
1252 */
1253 item_lsn = IOP_COMMITTED(lip, lsn);
1254
1255 /*
1256 * If the committed routine returns -1, make
1257 * no more references to the item.
1258 */
1259 if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0) {
1260 continue;
1261 }
1262
1263 /*
1264 * If the returned lsn is greater than what it
1265 * contained before, update the location of the
1266 * item in the AIL. If it is not, then do nothing.
1267 * Items can never move backwards in the AIL.
1268 *
1269 * While the new lsn should usually be greater, it
1270 * is possible that a later transaction completing
1271 * simultaneously with an earlier one using the
1272 * same item could complete first with a higher lsn.
1273 * This would cause the earlier transaction to fail
1274 * the test below.
1275 */
1276 mp = lip->li_mountp;
1277 AIL_LOCK(mp,s);
1278 if (XFS_LSN_CMP(item_lsn, lip->li_lsn) > 0) {
1279 /*
1280 * This will set the item's lsn to item_lsn
1281 * and update the position of the item in
1282 * the AIL.
1283 *
1284 * xfs_trans_update_ail() drops the AIL lock.
1285 */
1286 xfs_trans_update_ail(mp, lip, item_lsn, s);
1287 } else {
1288 AIL_UNLOCK(mp, s);
1289 }
1290
1291 /*
1292 * Now that we've repositioned the item in the AIL,
1293 * unpin it so it can be flushed. Pass information
1294 * about buffer stale state down from the log item
1295 * flags, if anyone else stales the buffer we do not
1296 * want to pay any attention to it.
1297 */
1298 IOP_UNPIN(lip, lidp->lid_flags & XFS_LID_BUF_STALE);
1299 }
1300}