jbd2: remove t_checkpoint_io_list
[platform/kernel/linux-starfive.git] / fs / jbd2 / checkpoint.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * linux/fs/jbd2/checkpoint.c
4  *
5  * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
6  *
7  * Copyright 1999 Red Hat Software --- All Rights Reserved
8  *
9  * Checkpoint routines for the generic filesystem journaling code.
10  * Part of the ext2fs journaling system.
11  *
12  * Checkpointing is the process of ensuring that a section of the log is
13  * committed fully to disk, so that that portion of the log can be
14  * reused.
15  */
16
17 #include <linux/time.h>
18 #include <linux/fs.h>
19 #include <linux/jbd2.h>
20 #include <linux/errno.h>
21 #include <linux/slab.h>
22 #include <linux/blkdev.h>
23 #include <trace/events/jbd2.h>
24
25 /*
26  * Unlink a buffer from a transaction checkpoint list.
27  *
28  * Called with j_list_lock held.
29  */
30 static inline void __buffer_unlink(struct journal_head *jh)
31 {
32         transaction_t *transaction = jh->b_cp_transaction;
33
34         jh->b_cpnext->b_cpprev = jh->b_cpprev;
35         jh->b_cpprev->b_cpnext = jh->b_cpnext;
36         if (transaction->t_checkpoint_list == jh) {
37                 transaction->t_checkpoint_list = jh->b_cpnext;
38                 if (transaction->t_checkpoint_list == jh)
39                         transaction->t_checkpoint_list = NULL;
40         }
41 }
42
43 /*
44  * Check a checkpoint buffer could be release or not.
45  *
46  * Requires j_list_lock
47  */
48 static inline bool __cp_buffer_busy(struct journal_head *jh)
49 {
50         struct buffer_head *bh = jh2bh(jh);
51
52         return (jh->b_transaction || buffer_locked(bh) || buffer_dirty(bh));
53 }
54
55 /*
56  * __jbd2_log_wait_for_space: wait until there is space in the journal.
57  *
58  * Called under j-state_lock *only*.  It will be unlocked if we have to wait
59  * for a checkpoint to free up some space in the log.
60  */
61 void __jbd2_log_wait_for_space(journal_t *journal)
62 __acquires(&journal->j_state_lock)
63 __releases(&journal->j_state_lock)
64 {
65         int nblocks, space_left;
66         /* assert_spin_locked(&journal->j_state_lock); */
67
68         nblocks = journal->j_max_transaction_buffers;
69         while (jbd2_log_space_left(journal) < nblocks) {
70                 write_unlock(&journal->j_state_lock);
71                 mutex_lock_io(&journal->j_checkpoint_mutex);
72
73                 /*
74                  * Test again, another process may have checkpointed while we
75                  * were waiting for the checkpoint lock. If there are no
76                  * transactions ready to be checkpointed, try to recover
77                  * journal space by calling cleanup_journal_tail(), and if
78                  * that doesn't work, by waiting for the currently committing
79                  * transaction to complete.  If there is absolutely no way
80                  * to make progress, this is either a BUG or corrupted
81                  * filesystem, so abort the journal and leave a stack
82                  * trace for forensic evidence.
83                  */
84                 write_lock(&journal->j_state_lock);
85                 if (journal->j_flags & JBD2_ABORT) {
86                         mutex_unlock(&journal->j_checkpoint_mutex);
87                         return;
88                 }
89                 spin_lock(&journal->j_list_lock);
90                 space_left = jbd2_log_space_left(journal);
91                 if (space_left < nblocks) {
92                         int chkpt = journal->j_checkpoint_transactions != NULL;
93                         tid_t tid = 0;
94
95                         if (journal->j_committing_transaction)
96                                 tid = journal->j_committing_transaction->t_tid;
97                         spin_unlock(&journal->j_list_lock);
98                         write_unlock(&journal->j_state_lock);
99                         if (chkpt) {
100                                 jbd2_log_do_checkpoint(journal);
101                         } else if (jbd2_cleanup_journal_tail(journal) == 0) {
102                                 /* We were able to recover space; yay! */
103                                 ;
104                         } else if (tid) {
105                                 /*
106                                  * jbd2_journal_commit_transaction() may want
107                                  * to take the checkpoint_mutex if JBD2_FLUSHED
108                                  * is set.  So we need to temporarily drop it.
109                                  */
110                                 mutex_unlock(&journal->j_checkpoint_mutex);
111                                 jbd2_log_wait_commit(journal, tid);
112                                 write_lock(&journal->j_state_lock);
113                                 continue;
114                         } else {
115                                 printk(KERN_ERR "%s: needed %d blocks and "
116                                        "only had %d space available\n",
117                                        __func__, nblocks, space_left);
118                                 printk(KERN_ERR "%s: no way to get more "
119                                        "journal space in %s\n", __func__,
120                                        journal->j_devname);
121                                 WARN_ON(1);
122                                 jbd2_journal_abort(journal, -EIO);
123                         }
124                         write_lock(&journal->j_state_lock);
125                 } else {
126                         spin_unlock(&journal->j_list_lock);
127                 }
128                 mutex_unlock(&journal->j_checkpoint_mutex);
129         }
130 }
131
132 static void
133 __flush_batch(journal_t *journal, int *batch_count)
134 {
135         int i;
136         struct blk_plug plug;
137
138         blk_start_plug(&plug);
139         for (i = 0; i < *batch_count; i++)
140                 write_dirty_buffer(journal->j_chkpt_bhs[i], REQ_SYNC);
141         blk_finish_plug(&plug);
142
143         for (i = 0; i < *batch_count; i++) {
144                 struct buffer_head *bh = journal->j_chkpt_bhs[i];
145                 BUFFER_TRACE(bh, "brelse");
146                 __brelse(bh);
147                 journal->j_chkpt_bhs[i] = NULL;
148         }
149         *batch_count = 0;
150 }
151
152 /*
153  * Perform an actual checkpoint. We take the first transaction on the
154  * list of transactions to be checkpointed and send all its buffers
155  * to disk. We submit larger chunks of data at once.
156  *
157  * The journal should be locked before calling this function.
158  * Called with j_checkpoint_mutex held.
159  */
160 int jbd2_log_do_checkpoint(journal_t *journal)
161 {
162         struct journal_head     *jh;
163         struct buffer_head      *bh;
164         transaction_t           *transaction;
165         tid_t                   this_tid;
166         int                     result, batch_count = 0;
167
168         jbd2_debug(1, "Start checkpoint\n");
169
170         /*
171          * First thing: if there are any transactions in the log which
172          * don't need checkpointing, just eliminate them from the
173          * journal straight away.
174          */
175         result = jbd2_cleanup_journal_tail(journal);
176         trace_jbd2_checkpoint(journal, result);
177         jbd2_debug(1, "cleanup_journal_tail returned %d\n", result);
178         if (result <= 0)
179                 return result;
180
181         /*
182          * OK, we need to start writing disk blocks.  Take one transaction
183          * and write it.
184          */
185         spin_lock(&journal->j_list_lock);
186         if (!journal->j_checkpoint_transactions)
187                 goto out;
188         transaction = journal->j_checkpoint_transactions;
189         if (transaction->t_chp_stats.cs_chp_time == 0)
190                 transaction->t_chp_stats.cs_chp_time = jiffies;
191         this_tid = transaction->t_tid;
192 restart:
193         /*
194          * If someone cleaned up this transaction while we slept, we're
195          * done (maybe it's a new transaction, but it fell at the same
196          * address).
197          */
198         if (journal->j_checkpoint_transactions != transaction ||
199             transaction->t_tid != this_tid)
200                 goto out;
201
202         /* checkpoint all of the transaction's buffers */
203         while (transaction->t_checkpoint_list) {
204                 jh = transaction->t_checkpoint_list;
205                 bh = jh2bh(jh);
206
207                 /*
208                  * The buffer may be writing back, or flushing out in the
209                  * last couple of cycles, or re-adding into a new transaction,
210                  * need to check it again until it's unlocked.
211                  */
212                 if (buffer_locked(bh)) {
213                         get_bh(bh);
214                         spin_unlock(&journal->j_list_lock);
215                         wait_on_buffer(bh);
216                         /* the journal_head may have gone by now */
217                         BUFFER_TRACE(bh, "brelse");
218                         __brelse(bh);
219                         goto retry;
220                 }
221                 if (jh->b_transaction != NULL) {
222                         transaction_t *t = jh->b_transaction;
223                         tid_t tid = t->t_tid;
224
225                         transaction->t_chp_stats.cs_forced_to_close++;
226                         spin_unlock(&journal->j_list_lock);
227                         if (unlikely(journal->j_flags & JBD2_UNMOUNT))
228                                 /*
229                                  * The journal thread is dead; so
230                                  * starting and waiting for a commit
231                                  * to finish will cause us to wait for
232                                  * a _very_ long time.
233                                  */
234                                 printk(KERN_ERR
235                 "JBD2: %s: Waiting for Godot: block %llu\n",
236                 journal->j_devname, (unsigned long long) bh->b_blocknr);
237
238                         if (batch_count)
239                                 __flush_batch(journal, &batch_count);
240                         jbd2_log_start_commit(journal, tid);
241                         /*
242                          * jbd2_journal_commit_transaction() may want
243                          * to take the checkpoint_mutex if JBD2_FLUSHED
244                          * is set, jbd2_update_log_tail() called by
245                          * jbd2_journal_commit_transaction() may also take
246                          * checkpoint_mutex.  So we need to temporarily
247                          * drop it.
248                          */
249                         mutex_unlock(&journal->j_checkpoint_mutex);
250                         jbd2_log_wait_commit(journal, tid);
251                         mutex_lock_io(&journal->j_checkpoint_mutex);
252                         spin_lock(&journal->j_list_lock);
253                         goto restart;
254                 }
255                 if (!buffer_dirty(bh)) {
256                         BUFFER_TRACE(bh, "remove from checkpoint");
257                         /*
258                          * If the transaction was released or the checkpoint
259                          * list was empty, we're done.
260                          */
261                         if (__jbd2_journal_remove_checkpoint(jh) ||
262                             !transaction->t_checkpoint_list)
263                                 goto out;
264                 } else {
265                         /*
266                          * We are about to write the buffer, it could be
267                          * raced by some other transaction shrink or buffer
268                          * re-log logic once we release the j_list_lock,
269                          * leave it on the checkpoint list and check status
270                          * again to make sure it's clean.
271                          */
272                         BUFFER_TRACE(bh, "queue");
273                         get_bh(bh);
274                         J_ASSERT_BH(bh, !buffer_jwrite(bh));
275                         journal->j_chkpt_bhs[batch_count++] = bh;
276                         transaction->t_chp_stats.cs_written++;
277                         transaction->t_checkpoint_list = jh->b_cpnext;
278                 }
279
280                 if ((batch_count == JBD2_NR_BATCH) ||
281                     need_resched() || spin_needbreak(&journal->j_list_lock) ||
282                     jh2bh(transaction->t_checkpoint_list) == journal->j_chkpt_bhs[0])
283                         goto unlock_and_flush;
284         }
285
286         if (batch_count) {
287                 unlock_and_flush:
288                         spin_unlock(&journal->j_list_lock);
289                 retry:
290                         if (batch_count)
291                                 __flush_batch(journal, &batch_count);
292                         spin_lock(&journal->j_list_lock);
293                         goto restart;
294         }
295
296 out:
297         spin_unlock(&journal->j_list_lock);
298         result = jbd2_cleanup_journal_tail(journal);
299
300         return (result < 0) ? result : 0;
301 }
302
303 /*
304  * Check the list of checkpoint transactions for the journal to see if
305  * we have already got rid of any since the last update of the log tail
306  * in the journal superblock.  If so, we can instantly roll the
307  * superblock forward to remove those transactions from the log.
308  *
309  * Return <0 on error, 0 on success, 1 if there was nothing to clean up.
310  *
311  * Called with the journal lock held.
312  *
313  * This is the only part of the journaling code which really needs to be
314  * aware of transaction aborts.  Checkpointing involves writing to the
315  * main filesystem area rather than to the journal, so it can proceed
316  * even in abort state, but we must not update the super block if
317  * checkpointing may have failed.  Otherwise, we would lose some metadata
318  * buffers which should be written-back to the filesystem.
319  */
320
321 int jbd2_cleanup_journal_tail(journal_t *journal)
322 {
323         tid_t           first_tid;
324         unsigned long   blocknr;
325
326         if (is_journal_aborted(journal))
327                 return -EIO;
328
329         if (!jbd2_journal_get_log_tail(journal, &first_tid, &blocknr))
330                 return 1;
331         J_ASSERT(blocknr != 0);
332
333         /*
334          * We need to make sure that any blocks that were recently written out
335          * --- perhaps by jbd2_log_do_checkpoint() --- are flushed out before
336          * we drop the transactions from the journal. It's unlikely this will
337          * be necessary, especially with an appropriately sized journal, but we
338          * need this to guarantee correctness.  Fortunately
339          * jbd2_cleanup_journal_tail() doesn't get called all that often.
340          */
341         if (journal->j_flags & JBD2_BARRIER)
342                 blkdev_issue_flush(journal->j_fs_dev);
343
344         return __jbd2_update_log_tail(journal, first_tid, blocknr);
345 }
346
347
348 /* Checkpoint list management */
349
350 /*
351  * journal_clean_one_cp_list
352  *
353  * Find all the written-back checkpoint buffers in the given list and
354  * release them. If 'destroy' is set, clean all buffers unconditionally.
355  *
356  * Called with j_list_lock held.
357  * Returns 1 if we freed the transaction, 0 otherwise.
358  */
359 static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
360 {
361         struct journal_head *last_jh;
362         struct journal_head *next_jh = jh;
363
364         if (!jh)
365                 return 0;
366
367         last_jh = jh->b_cpprev;
368         do {
369                 jh = next_jh;
370                 next_jh = jh->b_cpnext;
371
372                 if (!destroy && __cp_buffer_busy(jh))
373                         return 0;
374
375                 if (__jbd2_journal_remove_checkpoint(jh))
376                         return 1;
377                 /*
378                  * This function only frees up some memory
379                  * if possible so we dont have an obligation
380                  * to finish processing. Bail out if preemption
381                  * requested:
382                  */
383                 if (need_resched())
384                         return 0;
385         } while (jh != last_jh);
386
387         return 0;
388 }
389
390 /*
391  * journal_shrink_one_cp_list
392  *
393  * Find 'nr_to_scan' written-back checkpoint buffers in the given list
394  * and try to release them. If the whole transaction is released, set
395  * the 'released' parameter. Return the number of released checkpointed
396  * buffers.
397  *
398  * Called with j_list_lock held.
399  */
400 static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
401                                                 unsigned long *nr_to_scan,
402                                                 bool *released)
403 {
404         struct journal_head *last_jh;
405         struct journal_head *next_jh = jh;
406         unsigned long nr_freed = 0;
407         int ret;
408
409         if (!jh || *nr_to_scan == 0)
410                 return 0;
411
412         last_jh = jh->b_cpprev;
413         do {
414                 jh = next_jh;
415                 next_jh = jh->b_cpnext;
416
417                 (*nr_to_scan)--;
418                 if (__cp_buffer_busy(jh))
419                         continue;
420
421                 nr_freed++;
422                 ret = __jbd2_journal_remove_checkpoint(jh);
423                 if (ret) {
424                         *released = true;
425                         break;
426                 }
427
428                 if (need_resched())
429                         break;
430         } while (jh != last_jh && *nr_to_scan);
431
432         return nr_freed;
433 }
434
435 /*
436  * jbd2_journal_shrink_checkpoint_list
437  *
438  * Find 'nr_to_scan' written-back checkpoint buffers in the journal
439  * and try to release them. Return the number of released checkpointed
440  * buffers.
441  *
442  * Called with j_list_lock held.
443  */
444 unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
445                                                   unsigned long *nr_to_scan)
446 {
447         transaction_t *transaction, *last_transaction, *next_transaction;
448         bool released;
449         tid_t first_tid = 0, last_tid = 0, next_tid = 0;
450         tid_t tid = 0;
451         unsigned long nr_freed = 0;
452         unsigned long nr_scanned = *nr_to_scan;
453
454 again:
455         spin_lock(&journal->j_list_lock);
456         if (!journal->j_checkpoint_transactions) {
457                 spin_unlock(&journal->j_list_lock);
458                 goto out;
459         }
460
461         /*
462          * Get next shrink transaction, resume previous scan or start
463          * over again. If some others do checkpoint and drop transaction
464          * from the checkpoint list, we ignore saved j_shrink_transaction
465          * and start over unconditionally.
466          */
467         if (journal->j_shrink_transaction)
468                 transaction = journal->j_shrink_transaction;
469         else
470                 transaction = journal->j_checkpoint_transactions;
471
472         if (!first_tid)
473                 first_tid = transaction->t_tid;
474         last_transaction = journal->j_checkpoint_transactions->t_cpprev;
475         next_transaction = transaction;
476         last_tid = last_transaction->t_tid;
477         do {
478                 transaction = next_transaction;
479                 next_transaction = transaction->t_cpnext;
480                 tid = transaction->t_tid;
481                 released = false;
482
483                 nr_freed += journal_shrink_one_cp_list(transaction->t_checkpoint_list,
484                                                        nr_to_scan, &released);
485                 if (*nr_to_scan == 0)
486                         break;
487                 if (need_resched() || spin_needbreak(&journal->j_list_lock))
488                         break;
489         } while (transaction != last_transaction);
490
491         if (transaction != last_transaction) {
492                 journal->j_shrink_transaction = next_transaction;
493                 next_tid = next_transaction->t_tid;
494         } else {
495                 journal->j_shrink_transaction = NULL;
496                 next_tid = 0;
497         }
498
499         spin_unlock(&journal->j_list_lock);
500         cond_resched();
501
502         if (*nr_to_scan && next_tid)
503                 goto again;
504 out:
505         nr_scanned -= *nr_to_scan;
506         trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
507                                           nr_freed, nr_scanned, next_tid);
508
509         return nr_freed;
510 }
511
512 /*
513  * journal_clean_checkpoint_list
514  *
515  * Find all the written-back checkpoint buffers in the journal and release them.
516  * If 'destroy' is set, release all buffers unconditionally.
517  *
518  * Called with j_list_lock held.
519  */
520 void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
521 {
522         transaction_t *transaction, *last_transaction, *next_transaction;
523         int ret;
524
525         transaction = journal->j_checkpoint_transactions;
526         if (!transaction)
527                 return;
528
529         last_transaction = transaction->t_cpprev;
530         next_transaction = transaction;
531         do {
532                 transaction = next_transaction;
533                 next_transaction = transaction->t_cpnext;
534                 ret = journal_clean_one_cp_list(transaction->t_checkpoint_list,
535                                                 destroy);
536                 /*
537                  * This function only frees up some memory if possible so we
538                  * dont have an obligation to finish processing. Bail out if
539                  * preemption requested:
540                  */
541                 if (need_resched())
542                         return;
543                 /*
544                  * Stop scanning if we couldn't free the transaction. This
545                  * avoids pointless scanning of transactions which still
546                  * weren't checkpointed.
547                  */
548                 if (!ret)
549                         return;
550         } while (transaction != last_transaction);
551 }
552
553 /*
554  * Remove buffers from all checkpoint lists as journal is aborted and we just
555  * need to free memory
556  */
557 void jbd2_journal_destroy_checkpoint(journal_t *journal)
558 {
559         /*
560          * We loop because __jbd2_journal_clean_checkpoint_list() may abort
561          * early due to a need of rescheduling.
562          */
563         while (1) {
564                 spin_lock(&journal->j_list_lock);
565                 if (!journal->j_checkpoint_transactions) {
566                         spin_unlock(&journal->j_list_lock);
567                         break;
568                 }
569                 __jbd2_journal_clean_checkpoint_list(journal, true);
570                 spin_unlock(&journal->j_list_lock);
571                 cond_resched();
572         }
573 }
574
575 /*
576  * journal_remove_checkpoint: called after a buffer has been committed
577  * to disk (either by being write-back flushed to disk, or being
578  * committed to the log).
579  *
580  * We cannot safely clean a transaction out of the log until all of the
581  * buffer updates committed in that transaction have safely been stored
582  * elsewhere on disk.  To achieve this, all of the buffers in a
583  * transaction need to be maintained on the transaction's checkpoint
584  * lists until they have been rewritten, at which point this function is
585  * called to remove the buffer from the existing transaction's
586  * checkpoint lists.
587  *
588  * The function returns 1 if it frees the transaction, 0 otherwise.
589  * The function can free jh and bh.
590  *
591  * This function is called with j_list_lock held.
592  */
593 int __jbd2_journal_remove_checkpoint(struct journal_head *jh)
594 {
595         struct transaction_chp_stats_s *stats;
596         transaction_t *transaction;
597         journal_t *journal;
598         struct buffer_head *bh = jh2bh(jh);
599
600         JBUFFER_TRACE(jh, "entry");
601
602         transaction = jh->b_cp_transaction;
603         if (!transaction) {
604                 JBUFFER_TRACE(jh, "not on transaction");
605                 return 0;
606         }
607         journal = transaction->t_journal;
608
609         JBUFFER_TRACE(jh, "removing from transaction");
610
611         /*
612          * If we have failed to write the buffer out to disk, the filesystem
613          * may become inconsistent. We cannot abort the journal here since
614          * we hold j_list_lock and we have to be careful about races with
615          * jbd2_journal_destroy(). So mark the writeback IO error in the
616          * journal here and we abort the journal later from a better context.
617          */
618         if (buffer_write_io_error(bh))
619                 set_bit(JBD2_CHECKPOINT_IO_ERROR, &journal->j_atomic_flags);
620
621         __buffer_unlink(jh);
622         jh->b_cp_transaction = NULL;
623         percpu_counter_dec(&journal->j_checkpoint_jh_count);
624         jbd2_journal_put_journal_head(jh);
625
626         /* Is this transaction empty? */
627         if (transaction->t_checkpoint_list)
628                 return 0;
629
630         /*
631          * There is one special case to worry about: if we have just pulled the
632          * buffer off a running or committing transaction's checkpoing list,
633          * then even if the checkpoint list is empty, the transaction obviously
634          * cannot be dropped!
635          *
636          * The locking here around t_state is a bit sleazy.
637          * See the comment at the end of jbd2_journal_commit_transaction().
638          */
639         if (transaction->t_state != T_FINISHED)
640                 return 0;
641
642         /*
643          * OK, that was the last buffer for the transaction, we can now
644          * safely remove this transaction from the log.
645          */
646         stats = &transaction->t_chp_stats;
647         if (stats->cs_chp_time)
648                 stats->cs_chp_time = jbd2_time_diff(stats->cs_chp_time,
649                                                     jiffies);
650         trace_jbd2_checkpoint_stats(journal->j_fs_dev->bd_dev,
651                                     transaction->t_tid, stats);
652
653         __jbd2_journal_drop_transaction(journal, transaction);
654         jbd2_journal_free_transaction(transaction);
655         return 1;
656 }
657
658 /*
659  * journal_insert_checkpoint: put a committed buffer onto a checkpoint
660  * list so that we know when it is safe to clean the transaction out of
661  * the log.
662  *
663  * Called with the journal locked.
664  * Called with j_list_lock held.
665  */
666 void __jbd2_journal_insert_checkpoint(struct journal_head *jh,
667                                transaction_t *transaction)
668 {
669         JBUFFER_TRACE(jh, "entry");
670         J_ASSERT_JH(jh, buffer_dirty(jh2bh(jh)) || buffer_jbddirty(jh2bh(jh)));
671         J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
672
673         /* Get reference for checkpointing transaction */
674         jbd2_journal_grab_journal_head(jh2bh(jh));
675         jh->b_cp_transaction = transaction;
676
677         if (!transaction->t_checkpoint_list) {
678                 jh->b_cpnext = jh->b_cpprev = jh;
679         } else {
680                 jh->b_cpnext = transaction->t_checkpoint_list;
681                 jh->b_cpprev = transaction->t_checkpoint_list->b_cpprev;
682                 jh->b_cpprev->b_cpnext = jh;
683                 jh->b_cpnext->b_cpprev = jh;
684         }
685         transaction->t_checkpoint_list = jh;
686         percpu_counter_inc(&transaction->t_journal->j_checkpoint_jh_count);
687 }
688
689 /*
690  * We've finished with this transaction structure: adios...
691  *
692  * The transaction must have no links except for the checkpoint by this
693  * point.
694  *
695  * Called with the journal locked.
696  * Called with j_list_lock held.
697  */
698
699 void __jbd2_journal_drop_transaction(journal_t *journal, transaction_t *transaction)
700 {
701         assert_spin_locked(&journal->j_list_lock);
702
703         journal->j_shrink_transaction = NULL;
704         if (transaction->t_cpnext) {
705                 transaction->t_cpnext->t_cpprev = transaction->t_cpprev;
706                 transaction->t_cpprev->t_cpnext = transaction->t_cpnext;
707                 if (journal->j_checkpoint_transactions == transaction)
708                         journal->j_checkpoint_transactions =
709                                 transaction->t_cpnext;
710                 if (journal->j_checkpoint_transactions == transaction)
711                         journal->j_checkpoint_transactions = NULL;
712         }
713
714         J_ASSERT(transaction->t_state == T_FINISHED);
715         J_ASSERT(transaction->t_buffers == NULL);
716         J_ASSERT(transaction->t_forget == NULL);
717         J_ASSERT(transaction->t_shadow_list == NULL);
718         J_ASSERT(transaction->t_checkpoint_list == NULL);
719         J_ASSERT(atomic_read(&transaction->t_updates) == 0);
720         J_ASSERT(journal->j_committing_transaction != transaction);
721         J_ASSERT(journal->j_running_transaction != transaction);
722
723         trace_jbd2_drop_transaction(journal, transaction);
724
725         jbd2_debug(1, "Dropping transaction %d, all done\n", transaction->t_tid);
726 }