Commit 0fb3355d authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Improve bch2_bkey_make_mut()

bch2_bkey_make_mut() now takes the bkey_s_c by reference and points it
at the new, mutable key.

This helps in some fsck paths that may have multiple repair operations
on the same key.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 298ac24e
...@@ -1585,7 +1585,7 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans, ...@@ -1585,7 +1585,7 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
" should be %u", " should be %u",
(bch2_bkey_val_to_text(&buf, c, k), buf.buf), (bch2_bkey_val_to_text(&buf, c, k), buf.buf),
r->refcount)) { r->refcount)) {
struct bkey_i *new = bch2_bkey_make_mut(trans, iter, k, 0); struct bkey_i *new = bch2_bkey_make_mut(trans, iter, &k, 0);
ret = PTR_ERR_OR_ZERO(new); ret = PTR_ERR_OR_ZERO(new);
if (ret) if (ret)
...@@ -1913,7 +1913,7 @@ static int gc_btree_gens_key(struct btree_trans *trans, ...@@ -1913,7 +1913,7 @@ static int gc_btree_gens_key(struct btree_trans *trans,
percpu_up_read(&c->mark_lock); percpu_up_read(&c->mark_lock);
return 0; return 0;
update: update:
u = bch2_bkey_make_mut(trans, iter, k, 0); u = bch2_bkey_make_mut(trans, iter, &k, 0);
ret = PTR_ERR_OR_ZERO(u); ret = PTR_ERR_OR_ZERO(u);
if (ret) if (ret)
return ret; return ret;
......
...@@ -241,10 +241,10 @@ static inline struct bkey_i *bch2_bkey_make_mut_noupdate(struct btree_trans *tra ...@@ -241,10 +241,10 @@ static inline struct bkey_i *bch2_bkey_make_mut_noupdate(struct btree_trans *tra
KEY_TYPE_##_type, sizeof(struct bkey_i_##_type))) KEY_TYPE_##_type, sizeof(struct bkey_i_##_type)))
static inline struct bkey_i *__bch2_bkey_make_mut(struct btree_trans *trans, struct btree_iter *iter, static inline struct bkey_i *__bch2_bkey_make_mut(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_s_c k, unsigned flags, struct bkey_s_c *k, unsigned flags,
unsigned type, unsigned min_bytes) unsigned type, unsigned min_bytes)
{ {
struct bkey_i *mut = __bch2_bkey_make_mut_noupdate(trans, k, type, min_bytes); struct bkey_i *mut = __bch2_bkey_make_mut_noupdate(trans, *k, type, min_bytes);
int ret; int ret;
if (IS_ERR(mut)) if (IS_ERR(mut))
...@@ -253,11 +253,13 @@ static inline struct bkey_i *__bch2_bkey_make_mut(struct btree_trans *trans, str ...@@ -253,11 +253,13 @@ static inline struct bkey_i *__bch2_bkey_make_mut(struct btree_trans *trans, str
ret = bch2_trans_update(trans, iter, mut, flags); ret = bch2_trans_update(trans, iter, mut, flags);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
*k = bkey_i_to_s_c(mut);
return mut; return mut;
} }
static inline struct bkey_i *bch2_bkey_make_mut(struct btree_trans *trans, struct btree_iter *iter, static inline struct bkey_i *bch2_bkey_make_mut(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_s_c k, unsigned flags) struct bkey_s_c *k, unsigned flags)
{ {
return __bch2_bkey_make_mut(trans, iter, k, flags, 0, 0); return __bch2_bkey_make_mut(trans, iter, k, flags, 0, 0);
} }
......
...@@ -49,7 +49,7 @@ static int bch2_dev_usrdata_drop_key(struct btree_trans *trans, ...@@ -49,7 +49,7 @@ static int bch2_dev_usrdata_drop_key(struct btree_trans *trans,
if (!bch2_bkey_has_device_c(k, dev_idx)) if (!bch2_bkey_has_device_c(k, dev_idx))
return 0; return 0;
n = bch2_bkey_make_mut(trans, iter, k, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE); n = bch2_bkey_make_mut(trans, iter, &k, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);
ret = PTR_ERR_OR_ZERO(n); ret = PTR_ERR_OR_ZERO(n);
if (ret) if (ret)
return ret; return ret;
......
...@@ -385,7 +385,7 @@ static int check_snapshot_tree(struct btree_trans *trans, ...@@ -385,7 +385,7 @@ static int check_snapshot_tree(struct btree_trans *trans,
if (ret) if (ret)
goto err; goto err;
u = bch2_bkey_make_mut_typed(trans, iter, k, 0, snapshot_tree); u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot_tree);
ret = PTR_ERR_OR_ZERO(u); ret = PTR_ERR_OR_ZERO(u);
if (ret) if (ret)
goto err; goto err;
...@@ -473,7 +473,7 @@ static int snapshot_tree_ptr_repair(struct btree_trans *trans, ...@@ -473,7 +473,7 @@ static int snapshot_tree_ptr_repair(struct btree_trans *trans,
return ret; return ret;
if (ret || le32_to_cpu(s_t.root_snapshot) != root_id) { if (ret || le32_to_cpu(s_t.root_snapshot) != root_id) {
u = bch2_bkey_make_mut_typed(trans, &root_iter, root.s_c, 0, snapshot); u = bch2_bkey_make_mut_typed(trans, &root_iter, &root.s_c, 0, snapshot);
ret = PTR_ERR_OR_ZERO(u) ?: ret = PTR_ERR_OR_ZERO(u) ?:
snapshot_tree_create(trans, root_id, snapshot_tree_create(trans, root_id,
bch2_snapshot_tree_oldest_subvol(c, root_id), bch2_snapshot_tree_oldest_subvol(c, root_id),
...@@ -487,7 +487,7 @@ static int snapshot_tree_ptr_repair(struct btree_trans *trans, ...@@ -487,7 +487,7 @@ static int snapshot_tree_ptr_repair(struct btree_trans *trans,
} }
if (s->k->p.snapshot != root_id) { if (s->k->p.snapshot != root_id) {
u = bch2_bkey_make_mut_typed(trans, iter, s->s_c, 0, snapshot); u = bch2_bkey_make_mut_typed(trans, iter, &s->s_c, 0, snapshot);
ret = PTR_ERR_OR_ZERO(u); ret = PTR_ERR_OR_ZERO(u);
if (ret) if (ret)
goto err; goto err;
...@@ -677,7 +677,7 @@ static int check_subvol(struct btree_trans *trans, ...@@ -677,7 +677,7 @@ static int check_subvol(struct btree_trans *trans,
"subvolume %llu is not set as snapshot but is not master subvolume", "subvolume %llu is not set as snapshot but is not master subvolume",
k.k->p.offset)) { k.k->p.offset)) {
struct bkey_i_subvolume *s = struct bkey_i_subvolume *s =
bch2_bkey_make_mut_typed(trans, iter, subvol.s_c, 0, subvolume); bch2_bkey_make_mut_typed(trans, iter, &subvol.s_c, 0, subvolume);
ret = PTR_ERR_OR_ZERO(s); ret = PTR_ERR_OR_ZERO(s);
if (ret) if (ret)
return ret; return ret;
...@@ -1249,7 +1249,7 @@ static int bch2_subvolume_reparent(struct btree_trans *trans, ...@@ -1249,7 +1249,7 @@ static int bch2_subvolume_reparent(struct btree_trans *trans,
le32_to_cpu(bkey_s_c_to_subvolume(k).v->parent) != old_parent) le32_to_cpu(bkey_s_c_to_subvolume(k).v->parent) != old_parent)
return 0; return 0;
s = bch2_bkey_make_mut_typed(trans, iter, k, 0, subvolume); s = bch2_bkey_make_mut_typed(trans, iter, &k, 0, subvolume);
ret = PTR_ERR_OR_ZERO(s); ret = PTR_ERR_OR_ZERO(s);
if (ret) if (ret)
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