bcachefs: BTREE_TRIGGER_ATOMIC
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 7 Jan 2024 22:14:46 +0000 (17:14 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 21 Jan 2024 11:01:45 +0000 (06:01 -0500)
Add a new flag to be explicit about when we're running atomic triggers.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/bkey_methods.h
fs/bcachefs/btree_trans_commit.c
fs/bcachefs/btree_types.h
fs/bcachefs/ec.c
fs/bcachefs/inode.c
fs/bcachefs/reflink.c
fs/bcachefs/reflink.h

index f31541a..bebaaf8 100644 (file)
@@ -821,7 +821,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                }
        }
 
-       if (!(flags & BTREE_TRIGGER_TRANSACTIONAL) && (flags & BTREE_TRIGGER_INSERT)) {
+       if ((flags & BTREE_TRIGGER_ATOMIC) && (flags & BTREE_TRIGGER_INSERT)) {
                struct bch_alloc_v4 *new_a = bkey_s_to_alloc_v4(new).v;
                u64 journal_seq = trans->journal_res.seq;
                u64 bucket_journal_seq = new_a->journal_seq;
index ee82283..03efe8e 100644 (file)
@@ -83,9 +83,10 @@ enum btree_update_flags {
 
        __BTREE_TRIGGER_NORUN,
        __BTREE_TRIGGER_TRANSACTIONAL,
+       __BTREE_TRIGGER_ATOMIC,
+       __BTREE_TRIGGER_GC,
        __BTREE_TRIGGER_INSERT,
        __BTREE_TRIGGER_OVERWRITE,
-       __BTREE_TRIGGER_GC,
        __BTREE_TRIGGER_BUCKET_INVALIDATE,
 };
 
@@ -107,6 +108,10 @@ enum btree_update_flags {
  * causing us to go emergency read-only)
  */
 #define BTREE_TRIGGER_TRANSACTIONAL    (1U << __BTREE_TRIGGER_TRANSACTIONAL)
+#define BTREE_TRIGGER_ATOMIC           (1U << __BTREE_TRIGGER_ATOMIC)
+
+/* We're in gc/fsck: running triggers to recalculate e.g. disk usage */
+#define BTREE_TRIGGER_GC               (1U << __BTREE_TRIGGER_GC)
 
 /* @new is entering the btree */
 #define BTREE_TRIGGER_INSERT           (1U << __BTREE_TRIGGER_INSERT)
@@ -114,9 +119,6 @@ enum btree_update_flags {
 /* @old is leaving the btree */
 #define BTREE_TRIGGER_OVERWRITE                (1U << __BTREE_TRIGGER_OVERWRITE)
 
-/* We're in gc/fsck: running triggers to recalculate e.g. disk usage */
-#define BTREE_TRIGGER_GC               (1U << __BTREE_TRIGGER_GC)
-
 /* signal from bucket invalidate path to alloc trigger */
 #define BTREE_TRIGGER_BUCKET_INVALIDATE        (1U << __BTREE_TRIGGER_BUCKET_INVALIDATE)
 
index 90eb806..e3a82c3 100644 (file)
@@ -448,9 +448,6 @@ static int run_one_mem_trigger(struct btree_trans *trans,
        if (unlikely(flags & BTREE_TRIGGER_NORUN))
                return 0;
 
-       if (!btree_node_type_needs_gc(__btree_node_type(i->level, i->btree_id)))
-               return 0;
-
        if (old_ops->trigger == new_ops->trigger) {
                ret   = bch2_key_trigger(trans, i->btree_id, i->level,
                                old, bkey_i_to_s(new),
@@ -586,9 +583,6 @@ static int bch2_trans_commit_run_triggers(struct btree_trans *trans)
 
 static noinline int bch2_trans_commit_run_gc_triggers(struct btree_trans *trans)
 {
-       struct bch_fs *c = trans->c;
-       int ret = 0;
-
        trans_for_each_update(trans, i) {
                /*
                 * XXX: synchronization of cached update triggers with gc
@@ -596,14 +590,15 @@ static noinline int bch2_trans_commit_run_gc_triggers(struct btree_trans *trans)
                 */
                BUG_ON(i->cached || i->level);
 
-               if (gc_visited(c, gc_pos_btree_node(insert_l(trans, i)->b))) {
-                       ret = run_one_mem_trigger(trans, i, i->flags|BTREE_TRIGGER_GC);
+               if (btree_node_type_needs_gc(__btree_node_type(i->level, i->btree_id)) &&
+                   gc_visited(trans->c, gc_pos_btree_node(insert_l(trans, i)->b))) {
+                       int ret = run_one_mem_trigger(trans, i, i->flags|BTREE_TRIGGER_GC);
                        if (ret)
-                               break;
+                               return ret;
                }
        }
 
-       return ret;
+       return 0;
 }
 
 static inline int
@@ -689,8 +684,8 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
        }
 
        trans_for_each_update(trans, i)
-               if (BTREE_NODE_TYPE_HAS_MEM_TRIGGERS & (1U << i->bkey_type)) {
-                       ret = run_one_mem_trigger(trans, i, i->flags);
+               if (BTREE_NODE_TYPE_HAS_ATOMIC_TRIGGERS & (1U << i->bkey_type)) {
+                       ret = run_one_mem_trigger(trans, i, BTREE_TRIGGER_ATOMIC|i->flags);
                        if (ret)
                                goto fatal_err;
                }
index d530307..e468675 100644 (file)
@@ -653,7 +653,7 @@ const char *bch2_btree_node_type_str(enum btree_node_type);
         BIT_ULL(BKEY_TYPE_reflink)|                    \
         BIT_ULL(BKEY_TYPE_btree))
 
-#define BTREE_NODE_TYPE_HAS_MEM_TRIGGERS               \
+#define BTREE_NODE_TYPE_HAS_ATOMIC_TRIGGERS            \
        (BIT_ULL(BKEY_TYPE_alloc)|                      \
         BIT_ULL(BKEY_TYPE_inodes)|                     \
         BIT_ULL(BKEY_TYPE_stripes)|                    \
@@ -661,7 +661,7 @@ const char *bch2_btree_node_type_str(enum btree_node_type);
 
 #define BTREE_NODE_TYPE_HAS_TRIGGERS                   \
        (BTREE_NODE_TYPE_HAS_TRANS_TRIGGERS|            \
-        BTREE_NODE_TYPE_HAS_MEM_TRIGGERS)
+        BTREE_NODE_TYPE_HAS_ATOMIC_TRIGGERS)
 
 static inline bool btree_node_type_needs_gc(enum btree_node_type type)
 {
index d802bc6..b29b8a2 100644 (file)
@@ -367,7 +367,7 @@ int bch2_trigger_stripe(struct btree_trans *trans,
                }
        }
 
-       if (!(flags & (BTREE_TRIGGER_TRANSACTIONAL|BTREE_TRIGGER_GC))) {
+       if (flags & BTREE_TRIGGER_ATOMIC) {
                struct stripe *m = genradix_ptr(&c->stripes, idx);
 
                if (!m) {
index 37dce96..51a0632 100644 (file)
@@ -587,7 +587,7 @@ int bch2_trigger_inode(struct btree_trans *trans,
                }
        }
 
-       if (!(flags & BTREE_TRIGGER_TRANSACTIONAL) && (flags & BTREE_TRIGGER_INSERT)) {
+       if ((flags & BTREE_TRIGGER_ATOMIC) && (flags & BTREE_TRIGGER_INSERT)) {
                BUG_ON(!trans->journal_res.seq);
 
                bkey_s_to_inode_v3(new).v->bi_journal_seq = cpu_to_le64(trans->journal_res.seq);
index faa5d36..6070109 100644 (file)
@@ -292,10 +292,10 @@ static inline void check_indirect_extent_deleting(struct bkey_s new, unsigned *f
        }
 }
 
-int bch2_trans_mark_reflink_v(struct btree_trans *trans,
-                             enum btree_id btree_id, unsigned level,
-                             struct bkey_s_c old, struct bkey_s new,
-                             unsigned flags)
+int bch2_trigger_reflink_v(struct btree_trans *trans,
+                          enum btree_id btree_id, unsigned level,
+                          struct bkey_s_c old, struct bkey_s new,
+                          unsigned flags)
 {
        if ((flags & BTREE_TRIGGER_TRANSACTIONAL) &&
            (flags & BTREE_TRIGGER_INSERT))
@@ -324,7 +324,7 @@ void bch2_indirect_inline_data_to_text(struct printbuf *out,
               min(datalen, 32U), d.v->data);
 }
 
-int bch2_trans_mark_indirect_inline_data(struct btree_trans *trans,
+int bch2_trigger_indirect_inline_data(struct btree_trans *trans,
                              enum btree_id btree_id, unsigned level,
                              struct bkey_s_c old, struct bkey_s new,
                              unsigned flags)
index 8ee778e..4d88672 100644 (file)
@@ -24,14 +24,14 @@ int bch2_reflink_v_invalid(struct bch_fs *, struct bkey_s_c,
                           enum bkey_invalid_flags, struct printbuf *);
 void bch2_reflink_v_to_text(struct printbuf *, struct bch_fs *,
                            struct bkey_s_c);
-int bch2_trans_mark_reflink_v(struct btree_trans *, enum btree_id, unsigned,
+int bch2_trigger_reflink_v(struct btree_trans *, enum btree_id, unsigned,
                              struct bkey_s_c, struct bkey_s, unsigned);
 
 #define bch2_bkey_ops_reflink_v ((struct bkey_ops) {           \
        .key_invalid    = bch2_reflink_v_invalid,               \
        .val_to_text    = bch2_reflink_v_to_text,               \
        .swab           = bch2_ptr_swab,                        \
-       .trigger        = bch2_trans_mark_reflink_v,            \
+       .trigger        = bch2_trigger_reflink_v,               \
        .min_val_size   = 8,                                    \
 })
 
@@ -39,7 +39,7 @@ int bch2_indirect_inline_data_invalid(struct bch_fs *, struct bkey_s_c,
                                      enum bkey_invalid_flags, struct printbuf *);
 void bch2_indirect_inline_data_to_text(struct printbuf *,
                                struct bch_fs *, struct bkey_s_c);
-int bch2_trans_mark_indirect_inline_data(struct btree_trans *,
+int bch2_trigger_indirect_inline_data(struct btree_trans *,
                                         enum btree_id, unsigned,
                              struct bkey_s_c, struct bkey_s,
                              unsigned);
@@ -47,7 +47,7 @@ int bch2_trans_mark_indirect_inline_data(struct btree_trans *,
 #define bch2_bkey_ops_indirect_inline_data ((struct bkey_ops) {        \
        .key_invalid    = bch2_indirect_inline_data_invalid,    \
        .val_to_text    = bch2_indirect_inline_data_to_text,    \
-       .trigger        = bch2_trans_mark_indirect_inline_data, \
+       .trigger        = bch2_trigger_indirect_inline_data,    \
        .min_val_size   = 8,                                    \
 })