bcachefs: BTREE_TRIGGER_INSERT now only means insert
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 29 Oct 2021 22:58:50 +0000 (18:58 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:15 +0000 (17:09 -0400)
This allows triggers to distinguish between a key entering the btree -
i.e. being called from the trans commit path - vs. being called on a key
that already exists, i.e. by GC.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/btree_gc.c
fs/bcachefs/buckets.c
fs/bcachefs/ec.c

index 48fd8919535774b830e26b2a1616658ab2cffbec..197f5c0f3a9ad5812987c47f1853f15737275aa9 100644 (file)
@@ -697,7 +697,6 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
        struct bkey_ptrs_c ptrs;
        const struct bch_extent_ptr *ptr;
        unsigned flags =
-               BTREE_TRIGGER_INSERT|
                BTREE_TRIGGER_GC|
                (initial ? BTREE_TRIGGER_NOATOMIC : 0);
        char buf[200];
@@ -1117,8 +1116,7 @@ static void bch2_mark_pending_btree_node_frees(struct bch_fs *c)
 
        for_each_pending_btree_node_free(c, as, d)
                if (d->index_update_done)
-                       bch2_mark_key(c, bkey_i_to_s_c(&d->key),
-                                     BTREE_TRIGGER_INSERT|BTREE_TRIGGER_GC);
+                       bch2_mark_key(c, bkey_i_to_s_c(&d->key), BTREE_TRIGGER_GC);
 
        mutex_unlock(&c->btree_interior_update_lock);
 }
index a114a114234074cd25d97f6fcfe8af76b68bb3e7..6e1837a0fc64d4dc6e057ba466b9c33004eec85c 100644 (file)
@@ -929,7 +929,7 @@ static int bch2_mark_extent(struct btree_trans *trans,
        bool gc = flags & BTREE_TRIGGER_GC;
        u64 journal_seq = trans->journal_res.seq;
        struct bch_fs *c = trans->c;
-       struct bkey_s_c k = flags & BTREE_TRIGGER_INSERT ? new : old;
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
        const union bch_extent_entry *entry;
        struct extent_ptr_decoded p;
@@ -944,9 +944,6 @@ static int bch2_mark_extent(struct btree_trans *trans,
        bool stale;
        int ret;
 
-       BUG_ON((flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)) ==
-              (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE));
-
        r.e.data_type   = data_type;
        r.e.nr_devs     = 0;
        r.e.nr_required = 1;
@@ -1112,7 +1109,7 @@ static int bch2_mark_reservation(struct btree_trans *trans,
                                 unsigned flags)
 {
        struct bch_fs *c = trans->c;
-       struct bkey_s_c k = flags & BTREE_TRIGGER_INSERT ? new : old;
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
        struct bch_fs_usage __percpu *fs_usage;
        unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;
        s64 sectors = (s64) k.k->size;
@@ -1185,7 +1182,7 @@ static int bch2_mark_reflink_p(struct btree_trans *trans,
                               unsigned flags)
 {
        struct bch_fs *c = trans->c;
-       struct bkey_s_c k = flags & BTREE_TRIGGER_INSERT ? new : old;
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
        struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
        struct reflink_gc *ref;
        size_t l, r, m;
@@ -1194,9 +1191,6 @@ static int bch2_mark_reflink_p(struct btree_trans *trans,
                le32_to_cpu(p.v->back_pad);
        int ret = 0;
 
-       BUG_ON((flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)) ==
-              (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE));
-
        l = 0;
        r = c->reflink_gc_nr;
        while (l < r) {
@@ -1220,9 +1214,7 @@ static int bch2_mark_key_locked(struct btree_trans *trans,
                   struct bkey_s_c new,
                   unsigned flags)
 {
-       struct bkey_s_c k = flags & BTREE_TRIGGER_INSERT ? new : old;
-
-       BUG_ON(!(flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)));
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
 
        switch (k.k->type) {
        case KEY_TYPE_alloc:
@@ -1541,9 +1533,6 @@ static int bch2_trans_mark_extent(struct btree_trans *trans,
        bool stale;
        int ret;
 
-       BUG_ON((flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)) ==
-              (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE));
-
        r.e.data_type   = data_type;
        r.e.nr_devs     = 0;
        r.e.nr_required = 1;
@@ -1715,9 +1704,6 @@ static int bch2_trans_mark_reservation(struct btree_trans *trans,
        s64 sectors = (s64) k.k->size;
        struct replicas_delta_list *d;
 
-       BUG_ON((flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)) ==
-              (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE));
-
        if (flags & BTREE_TRIGGER_OVERWRITE)
                sectors = -sectors;
        sectors *= replicas;
@@ -1837,9 +1823,7 @@ static int bch2_trans_mark_reflink_p(struct btree_trans *trans,
 int bch2_trans_mark_key(struct btree_trans *trans, struct bkey_s_c old,
                        struct bkey_s_c new, unsigned flags)
 {
-       struct bkey_s_c k = flags & BTREE_TRIGGER_INSERT ? new : old;
-
-       BUG_ON(!(flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)));
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
 
        switch (k.k->type) {
        case KEY_TYPE_btree_ptr:
index 74dc6c40dc9e81818163e41b75c455a197eae6d1..32b17f05a750925c80bfd80d31a840992feca8f6 100644 (file)
@@ -1642,7 +1642,6 @@ static int bch2_stripes_read_fn(struct btree_trans *trans, struct bkey_s_c k)
        if (k.k->type == KEY_TYPE_stripe)
                ret = __ec_stripe_mem_alloc(c, k.k->p.offset, GFP_KERNEL) ?:
                        bch2_mark_key(trans, k,
-                                     BTREE_TRIGGER_INSERT|
                                      BTREE_TRIGGER_NOATOMIC);
 
        return ret;