Skip to content

Commit e16c4c2

Browse files
Ye Bingregkh
Ye Bin
authored andcommitted
jbd2: avoid mount failed when commit block is partial submitted
[ Upstream commit 0bab8db ] 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 <yebin10@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://patch.msgid.link/20240620072405.3533701-1-yebin@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3236afd commit e16c4c2

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
@@ -448,6 +448,27 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)
448448
return provided == cpu_to_be32(calculated);
449449
}
450450

451+
static bool jbd2_commit_block_csum_verify_partial(journal_t *j, void *buf)
452+
{
453+
struct commit_header *h;
454+
__be32 provided;
455+
__u32 calculated;
456+
void *tmpbuf;
457+
458+
tmpbuf = kzalloc(j->j_blocksize, GFP_KERNEL);
459+
if (!tmpbuf)
460+
return false;
461+
462+
memcpy(tmpbuf, buf, sizeof(struct commit_header));
463+
h = tmpbuf;
464+
provided = h->h_chksum[0];
465+
h->h_chksum[0] = 0;
466+
calculated = jbd2_chksum(j, j->j_csum_seed, tmpbuf, j->j_blocksize);
467+
kfree(tmpbuf);
468+
469+
return provided == cpu_to_be32(calculated);
470+
}
471+
451472
static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
452473
journal_block_tag3_t *tag3,
453474
void *buf, __u32 sequence)
@@ -814,6 +835,13 @@ static int do_one_pass(journal_t *journal,
814835
if (pass == PASS_SCAN &&
815836
!jbd2_commit_block_csum_verify(journal,
816837
bh->b_data)) {
838+
if (jbd2_commit_block_csum_verify_partial(
839+
journal,
840+
bh->b_data)) {
841+
pr_notice("JBD2: Find incomplete commit block in transaction %u block %lu\n",
842+
next_commit_ID, next_log_block);
843+
goto chksum_ok;
844+
}
817845
chksum_error:
818846
if (commit_time < last_trans_commit_time)
819847
goto ignore_crc_mismatch;
@@ -828,6 +856,7 @@ static int do_one_pass(journal_t *journal,
828856
}
829857
}
830858
if (pass == PASS_SCAN) {
859+
chksum_ok:
831860
last_trans_commit_time = commit_time;
832861
head_block = next_log_block;
833862
}
@@ -847,6 +876,7 @@ static int do_one_pass(journal_t *journal,
847876
next_log_block);
848877
need_check_commit_time = true;
849878
}
879+
850880
/* If we aren't in the REVOKE pass, then we can
851881
* just skip over this block. */
852882
if (pass != PASS_REVOKE) {

0 commit comments

Comments
 (0)