Tune2fs and fuse2fs do not change j_tail_sequence in journal superblock
There are two recover_ext3_journal functions in e2fsprogs, the recover_ext3_journal function in debugfs/journal.c is called when the programs tune2fs and fuse2fs do log replay, but in this recover_ext3_journal function, after the log replay is over, the j_tail_sequence in journal superblock is not changed to the value of the last transaction sequence, this will cause subsequent log commitids to count from the commitid in last time.
```
e2fsck/journal.c
static errcode_t recover_ext3_journal(e2fsck_t ctx)
{
... ...
journal->j_superblock->s_errno = -EINVAL;
mark_buffer_dirty(journal->j_sb_buffer);
}
journal->j_tail_sequence = journal->j_transaction_sequence;
errout:
journal_destroy_revoke(journal);
... ...
}
```
```
debugfs/journal.c
static errcode_t recover_ext3_journal(ext2_filsys fs)
{
... ...
journal->j_superblock->s_errno = -EINVAL;
mark_buffer_dirty(journal->j_sb_buffer);
}
errout:
journal_destroy_revoke(journal);
... ...
}
```result:
After tune2fs -e, the log commitid is counted from the commitid in last time, if the log ID of the current operation overlaps with that of the last operation, this will cause logs that were previously replayed by tune2fs to be replayed here. The code used by tune2fs to determine whether to replay the transaction is as follows:
```
static int do_one_pass(journal_t *journal,
struct recovery_info *info, enum passtype pass)
{
... ...
while (1) {
... ...
if (sequence != next_commit_ID) {
brelse(bh);
break;
}
... ...
next_commit_ID++;
}
... ...
}
```
This moment, commitid is "34 c7", commit time stamp is "62 e0 f7 a5"
004aa000 c0 3b 39 98 00 00 00 02 00 00 34 c7 00 00 00 00
|.;9.......4.....|
004aa010 4e 93 2f fb 00 00 00 00 00 00 00 00 00 00 00 00
|N./.............|
004aa020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|................|
004aa030 00 00 00 00 62 e0 f7 a5 0a 16 56 20 00 00 00 00
|....b.....V ....|
--
This moment, commitid is "34 c8", commit time stamp is "62 e0 e7 1e"
004ad000 c0 3b 39 98 00 00 00 02 00 00 34 c8 00 00 00 00
|.;9.......4.....|
004ad010 75 a6 12 01 00 00 00 00 00 00 00 00 00 00 00 00
|u...............|
004ad020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|................|
004ad030 00 00 00 00 62 e0 e7 1e 18 32 cf 18 00 00 00 00
|....b....2......|
--The probability of this happening is very small, but we do, and I think it's a problem.
There are two existing solutions:
1) Add "journal->j_tail_sequence = journal->j_transaction_sequence" in to the recover_ext3_journal in debugfs/journal.c.
2) There is a timestamp in the commit block, so we can add timestamp check when the log is replayed.
Hi
Thanks for you report.
Problem much bigger than it. Debugs based code lack many parts of journal handling, including fast commit. Journal tag v3, and other.
Alex
Quoted 79 lines · zhanchengbin
There are two
recover_ext3_journalfunctions in e2fsprogs, therecover_ext3_journalfunction indebugfs/journal.cis called when the programs tune2fs and fuse2fs do log replay, but in thisrecover_ext3_journalfunction, after the log replay is over, thej_tail_sequencein journal superblock is not changed to the value of the last transaction sequence, this will cause subsequent log commitids to count from the commitid in last time.``` e2fsck/journal.c static errcode_t recover_ext3_journal(e2fsck_t ctx) { ... ... journal->j_superblock->s_errno = -EINVAL; mark_buffer_dirty(journal->j_sb_buffer); } journal->j_tail_sequence = journal->j_transaction_sequence; errout: journal_destroy_revoke(journal); ... ... } ``` ``` debugfs/journal.c static errcode_t recover_ext3_journal(ext2_filsys fs) { ... ... journal->j_superblock->s_errno = -EINVAL; mark_buffer_dirty(journal->j_sb_buffer); } errout: journal_destroy_revoke(journal); ... ... } ```result:
After tune2fs -e, the log commitid is counted from the commitid in last time, if the log ID of the current operation overlaps with that of the last operation, this will cause logs that were previously replayed by tune2fs to be replayed here. The code used by tune2fs to determine whether to replay the transaction is as follows:``` static int do_one_pass(journal_t *journal, struct recovery_info *info, enum passtype pass) { ... ... while (1) { ... ... if (sequence != next_commit_ID) { brelse(bh); break; } ... ... next_commit_ID++; } ... ... } ``` This moment, commitid is "34 c7", commit time stamp is "62 e0 f7 a5" 004aa000 c0 3b 39 98 00 00 00 02 00 00 34 c7 00 00 00 00 |.;9.......4.....| 004aa010 4e 93 2f fb 00 00 00 00 00 00 00 00 00 00 00 00 |N./.............| 004aa020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 004aa030 00 00 00 00 62 e0 f7 a5 0a 16 56 20 00 00 00 00 |....b.....V ....| -- This moment, commitid is "34 c8", commit time stamp is "62 e0 e7 1e" 004ad000 c0 3b 39 98 00 00 00 02 00 00 34 c8 00 00 00 00 |.;9.......4.....| 004ad010 75 a6 12 01 00 00 00 00 00 00 00 00 00 00 00 00 |u...............| 004ad020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 004ad030 00 00 00 00 62 e0 e7 1e 18 32 cf 18 00 00 00 00 |....b....2......|--
The probability of this happening is very small, but we do, and I think it's a problem.There are two existing solutions:
1) Add "journal->j_tail_sequence=journal->j_transaction_sequence" in to therecover_ext3_journalindebugfs/journal.c.
2) There is a timestamp in the commit block, so we can add timestamp check when the log is replayed.
Quoted 5 lines
Hi
Thanks for you report.
Problem much bigger than it. Debugs based code lack many parts of journal handling, including fast commit. Journal tag v3, and other.
I think we can solve the current problem first.
Quoted 4 lines
Alex
Quoted 1 line · zhanchengbin
<snip>
Quoted 3 lines
Quoted 3 lines
There are two existing solutions:
1) Add "journal->j_tail_sequence=journal->j_transaction_sequence" in to therecover_ext3_journalindebugfs/journal.c.
I want to use the first solution, do you have any other solutions?
Thanks.
Quoted 5 lines
Quoted 2 lines
2) There is a timestamp in the commit block, so we can add timestamp check when the log is replayed.
.
PATCH 1/1 tune2fs: do not change j_tail_sequence in journal superblock
In reply to zhanchengbinThe function recover_ext3_journal in debugfs/journal.c, if the log replay is over, the j_tail_sequence in journal superblock is not changed to the value of the last transaction sequence, this will cause subsequent log commitids to count from the commitid in last time.
After tune2fs -e, the log commitid is counted from the commitid in last time, if the log ID of the current operation overlaps with that of the last operation, this will cause logs that were previously replayed by tune2fs to be replayed here.
--- debugfs/journal.c | 2 ++ 1 file changed, 2 insertions(+)
debugfs/journal.c +2 -0
@@ -769,6 +769,8 @@ static errcode_t recover_ext3_journal(ext2_filsys fs)mark_buffer_dirty (journal->j_sb_buffer); } + journal->j_tail_sequence = journal->j_transaction_sequence; + errout:jbd2_journal_destroy_revoke (journal);jbd2_journal_destroy_revoke_record_cache ();
Signature · 1 line
2.27.0
Re: [PATCH] tune2fs: do not change j_tail_sequence in journal superblock
Friendly ping...
Quoted 28 lines · zhanchengbin
The function
recover_ext3_journalindebugfs/journal.c, if the log replay is over, thej_tail_sequencein journal superblock is not changed to the value of the last transaction sequence, this will cause subsequent log commitids to count from the commitid in last time.
After tune2fs -e, the log commitid is counted from the commitid in last time, if the log ID of the current operation overlaps with that of the last operation, this will cause logs that were previously replayed by tune2fs to be replayed here.Signed-off-by zhanchengbin <[email protected]>Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by liangyun <[email protected]>--- debugfs/journal.c | 2 ++ 1 file changed, 2 insertions(+)debugfs/journal.c +2
-0@@ -769,6 +769,8 @@ static errcode_t recover_ext3_journal(ext2_filsys fs) mark_buffer_dirty(journal->j_sb_buffer); } + journal->j_tail_sequence = journal->j_transaction_sequence; + errout: jbd2_journal_destroy_revoke(journal); jbd2_journal_destroy_revoke_record_cache();
Theodore Ts'o
AppliedRe: [PATCH] tune2fs: do not change j_tail_sequence in journal superblock
In reply to zhanchengbinQuoted 14 lines · zhanchengbin
The function
recover_ext3_journalindebugfs/journal.c, if the log replay is over,
thej_tail_sequencein journal superblock is not changed to the value of the last
transaction sequence, this will cause subsequent log commitids to count from the
commitid in last time.
After tune2fs -e, the log commitid is counted from the commitid in last time, if
the log ID of the current operation overlaps with that of the last operation, this
will cause logs that were previously replayed by tune2fs to be replayed here.
Quoted 3 lines
Signed-off-by zhanchengbin <[email protected]>Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by liangyun <[email protected]>
Applied, thanks!
- Ted