diff options
author | Kent Overstreet <[email protected]> | 2021-01-04 15:46:57 -0500 |
---|---|---|
committer | Kent Overstreet <[email protected]> | 2023-10-22 17:08:50 -0400 |
commit | c859430b1728d59ca6e4d7e9356db82979e2fd5b (patch) | |
tree | 6868ea5d3403729f20021a752ba53e3b754b7ef8 | |
parent | 07a1006ae81580c6a1b52b80e32fa9dadea1954b (diff) |
bcachefs: Fix journal_buf_realloc()
It used to be safe to reallocate a buf that the write path owns without
holding the journal lock, but now this can trigger an assertion in
journal_seq_to_buf().
Signed-off-by: Kent Overstreet <[email protected]>
Signed-off-by: Kent Overstreet <[email protected]>
-rw-r--r-- | fs/bcachefs/journal_io.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c index 25010aa42af6..cba420565248 100644 --- a/fs/bcachefs/journal_io.c +++ b/fs/bcachefs/journal_io.c @@ -1051,9 +1051,13 @@ static void journal_buf_realloc(struct journal *j, struct journal_buf *buf) return; memcpy(new_buf, buf->data, buf->buf_size); - kvpfree(buf->data, buf->buf_size); - buf->data = new_buf; - buf->buf_size = new_size; + + spin_lock(&j->lock); + swap(buf->data, new_buf); + swap(buf->buf_size, new_size); + spin_unlock(&j->lock); + + kvpfree(new_buf, new_size); } static inline struct journal_buf *journal_last_unwritten_buf(struct journal *j) |