summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-05-07 23:32:26 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:02 -0400
commit1784d43a88ecf0da66514f4b7f0f52b4182ef81c (patch)
treebe21ccd70b36a4f3c361f9a143879c2057849ee0
parentac1019d32b31c8bca6e0e5f86b403e91a1da5786 (diff)
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 <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/journal.c3
-rw-r--r--fs/bcachefs/journal_io.c7
-rw-r--r--fs/bcachefs/journal_types.h1
3 files changed, 6 insertions, 5 deletions
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 */