Skip to content

Commit 00a3fff

Browse files
Shijie Luotytso
authored andcommitted
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: Shijie Luo <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 70d7ced commit 00a3fff

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed

fs/jbd2/recovery.c

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -690,57 +690,35 @@ static int do_one_pass(journal_t *journal,
690690
* number. */
691691
if (pass == PASS_SCAN &&
692692
jbd2_has_feature_checksum(journal)) {
693-
int chksum_err, chksum_seen;
694693
struct commit_header *cbh =
695694
(struct commit_header *)bh->b_data;
696695
unsigned found_chksum =
697696
be32_to_cpu(cbh->h_chksum[0]);
698697

699-
chksum_err = chksum_seen = 0;
700-
701698
if (info->end_transaction) {
702699
journal->j_failed_commit =
703700
info->end_transaction;
704701
brelse(bh);
705702
break;
706703
}
707704

708-
if (crc32_sum == found_chksum &&
709-
cbh->h_chksum_type == JBD2_CRC32_CHKSUM &&
710-
cbh->h_chksum_size ==
711-
JBD2_CRC32_CHKSUM_SIZE)
712-
chksum_seen = 1;
713-
else if (!(cbh->h_chksum_type == 0 &&
714-
cbh->h_chksum_size == 0 &&
715-
found_chksum == 0 &&
716-
!chksum_seen))
717-
/*
718-
* If fs is mounted using an old kernel and then
719-
* kernel with journal_chksum is used then we
720-
* get a situation where the journal flag has
721-
* checksum flag set but checksums are not
722-
* present i.e chksum = 0, in the individual
723-
* commit blocks.
724-
* Hence to avoid checksum failures, in this
725-
* situation, this extra check is added.
726-
*/
727-
chksum_err = 1;
728-
729-
if (chksum_err) {
730-
info->end_transaction = next_commit_ID;
731-
732-
if (!jbd2_has_feature_async_commit(journal)) {
733-
journal->j_failed_commit =
734-
next_commit_ID;
735-
brelse(bh);
736-
break;
737-
}
738-
}
705+
/* Neither checksum match nor unused? */
706+
if (!((crc32_sum == found_chksum &&
707+
cbh->h_chksum_type ==
708+
JBD2_CRC32_CHKSUM &&
709+
cbh->h_chksum_size ==
710+
JBD2_CRC32_CHKSUM_SIZE) ||
711+
(cbh->h_chksum_type == 0 &&
712+
cbh->h_chksum_size == 0 &&
713+
found_chksum == 0)))
714+
goto chksum_error;
715+
739716
crc32_sum = ~0;
740717
}
741718
if (pass == PASS_SCAN &&
742719
!jbd2_commit_block_csum_verify(journal,
743720
bh->b_data)) {
721+
chksum_error:
744722
info->end_transaction = next_commit_ID;
745723

746724
if (!jbd2_has_feature_async_commit(journal)) {

0 commit comments

Comments
 (0)