.. | .. |
---|
9 | 9 | #include "xfs_shared.h" |
---|
10 | 10 | #include "xfs_format.h" |
---|
11 | 11 | #include "xfs_log_format.h" |
---|
| 12 | +#include "xfs_log_priv.h" |
---|
12 | 13 | #include "xfs_trans_resv.h" |
---|
13 | 14 | #include "xfs_mount.h" |
---|
14 | | -#include "xfs_inode.h" |
---|
15 | 15 | #include "xfs_extent_busy.h" |
---|
16 | 16 | #include "xfs_quota.h" |
---|
17 | 17 | #include "xfs_trans.h" |
---|
.. | .. |
---|
68 | 68 | xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false); |
---|
69 | 69 | |
---|
70 | 70 | trace_xfs_trans_free(tp, _RET_IP_); |
---|
71 | | - atomic_dec(&tp->t_mountp->m_active_trans); |
---|
| 71 | + xfs_trans_clear_context(tp); |
---|
72 | 72 | if (!(tp->t_flags & XFS_TRANS_NO_WRITECOUNT)) |
---|
73 | 73 | sb_end_intwrite(tp->t_mountp->m_super); |
---|
74 | 74 | xfs_trans_free_dqinfo(tp); |
---|
75 | | - kmem_zone_free(xfs_trans_zone, tp); |
---|
| 75 | + kmem_cache_free(xfs_trans_zone, tp); |
---|
76 | 76 | } |
---|
77 | 77 | |
---|
78 | 78 | /* |
---|
.. | .. |
---|
91 | 91 | |
---|
92 | 92 | trace_xfs_trans_dup(tp, _RET_IP_); |
---|
93 | 93 | |
---|
94 | | - ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP); |
---|
| 94 | + ntp = kmem_cache_zalloc(xfs_trans_zone, GFP_KERNEL | __GFP_NOFAIL); |
---|
95 | 95 | |
---|
96 | 96 | /* |
---|
97 | 97 | * Initialize the new transaction structure. |
---|
.. | .. |
---|
108 | 108 | |
---|
109 | 109 | ntp->t_flags = XFS_TRANS_PERM_LOG_RES | |
---|
110 | 110 | (tp->t_flags & XFS_TRANS_RESERVE) | |
---|
111 | | - (tp->t_flags & XFS_TRANS_NO_WRITECOUNT); |
---|
| 111 | + (tp->t_flags & XFS_TRANS_NO_WRITECOUNT) | |
---|
| 112 | + (tp->t_flags & XFS_TRANS_RES_FDBLKS); |
---|
112 | 113 | /* We gave our writer reference to the new transaction */ |
---|
113 | 114 | tp->t_flags |= XFS_TRANS_NO_WRITECOUNT; |
---|
114 | 115 | ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket); |
---|
.. | .. |
---|
119 | 120 | |
---|
120 | 121 | ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used; |
---|
121 | 122 | tp->t_rtx_res = tp->t_rtx_res_used; |
---|
122 | | - ntp->t_pflags = tp->t_pflags; |
---|
| 123 | + |
---|
| 124 | + xfs_trans_switch_context(tp, ntp); |
---|
123 | 125 | |
---|
124 | 126 | /* move deferred ops over to the new tp */ |
---|
125 | 127 | xfs_defer_move(ntp, tp); |
---|
126 | 128 | |
---|
127 | 129 | xfs_trans_dup_dqinfo(tp, ntp); |
---|
128 | | - |
---|
129 | | - atomic_inc(&tp->t_mountp->m_active_trans); |
---|
130 | 130 | return ntp; |
---|
131 | 131 | } |
---|
132 | 132 | |
---|
.. | .. |
---|
151 | 151 | uint blocks, |
---|
152 | 152 | uint rtextents) |
---|
153 | 153 | { |
---|
154 | | - int error = 0; |
---|
155 | | - bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; |
---|
156 | | - |
---|
157 | | - /* Mark this thread as being in a transaction */ |
---|
158 | | - current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
---|
| 154 | + struct xfs_mount *mp = tp->t_mountp; |
---|
| 155 | + int error = 0; |
---|
| 156 | + bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; |
---|
159 | 157 | |
---|
160 | 158 | /* |
---|
161 | 159 | * Attempt to reserve the needed disk blocks by decrementing |
---|
.. | .. |
---|
163 | 161 | * fail if the count would go below zero. |
---|
164 | 162 | */ |
---|
165 | 163 | if (blocks > 0) { |
---|
166 | | - error = xfs_mod_fdblocks(tp->t_mountp, -((int64_t)blocks), rsvd); |
---|
167 | | - if (error != 0) { |
---|
168 | | - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
---|
| 164 | + error = xfs_mod_fdblocks(mp, -((int64_t)blocks), rsvd); |
---|
| 165 | + if (error != 0) |
---|
169 | 166 | return -ENOSPC; |
---|
170 | | - } |
---|
171 | 167 | tp->t_blk_res += blocks; |
---|
172 | 168 | } |
---|
173 | 169 | |
---|
.. | .. |
---|
192 | 188 | |
---|
193 | 189 | if (tp->t_ticket != NULL) { |
---|
194 | 190 | ASSERT(resp->tr_logflags & XFS_TRANS_PERM_LOG_RES); |
---|
195 | | - error = xfs_log_regrant(tp->t_mountp, tp->t_ticket); |
---|
| 191 | + error = xfs_log_regrant(mp, tp->t_ticket); |
---|
196 | 192 | } else { |
---|
197 | | - error = xfs_log_reserve(tp->t_mountp, |
---|
| 193 | + error = xfs_log_reserve(mp, |
---|
198 | 194 | resp->tr_logres, |
---|
199 | 195 | resp->tr_logcount, |
---|
200 | 196 | &tp->t_ticket, XFS_TRANSACTION, |
---|
.. | .. |
---|
214 | 210 | * fail if the count would go below zero. |
---|
215 | 211 | */ |
---|
216 | 212 | if (rtextents > 0) { |
---|
217 | | - error = xfs_mod_frextents(tp->t_mountp, -((int64_t)rtextents)); |
---|
| 213 | + error = xfs_mod_frextents(mp, -((int64_t)rtextents)); |
---|
218 | 214 | if (error) { |
---|
219 | 215 | error = -ENOSPC; |
---|
220 | 216 | goto undo_log; |
---|
.. | .. |
---|
230 | 226 | */ |
---|
231 | 227 | undo_log: |
---|
232 | 228 | if (resp->tr_logres > 0) { |
---|
233 | | - xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, false); |
---|
| 229 | + xfs_log_ticket_ungrant(mp->m_log, tp->t_ticket); |
---|
234 | 230 | tp->t_ticket = NULL; |
---|
235 | 231 | tp->t_log_res = 0; |
---|
236 | 232 | tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES; |
---|
.. | .. |
---|
238 | 234 | |
---|
239 | 235 | undo_blocks: |
---|
240 | 236 | if (blocks > 0) { |
---|
241 | | - xfs_mod_fdblocks(tp->t_mountp, (int64_t)blocks, rsvd); |
---|
| 237 | + xfs_mod_fdblocks(mp, (int64_t)blocks, rsvd); |
---|
242 | 238 | tp->t_blk_res = 0; |
---|
243 | 239 | } |
---|
244 | | - |
---|
245 | | - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
---|
246 | | - |
---|
247 | 240 | return error; |
---|
248 | 241 | } |
---|
249 | 242 | |
---|
.. | .. |
---|
264 | 257 | * GFP_NOFS allocation context so that we avoid lockdep false positives |
---|
265 | 258 | * by doing GFP_KERNEL allocations inside sb_start_intwrite(). |
---|
266 | 259 | */ |
---|
267 | | - tp = kmem_zone_zalloc(xfs_trans_zone, |
---|
268 | | - (flags & XFS_TRANS_NOFS) ? KM_NOFS : KM_SLEEP); |
---|
269 | | - |
---|
| 260 | + tp = kmem_cache_zalloc(xfs_trans_zone, GFP_KERNEL | __GFP_NOFAIL); |
---|
270 | 261 | if (!(flags & XFS_TRANS_NO_WRITECOUNT)) |
---|
271 | 262 | sb_start_intwrite(mp->m_super); |
---|
| 263 | + xfs_trans_set_context(tp); |
---|
272 | 264 | |
---|
273 | 265 | /* |
---|
274 | 266 | * Zero-reservation ("empty") transactions can't modify anything, so |
---|
.. | .. |
---|
276 | 268 | */ |
---|
277 | 269 | WARN_ON(resp->tr_logres > 0 && |
---|
278 | 270 | mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE); |
---|
279 | | - atomic_inc(&mp->m_active_trans); |
---|
| 271 | + ASSERT(!(flags & XFS_TRANS_RES_FDBLKS) || |
---|
| 272 | + xfs_sb_version_haslazysbcount(&mp->m_sb)); |
---|
280 | 273 | |
---|
281 | 274 | tp->t_magic = XFS_TRANS_HEADER_MAGIC; |
---|
282 | 275 | tp->t_flags = flags; |
---|
.. | .. |
---|
300 | 293 | |
---|
301 | 294 | /* |
---|
302 | 295 | * Create an empty transaction with no reservation. This is a defensive |
---|
303 | | - * mechanism for routines that query metadata without actually modifying |
---|
304 | | - * them -- if the metadata being queried is somehow cross-linked (think a |
---|
305 | | - * btree block pointer that points higher in the tree), we risk deadlock. |
---|
306 | | - * However, blocks grabbed as part of a transaction can be re-grabbed. |
---|
307 | | - * The verifiers will notice the corrupt block and the operation will fail |
---|
308 | | - * back to userspace without deadlocking. |
---|
| 296 | + * mechanism for routines that query metadata without actually modifying them -- |
---|
| 297 | + * if the metadata being queried is somehow cross-linked (think a btree block |
---|
| 298 | + * pointer that points higher in the tree), we risk deadlock. However, blocks |
---|
| 299 | + * grabbed as part of a transaction can be re-grabbed. The verifiers will |
---|
| 300 | + * notice the corrupt block and the operation will fail back to userspace |
---|
| 301 | + * without deadlocking. |
---|
309 | 302 | * |
---|
310 | | - * Note the zero-length reservation; this transaction MUST be cancelled |
---|
311 | | - * without any dirty data. |
---|
| 303 | + * Note the zero-length reservation; this transaction MUST be cancelled without |
---|
| 304 | + * any dirty data. |
---|
| 305 | + * |
---|
| 306 | + * Callers should obtain freeze protection to avoid a conflict with fs freezing |
---|
| 307 | + * where we can be grabbing buffers at the same time that freeze is trying to |
---|
| 308 | + * drain the buffer LRU list. |
---|
312 | 309 | */ |
---|
313 | 310 | int |
---|
314 | 311 | xfs_trans_alloc_empty( |
---|
.. | .. |
---|
366 | 363 | tp->t_blk_res_used += (uint)-delta; |
---|
367 | 364 | if (tp->t_blk_res_used > tp->t_blk_res) |
---|
368 | 365 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
---|
| 366 | + } else if (delta > 0 && (tp->t_flags & XFS_TRANS_RES_FDBLKS)) { |
---|
| 367 | + int64_t blkres_delta; |
---|
| 368 | + |
---|
| 369 | + /* |
---|
| 370 | + * Return freed blocks directly to the reservation |
---|
| 371 | + * instead of the global pool, being careful not to |
---|
| 372 | + * overflow the trans counter. This is used to preserve |
---|
| 373 | + * reservation across chains of transaction rolls that |
---|
| 374 | + * repeatedly free and allocate blocks. |
---|
| 375 | + */ |
---|
| 376 | + blkres_delta = min_t(int64_t, delta, |
---|
| 377 | + UINT_MAX - tp->t_blk_res); |
---|
| 378 | + tp->t_blk_res += blkres_delta; |
---|
| 379 | + delta -= blkres_delta; |
---|
369 | 380 | } |
---|
370 | 381 | tp->t_fdblocks_delta += delta; |
---|
371 | 382 | if (xfs_sb_version_haslazysbcount(&mp->m_sb)) |
---|
.. | .. |
---|
452 | 463 | xfs_buf_t *bp; |
---|
453 | 464 | int whole = 0; |
---|
454 | 465 | |
---|
455 | | - bp = xfs_trans_getsb(tp, tp->t_mountp, 0); |
---|
456 | | - sbp = XFS_BUF_TO_SBP(bp); |
---|
| 466 | + bp = xfs_trans_getsb(tp); |
---|
| 467 | + sbp = bp->b_addr; |
---|
457 | 468 | |
---|
458 | 469 | /* |
---|
459 | 470 | * Check that superblock mods match the mods made to AGF counters. |
---|
.. | .. |
---|
530 | 541 | sizeof(sbp->sb_frextents) - 1); |
---|
531 | 542 | } |
---|
532 | 543 | |
---|
533 | | -STATIC int |
---|
534 | | -xfs_sb_mod8( |
---|
535 | | - uint8_t *field, |
---|
536 | | - int8_t delta) |
---|
537 | | -{ |
---|
538 | | - int8_t counter = *field; |
---|
539 | | - |
---|
540 | | - counter += delta; |
---|
541 | | - if (counter < 0) { |
---|
542 | | - ASSERT(0); |
---|
543 | | - return -EINVAL; |
---|
544 | | - } |
---|
545 | | - *field = counter; |
---|
546 | | - return 0; |
---|
547 | | -} |
---|
548 | | - |
---|
549 | | -STATIC int |
---|
550 | | -xfs_sb_mod32( |
---|
551 | | - uint32_t *field, |
---|
552 | | - int32_t delta) |
---|
553 | | -{ |
---|
554 | | - int32_t counter = *field; |
---|
555 | | - |
---|
556 | | - counter += delta; |
---|
557 | | - if (counter < 0) { |
---|
558 | | - ASSERT(0); |
---|
559 | | - return -EINVAL; |
---|
560 | | - } |
---|
561 | | - *field = counter; |
---|
562 | | - return 0; |
---|
563 | | -} |
---|
564 | | - |
---|
565 | | -STATIC int |
---|
566 | | -xfs_sb_mod64( |
---|
567 | | - uint64_t *field, |
---|
568 | | - int64_t delta) |
---|
569 | | -{ |
---|
570 | | - int64_t counter = *field; |
---|
571 | | - |
---|
572 | | - counter += delta; |
---|
573 | | - if (counter < 0) { |
---|
574 | | - ASSERT(0); |
---|
575 | | - return -EINVAL; |
---|
576 | | - } |
---|
577 | | - *field = counter; |
---|
578 | | - return 0; |
---|
579 | | -} |
---|
580 | | - |
---|
581 | 544 | /* |
---|
582 | | - * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations |
---|
583 | | - * and apply superblock counter changes to the in-core superblock. The |
---|
| 545 | + * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations and |
---|
| 546 | + * apply superblock counter changes to the in-core superblock. The |
---|
584 | 547 | * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT |
---|
585 | 548 | * applied to the in-core superblock. The idea is that that has already been |
---|
586 | 549 | * done. |
---|
.. | .. |
---|
589 | 552 | * used block counts are not updated in the on disk superblock. In this case, |
---|
590 | 553 | * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we |
---|
591 | 554 | * still need to update the incore superblock with the changes. |
---|
| 555 | + * |
---|
| 556 | + * Deltas for the inode count are +/-64, hence we use a large batch size of 128 |
---|
| 557 | + * so we don't need to take the counter lock on every update. |
---|
592 | 558 | */ |
---|
| 559 | +#define XFS_ICOUNT_BATCH 128 |
---|
| 560 | + |
---|
593 | 561 | void |
---|
594 | 562 | xfs_trans_unreserve_and_mod_sb( |
---|
595 | 563 | struct xfs_trans *tp) |
---|
.. | .. |
---|
625 | 593 | /* apply the per-cpu counters */ |
---|
626 | 594 | if (blkdelta) { |
---|
627 | 595 | error = xfs_mod_fdblocks(mp, blkdelta, rsvd); |
---|
628 | | - if (error) |
---|
629 | | - goto out; |
---|
| 596 | + ASSERT(!error); |
---|
630 | 597 | } |
---|
631 | 598 | |
---|
632 | 599 | if (idelta) { |
---|
633 | | - error = xfs_mod_icount(mp, idelta); |
---|
634 | | - if (error) |
---|
635 | | - goto out_undo_fdblocks; |
---|
| 600 | + percpu_counter_add_batch(&mp->m_icount, idelta, |
---|
| 601 | + XFS_ICOUNT_BATCH); |
---|
| 602 | + if (idelta < 0) |
---|
| 603 | + ASSERT(__percpu_counter_compare(&mp->m_icount, 0, |
---|
| 604 | + XFS_ICOUNT_BATCH) >= 0); |
---|
636 | 605 | } |
---|
637 | 606 | |
---|
638 | 607 | if (ifreedelta) { |
---|
639 | | - error = xfs_mod_ifree(mp, ifreedelta); |
---|
640 | | - if (error) |
---|
641 | | - goto out_undo_icount; |
---|
| 608 | + percpu_counter_add(&mp->m_ifree, ifreedelta); |
---|
| 609 | + if (ifreedelta < 0) |
---|
| 610 | + ASSERT(percpu_counter_compare(&mp->m_ifree, 0) >= 0); |
---|
642 | 611 | } |
---|
643 | 612 | |
---|
644 | 613 | if (rtxdelta == 0 && !(tp->t_flags & XFS_TRANS_SB_DIRTY)) |
---|
.. | .. |
---|
646 | 615 | |
---|
647 | 616 | /* apply remaining deltas */ |
---|
648 | 617 | spin_lock(&mp->m_sb_lock); |
---|
649 | | - if (rtxdelta) { |
---|
650 | | - error = xfs_sb_mod64(&mp->m_sb.sb_frextents, rtxdelta); |
---|
651 | | - if (error) |
---|
652 | | - goto out_undo_ifree; |
---|
653 | | - } |
---|
654 | | - |
---|
655 | | - if (tp->t_dblocks_delta != 0) { |
---|
656 | | - error = xfs_sb_mod64(&mp->m_sb.sb_dblocks, tp->t_dblocks_delta); |
---|
657 | | - if (error) |
---|
658 | | - goto out_undo_frextents; |
---|
659 | | - } |
---|
660 | | - if (tp->t_agcount_delta != 0) { |
---|
661 | | - error = xfs_sb_mod32(&mp->m_sb.sb_agcount, tp->t_agcount_delta); |
---|
662 | | - if (error) |
---|
663 | | - goto out_undo_dblocks; |
---|
664 | | - } |
---|
665 | | - if (tp->t_imaxpct_delta != 0) { |
---|
666 | | - error = xfs_sb_mod8(&mp->m_sb.sb_imax_pct, tp->t_imaxpct_delta); |
---|
667 | | - if (error) |
---|
668 | | - goto out_undo_agcount; |
---|
669 | | - } |
---|
670 | | - if (tp->t_rextsize_delta != 0) { |
---|
671 | | - error = xfs_sb_mod32(&mp->m_sb.sb_rextsize, |
---|
672 | | - tp->t_rextsize_delta); |
---|
673 | | - if (error) |
---|
674 | | - goto out_undo_imaxpct; |
---|
675 | | - } |
---|
676 | | - if (tp->t_rbmblocks_delta != 0) { |
---|
677 | | - error = xfs_sb_mod32(&mp->m_sb.sb_rbmblocks, |
---|
678 | | - tp->t_rbmblocks_delta); |
---|
679 | | - if (error) |
---|
680 | | - goto out_undo_rextsize; |
---|
681 | | - } |
---|
682 | | - if (tp->t_rblocks_delta != 0) { |
---|
683 | | - error = xfs_sb_mod64(&mp->m_sb.sb_rblocks, tp->t_rblocks_delta); |
---|
684 | | - if (error) |
---|
685 | | - goto out_undo_rbmblocks; |
---|
686 | | - } |
---|
687 | | - if (tp->t_rextents_delta != 0) { |
---|
688 | | - error = xfs_sb_mod64(&mp->m_sb.sb_rextents, |
---|
689 | | - tp->t_rextents_delta); |
---|
690 | | - if (error) |
---|
691 | | - goto out_undo_rblocks; |
---|
692 | | - } |
---|
693 | | - if (tp->t_rextslog_delta != 0) { |
---|
694 | | - error = xfs_sb_mod8(&mp->m_sb.sb_rextslog, |
---|
695 | | - tp->t_rextslog_delta); |
---|
696 | | - if (error) |
---|
697 | | - goto out_undo_rextents; |
---|
698 | | - } |
---|
| 618 | + mp->m_sb.sb_fdblocks += tp->t_fdblocks_delta + tp->t_res_fdblocks_delta; |
---|
| 619 | + mp->m_sb.sb_icount += idelta; |
---|
| 620 | + mp->m_sb.sb_ifree += ifreedelta; |
---|
| 621 | + mp->m_sb.sb_frextents += rtxdelta; |
---|
| 622 | + mp->m_sb.sb_dblocks += tp->t_dblocks_delta; |
---|
| 623 | + mp->m_sb.sb_agcount += tp->t_agcount_delta; |
---|
| 624 | + mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta; |
---|
| 625 | + mp->m_sb.sb_rextsize += tp->t_rextsize_delta; |
---|
| 626 | + mp->m_sb.sb_rbmblocks += tp->t_rbmblocks_delta; |
---|
| 627 | + mp->m_sb.sb_rblocks += tp->t_rblocks_delta; |
---|
| 628 | + mp->m_sb.sb_rextents += tp->t_rextents_delta; |
---|
| 629 | + mp->m_sb.sb_rextslog += tp->t_rextslog_delta; |
---|
699 | 630 | spin_unlock(&mp->m_sb_lock); |
---|
700 | | - return; |
---|
701 | 631 | |
---|
702 | | -out_undo_rextents: |
---|
703 | | - if (tp->t_rextents_delta) |
---|
704 | | - xfs_sb_mod64(&mp->m_sb.sb_rextents, -tp->t_rextents_delta); |
---|
705 | | -out_undo_rblocks: |
---|
706 | | - if (tp->t_rblocks_delta) |
---|
707 | | - xfs_sb_mod64(&mp->m_sb.sb_rblocks, -tp->t_rblocks_delta); |
---|
708 | | -out_undo_rbmblocks: |
---|
709 | | - if (tp->t_rbmblocks_delta) |
---|
710 | | - xfs_sb_mod32(&mp->m_sb.sb_rbmblocks, -tp->t_rbmblocks_delta); |
---|
711 | | -out_undo_rextsize: |
---|
712 | | - if (tp->t_rextsize_delta) |
---|
713 | | - xfs_sb_mod32(&mp->m_sb.sb_rextsize, -tp->t_rextsize_delta); |
---|
714 | | -out_undo_imaxpct: |
---|
715 | | - if (tp->t_rextsize_delta) |
---|
716 | | - xfs_sb_mod8(&mp->m_sb.sb_imax_pct, -tp->t_imaxpct_delta); |
---|
717 | | -out_undo_agcount: |
---|
718 | | - if (tp->t_agcount_delta) |
---|
719 | | - xfs_sb_mod32(&mp->m_sb.sb_agcount, -tp->t_agcount_delta); |
---|
720 | | -out_undo_dblocks: |
---|
721 | | - if (tp->t_dblocks_delta) |
---|
722 | | - xfs_sb_mod64(&mp->m_sb.sb_dblocks, -tp->t_dblocks_delta); |
---|
723 | | -out_undo_frextents: |
---|
724 | | - if (rtxdelta) |
---|
725 | | - xfs_sb_mod64(&mp->m_sb.sb_frextents, -rtxdelta); |
---|
726 | | -out_undo_ifree: |
---|
727 | | - spin_unlock(&mp->m_sb_lock); |
---|
728 | | - if (ifreedelta) |
---|
729 | | - xfs_mod_ifree(mp, -ifreedelta); |
---|
730 | | -out_undo_icount: |
---|
731 | | - if (idelta) |
---|
732 | | - xfs_mod_icount(mp, -idelta); |
---|
733 | | -out_undo_fdblocks: |
---|
734 | | - if (blkdelta) |
---|
735 | | - xfs_mod_fdblocks(mp, -blkdelta, rsvd); |
---|
736 | | -out: |
---|
737 | | - ASSERT(error == 0); |
---|
| 632 | + /* |
---|
| 633 | + * Debug checks outside of the spinlock so they don't lock up the |
---|
| 634 | + * machine if they fail. |
---|
| 635 | + */ |
---|
| 636 | + ASSERT(mp->m_sb.sb_imax_pct >= 0); |
---|
| 637 | + ASSERT(mp->m_sb.sb_rextslog >= 0); |
---|
738 | 638 | return; |
---|
739 | 639 | } |
---|
740 | 640 | |
---|
.. | .. |
---|
767 | 667 | } |
---|
768 | 668 | |
---|
769 | 669 | /* Detach and unlock all of the items in a transaction */ |
---|
770 | | -void |
---|
| 670 | +static void |
---|
771 | 671 | xfs_trans_free_items( |
---|
772 | 672 | struct xfs_trans *tp, |
---|
773 | | - xfs_lsn_t commit_lsn, |
---|
774 | 673 | bool abort) |
---|
775 | 674 | { |
---|
776 | 675 | struct xfs_log_item *lip, *next; |
---|
.. | .. |
---|
779 | 678 | |
---|
780 | 679 | list_for_each_entry_safe(lip, next, &tp->t_items, li_trans) { |
---|
781 | 680 | xfs_trans_del_item(lip); |
---|
782 | | - if (commit_lsn != NULLCOMMITLSN) |
---|
783 | | - lip->li_ops->iop_committing(lip, commit_lsn); |
---|
784 | 681 | if (abort) |
---|
785 | 682 | set_bit(XFS_LI_ABORTED, &lip->li_flags); |
---|
786 | | - lip->li_ops->iop_unlock(lip); |
---|
| 683 | + if (lip->li_ops->iop_release) |
---|
| 684 | + lip->li_ops->iop_release(lip); |
---|
787 | 685 | } |
---|
788 | 686 | } |
---|
789 | 687 | |
---|
.. | .. |
---|
804 | 702 | for (i = 0; i < nr_items; i++) { |
---|
805 | 703 | struct xfs_log_item *lip = log_items[i]; |
---|
806 | 704 | |
---|
807 | | - lip->li_ops->iop_unpin(lip, 0); |
---|
| 705 | + if (lip->li_ops->iop_unpin) |
---|
| 706 | + lip->li_ops->iop_unpin(lip, 0); |
---|
808 | 707 | } |
---|
809 | 708 | } |
---|
810 | 709 | |
---|
.. | .. |
---|
815 | 714 | * |
---|
816 | 715 | * If we are called with the aborted flag set, it is because a log write during |
---|
817 | 716 | * a CIL checkpoint commit has failed. In this case, all the items in the |
---|
818 | | - * checkpoint have already gone through iop_commited and iop_unlock, which |
---|
| 717 | + * checkpoint have already gone through iop_committed and iop_committing, which |
---|
819 | 718 | * means that checkpoint commit abort handling is treated exactly the same |
---|
820 | 719 | * as an iclog write error even though we haven't started any IO yet. Hence in |
---|
821 | 720 | * this case all we need to do is iop_committed processing, followed by an |
---|
.. | .. |
---|
833 | 732 | struct xfs_ail *ailp, |
---|
834 | 733 | struct xfs_log_vec *log_vector, |
---|
835 | 734 | xfs_lsn_t commit_lsn, |
---|
836 | | - int aborted) |
---|
| 735 | + bool aborted) |
---|
837 | 736 | { |
---|
838 | 737 | #define LOG_ITEM_BATCH_SIZE 32 |
---|
839 | 738 | struct xfs_log_item *log_items[LOG_ITEM_BATCH_SIZE]; |
---|
.. | .. |
---|
852 | 751 | |
---|
853 | 752 | if (aborted) |
---|
854 | 753 | set_bit(XFS_LI_ABORTED, &lip->li_flags); |
---|
855 | | - item_lsn = lip->li_ops->iop_committed(lip, commit_lsn); |
---|
| 754 | + |
---|
| 755 | + if (lip->li_ops->flags & XFS_ITEM_RELEASE_WHEN_COMMITTED) { |
---|
| 756 | + lip->li_ops->iop_release(lip); |
---|
| 757 | + continue; |
---|
| 758 | + } |
---|
| 759 | + |
---|
| 760 | + if (lip->li_ops->iop_committed) |
---|
| 761 | + item_lsn = lip->li_ops->iop_committed(lip, commit_lsn); |
---|
| 762 | + else |
---|
| 763 | + item_lsn = commit_lsn; |
---|
856 | 764 | |
---|
857 | 765 | /* item_lsn of -1 means the item needs no further processing */ |
---|
858 | 766 | if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0) |
---|
.. | .. |
---|
864 | 772 | */ |
---|
865 | 773 | if (aborted) { |
---|
866 | 774 | ASSERT(XFS_FORCED_SHUTDOWN(ailp->ail_mount)); |
---|
867 | | - lip->li_ops->iop_unpin(lip, 1); |
---|
| 775 | + if (lip->li_ops->iop_unpin) |
---|
| 776 | + lip->li_ops->iop_unpin(lip, 1); |
---|
868 | 777 | continue; |
---|
869 | 778 | } |
---|
870 | 779 | |
---|
.. | .. |
---|
882 | 791 | xfs_trans_ail_update(ailp, lip, item_lsn); |
---|
883 | 792 | else |
---|
884 | 793 | spin_unlock(&ailp->ail_lock); |
---|
885 | | - lip->li_ops->iop_unpin(lip, 0); |
---|
| 794 | + if (lip->li_ops->iop_unpin) |
---|
| 795 | + lip->li_ops->iop_unpin(lip, 0); |
---|
886 | 796 | continue; |
---|
887 | 797 | } |
---|
888 | 798 | |
---|
.. | .. |
---|
922 | 832 | bool regrant) |
---|
923 | 833 | { |
---|
924 | 834 | struct xfs_mount *mp = tp->t_mountp; |
---|
925 | | - xfs_lsn_t commit_lsn = -1; |
---|
| 835 | + xfs_csn_t commit_seq = 0; |
---|
926 | 836 | int error = 0; |
---|
927 | 837 | int sync = tp->t_flags & XFS_TRANS_SYNC; |
---|
928 | 838 | |
---|
.. | .. |
---|
964 | 874 | xfs_trans_apply_sb_deltas(tp); |
---|
965 | 875 | xfs_trans_apply_dquot_deltas(tp); |
---|
966 | 876 | |
---|
967 | | - xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); |
---|
| 877 | + xlog_cil_commit(mp->m_log, tp, &commit_seq, regrant); |
---|
968 | 878 | |
---|
969 | | - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
---|
970 | 879 | xfs_trans_free(tp); |
---|
971 | 880 | |
---|
972 | 881 | /* |
---|
.. | .. |
---|
974 | 883 | * log out now and wait for it. |
---|
975 | 884 | */ |
---|
976 | 885 | if (sync) { |
---|
977 | | - error = xfs_log_force_lsn(mp, commit_lsn, XFS_LOG_SYNC, NULL); |
---|
| 886 | + error = xfs_log_force_seq(mp, commit_seq, XFS_LOG_SYNC, NULL); |
---|
978 | 887 | XFS_STATS_INC(mp, xs_trans_sync); |
---|
979 | 888 | } else { |
---|
980 | 889 | XFS_STATS_INC(mp, xs_trans_async); |
---|
.. | .. |
---|
992 | 901 | */ |
---|
993 | 902 | xfs_trans_unreserve_and_mod_dquots(tp); |
---|
994 | 903 | if (tp->t_ticket) { |
---|
995 | | - commit_lsn = xfs_log_done(mp, tp->t_ticket, NULL, regrant); |
---|
996 | | - if (commit_lsn == -1 && !error) |
---|
997 | | - error = -EIO; |
---|
| 904 | + if (regrant && !XLOG_FORCED_SHUTDOWN(mp->m_log)) |
---|
| 905 | + xfs_log_ticket_regrant(mp->m_log, tp->t_ticket); |
---|
| 906 | + else |
---|
| 907 | + xfs_log_ticket_ungrant(mp->m_log, tp->t_ticket); |
---|
998 | 908 | tp->t_ticket = NULL; |
---|
999 | 909 | } |
---|
1000 | | - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
---|
1001 | | - xfs_trans_free_items(tp, NULLCOMMITLSN, !!error); |
---|
| 910 | + xfs_trans_free_items(tp, !!error); |
---|
1002 | 911 | xfs_trans_free(tp); |
---|
1003 | 912 | |
---|
1004 | 913 | XFS_STATS_INC(mp, xs_trans_empty); |
---|
.. | .. |
---|
1046 | 955 | struct xfs_log_item *lip; |
---|
1047 | 956 | |
---|
1048 | 957 | list_for_each_entry(lip, &tp->t_items, li_trans) |
---|
1049 | | - ASSERT(!(lip->li_type == XFS_LI_EFD)); |
---|
| 958 | + ASSERT(!xlog_item_is_intent_done(lip)); |
---|
1050 | 959 | } |
---|
1051 | 960 | #endif |
---|
1052 | 961 | xfs_trans_unreserve_and_mod_sb(tp); |
---|
1053 | 962 | xfs_trans_unreserve_and_mod_dquots(tp); |
---|
1054 | 963 | |
---|
1055 | 964 | if (tp->t_ticket) { |
---|
1056 | | - xfs_log_done(mp, tp->t_ticket, NULL, false); |
---|
| 965 | + xfs_log_ticket_ungrant(mp->m_log, tp->t_ticket); |
---|
1057 | 966 | tp->t_ticket = NULL; |
---|
1058 | 967 | } |
---|
1059 | 968 | |
---|
1060 | | - /* mark this thread as no longer being in a transaction */ |
---|
1061 | | - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
---|
1062 | | - |
---|
1063 | | - xfs_trans_free_items(tp, NULLCOMMITLSN, dirty); |
---|
| 969 | + xfs_trans_free_items(tp, dirty); |
---|
1064 | 970 | xfs_trans_free(tp); |
---|
1065 | 971 | } |
---|
1066 | 972 | |
---|