Unverified Commit ac4b00b3 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!11333 jbd2: avoid mount failed when commit block is partial submitted

parents 74c396a0 12f8e18a
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -401,6 +401,27 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)
	return provided == cpu_to_be32(calculated);
}

static bool jbd2_commit_block_csum_verify_partial(journal_t *j, void *buf)
{
	struct commit_header *h;
	__be32 provided;
	__u32 calculated;
	void *tmpbuf;

	tmpbuf = kzalloc(j->j_blocksize, GFP_KERNEL);
	if (!tmpbuf)
		return false;

	memcpy(tmpbuf, buf, sizeof(struct commit_header));
	h = tmpbuf;
	provided = h->h_chksum[0];
	h->h_chksum[0] = 0;
	calculated = jbd2_chksum(j, j->j_csum_seed, tmpbuf, j->j_blocksize);
	kfree(tmpbuf);

	return provided == cpu_to_be32(calculated);
}

static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
				      void *buf, __u32 sequence)
{
@@ -768,6 +789,13 @@ static int do_one_pass(journal_t *journal,
			if (pass == PASS_SCAN &&
			    !jbd2_commit_block_csum_verify(journal,
							   bh->b_data)) {
				if (jbd2_commit_block_csum_verify_partial(
								  journal,
								  bh->b_data)) {
					pr_notice("JBD2: Find incomplete commit block in transaction %u block %lu\n",
						  next_commit_ID, next_log_block);
					goto chksum_ok;
				}
			chksum_error:
				if (commit_time < last_trans_commit_time)
					goto ignore_crc_mismatch;
@@ -780,8 +808,10 @@ static int do_one_pass(journal_t *journal,
					break;
				}
			}
			if (pass == PASS_SCAN)
			if (pass == PASS_SCAN) {
			chksum_ok:
				last_trans_commit_time = commit_time;
			}
			brelse(bh);
			next_commit_ID++;
			continue;
@@ -798,6 +828,7 @@ static int do_one_pass(journal_t *journal,
					  next_log_block);
				need_check_commit_time = true;
			}

			/* If we aren't in the REVOKE pass, then we can
			 * just skip over this block. */
			if (pass != PASS_REVOKE) {