From: 常凤楠 <changfengnan@hikvision.com>
To: Jan Kara <jack@suse.cz>
Cc: changfengnan <changfengnan@qq.com>,
"adilger@dilger.ca" <adilger@dilger.ca>,
"darrick.wong@oracle.com" <darrick.wong@oracle.com>,
"jack@suse.com" <jack@suse.com>,
"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
"tytso@mit.edu" <tytso@mit.edu>
Subject: 答复: 答复: 答复: [PATCH] jbd2: avoid transaction reuse after reformatting
Date: Wed, 23 Sep 2020 06:29:12 +0000 [thread overview]
Message-ID: <708254ddee9b49d18ced1885dc7c29fa@hikvision.com> (raw)
In-Reply-To: <20200918130252.GG18920@quack2.suse.cz>
[-- Attachment #1: Type: text/plain, Size: 6542 bytes --]
The attachment is new patch.
I have fix the logic in JBD2_REVOKE_BLOCK and JBD2_COMMIT_BLOCK case.
If the revoke block is the first block after valid transaction, I set the flag like descriptor block ,and check it in commit block.
If the commit block is the first block after valid transaction, I use ri_commit_block to judge whether this commit block is next to another
commit block, if so it is illegal. I did't use time to judge commit block, because of the possibility of time calibration, I think use
ri_commit_block is more reliable.
-----邮件原件-----
发件人: Jan Kara <jack@suse.cz>
发送时间: 2020年9月18日 21:03
收件人: 常凤楠 <changfengnan@hikvision.com>
抄送: Jan Kara <jack@suse.cz>; changfengnan <changfengnan@qq.com>; adilger@dilger.ca; darrick.wong@oracle.com; jack@suse.com; linux-ext4@vger.kernel.org; tytso@mit.edu
主题: Re: 答复: 答复: [PATCH] jbd2: avoid transaction reuse after reformatting
Hello,
On Fri 18-09-20 01:49:09, 常凤楠 wrote:
> Sorry about my mailer, the patch is in the attachment.
Thanks for the patch. Functionally the patch looks mostly OK now. The only concern I have is that it handles checksum failures only in JBD2_DESCRIPTOR_BLOCK. This is the most likely case but it could also happen that JBD2_REVOKE_BLOCK or JBD2_COMMIT_BLOCK is the first one you see with mismatching checksum. So I think you need to handle these cases as well. I think your ri_commit_block logic below is an attempt to deal with these cases (but it's difficult to be sure because of complete lack of
comments) but it is not reliable. A valid transaction can begin both with a descriptor or with a revoke block.
A few other comments mostly about coding style below:
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index a4967b27ffb6..f7702e14077f 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -417,7 +417,7 @@ static int do_one_pass(journal_t *journal,
struct recovery_info *info, enum passtype pass) {
unsigned intfirst_commit_ID, next_commit_ID;
-unsigned longnext_log_block;
+unsigned longnext_log_block, ri_commit_block = 0;
interr, success = 0;
journal_superblock_t *sb;
journal_header_t *tmp;
@@ -428,7 +428,9 @@ static int do_one_pass(journal_t *journal,
__u32crc32_sum = ~0; /* Transactional Checksums */
intdescr_csum_size = 0;
intblock_error = 0;
-
+boolneed_check_commit_time = false;
+__be64last_trans_commit_time;
All variable names in this function seem to be indented by one more column. Please keep the indentation.
+
This empty line has whitespace on it. Please delete.
/*
* First thing is to establish what we expect to find in the log
* (in terms of transaction IDs), and where (in terms of log @@ -514,18 +516,18 @@ static int do_one_pass(journal_t *journal,
switch(blocktype) {
case JBD2_DESCRIPTOR_BLOCK:
/* Verify checksum first */
+if(pass == PASS_SCAN)
^ Coding style requires space before opening (.
You have this problem at multiple places.
+ri_commit_block = 0;
+
if (jbd2_journal_has_csum_v2or3(journal))
descr_csum_size =
sizeof(struct jbd2_journal_block_tail);
if (descr_csum_size > 0 &&
!jbd2_descriptor_block_csum_verify(journal,
bh->b_data)) {
-printk(KERN_ERR "JBD2: Invalid checksum "
- "recovering block %lu in log\n",
- next_log_block);
-err = -EFSBADCRC;
-brelse(bh);
-goto failed;
+need_check_commit_time = true;
+jbd_debug(1, "invalid descriptor block found in %lu, continue
+recovery first.\n",next_log_block);
+
}
/* If it is a valid descriptor block, replay it @@ -535,6 +537,7 @@ static int do_one_pass(journal_t *journal,
if (pass != PASS_REPLAY) {
if (pass == PASS_SCAN &&
jbd2_has_feature_checksum(journal) &&
+ !need_check_commit_time &&
!info->end_transaction) {
if (calc_chksums(journal, bh,
&next_log_block,
@@ -688,6 +691,36 @@ static int do_one_pass(journal_t *journal,
* are present verify them in PASS_SCAN; else not
* much to do other than move on to the next sequence
* number. */
+if(pass == PASS_SCAN) {
+struct commit_header *cbh =
+(struct commit_header *)bh->b_data;
+if(need_check_commit_time) {
+__be64 commit_time = be64_to_cpu(cbh->h_commit_sec);
+if(commit_time >= last_trans_commit_time) {
+printk(KERN_ERR "JBD2: Invalid checksum found in log, %d\n",
+next_commit_ID);
+err = -EFSBADCRC;
+brelse(bh);
+goto failed;
+}
+else
+{
Coding style requires to put opening { on the same line as 'else'. Like:
else {
+/*it's not belong to same journal, just end this recovery with success*/
+jbd_debug(1, "JBD2: Invalid checksum found in block in log, but not same journal %d\n",
+next_commit_ID);
+err = 0;
+brelse(bh);
+goto done;
+}
+}
+if(ri_commit_block) {
+jbd_debug(1, "invalid commit block found in %lu, stop here.\n",next_log_block);
+brelse(bh);
+goto done;
+}
+ri_commit_block = next_log_block;
Why does the ri_commit_block logic exist? I don't see it bringing any benefit...
+last_trans_commit_time = be64_to_cpu(cbh->h_commit_sec);
+}
if (pass == PASS_SCAN &&
jbd2_has_feature_checksum(journal)) {
int chksum_err, chksum_seen;
@@ -755,6 +788,12 @@ static int do_one_pass(journal_t *journal,
continue;
case JBD2_REVOKE_BLOCK:
+if (pass == PASS_SCAN &&
+ri_commit_block) {
+jbd_debug(1, "invalid revoke block found in %lu, stop here.\n",next_log_block);
+brelse(bh);
+goto done;
+}
This is wrong. A valid transaction can start with a revoke block...
/* If we aren't in the REVOKE pass, then we can
* just skip over this block. */
if (pass != PASS_REVOKE) {
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
________________________________
CONFIDENTIALITY NOTICE: This electronic message is intended to be viewed only by the individual or entity to whom it is addressed. It may contain information that is privileged, confidential and exempt from disclosure under applicable law. Any dissemination, distribution or copying of this communication is strictly prohibited without our prior permission. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, or if you have received this communication in error, please notify us immediately by return e-mail and delete the original message and any copies of it from your computer system. For further information about Hikvision company. please see our website at www.hikvision.com<http://www.hikvision.com>
[-- Attachment #2: jbd2.patch --]
[-- Type: application/octet-stream, Size: 4579 bytes --]
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index a4967b27ffb6..631a42b50516 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -417,7 +417,7 @@ static int do_one_pass(journal_t *journal,
struct recovery_info *info, enum passtype pass)
{
unsigned int first_commit_ID, next_commit_ID;
- unsigned long next_log_block;
+ unsigned long next_log_block, ri_commit_block = 0;
int err, success = 0;
journal_superblock_t * sb;
journal_header_t * tmp;
@@ -428,6 +428,8 @@ static int do_one_pass(journal_t *journal,
__u32 crc32_sum = ~0; /* Transactional Checksums */
int descr_csum_size = 0;
int block_error = 0;
+ bool need_check_commit_time = false;
+ __be64 last_trans_commit_time = 0;
/*
* First thing is to establish what we expect to find in the log
@@ -514,18 +516,17 @@ static int do_one_pass(journal_t *journal,
switch(blocktype) {
case JBD2_DESCRIPTOR_BLOCK:
/* Verify checksum first */
+ if (pass == PASS_SCAN)
+ ri_commit_block = 0;
if (jbd2_journal_has_csum_v2or3(journal))
descr_csum_size =
sizeof(struct jbd2_journal_block_tail);
if (descr_csum_size > 0 &&
!jbd2_descriptor_block_csum_verify(journal,
bh->b_data)) {
- printk(KERN_ERR "JBD2: Invalid checksum "
- "recovering block %lu in log\n",
- next_log_block);
- err = -EFSBADCRC;
- brelse(bh);
- goto failed;
+ need_check_commit_time = true;
+ jbd_debug(1, "invalid descriptor block found in %lu, continue recovery first.\n",
+ next_log_block);
}
/* If it is a valid descriptor block, replay it
@@ -535,6 +536,7 @@ static int do_one_pass(journal_t *journal,
if (pass != PASS_REPLAY) {
if (pass == PASS_SCAN &&
jbd2_has_feature_checksum(journal) &&
+ !need_check_commit_time &&
!info->end_transaction) {
if (calc_chksums(journal, bh,
&next_log_block,
@@ -688,6 +690,47 @@ static int do_one_pass(journal_t *journal,
* are present verify them in PASS_SCAN; else not
* much to do other than move on to the next sequence
* number. */
+ if (pass == PASS_SCAN) {
+ struct commit_header *cbh =
+ (struct commit_header *)bh->b_data;
+ /*
+ * When need check commit time, it means csum
+ * verify failed before, if commit time is
+ * increasing, it's same journal, otherwise
+ * not same journal, just end this recovery.
+ */
+ if (need_check_commit_time) {
+ __be64 commit_time =
+ be64_to_cpu(cbh->h_commit_sec);
+
+ if (commit_time >= last_trans_commit_time) {
+ pr_err("JBD2: Invalid checksum found in log, %d\n",
+ next_commit_ID);
+ err = -EFSBADCRC;
+ brelse(bh);
+ goto failed;
+ } else {
+ /*
+ * it's not belong to same journal, just
+ * end this recovery with success.
+ */
+ jbd_debug(1, "JBD2: Invalid checksum found in block in log, but not same journal %d\n",
+ next_commit_ID);
+ err = 0;
+ brelse(bh);
+ goto done;
+ }
+ }
+ if (ri_commit_block) {
+ jbd_debug(1, "invalid commit block found in %lu, stop here.\n",
+ next_log_block);
+ brelse(bh);
+ goto done;
+ }
+ ri_commit_block = next_log_block;
+ last_trans_commit_time =
+ be64_to_cpu(cbh->h_commit_sec);
+ }
if (pass == PASS_SCAN &&
jbd2_has_feature_checksum(journal)) {
int chksum_err, chksum_seen;
@@ -755,6 +798,21 @@ static int do_one_pass(journal_t *journal,
continue;
case JBD2_REVOKE_BLOCK:
+ /*
+ * Check revoke block crc in pass_scan, if csum verify
+ * failed, check commit block time later.
+ */
+ if (pass == PASS_SCAN) {
+ jbd2_journal_revoke_header_t *header =
+ (jbd2_journal_revoke_header_t *)bh->b_data;
+ ri_commit_block = 0;
+ if (!jbd2_descriptor_block_csum_verify(journal,
+ header)) {
+ jbd_debug(1, "invalid revoke block found in %lu, continue recovery first.\n",
+ 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) {
@@ -822,9 +880,6 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
offset = sizeof(jbd2_journal_revoke_header_t);
rcount = be32_to_cpu(header->r_count);
- if (!jbd2_descriptor_block_csum_verify(journal, header))
- return -EFSBADCRC;
-
if (jbd2_journal_has_csum_v2or3(journal))
csum_size = sizeof(struct jbd2_journal_block_tail);
if (rcount > journal->j_blocksize - csum_size)
next prev parent reply other threads:[~2020-09-23 6:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <tencent_2341B065211F204FA07C3ADDA1AE07706405@qq.com>
2020-09-10 12:06 ` [PATCH] jbd2: avoid transaction reuse after reformatting 常凤楠
2020-09-10 18:45 ` Andreas Dilger
2020-09-11 10:06 ` Jan Kara
2020-09-14 11:50 ` 答复: " 常凤楠
2020-09-17 10:44 ` Jan Kara
2020-09-18 1:49 ` 答复: " 常凤楠
2020-09-18 13:02 ` Jan Kara
2020-09-23 6:29 ` 常凤楠 [this message]
2020-09-23 12:24 ` 答复: " Jan Kara
2020-10-03 4:24 ` Theodore Y. Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=708254ddee9b49d18ced1885dc7c29fa@hikvision.com \
--to=changfengnan@hikvision.com \
--cc=adilger@dilger.ca \
--cc=changfengnan@qq.com \
--cc=darrick.wong@oracle.com \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).