summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-12-10 17:04:26 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:25 -0400
commitae94c78fb1d5acc8315b7d17583ddb92df29bd3a (patch)
tree82ac0648987acfa9c228ae1421460b11a293df8a
parent82697a10dd4b9a6f7c6f98a525778d032db2f2fb (diff)
downloadlinux-stable-ae94c78fb1d5acc8315b7d17583ddb92df29bd3a.tar.gz
linux-stable-ae94c78fb1d5acc8315b7d17583ddb92df29bd3a.tar.bz2
linux-stable-ae94c78fb1d5acc8315b7d17583ddb92df29bd3a.zip
bcachefs: bch2_trans_mark_key() now takes a bkey_i *
We're now coming up with triggers that modify the update being done. A bkey_s_c is const - bkey_i is the correct type to be using here. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/btree_update_interior.c20
-rw-r--r--fs/bcachefs/btree_update_leaf.c11
-rw-r--r--fs/bcachefs/buckets.c72
-rw-r--r--fs/bcachefs/buckets.h27
4 files changed, 71 insertions, 59 deletions
diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c
index 644ac4e5d1d1..255753b2dc0e 100644
--- a/fs/bcachefs/btree_update_interior.c
+++ b/fs/bcachefs/btree_update_interior.c
@@ -510,19 +510,13 @@ static int btree_update_nodes_written_trans(struct btree_trans *trans,
trans->journal_pin = &as->journal;
for_each_keylist_key(&as->new_keys, k) {
- ret = bch2_trans_mark_key(trans,
- bkey_s_c_null,
- bkey_i_to_s_c(k),
- BTREE_TRIGGER_INSERT);
+ ret = bch2_trans_mark_new(trans, k, 0);
if (ret)
return ret;
}
for_each_keylist_key(&as->old_keys, k) {
- ret = bch2_trans_mark_key(trans,
- bkey_i_to_s_c(k),
- bkey_s_c_null,
- BTREE_TRIGGER_OVERWRITE);
+ ret = bch2_trans_mark_old(trans, bkey_i_to_s_c(k), 0);
if (ret)
return ret;
}
@@ -1891,17 +1885,11 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans,
int ret;
if (!skip_triggers) {
- ret = bch2_trans_mark_key(trans,
- bkey_s_c_null,
- bkey_i_to_s_c(new_key),
- BTREE_TRIGGER_INSERT);
+ ret = bch2_trans_mark_new(trans, new_key, 0);
if (ret)
return ret;
- ret = bch2_trans_mark_key(trans,
- bkey_i_to_s_c(&b->key),
- bkey_s_c_null,
- BTREE_TRIGGER_OVERWRITE);
+ ret = bch2_trans_mark_old(trans, bkey_i_to_s_c(&b->key), 0);
if (ret)
return ret;
}
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c
index fcc56235ae90..5ed0b0296ad4 100644
--- a/fs/bcachefs/btree_update_leaf.c
+++ b/fs/bcachefs/btree_update_leaf.c
@@ -860,8 +860,6 @@ bch2_trans_commit_get_rw_cold(struct btree_trans *trans)
static int run_one_trigger(struct btree_trans *trans, struct btree_insert_entry *i,
bool overwrite)
{
- struct bkey _deleted = KEY(0, 0, 0);
- struct bkey_s_c deleted = (struct bkey_s_c) { &_deleted, NULL };
struct bkey_s_c old;
struct bkey unpacked;
int ret = 0;
@@ -885,19 +883,16 @@ static int run_one_trigger(struct btree_trans *trans, struct btree_insert_entry
}
old = bch2_btree_path_peek_slot(i->path, &unpacked);
- _deleted.p = i->path->pos;
if (overwrite) {
- ret = bch2_trans_mark_key(trans, old, deleted,
- BTREE_TRIGGER_OVERWRITE|i->flags);
+ ret = bch2_trans_mark_old(trans, old, i->flags);
} else if (old.k->type == i->k->k.type &&
((1U << old.k->type) & BTREE_TRIGGER_WANTS_OLD_AND_NEW)) {
i->overwrite_trigger_run = true;
- ret = bch2_trans_mark_key(trans, old, bkey_i_to_s_c(i->k),
+ ret = bch2_trans_mark_key(trans, old, i->k,
BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|i->flags);
} else {
- ret = bch2_trans_mark_key(trans, deleted, bkey_i_to_s_c(i->k),
- BTREE_TRIGGER_INSERT|i->flags);
+ ret = bch2_trans_mark_new(trans, i->k, i->flags);
}
if (ret == -EINTR)
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index f4403011f626..ed1632c75e56 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -1662,65 +1662,67 @@ err:
}
static int bch2_trans_mark_stripe(struct btree_trans *trans,
- struct bkey_s_c old, struct bkey_s_c new,
+ struct bkey_s_c old, struct bkey_i *new,
unsigned flags)
{
- struct bkey_s_c_stripe old_s = { .k = NULL };
- struct bkey_s_c_stripe new_s = { .k = NULL };
+ const struct bch_stripe *old_s = NULL;
+ struct bch_stripe *new_s = NULL;
struct bch_replicas_padded r;
unsigned i, nr_blocks;
int ret = 0;
if (old.k->type == KEY_TYPE_stripe)
- old_s = bkey_s_c_to_stripe(old);
- if (new.k->type == KEY_TYPE_stripe)
- new_s = bkey_s_c_to_stripe(new);
+ old_s = bkey_s_c_to_stripe(old).v;
+ if (new->k.type == KEY_TYPE_stripe)
+ new_s = &bkey_i_to_stripe(new)->v;
/*
* If the pointers aren't changing, we don't need to do anything:
*/
- if (new_s.k && old_s.k &&
- new_s.v->nr_blocks == old_s.v->nr_blocks &&
- new_s.v->nr_redundant == old_s.v->nr_redundant &&
- !memcmp(old_s.v->ptrs, new_s.v->ptrs,
- new_s.v->nr_blocks * sizeof(struct bch_extent_ptr)))
+ if (new_s && old_s &&
+ new_s->nr_blocks == old_s->nr_blocks &&
+ new_s->nr_redundant == old_s->nr_redundant &&
+ !memcmp(old_s->ptrs, new_s->ptrs,
+ new_s->nr_blocks * sizeof(struct bch_extent_ptr)))
return 0;
- BUG_ON(new_s.k && old_s.k &&
- (new_s.v->nr_blocks != old_s.v->nr_blocks ||
- new_s.v->nr_redundant != old_s.v->nr_redundant));
+ BUG_ON(new_s && old_s &&
+ (new_s->nr_blocks != old_s->nr_blocks ||
+ new_s->nr_redundant != old_s->nr_redundant));
- nr_blocks = new_s.k ? new_s.v->nr_blocks : old_s.v->nr_blocks;
+ nr_blocks = new_s ? new_s->nr_blocks : old_s->nr_blocks;
- if (new_s.k) {
- s64 sectors = le16_to_cpu(new_s.v->sectors);
+ if (new_s) {
+ s64 sectors = le16_to_cpu(new_s->sectors);
- bch2_bkey_to_replicas(&r.e, new);
- update_replicas_list(trans, &r.e, sectors * new_s.v->nr_redundant);
+ bch2_bkey_to_replicas(&r.e, bkey_i_to_s_c(new));
+ update_replicas_list(trans, &r.e, sectors * new_s->nr_redundant);
}
- if (old_s.k) {
- s64 sectors = -((s64) le16_to_cpu(old_s.v->sectors));
+ if (old_s) {
+ s64 sectors = -((s64) le16_to_cpu(old_s->sectors));
bch2_bkey_to_replicas(&r.e, old);
- update_replicas_list(trans, &r.e, sectors * old_s.v->nr_redundant);
+ update_replicas_list(trans, &r.e, sectors * old_s->nr_redundant);
}
for (i = 0; i < nr_blocks; i++) {
- if (new_s.k && old_s.k &&
- !memcmp(&new_s.v->ptrs[i],
- &old_s.v->ptrs[i],
- sizeof(new_s.v->ptrs[i])))
+ if (new_s && old_s &&
+ !memcmp(&new_s->ptrs[i],
+ &old_s->ptrs[i],
+ sizeof(new_s->ptrs[i])))
continue;
- if (new_s.k) {
- ret = bch2_trans_mark_stripe_bucket(trans, new_s, i, false);
+ if (new_s) {
+ ret = bch2_trans_mark_stripe_bucket(trans,
+ bkey_i_to_s_c_stripe(new), i, false);
if (ret)
break;
}
- if (old_s.k) {
- ret = bch2_trans_mark_stripe_bucket(trans, old_s, i, true);
+ if (old_s) {
+ ret = bch2_trans_mark_stripe_bucket(trans,
+ bkey_s_c_to_stripe(old), i, true);
if (ret)
break;
}
@@ -1731,10 +1733,10 @@ static int bch2_trans_mark_stripe(struct btree_trans *trans,
static int bch2_trans_mark_inode(struct btree_trans *trans,
struct bkey_s_c old,
- struct bkey_s_c new,
+ struct bkey_i *new,
unsigned flags)
{
- int nr = bkey_is_inode(new.k) - bkey_is_inode(old.k);
+ int nr = bkey_is_inode(&new->k) - bkey_is_inode(old.k);
if (nr) {
struct replicas_delta_list *d =
@@ -1869,9 +1871,11 @@ 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_i *new, unsigned flags)
{
- struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
+ struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE
+ ? old
+ : bkey_i_to_s_c(new);
switch (k.k->type) {
case KEY_TYPE_btree_ptr:
diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h
index 8a3cea6f94df..a04d15154304 100644
--- a/fs/bcachefs/buckets.h
+++ b/fs/bcachefs/buckets.h
@@ -235,7 +235,32 @@ int bch2_mark_update(struct btree_trans *, struct btree_path *,
struct bkey_i *, unsigned);
int bch2_trans_mark_key(struct btree_trans *, struct bkey_s_c,
- struct bkey_s_c, unsigned);
+ struct bkey_i *, unsigned);
+
+static inline int bch2_trans_mark_old(struct btree_trans *trans,
+ struct bkey_s_c old, unsigned flags)
+{
+ struct bkey_i deleted;
+
+ bkey_init(&deleted.k);
+ deleted.k.p = old.k->p;
+
+ return bch2_trans_mark_key(trans, old, &deleted,
+ BTREE_TRIGGER_OVERWRITE|flags);
+}
+
+static inline int bch2_trans_mark_new(struct btree_trans *trans,
+ struct bkey_i *new, unsigned flags)
+{
+ struct bkey_i deleted;
+
+ bkey_init(&deleted.k);
+ deleted.k.p = new->k.p;
+
+ return bch2_trans_mark_key(trans, bkey_i_to_s_c(&deleted), new,
+ BTREE_TRIGGER_INSERT|flags);
+}
+
int bch2_trans_fs_usage_apply(struct btree_trans *, struct replicas_delta_list *);
int bch2_trans_mark_metadata_bucket(struct btree_trans *, struct bch_dev *,