Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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