Skip to content

Commit 0bab8db

Browse files
Ye Bintytso
authored andcommitted
jbd2: avoid mount failed when commit block is partial submitted
We encountered a problem that the file system could not be mounted in the power-off scenario. The analysis of the file system mirror shows that only part of the data is written to the last commit block. The valid data of the commit block is concentrated in the first sector. However, the data of the entire block is involved in the checksum calculation. For different hardware, the minimum atomic unit may be different. If the checksum of a committed block is incorrect, clear the data except the 'commit_header' and then calculate the checksum. If the checkusm is correct, it is considered that the block is partially committed, Then continue to replay journal. Signed-off-by: Ye Bin <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 65121ef commit 0bab8db

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

fs/jbd2/recovery.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,27 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)
444444
return provided == cpu_to_be32(calculated);
445445
}
446446

447+
static bool jbd2_commit_block_csum_verify_partial(journal_t *j, void *buf)
448+
{
449+
struct commit_header *h;
450+
__be32 provided;
451+
__u32 calculated;
452+
void *tmpbuf;
453+
454+
tmpbuf = kzalloc(j->j_blocksize, GFP_KERNEL);
455+
if (!tmpbuf)
456+
return false;
457+
458+
memcpy(tmpbuf, buf, sizeof(struct commit_header));
459+
h = tmpbuf;
460+
provided = h->h_chksum[0];
461+
h->h_chksum[0] = 0;
462+
calculated = jbd2_chksum(j, j->j_csum_seed, tmpbuf, j->j_blocksize);
463+
kfree(tmpbuf);
464+
465+
return provided == cpu_to_be32(calculated);
466+
}
467+
447468
static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
448469
journal_block_tag3_t *tag3,
449470
void *buf, __u32 sequence)
@@ -811,6 +832,13 @@ static int do_one_pass(journal_t *journal,
811832
if (pass == PASS_SCAN &&
812833
!jbd2_commit_block_csum_verify(journal,
813834
bh->b_data)) {
835+
if (jbd2_commit_block_csum_verify_partial(
836+
journal,
837+
bh->b_data)) {
838+
pr_notice("JBD2: Find incomplete commit block in transaction %u block %lu\n",
839+
next_commit_ID, next_log_block);
840+
goto chksum_ok;
841+
}
814842
chksum_error:
815843
if (commit_time < last_trans_commit_time)
816844
goto ignore_crc_mismatch;
@@ -825,6 +853,7 @@ static int do_one_pass(journal_t *journal,
825853
}
826854
}
827855
if (pass == PASS_SCAN) {
856+
chksum_ok:
828857
last_trans_commit_time = commit_time;
829858
head_block = next_log_block;
830859
}
@@ -844,6 +873,7 @@ static int do_one_pass(journal_t *journal,
844873
next_log_block);
845874
need_check_commit_time = true;
846875
}
876+
847877
/* If we aren't in the REVOKE pass, then we can
848878
* just skip over this block. */
849879
if (pass != PASS_REVOKE) {

0 commit comments

Comments
 (0)