From 33e339619f7fda8c428daa5cb8fde7d68dad2edb Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 22 Jul 2020 22:40:32 -0400 Subject: [PATCH] bcachefs: Fix a race with BCH_WRITE_SKIP_CLOSURE_PUT Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index 7e57ca2e1071a..d9e35329f7078 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -1110,6 +1110,16 @@ again: goto flush_io; } + /* + * It's possible for the allocator to fail, put us on the + * freelist waitlist, and then succeed in one of various retry + * paths: if that happens, we need to disable the skip_put + * optimization because otherwise there won't necessarily be a + * barrier before we free the bch_write_op: + */ + if (atomic_read(&cl->remaining) & CLOSURE_WAITING) + skip_put = false; + bch2_open_bucket_get(c, wp, &op->open_buckets); ret = bch2_write_extent(op, wp, &bio); bch2_alloc_sectors_done(c, wp); -- 2.30.2