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: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-06-26 18:36:24 -04:00
parent 298ac24e63
commit 0fb3355d0a
4 changed files with 13 additions and 11 deletions

View File

@ -1585,7 +1585,7 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
" should be %u",
(bch2_bkey_val_to_text(&buf, c, k), buf.buf),
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);
if (ret)
@ -1913,7 +1913,7 @@ static int gc_btree_gens_key(struct btree_trans *trans,
percpu_up_read(&c->mark_lock);
return 0;
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);
if (ret)
return ret;

View File

@ -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)))
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)
{
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;
if (IS_ERR(mut))
@ -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);
if (ret)
return ERR_PTR(ret);
*k = bkey_i_to_s_c(mut);
return mut;
}
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);
}

View File

@ -49,7 +49,7 @@ static int bch2_dev_usrdata_drop_key(struct btree_trans *trans,
if (!bch2_bkey_has_device_c(k, dev_idx))
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);
if (ret)
return ret;

View File

@ -385,7 +385,7 @@ static int check_snapshot_tree(struct btree_trans *trans,
if (ret)
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);
if (ret)
goto err;
@ -473,7 +473,7 @@ static int snapshot_tree_ptr_repair(struct btree_trans *trans,
return ret;
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) ?:
snapshot_tree_create(trans, root_id,
bch2_snapshot_tree_oldest_subvol(c, root_id),
@ -487,7 +487,7 @@ static int snapshot_tree_ptr_repair(struct btree_trans *trans,
}
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);
if (ret)
goto err;
@ -677,7 +677,7 @@ static int check_subvol(struct btree_trans *trans,
"subvolume %llu is not set as snapshot but is not master subvolume",
k.k->p.offset)) {
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);
if (ret)
return ret;
@ -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)
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);
if (ret)
return ret;