Commit 00a3fff0 authored by Shijie Luo's avatar Shijie Luo Committed by Theodore Ts'o

jbd2: clean up checksum verification in do_one_pass()

Remove the unnecessary chksum_err and checksum_seen variables as well as
some redundant code to make the function easier to understand.

[ With changes suggested by jack@ and tytso@ ]
Signed-off-by: default avatarShijie Luo <luoshijie1@huawei.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20200819122955.33526-1-luoshijie1@huawei.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 70d7ced2
...@@ -690,14 +690,11 @@ static int do_one_pass(journal_t *journal, ...@@ -690,14 +690,11 @@ static int do_one_pass(journal_t *journal,
* number. */ * number. */
if (pass == PASS_SCAN && if (pass == PASS_SCAN &&
jbd2_has_feature_checksum(journal)) { jbd2_has_feature_checksum(journal)) {
int chksum_err, chksum_seen;
struct commit_header *cbh = struct commit_header *cbh =
(struct commit_header *)bh->b_data; (struct commit_header *)bh->b_data;
unsigned found_chksum = unsigned found_chksum =
be32_to_cpu(cbh->h_chksum[0]); be32_to_cpu(cbh->h_chksum[0]);
chksum_err = chksum_seen = 0;
if (info->end_transaction) { if (info->end_transaction) {
journal->j_failed_commit = journal->j_failed_commit =
info->end_transaction; info->end_transaction;
...@@ -705,42 +702,23 @@ static int do_one_pass(journal_t *journal, ...@@ -705,42 +702,23 @@ static int do_one_pass(journal_t *journal,
break; break;
} }
if (crc32_sum == found_chksum && /* Neither checksum match nor unused? */
cbh->h_chksum_type == JBD2_CRC32_CHKSUM && if (!((crc32_sum == found_chksum &&
cbh->h_chksum_size == cbh->h_chksum_type ==
JBD2_CRC32_CHKSUM_SIZE) JBD2_CRC32_CHKSUM &&
chksum_seen = 1; cbh->h_chksum_size ==
else if (!(cbh->h_chksum_type == 0 && JBD2_CRC32_CHKSUM_SIZE) ||
cbh->h_chksum_size == 0 && (cbh->h_chksum_type == 0 &&
found_chksum == 0 && cbh->h_chksum_size == 0 &&
!chksum_seen)) found_chksum == 0)))
/* goto chksum_error;
* If fs is mounted using an old kernel and then
* kernel with journal_chksum is used then we
* get a situation where the journal flag has
* checksum flag set but checksums are not
* present i.e chksum = 0, in the individual
* commit blocks.
* Hence to avoid checksum failures, in this
* situation, this extra check is added.
*/
chksum_err = 1;
if (chksum_err) {
info->end_transaction = next_commit_ID;
if (!jbd2_has_feature_async_commit(journal)) {
journal->j_failed_commit =
next_commit_ID;
brelse(bh);
break;
}
}
crc32_sum = ~0; crc32_sum = ~0;
} }
if (pass == PASS_SCAN && if (pass == PASS_SCAN &&
!jbd2_commit_block_csum_verify(journal, !jbd2_commit_block_csum_verify(journal,
bh->b_data)) { bh->b_data)) {
chksum_error:
info->end_transaction = next_commit_ID; info->end_transaction = next_commit_ID;
if (!jbd2_has_feature_async_commit(journal)) { if (!jbd2_has_feature_async_commit(journal)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment