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/recovery.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-2000 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)  * Journal recovery 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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #ifndef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "jfs_user.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/jbd2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Maintain information about the progress of the recovery job, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * the different passes can carry information between them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct recovery_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	tid_t		start_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	tid_t		end_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int		nr_replays;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int		nr_revokes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	int		nr_revoke_hits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int do_one_pass(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				struct recovery_info *info, enum passtype pass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static int scan_revoke_records(journal_t *, struct buffer_head *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 				tid_t, struct recovery_info *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* Release readahead buffers after use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static void journal_brelse_array(struct buffer_head *b[], int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	while (--n >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		brelse (b[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * When reading from the journal, we are going through the block device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * layer directly and so there is no readahead being done for us.  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * need to implement any readahead ourselves if we want it to happen at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * all.  Recovery is basically one long sequential read, so make sure we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * do the IO in reasonably large chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * This is not so critical that we need to be enormously clever about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * the readahead size, though.  128K is a purely arbitrary, good-enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * fixed value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define MAXBUF 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int do_readahead(journal_t *journal, unsigned int start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned int max, nbufs, next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned long long blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct buffer_head * bufs[MAXBUF];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* Do up to 128K of readahead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	max = start + (128 * 1024 / journal->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (max > journal->j_total_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		max = journal->j_total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	/* Do the readahead itself.  We'll submit MAXBUF buffer_heads at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * a time to the block device IO layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	nbufs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	for (next = start; next < max; next++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		err = jbd2_journal_bmap(journal, next, &blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			printk(KERN_ERR "JBD2: bad block at offset %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			bufs[nbufs++] = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			if (nbufs == MAXBUF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				ll_rw_block(REQ_OP_READ, 0, nbufs, bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				journal_brelse_array(bufs, nbufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				nbufs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (nbufs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		ll_rw_block(REQ_OP_READ, 0, nbufs, bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (nbufs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		journal_brelse_array(bufs, nbufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return err;
^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) #endif /* __KERNEL__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * Read a block from the journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int jread(struct buffer_head **bhp, journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		 unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	unsigned long long blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	*bhp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (offset >= journal->j_total_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		printk(KERN_ERR "JBD2: corrupted journal superblock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	err = jbd2_journal_bmap(journal, offset, &blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		printk(KERN_ERR "JBD2: bad block at offset %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (!buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		/* If this is a brand new buffer, start readahead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)                    Otherwise, we assume we are already reading it.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (!buffer_req(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			do_readahead(journal, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (!buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		printk(KERN_ERR "JBD2: Failed to read block at offset %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	*bhp = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static int jbd2_descriptor_block_csum_verify(journal_t *j, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct jbd2_journal_block_tail *tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	__be32 provided;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	__u32 calculated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (!jbd2_journal_has_csum_v2or3(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	tail = (struct jbd2_journal_block_tail *)(buf + j->j_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			sizeof(struct jbd2_journal_block_tail));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	provided = tail->t_checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	tail->t_checksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	tail->t_checksum = provided;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return provided == cpu_to_be32(calculated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * Count the number of in-use tags in a journal descriptor block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int count_tags(journal_t *journal, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	char *			tagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	journal_block_tag_t *	tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	int			nr = 0, size = journal->j_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	int			tag_bytes = journal_tag_bytes(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (jbd2_journal_has_csum_v2or3(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		size -= sizeof(struct jbd2_journal_block_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	tagp = &bh->b_data[sizeof(journal_header_t)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	while ((tagp - bh->b_data + tag_bytes) <= size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		tag = (journal_block_tag_t *) tagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		tagp += tag_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (!(tag->t_flags & cpu_to_be16(JBD2_FLAG_SAME_UUID)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			tagp += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (tag->t_flags & cpu_to_be16(JBD2_FLAG_LAST_TAG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* Make sure we wrap around the log correctly! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define wrap(journal, var)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	unsigned long _wrap_last =					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		jbd2_has_feature_fast_commit(journal) ?			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			(journal)->j_fc_last : (journal)->j_last;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (var >= _wrap_last)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		var -= (_wrap_last - (journal)->j_first);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int fc_do_one_pass(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			  struct recovery_info *info, enum passtype pass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	unsigned int expected_commit_id = info->end_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	unsigned long next_fc_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	next_fc_block = journal->j_fc_first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (!journal->j_fc_replay_callback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	while (next_fc_block <= journal->j_fc_last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		jbd_debug(3, "Fast commit replay: next block %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			  next_fc_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		err = jread(&bh, journal, next_fc_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			jbd_debug(3, "Fast commit replay: read error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		err = journal->j_fc_replay_callback(journal, bh, pass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 					next_fc_block - journal->j_fc_first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 					expected_commit_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		next_fc_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (err < 0 || err == JBD2_FC_REPLAY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		jbd_debug(3, "Fast commit replay failed, err = %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * jbd2_journal_recover - recovers a on-disk journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * @journal: the journal to recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * The primary function for recovering the log contents when mounting a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * journaled device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * Recovery is done in three passes.  In the first pass, we look for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * end of the log.  In the second, we assemble the list of revoke
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * blocks.  In the third and final pass, we replay any un-revoked blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * in the log.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int jbd2_journal_recover(journal_t *journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	int			err, err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	journal_superblock_t *	sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct recovery_info	info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	memset(&info, 0, sizeof(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	sb = journal->j_superblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	 * The journal superblock's s_start field (the current log head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * is always zero if, and only if, the journal was cleanly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 * unmounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (!sb->s_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		jbd_debug(1, "No recovery required, last transaction %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			  be32_to_cpu(sb->s_sequence));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		journal->j_transaction_sequence = be32_to_cpu(sb->s_sequence) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	err = do_one_pass(journal, &info, PASS_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		err = do_one_pass(journal, &info, PASS_REVOKE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		err = do_one_pass(journal, &info, PASS_REPLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	jbd_debug(1, "JBD2: recovery, exit status %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		  "recovered transactions %u to %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		  err, info.start_transaction, info.end_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	jbd_debug(1, "JBD2: Replayed %d and revoked %d/%d blocks\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		  info.nr_replays, info.nr_revoke_hits, info.nr_revokes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* Restart the log at the next transaction ID, thus invalidating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * any existing commit records in the log. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	journal->j_transaction_sequence = ++info.end_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	jbd2_journal_clear_revoke(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	err2 = sync_blockdev(journal->j_fs_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		err = err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	/* Make sure all replayed data is on permanent storage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (journal->j_flags & JBD2_BARRIER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		err2 = blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			err = err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^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)  * jbd2_journal_skip_recovery - Start journal and wipe exiting records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * @journal: journal to startup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * Locate any valid recovery information from the journal and set up the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * journal structures in memory to ignore it (presumably because the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * caller has evidence that it is out of date).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  * This function doesn't appear to be exported..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  * We perform one pass over the journal to allow us to tell the user how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  * much recovery information is being erased, and to let us initialise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  * the journal transaction sequence numbers to the next unused ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int jbd2_journal_skip_recovery(journal_t *journal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	int			err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct recovery_info	info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	memset (&info, 0, sizeof(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	err = do_one_pass(journal, &info, PASS_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		printk(KERN_ERR "JBD2: error %d scanning journal\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		++journal->j_transaction_sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #ifdef CONFIG_JBD2_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		int dropped = info.end_transaction - 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			be32_to_cpu(journal->j_superblock->s_sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		jbd_debug(1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			  "JBD2: ignoring %d transaction%s from the journal.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			  dropped, (dropped == 1) ? "" : "s");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		journal->j_transaction_sequence = ++info.end_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	journal->j_tail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static inline unsigned long long read_tag_block(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 						journal_block_tag_t *tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	unsigned long long block = be32_to_cpu(tag->t_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (jbd2_has_feature_64bit(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		block |= (u64)be32_to_cpu(tag->t_blocknr_high) << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	return block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  * calc_chksums calculates the checksums for the blocks described in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * descriptor block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static int calc_chksums(journal_t *journal, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			unsigned long *next_log_block, __u32 *crc32_sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	int i, num_blks, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	unsigned long io_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct buffer_head *obh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	num_blks = count_tags(journal, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	/* Calculate checksum of the descriptor block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	*crc32_sum = crc32_be(*crc32_sum, (void *)bh->b_data, bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	for (i = 0; i < num_blks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		io_block = (*next_log_block)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		wrap(journal, *next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		err = jread(&obh, journal, io_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			printk(KERN_ERR "JBD2: IO error %d recovering block "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				"%lu in log\n", err, io_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			*crc32_sum = crc32_be(*crc32_sum, (void *)obh->b_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				     obh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		put_bh(obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	struct commit_header *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	__be32 provided;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	__u32 calculated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (!jbd2_journal_has_csum_v2or3(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	h = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	provided = h->h_chksum[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	h->h_chksum[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	h->h_chksum[0] = provided;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	return provided == cpu_to_be32(calculated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 				      void *buf, __u32 sequence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	journal_block_tag3_t *tag3 = (journal_block_tag3_t *)tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	__u32 csum32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	__be32 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if (!jbd2_journal_has_csum_v2or3(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	seq = cpu_to_be32(sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (jbd2_has_feature_csum3(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return tag3->t_checksum == cpu_to_be32(csum32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		return tag->t_checksum == cpu_to_be16(csum32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static int do_one_pass(journal_t *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			struct recovery_info *info, enum passtype pass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	unsigned int		first_commit_ID, next_commit_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	unsigned long		next_log_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	int			err, success = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	journal_superblock_t *	sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	journal_header_t *	tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	struct buffer_head *	bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	unsigned int		sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	int			blocktype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	int			tag_bytes = journal_tag_bytes(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	__u32			crc32_sum = ~0; /* Transactional Checksums */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	int			descr_csum_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	int			block_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	bool			need_check_commit_time = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	__u64			last_trans_commit_time = 0, commit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	 * First thing is to establish what we expect to find in the log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	 * (in terms of transaction IDs), and where (in terms of log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	 * block offsets): query the superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	sb = journal->j_superblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	next_commit_ID = be32_to_cpu(sb->s_sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	next_log_block = be32_to_cpu(sb->s_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	first_commit_ID = next_commit_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (pass == PASS_SCAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		info->start_transaction = first_commit_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	jbd_debug(1, "Starting recovery pass %d\n", pass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	 * Now we walk through the log, transaction by transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	 * making sure that each transaction has a commit block in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	 * expected place.  Each complete transaction gets replayed back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	 * into the main filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		int			flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		char *			tagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		journal_block_tag_t *	tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		struct buffer_head *	obh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		struct buffer_head *	nbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		/* If we already know where to stop the log traversal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		 * check right now that we haven't gone past the end of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		 * the log. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		if (pass != PASS_SCAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			if (tid_geq(next_commit_ID, info->end_transaction))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		jbd_debug(2, "Scanning for sequence ID %u at %lu/%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 			  next_commit_ID, next_log_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			  jbd2_has_feature_fast_commit(journal) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 			  journal->j_fc_last : journal->j_last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		/* Skip over each chunk of the transaction looking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		 * either the next descriptor block or the final commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		 * record. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		jbd_debug(3, "JBD2: checking block %ld\n", next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		err = jread(&bh, journal, next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		next_log_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		wrap(journal, next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		/* What kind of buffer is it?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		 * If it is a descriptor block, check that it has the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		 * expected sequence number.  Otherwise, we're all done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		 * here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		tmp = (journal_header_t *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		if (tmp->h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			break;
^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) 		blocktype = be32_to_cpu(tmp->h_blocktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		sequence = be32_to_cpu(tmp->h_sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		jbd_debug(3, "Found magic %d, sequence %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 			  blocktype, sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		if (sequence != next_commit_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		/* OK, we have a valid descriptor block which matches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		 * all of the sequence number checks.  What are we going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		 * to do with it?  That depends on the pass... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		switch(blocktype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		case JBD2_DESCRIPTOR_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			/* Verify checksum first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			if (jbd2_journal_has_csum_v2or3(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 				descr_csum_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 					sizeof(struct jbd2_journal_block_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			if (descr_csum_size > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 			    !jbd2_descriptor_block_csum_verify(journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 							       bh->b_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 				 * PASS_SCAN can see stale blocks due to lazy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 				 * journal init. Don't error out on those yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 				if (pass != PASS_SCAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 					pr_err("JBD2: Invalid checksum recovering block %lu in log\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 					       next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 					err = -EFSBADCRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 					brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 					goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 				need_check_commit_time = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 				jbd_debug(1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 					"invalid descriptor block found in %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 					next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			/* If it is a valid descriptor block, replay it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 			 * in pass REPLAY; if journal_checksums enabled, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 			 * calculate checksums in PASS_SCAN, otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 			 * just skip over the blocks it describes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 			if (pass != PASS_REPLAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 				if (pass == PASS_SCAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 				    jbd2_has_feature_checksum(journal) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 				    !need_check_commit_time &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 				    !info->end_transaction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 					if (calc_chksums(journal, bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 							&next_log_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 							&crc32_sum)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 						put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 						break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 					put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 				next_log_block += count_tags(journal, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 				wrap(journal, next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 				put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 			/* A descriptor block: we can now write all of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 			 * the data blocks.  Yay, useful work is finally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 			 * getting done here! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 			tagp = &bh->b_data[sizeof(journal_header_t)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 			while ((tagp - bh->b_data + tag_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 			       <= journal->j_blocksize - descr_csum_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 				unsigned long io_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 				tag = (journal_block_tag_t *) tagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 				flags = be16_to_cpu(tag->t_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 				io_block = next_log_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 				wrap(journal, next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 				err = jread(&obh, journal, io_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 				if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 					/* Recover what we can, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 					 * report failure at the end. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 					success = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 					printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 						"JBD2: IO error %d recovering "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 						"block %ld in log\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 						err, io_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 					unsigned long long blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 					J_ASSERT(obh != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 					blocknr = read_tag_block(journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 								 tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 					/* If the block has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 					 * revoked, then we're all done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 					 * here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 					if (jbd2_journal_test_revoke
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 					    (journal, blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 					     next_commit_ID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 						brelse(obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 						++info->nr_revoke_hits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 						goto skip_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 					/* Look for block corruption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 					if (!jbd2_block_tag_csum_verify(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 						journal, tag, obh->b_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 						be32_to_cpu(tmp->h_sequence))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 						brelse(obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 						success = -EFSBADCRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 						printk(KERN_ERR "JBD2: Invalid "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 						       "checksum recovering "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 						       "data block %llu in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 						       "log\n", blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 						block_error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 						goto skip_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 					/* Find a buffer for the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 					 * data being restored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 					nbh = __getblk(journal->j_fs_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 							blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 							journal->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 					if (nbh == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 						printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 						       "JBD2: Out of memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 						       "during recovery.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 						err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 						brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 						brelse(obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 						goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 					lock_buffer(nbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 					memcpy(nbh->b_data, obh->b_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 							journal->j_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 					if (flags & JBD2_FLAG_ESCAPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 						*((__be32 *)nbh->b_data) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 						cpu_to_be32(JBD2_MAGIC_NUMBER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 					BUFFER_TRACE(nbh, "marking dirty");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 					set_buffer_uptodate(nbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 					mark_buffer_dirty(nbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 					BUFFER_TRACE(nbh, "marking uptodate");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 					++info->nr_replays;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 					/* ll_rw_block(WRITE, 1, &nbh); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 					unlock_buffer(nbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 					brelse(obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 					brelse(nbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 			skip_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 				tagp += tag_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 				if (!(flags & JBD2_FLAG_SAME_UUID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 					tagp += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 				if (flags & JBD2_FLAG_LAST_TAG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 		case JBD2_COMMIT_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 			/*     How to differentiate between interrupted commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 			 *               and journal corruption ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			 * {nth transaction}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 			 *        Checksum Verification Failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 			 *			 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 			 *		 ____________________
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 			 *		|		     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 			 * 	async_commit             sync_commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 			 *     		|                    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 			 *		| GO TO NEXT    "Journal Corruption"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 			 *		| TRANSACTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 			 *		|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 			 * {(n+1)th transanction}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 			 *		|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 			 * 	 _______|______________
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 			 * 	|	 	      |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 			 * Commit block found	Commit block not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 			 *      |		      |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 			 * "Journal Corruption"       |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 			 *		 _____________|_________
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 			 *     		|	           	|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 			 *	nth trans corrupt	OR   nth trans
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 			 *	and (n+1)th interrupted     interrupted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 			 *	before commit block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 			 *      could reach the disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 			 *	(Cannot find the difference in above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 			 *	 mentioned conditions. Hence assume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 			 *	 "Interrupted Commit".)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 			commit_time = be64_to_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 				((struct commit_header *)bh->b_data)->h_commit_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 			 * If need_check_commit_time is set, it means we are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 			 * PASS_SCAN and csum verify failed before. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 			 * commit_time is increasing, it's the same journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 			 * otherwise it is stale journal block, just end this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 			 * recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 			if (need_check_commit_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 				if (commit_time >= last_trans_commit_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 					pr_err("JBD2: Invalid checksum found in transaction %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 					       next_commit_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 					err = -EFSBADCRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 					brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 					goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 			ignore_crc_mismatch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 				 * It likely does not belong to same journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 				 * just end this recovery with success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 				jbd_debug(1, "JBD2: Invalid checksum ignored in transaction %u, likely stale data\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 					  next_commit_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 				err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 				brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 			 * Found an expected commit block: if checksums
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 			 * are present, verify them in PASS_SCAN; else not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 			 * much to do other than move on to the next sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 			 * number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 			if (pass == PASS_SCAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 			    jbd2_has_feature_checksum(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 				struct commit_header *cbh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 					(struct commit_header *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 				unsigned found_chksum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 					be32_to_cpu(cbh->h_chksum[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 				if (info->end_transaction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 					journal->j_failed_commit =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 						info->end_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 					brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 				/* Neither checksum match nor unused? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 				if (!((crc32_sum == found_chksum &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 				       cbh->h_chksum_type ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 						JBD2_CRC32_CHKSUM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 				       cbh->h_chksum_size ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 						JBD2_CRC32_CHKSUM_SIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 				      (cbh->h_chksum_type == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 				       cbh->h_chksum_size == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 				       found_chksum == 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 					goto chksum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 				crc32_sum = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 			if (pass == PASS_SCAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 			    !jbd2_commit_block_csum_verify(journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 							   bh->b_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 			chksum_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 				if (commit_time < last_trans_commit_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 					goto ignore_crc_mismatch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 				info->end_transaction = next_commit_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 				if (!jbd2_has_feature_async_commit(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 					journal->j_failed_commit =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 						next_commit_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 					brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 			if (pass == PASS_SCAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 				last_trans_commit_time = commit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 			next_commit_ID++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		case JBD2_REVOKE_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 			 * Check revoke block crc in pass_scan, if csum verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 			 * failed, check commit block time later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 			if (pass == PASS_SCAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 			    !jbd2_descriptor_block_csum_verify(journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 							       bh->b_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 				jbd_debug(1, "JBD2: invalid revoke block found in %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 					  next_log_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 				need_check_commit_time = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 			/* If we aren't in the REVOKE pass, then we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 			 * just skip over this block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 			if (pass != PASS_REVOKE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 				brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 			err = scan_revoke_records(journal, bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 						  next_commit_ID, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 				goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 			jbd_debug(3, "Unrecognised magic %d, end of scan.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 				  blocktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)  done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	 * We broke out of the log scan loop: either we came to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	 * known end of the log or we found an unexpected block in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	 * log.  If the latter happened, then we know that the "current"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	 * transaction marks the end of the valid log.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	if (pass == PASS_SCAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 		if (!info->end_transaction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 			info->end_transaction = next_commit_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 		/* It's really bad news if different passes end up at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 		 * different places (but possible due to IO errors). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 		if (info->end_transaction != next_commit_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 			printk(KERN_ERR "JBD2: recovery pass %d ended at "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 				"transaction %u, expected %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 				pass, next_commit_ID, info->end_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 			if (!success)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 				success = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	if (jbd2_has_feature_fast_commit(journal) &&  pass != PASS_REVOKE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 		err = fc_do_one_pass(journal, info, pass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 			success = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	if (block_error && success == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 		success = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	return success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)  failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) /* Scan a revoke record, marking all blocks mentioned as revoked. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 			       tid_t sequence, struct recovery_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	jbd2_journal_revoke_header_t *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	int offset, max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	int csum_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	__u32 rcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	int record_len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 	header = (jbd2_journal_revoke_header_t *) bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 	offset = sizeof(jbd2_journal_revoke_header_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 	rcount = be32_to_cpu(header->r_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 	if (jbd2_journal_has_csum_v2or3(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 		csum_size = sizeof(struct jbd2_journal_block_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 	if (rcount > journal->j_blocksize - csum_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 	max = rcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 	if (jbd2_has_feature_64bit(journal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 		record_len = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 	while (offset + record_len <= max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 		unsigned long long blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) 		if (record_len == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 			blocknr = be32_to_cpu(* ((__be32 *) (bh->b_data+offset)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 			blocknr = be64_to_cpu(* ((__be64 *) (bh->b_data+offset)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 		offset += record_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 		err = jbd2_journal_set_revoke(journal, blocknr, sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 		++info->nr_revokes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }