Commit 2debb1b8 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: BTREE_TRIGGER_INSERT now only means insert

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 904823de
...@@ -697,7 +697,6 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id, ...@@ -697,7 +697,6 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
struct bkey_ptrs_c ptrs; struct bkey_ptrs_c ptrs;
const struct bch_extent_ptr *ptr; const struct bch_extent_ptr *ptr;
unsigned flags = unsigned flags =
BTREE_TRIGGER_INSERT|
BTREE_TRIGGER_GC| BTREE_TRIGGER_GC|
(initial ? BTREE_TRIGGER_NOATOMIC : 0); (initial ? BTREE_TRIGGER_NOATOMIC : 0);
char buf[200]; char buf[200];
...@@ -1117,8 +1116,7 @@ static void bch2_mark_pending_btree_node_frees(struct bch_fs *c) ...@@ -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) for_each_pending_btree_node_free(c, as, d)
if (d->index_update_done) if (d->index_update_done)
bch2_mark_key(c, bkey_i_to_s_c(&d->key), bch2_mark_key(c, bkey_i_to_s_c(&d->key), BTREE_TRIGGER_GC);
BTREE_TRIGGER_INSERT|BTREE_TRIGGER_GC);
mutex_unlock(&c->btree_interior_update_lock); mutex_unlock(&c->btree_interior_update_lock);
} }
......
...@@ -929,7 +929,7 @@ static int bch2_mark_extent(struct btree_trans *trans, ...@@ -929,7 +929,7 @@ static int bch2_mark_extent(struct btree_trans *trans,
bool gc = flags & BTREE_TRIGGER_GC; bool gc = flags & BTREE_TRIGGER_GC;
u64 journal_seq = trans->journal_res.seq; u64 journal_seq = trans->journal_res.seq;
struct bch_fs *c = trans->c; 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); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const union bch_extent_entry *entry; const union bch_extent_entry *entry;
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
...@@ -944,9 +944,6 @@ static int bch2_mark_extent(struct btree_trans *trans, ...@@ -944,9 +944,6 @@ static int bch2_mark_extent(struct btree_trans *trans,
bool stale; bool stale;
int ret; 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.data_type = data_type;
r.e.nr_devs = 0; r.e.nr_devs = 0;
r.e.nr_required = 1; r.e.nr_required = 1;
...@@ -1112,7 +1109,7 @@ static int bch2_mark_reservation(struct btree_trans *trans, ...@@ -1112,7 +1109,7 @@ static int bch2_mark_reservation(struct btree_trans *trans,
unsigned flags) unsigned flags)
{ {
struct bch_fs *c = trans->c; 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; struct bch_fs_usage __percpu *fs_usage;
unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas; unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;
s64 sectors = (s64) k.k->size; s64 sectors = (s64) k.k->size;
...@@ -1185,7 +1182,7 @@ static int bch2_mark_reflink_p(struct btree_trans *trans, ...@@ -1185,7 +1182,7 @@ static int bch2_mark_reflink_p(struct btree_trans *trans,
unsigned flags) unsigned flags)
{ {
struct bch_fs *c = trans->c; 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 bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
struct reflink_gc *ref; struct reflink_gc *ref;
size_t l, r, m; size_t l, r, m;
...@@ -1194,9 +1191,6 @@ static int bch2_mark_reflink_p(struct btree_trans *trans, ...@@ -1194,9 +1191,6 @@ static int bch2_mark_reflink_p(struct btree_trans *trans,
le32_to_cpu(p.v->back_pad); le32_to_cpu(p.v->back_pad);
int ret = 0; int ret = 0;
BUG_ON((flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)) ==
(BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE));
l = 0; l = 0;
r = c->reflink_gc_nr; r = c->reflink_gc_nr;
while (l < r) { while (l < r) {
...@@ -1220,9 +1214,7 @@ static int bch2_mark_key_locked(struct btree_trans *trans, ...@@ -1220,9 +1214,7 @@ static int bch2_mark_key_locked(struct btree_trans *trans,
struct bkey_s_c new, struct bkey_s_c new,
unsigned flags) unsigned flags)
{ {
struct bkey_s_c k = flags & BTREE_TRIGGER_INSERT ? new : old; struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
BUG_ON(!(flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)));
switch (k.k->type) { switch (k.k->type) {
case KEY_TYPE_alloc: case KEY_TYPE_alloc:
...@@ -1541,9 +1533,6 @@ static int bch2_trans_mark_extent(struct btree_trans *trans, ...@@ -1541,9 +1533,6 @@ static int bch2_trans_mark_extent(struct btree_trans *trans,
bool stale; bool stale;
int ret; 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.data_type = data_type;
r.e.nr_devs = 0; r.e.nr_devs = 0;
r.e.nr_required = 1; r.e.nr_required = 1;
...@@ -1715,9 +1704,6 @@ static int bch2_trans_mark_reservation(struct btree_trans *trans, ...@@ -1715,9 +1704,6 @@ static int bch2_trans_mark_reservation(struct btree_trans *trans,
s64 sectors = (s64) k.k->size; s64 sectors = (s64) k.k->size;
struct replicas_delta_list *d; 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) if (flags & BTREE_TRIGGER_OVERWRITE)
sectors = -sectors; sectors = -sectors;
sectors *= replicas; sectors *= replicas;
...@@ -1837,9 +1823,7 @@ static int bch2_trans_mark_reflink_p(struct btree_trans *trans, ...@@ -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, 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 new, unsigned flags)
{ {
struct bkey_s_c k = flags & BTREE_TRIGGER_INSERT ? new : old; struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
BUG_ON(!(flags & (BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE)));
switch (k.k->type) { switch (k.k->type) {
case KEY_TYPE_btree_ptr: case KEY_TYPE_btree_ptr:
......
...@@ -1642,7 +1642,6 @@ static int bch2_stripes_read_fn(struct btree_trans *trans, struct bkey_s_c k) ...@@ -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) if (k.k->type == KEY_TYPE_stripe)
ret = __ec_stripe_mem_alloc(c, k.k->p.offset, GFP_KERNEL) ?: ret = __ec_stripe_mem_alloc(c, k.k->p.offset, GFP_KERNEL) ?:
bch2_mark_key(trans, k, bch2_mark_key(trans, k,
BTREE_TRIGGER_INSERT|
BTREE_TRIGGER_NOATOMIC); BTREE_TRIGGER_NOATOMIC);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment