From: Kent Overstreet Date: Sat, 8 May 2021 03:32:26 +0000 (-0400) Subject: bcachefs: Fix usage of last_seq + encryption X-Git-Tag: io_uring-6.7-2023-11-10~119^2~1593 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=1784d43a88ecf0da66514f4b7f0f52b4182ef81c;p=linux-2.6-block.git bcachefs: Fix usage of last_seq + encryption jset->last_seq is in the region that's encrypted - on journal write completion, we were using it and getting garbage. This patch shadows it to fix. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index a70540853586..a7cc0b167072 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -189,7 +189,8 @@ static bool __journal_entry_close(struct journal *j) * Hence, we want update/set last_seq on the current journal entry right * before we open a new one: */ - buf->data->last_seq = cpu_to_le64(journal_last_seq(j)); + buf->last_seq = journal_last_seq(j); + buf->data->last_seq = cpu_to_le64(buf->last_seq); __bch2_journal_pin_put(j, le64_to_cpu(buf->data->seq)); diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c index 4ab9cebee218..2d3fc33720b8 100644 --- a/fs/bcachefs/journal_io.c +++ b/fs/bcachefs/journal_io.c @@ -1236,7 +1236,7 @@ static void journal_write_done(struct closure *cl) bch2_bkey_devs(bkey_i_to_s_c(&w->key)); struct bch_replicas_padded replicas; union journal_res_state old, new; - u64 v, seq, last_seq; + u64 v, seq; int err = 0; bch2_time_stats_update(j->write_time, j->write_start_time); @@ -1255,7 +1255,6 @@ static void journal_write_done(struct closure *cl) spin_lock(&j->lock); seq = le64_to_cpu(w->data->seq); - last_seq = le64_to_cpu(w->data->last_seq); if (seq >= j->pin.front) journal_seq_pin(j, seq)->devs = devs; @@ -1266,7 +1265,7 @@ static void journal_write_done(struct closure *cl) if (!JSET_NO_FLUSH(w->data)) { j->flushed_seq_ondisk = seq; - j->last_seq_ondisk = last_seq; + j->last_seq_ondisk = w->last_seq; } /* @@ -1400,7 +1399,7 @@ void bch2_journal_write(struct closure *cl) test_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags)) { w->noflush = true; SET_JSET_NO_FLUSH(jset, true); - jset->last_seq = 0; + jset->last_seq = w->last_seq = 0; j->nr_noflush_writes++; } else { diff --git a/fs/bcachefs/journal_types.h b/fs/bcachefs/journal_types.h index 6e2a2d6b8346..b4e4d5e0bc93 100644 --- a/fs/bcachefs/journal_types.h +++ b/fs/bcachefs/journal_types.h @@ -23,6 +23,7 @@ struct journal_buf { __BKEY_PADDED(key, BCH_REPLICAS_MAX); struct closure_waitlist wait; + u64 last_seq; /* copy of data->last_seq */ unsigned buf_size; /* size in bytes of @data */ unsigned sectors; /* maximum size for current entry */