bcachefs: Fix a race with BCH_WRITE_SKIP_CLOSURE_PUT
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 23 Jul 2020 02:40:32 +0000 (22:40 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:43 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/io.c

index 7e57ca2e1071a7bc438a09d79c5a6338eda60aea..d9e35329f7078d2e8b799ff666a58e77612d8305 100644 (file)
@@ -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);