Update to indicate that we have rebased to 2.6.23-rc7
[ext4-patch-queue.git] / ext4-journal-chksum-review-fix.patch
blob66890d4e5a2968b1b9c74bfb71cbfe26d743672a
1 address review comments from anrew morton, should be fold to parent patch before submittion.
3 From: Girish Shilamkar <girish@clusterfs.com>
5 Signed-off-by: Andreas Dilger <adilger@clusterfs.com>
6 Signed-off-by: Girish Shilamkar <girish@clusterfs.com>
7 ---
9 Documentation/filesystems/ext4.txt | 10 +++++++++
10 fs/Kconfig | 1
11 fs/jbd2/commit.c | 30 +++++++++++++---------------
12 fs/jbd2/journal.c | 10 ++++-----
13 fs/jbd2/recovery.c | 39 ++++++++++++++++++++++++++++++-------
14 5 files changed, 62 insertions(+), 28 deletions(-)
17 Index: linux-2.6.23-rc6/Documentation/filesystems/ext4.txt
18 ===================================================================
19 --- linux-2.6.23-rc6.orig/Documentation/filesystems/ext4.txt 2007-09-19 11:37:34.000000000 -0700
20 +++ linux-2.6.23-rc6/Documentation/filesystems/ext4.txt 2007-09-20 17:25:52.000000000 -0700
21 @@ -89,6 +89,16 @@ When mounting an ext4 filesystem, the fo
22 extents ext4 will use extents to address file data. The
23 file system will no longer be mountable by ext3.
25 +journal_checksum Enable checksumming of the journal transactions.
26 + This will allow the recovery code in e2fsck and the
27 + kernel to detect corruption in the kernel. It is a
28 + compatible change and will be ignored by older kernels.
30 +journal_async_commit Commit block can be written to disk without waiting
31 + for descriptor blocks. If enabled older kernels cannot
32 + mount the device. This will enable 'journal_checksum'
33 + internally.
35 journal=update Update the ext4 file system's journal to the current
36 format.
38 Index: linux-2.6.23-rc6/fs/Kconfig
39 ===================================================================
40 --- linux-2.6.23-rc6.orig/fs/Kconfig 2007-09-20 17:25:36.000000000 -0700
41 +++ linux-2.6.23-rc6/fs/Kconfig 2007-09-20 17:25:52.000000000 -0700
42 @@ -236,6 +236,7 @@ config JBD_DEBUG
44 config JBD2
45 tristate
46 + select CRC32
47 help
48 This is a generic journaling layer for block devices that support
49 both 32-bit and 64-bit block numbers. It is currently used by
50 Index: linux-2.6.23-rc6/fs/jbd2/commit.c
51 ===================================================================
52 --- linux-2.6.23-rc6.orig/fs/jbd2/commit.c 2007-09-20 17:25:49.000000000 -0700
53 +++ linux-2.6.23-rc6/fs/jbd2/commit.c 2007-09-20 17:25:52.000000000 -0700
54 @@ -107,8 +107,9 @@ static int journal_submit_commit_record(
55 __u32 crc32_sum)
57 struct journal_head *descriptor;
58 + struct commit_header *tmp;
59 struct buffer_head *bh;
60 - int i, ret;
61 + int ret;
62 int barrier_done = 0;
64 if (is_journal_aborted(journal))
65 @@ -120,19 +121,16 @@ static int journal_submit_commit_record(
67 bh = jh2bh(descriptor);
69 - for (i = 0; i < bh->b_size; i += 512) {
70 - struct commit_header *tmp =
71 - (struct commit_header *)(bh->b_data + i);
72 - tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
73 - tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK);
74 - tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);
76 - if (JBD2_HAS_COMPAT_FEATURE(journal,
77 - JBD2_FEATURE_COMPAT_CHECKSUM)) {
78 - tmp->h_chksum_type = JBD2_CRC32_CHKSUM;
79 - tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
80 - tmp->h_chksum[0] = cpu_to_be32(crc32_sum);
81 - }
82 + tmp = (struct commit_header *)bh->b_data;
83 + tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
84 + tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK);
85 + tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);
87 + if (JBD2_HAS_COMPAT_FEATURE(journal,
88 + JBD2_FEATURE_COMPAT_CHECKSUM)) {
89 + tmp->h_chksum_type = JBD2_CRC32_CHKSUM;
90 + tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
91 + tmp->h_chksum[0] = cpu_to_be32(crc32_sum);
94 JBUFFER_TRACE(descriptor, "submit commit block");
95 @@ -184,8 +182,8 @@ static int journal_wait_on_commit_record
97 int ret = 0;
99 - if (buffer_locked(bh))
100 - wait_on_buffer(bh);
101 + clear_buffer_dirty(bh);
102 + wait_on_buffer(bh);
104 if (unlikely(!buffer_uptodate(bh)))
105 ret = -EIO;
106 Index: linux-2.6.23-rc6/fs/jbd2/journal.c
107 ===================================================================
108 --- linux-2.6.23-rc6.orig/fs/jbd2/journal.c 2007-09-20 17:25:49.000000000 -0700
109 +++ linux-2.6.23-rc6/fs/jbd2/journal.c 2007-09-20 17:25:52.000000000 -0700
110 @@ -1266,8 +1266,9 @@ int jbd2_journal_set_features (journal_t
111 return 1;
114 -/**
115 - * int jbd2_journal_clear_features () - Clear a given journal feature in the superblock
117 + * jbd2_journal_clear_features () - Clear a given journal feature in the
118 + * superblock
119 * @journal: Journal to act on.
120 * @compat: bitmask of compatible features
121 * @ro: bitmask of features that force read-only mount
122 @@ -1275,10 +1276,9 @@ int jbd2_journal_set_features (journal_t
124 * Clear a given journal feature as present on the
125 * superblock. Returns true if the requested features could be reset.
128 -int jbd2_journal_clear_features (journal_t *journal, unsigned long compat,
129 - unsigned long ro, unsigned long incompat)
130 +int jbd2_journal_clear_features(journal_t *journal, unsigned long compat,
131 + unsigned long ro, unsigned long incompat)
133 journal_superblock_t *sb;
135 Index: linux-2.6.23-rc6/fs/jbd2/recovery.c
136 ===================================================================
137 --- linux-2.6.23-rc6.orig/fs/jbd2/recovery.c 2007-09-20 17:25:49.000000000 -0700
138 +++ linux-2.6.23-rc6/fs/jbd2/recovery.c 2007-09-20 17:25:52.000000000 -0700
139 @@ -318,14 +318,14 @@ static inline unsigned long long read_ta
143 - * cal_chksums calculates the checksums for the blocks described in the
144 + * calc_chksums calculates the checksums for the blocks described in the
145 * descriptor block.
147 -static int cal_chksums(journal_t *journal, struct buffer_head *bh,
148 - unsigned long *next_log_block, __u32 *crc32_sum)
149 +static int calc_chksums(journal_t *journal, struct buffer_head *bh,
150 + unsigned long *next_log_block, __u32 *crc32_sum)
152 int i, num_blks, err;
153 - unsigned long io_block;
154 + unsigned io_block;
155 struct buffer_head *obh;
157 num_blks = count_tags(journal, bh);
158 @@ -338,7 +338,7 @@ static int cal_chksums(journal_t *journa
159 err = jread(&obh, journal, io_block);
160 if (err) {
161 printk(KERN_ERR "JBD: IO error %d recovering block "
162 - "%ld in log\n", err, io_block);
163 + "%u in log\n", err, io_block);
164 return 1;
165 } else {
166 *crc32_sum = crc32_be(*crc32_sum, (void *)obh->b_data,
167 @@ -460,7 +460,7 @@ static int do_one_pass(journal_t *journa
168 JBD2_HAS_COMPAT_FEATURE(journal,
169 JBD2_FEATURE_COMPAT_CHECKSUM) &&
170 !info->end_transaction) {
171 - if (cal_chksums(journal, bh,
172 + if (calc_chksums(journal, bh,
173 &next_log_block,
174 &crc32_sum)) {
175 brelse(bh);
176 @@ -601,11 +601,14 @@ static int do_one_pass(journal_t *journa
177 if (pass == PASS_SCAN &&
178 JBD2_HAS_COMPAT_FEATURE(journal,
179 JBD2_FEATURE_COMPAT_CHECKSUM)) {
180 + int chksum_err, chksum_seen;
181 struct commit_header *cbh =
182 (struct commit_header *)bh->b_data;
183 unsigned found_chksum =
184 be32_to_cpu(cbh->h_chksum[0]);
186 + chksum_err = chksum_seen = 0;
188 if (info->end_transaction) {
189 printk(KERN_ERR "JBD: Transaction %u "
190 "found to be corrupt.\n",
191 @@ -614,7 +617,29 @@ static int do_one_pass(journal_t *journa
192 break;
195 - if (crc32_sum != found_chksum) {
196 + if (crc32_sum == found_chksum &&
197 + cbh->h_chksum_type == JBD2_CRC32_CHKSUM &&
198 + cbh->h_chksum_size ==
199 + JBD2_CRC32_CHKSUM_SIZE) {
200 + chksum_seen = 1;
201 + } else if (!(cbh->h_chksum_type == 0 &&
202 + cbh->h_chksum_size == 0 &&
203 + found_chksum == 0 &&
204 + !chksum_seen)) {
205 + /*
206 + * If fs is mounted using an old kernel and then
207 + * kernel with journal_chksum is used then we
208 + * get a situation where the journal flag has
209 + * checksum flag set but checksums are not
210 + * present i.e chksum = 0, in the individual
211 + * commit blocks.
212 + * Hence to avoid checksum failures, in this
213 + * situation, this extra check is added.
214 + */
215 + chksum_err = 1;
218 + if (chksum_err) {
219 info->end_transaction = next_commit_ID;
221 if (!JBD2_HAS_COMPAT_FEATURE(journal,