bcachefs: Fix move_ctxt_wait_event()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 4 Jan 2023 04:39:42 +0000 (23:39 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:52 +0000 (17:09 -0400)
We shouldn't be evaluating cond again if it already returned true.

This fixes a bug when this helper is used for taking nocow locks.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/move.h

index a2822d4a4afb84679cf4433e0b8a368b6ab74330..34b9cadef6b59b5f332b200f6a40521581668d26 100644 (file)
@@ -28,14 +28,18 @@ struct moving_context {
        wait_queue_head_t       wait;
 };
 
-#define move_ctxt_wait_event(_ctxt, _trans, _cond)             \
-do {                                                           \
-       bch2_moving_ctxt_do_pending_writes(_ctxt, _trans);      \
-                                                               \
-       if (_cond)                                              \
-               break;                                          \
-       __wait_event((_ctxt)->wait,                             \
-                    bch2_moving_ctxt_next_pending_write(_ctxt) || (_cond));\
+#define move_ctxt_wait_event(_ctxt, _trans, _cond)                     \
+do {                                                                   \
+       bool cond_finished = false;                                     \
+       bch2_moving_ctxt_do_pending_writes(_ctxt, _trans);              \
+                                                                       \
+       if (_cond)                                                      \
+               break;                                                  \
+       __wait_event((_ctxt)->wait,                                     \
+                    bch2_moving_ctxt_next_pending_write(_ctxt) ||      \
+                    (cond_finished = (_cond)));                        \
+       if (cond_finished)                                              \
+               break;                                                  \
 } while (1)
 
 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,