bcachefs: Kill bch2_btree_node_write_cond()
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 27 Feb 2022 14:42:46 +0000 (09:42 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:26 +0000 (17:09 -0400)
bch2_btree_node_write_cond() was only used in one place - this inlines
it into __btree_node_flush() and makes the cmpxchg loop actually
correct.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/btree_io.h
fs/bcachefs/btree_update_leaf.c

index 3dbb518c4da4f30462d46405b7205cced37c7896..7ed88089f6f94185a56d7a88b74de196bce56eaa 100644 (file)
@@ -158,22 +158,6 @@ static inline void btree_node_write_if_need(struct bch_fs *c, struct btree *b,
        bch2_btree_node_write(c, b, lock_held, BTREE_WRITE_ONLY_IF_NEED);
 }
 
-#define bch2_btree_node_write_cond(_c, _b, cond)                       \
-do {                                                                   \
-       unsigned long old, new, v = READ_ONCE((_b)->flags);             \
-                                                                       \
-       do {                                                            \
-               old = new = v;                                          \
-                                                                       \
-               if (!(old & (1 << BTREE_NODE_dirty)) || !(cond))        \
-                       break;                                          \
-                                                                       \
-               new |= (1 << BTREE_NODE_need_write);                    \
-       } while ((v = cmpxchg(&(_b)->flags, old, new)) != old);         \
-                                                                       \
-       btree_node_write_if_need(_c, _b, SIX_LOCK_read);                \
-} while (0)
-
 void bch2_btree_flush_all_reads(struct bch_fs *);
 void bch2_btree_flush_all_writes(struct bch_fs *);
 
index 94d0b8bd014bfa590ffd08909d64f69461688cb2..dc4dfcda8f21d65b2f42a5b17a0aed8ff9fdaa7b 100644 (file)
@@ -168,10 +168,24 @@ static int __btree_node_flush(struct journal *j, struct journal_entry_pin *pin,
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
        struct btree_write *w = container_of(pin, struct btree_write, journal);
        struct btree *b = container_of(w, struct btree, writes[i]);
+       unsigned long old, new, v;
+       unsigned idx = w - b->writes;
 
        six_lock_read(&b->c.lock, NULL, NULL);
-       bch2_btree_node_write_cond(c, b,
-               (btree_current_write(b) == w && w->journal.seq == seq));
+       v = READ_ONCE(b->flags);
+
+       do {
+               old = new = v;
+
+               if (!(old & (1 << BTREE_NODE_dirty)) ||
+                   !!(old & (1 << BTREE_NODE_write_idx)) != idx ||
+                   w->journal.seq != seq)
+                       break;
+
+               new |= 1 << BTREE_NODE_need_write;
+       } while ((v = cmpxchg(&b->flags, old, new)) != old);
+
+       btree_node_write_if_need(c, b, SIX_LOCK_read);
        six_unlock_read(&b->c.lock);
        return 0;
 }