bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start()
PATCH v2 1/1 bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start()
Values were left as the next possible sequence number when there were no entries.
The fix involves updating the last_seq initial value and setting last_empty_seq to cur_seq - 1.
---
Changes in v2:
- Introduce a new variable to distinguish the last sequence number, from the last written sequence number
- Abstract cur_seq - 1 into a variable named last_seq
- Reference to the last sequence number are changed from cur_seq - 1 to last_seq
--- fs/bcachefs/journal.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
fs/bcachefs/journal.c +11 -11
@@ -1195,8 +1195,8 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)struct journal_entry_pin_list *p;struct journal_replay *i, **_i;struct genradix_iter iter; -bool had_entries = false; -u64 last_seq = cur_seq, nr, seq; +bool had_entries = false; +u64 last_written_seq = cur_seq -1 , last_seq = cur_seq -1 , nr, seq;genradix_for_each_reverse (&c->journal_entries, iter, _i) { i = *_i;
@@ -1204,11 +1204,11 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)if (journal_replay_ignore (i))continue ; - last_seq =le64_to_cpu (i->j.last_seq); + last_written_seq =le64_to_cpu (i->j.last_seq);break ; } - nr = cur_seq - last_seq; + nr = cur_seq - last_written_seq;if (nr +1 > j->pin.size) {free_fifo (&j->pin);
@@ -1219,14 +1219,14 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) } } - j->replay_journal_seq = last_seq; + j->replay_journal_seq = last_written_seq; j->replay_journal_seq_end = cur_seq; - j->last_seq_ondisk = last_seq; - j->flushed_seq_ondisk = cur_seq -1 ; - j->seq_ondisk = cur_seq -1 ; - j->pin.front = last_seq; + j->last_seq_ondisk = last_written_seq; + j->flushed_seq_ondisk = last_seq; + j->seq_ondisk = last_seq; + j->pin.front = last_written_seq; j->pin.back = cur_seq; -atomic64_set (&j->seq, cur_seq -1 ); +atomic64_set (&j->seq, last_seq);fifo_for_each_entry_ptr (p, &j->pin, seq)journal_pin_list_init (p,1 );
@@ -1256,7 +1256,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) }if (!had_entries) - j->last_empty_seq = cur_seq; + j->last_empty_seq = last_seq;spin_lock (&j->lock);
Signature · 1 line
2.34.1
Hello,
I was wondering if you had had the time to take a look at this. Please let me know if there's something I'm missing.
Thanks!
Quoted 82 lines · Camila Alvarez
Values were left as the next possible sequence number when there were no entries.
The fix involves updating the
last_seqinitial value and settinglast_empty_seqtocur_seq- 1.Reported-by [email protected]Signed-off-by Camila Alvarez <[email protected]>---
Changes in v2:
- Introduce a new variable to distinguish the last sequence number, from the last written sequence number
- Abstractcur_seq - 1into a variable namedlast_seq
- Reference to the last sequence number are changed fromcur_seq - 1tolast_seq
---fs/bcachefs/journal.c| 22 +++++++++++-----------1 file changed, 11 insertions(+), 11 deletions(-)fs/bcachefs/journal.c +11
-11@@ -1195,8 +1195,8 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)struct journal_entry_pin_list *p;struct journal_replay *i, **_i;struct genradix_iter iter; -bool had_entries = false; -u64 last_seq = cur_seq, nr, seq; +bool had_entries = false; +u64 last_written_seq = cur_seq -1 , last_seq = cur_seq -1 , nr, seq;genradix_for_each_reverse (&c->journal_entries, iter, _i) { i = *_i;@@ -1204,11 +1204,11 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)if (journal_replay_ignore (i))continue ; - last_seq =le64_to_cpu (i->j.last_seq); + last_written_seq =le64_to_cpu (i->j.last_seq);break ; } - nr = cur_seq - last_seq; + nr = cur_seq - last_written_seq;if (nr +1 > j->pin.size) {free_fifo (&j->pin);@@ -1219,14 +1219,14 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) } } - j->replay_journal_seq = last_seq; + j->replay_journal_seq = last_written_seq; j->replay_journal_seq_end = cur_seq; - j->last_seq_ondisk = last_seq; - j->flushed_seq_ondisk = cur_seq -1 ; - j->seq_ondisk = cur_seq -1 ; - j->pin.front = last_seq; + j->last_seq_ondisk = last_written_seq; + j->flushed_seq_ondisk = last_seq; + j->seq_ondisk = last_seq; + j->pin.front = last_written_seq; j->pin.back = cur_seq; -atomic64_set (&j->seq, cur_seq -1 ); +atomic64_set (&j->seq, last_seq);fifo_for_each_entry_ptr (p, &j->pin, seq)journal_pin_list_init (p,1 );@@ -1256,7 +1256,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) }if (!had_entries) - j->last_empty_seq = cur_seq; + j->last_empty_seq = last_seq;spin_lock (&j->lock);Signature · 1 line
2.34.1
Quoted 3 lines · Camila Alvarez Inostroza
Hello,
I was wondering if you had had the time to take a look at this. Please let me know if there's something I'm missing.
Sorry, I'll get to it - I'm going to need to stare at this one and try and figure out what the assertions should be