bcachefs: Kill __btree_delete_at()
With trans->updates2 gone, we can now drop this helper and use bch2_btree_delete_at() instead. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
8ee529e9c1
commit
b89726ab86
@ -771,34 +771,12 @@ bch2_trans_commit_get_rw_cold(struct btree_trans *trans)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __btree_delete_at(struct btree_trans *trans, enum btree_id btree_id,
|
||||
struct bpos pos, unsigned trigger_flags)
|
||||
{
|
||||
struct btree_iter *iter;
|
||||
struct bkey_i *update;
|
||||
int ret;
|
||||
|
||||
update = bch2_trans_kmalloc(trans, sizeof(struct bkey));
|
||||
if ((ret = PTR_ERR_OR_ZERO(update)))
|
||||
return ret;
|
||||
|
||||
bkey_init(&update->k);
|
||||
update->k.p = pos;
|
||||
|
||||
iter = bch2_trans_get_iter(trans, btree_id, pos,
|
||||
BTREE_ITER_NOT_EXTENTS|
|
||||
BTREE_ITER_INTENT);
|
||||
bch2_trans_update(trans, iter, update, trigger_flags);
|
||||
bch2_trans_iter_put(trans, iter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static noinline int extent_front_merge(struct btree_trans *trans,
|
||||
struct btree_iter *iter,
|
||||
struct bkey_s_c k,
|
||||
struct btree_insert_entry *i)
|
||||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct bpos l_pos = k.k->p;
|
||||
struct bkey_i *update;
|
||||
int ret;
|
||||
|
||||
@ -810,8 +788,13 @@ static noinline int extent_front_merge(struct btree_trans *trans,
|
||||
bkey_reassemble(update, k);
|
||||
|
||||
if (bch2_bkey_merge(c, bkey_i_to_s(update), bkey_i_to_s_c(i->k))) {
|
||||
ret = __btree_delete_at(trans, i->btree_id, l_pos,
|
||||
i->trigger_flags);
|
||||
struct btree_iter *update_iter =
|
||||
bch2_trans_copy_iter(trans, iter);
|
||||
|
||||
ret = bch2_btree_delete_at(trans, update_iter,
|
||||
i->trigger_flags);
|
||||
bch2_trans_iter_put(trans, update_iter);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -841,7 +824,7 @@ static int extent_handle_overwrites(struct btree_trans *trans,
|
||||
|
||||
if (!bkey_cmp(k.k->p, bkey_start_pos(&i->k->k))) {
|
||||
if (bch2_bkey_maybe_mergable(k.k, &i->k->k)) {
|
||||
ret = extent_front_merge(trans, k, i);
|
||||
ret = extent_front_merge(trans, iter, k, i);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
@ -877,8 +860,11 @@ static int extent_handle_overwrites(struct btree_trans *trans,
|
||||
}
|
||||
|
||||
if (bkey_cmp(k.k->p, i->k->k.p) <= 0) {
|
||||
ret = __btree_delete_at(trans, i->btree_id, k.k->p,
|
||||
i->trigger_flags);
|
||||
update_iter = bch2_trans_copy_iter(trans, iter);
|
||||
ret = bch2_btree_delete_at(trans, update_iter,
|
||||
i->trigger_flags);
|
||||
bch2_trans_iter_put(trans, update_iter);
|
||||
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
@ -891,12 +877,7 @@ static int extent_handle_overwrites(struct btree_trans *trans,
|
||||
bkey_reassemble(update, k);
|
||||
bch2_cut_front(i->k->k.p, update);
|
||||
|
||||
update_iter = bch2_trans_get_iter(trans, i->btree_id, update->k.p,
|
||||
BTREE_ITER_NOT_EXTENTS|
|
||||
BTREE_ITER_INTENT);
|
||||
bch2_trans_update(trans, update_iter, update,
|
||||
i->trigger_flags);
|
||||
bch2_trans_iter_put(trans, update_iter);
|
||||
bch2_trans_update(trans, iter, update, i->trigger_flags);
|
||||
goto out;
|
||||
}
|
||||
next:
|
||||
@ -1143,16 +1124,17 @@ int bch2_btree_insert(struct bch_fs *c, enum btree_id id,
|
||||
}
|
||||
|
||||
int bch2_btree_delete_at(struct btree_trans *trans,
|
||||
struct btree_iter *iter, unsigned flags)
|
||||
struct btree_iter *iter, unsigned trigger_flags)
|
||||
{
|
||||
struct bkey_i k;
|
||||
struct bkey_i *k;
|
||||
|
||||
bkey_init(&k.k);
|
||||
k.k.p = iter->pos;
|
||||
k = bch2_trans_kmalloc(trans, sizeof(*k));
|
||||
if (IS_ERR(k))
|
||||
return PTR_ERR(k);
|
||||
|
||||
return bch2_trans_update(trans, iter, &k, 0) ?:
|
||||
bch2_trans_commit(trans, NULL, NULL,
|
||||
BTREE_INSERT_NOFAIL|flags);
|
||||
bkey_init(&k->k);
|
||||
k->k.p = iter->pos;
|
||||
return bch2_trans_update(trans, iter, k, trigger_flags);
|
||||
}
|
||||
|
||||
int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id,
|
||||
|
@ -761,7 +761,7 @@ retry:
|
||||
mode_to_type(w.inode.bi_mode),
|
||||
(bch2_bkey_val_to_text(&PBUF(buf), c,
|
||||
k), buf))) {
|
||||
ret = lockrestart_do(&trans,
|
||||
ret = __bch2_trans_do(&trans, NULL, NULL, 0,
|
||||
bch2_btree_delete_at(&trans, iter, 0));
|
||||
if (ret)
|
||||
goto err;
|
||||
|
@ -54,14 +54,16 @@ static int test_delete(struct bch_fs *c, u64 nr)
|
||||
}
|
||||
|
||||
pr_info("deleting once");
|
||||
ret = bch2_btree_delete_at(&trans, iter, 0);
|
||||
ret = __bch2_trans_do(&trans, NULL, NULL, 0,
|
||||
bch2_btree_delete_at(&trans, iter, 0));
|
||||
if (ret) {
|
||||
bch_err(c, "delete error (first) in test_delete: %i", ret);
|
||||
goto err;
|
||||
}
|
||||
|
||||
pr_info("deleting twice");
|
||||
ret = bch2_btree_delete_at(&trans, iter, 0);
|
||||
ret = __bch2_trans_do(&trans, NULL, NULL, 0,
|
||||
bch2_btree_delete_at(&trans, iter, 0));
|
||||
if (ret) {
|
||||
bch_err(c, "delete error (second) in test_delete: %i", ret);
|
||||
goto err;
|
||||
@ -101,7 +103,8 @@ static int test_delete_written(struct bch_fs *c, u64 nr)
|
||||
|
||||
bch2_journal_flush_all_pins(&c->journal);
|
||||
|
||||
ret = bch2_btree_delete_at(&trans, iter, 0);
|
||||
ret = __bch2_trans_do(&trans, NULL, NULL, 0,
|
||||
bch2_btree_delete_at(&trans, iter, 0));
|
||||
if (ret) {
|
||||
bch_err(c, "delete error in test_delete_written: %i", ret);
|
||||
goto err;
|
||||
|
Loading…
Reference in New Issue
Block a user