Commit aae29082 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: bch2_btree_delete_extent_at()

New helper, for deleting extents.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 7c4ca54a
......@@ -706,7 +706,6 @@ static int bch2_check_discard_freespace_key(struct btree_trans *trans,
struct bch_alloc_v4 a;
u64 genbits;
struct bpos pos;
struct bkey_i *update;
enum bch_data_type state = iter->btree_id == BTREE_ID_need_discard
? BCH_DATA_need_discard
: BCH_DATA_free;
......@@ -756,21 +755,8 @@ static int bch2_check_discard_freespace_key(struct btree_trans *trans,
printbuf_exit(&buf);
return ret;
delete:
if (iter->btree_id == BTREE_ID_freespace) {
/* should probably add a helper for deleting extents */
update = bch2_trans_kmalloc(trans, sizeof(*update));
ret = PTR_ERR_OR_ZERO(update);
if (ret)
goto err;
bkey_init(&update->k);
update->k.p = iter->pos;
bch2_key_resize(&update->k, 1);
ret = bch2_trans_update(trans, iter, update, 0);
} else {
ret = bch2_btree_delete_at(trans, iter, 0);
}
ret = bch2_btree_delete_extent_at(trans, iter,
iter->btree_id == BTREE_ID_freespace ? 1 : 0, 0);
goto out;
}
......
......@@ -51,6 +51,8 @@ enum btree_insert_flags {
#define BCH_HASH_SET_MUST_CREATE (1 << __BCH_HASH_SET_MUST_CREATE)
#define BCH_HASH_SET_MUST_REPLACE (1 << __BCH_HASH_SET_MUST_REPLACE)
int bch2_btree_delete_extent_at(struct btree_trans *, struct btree_iter *,
unsigned, unsigned);
int bch2_btree_delete_at(struct btree_trans *, struct btree_iter *, unsigned);
int __bch2_btree_insert(struct btree_trans *, enum btree_id, struct bkey_i *);
......
......@@ -1697,8 +1697,8 @@ int bch2_btree_insert(struct bch_fs *c, enum btree_id id,
__bch2_btree_insert(&trans, id, k));
}
int bch2_btree_delete_at(struct btree_trans *trans,
struct btree_iter *iter, unsigned update_flags)
int bch2_btree_delete_extent_at(struct btree_trans *trans, struct btree_iter *iter,
unsigned len, unsigned update_flags)
{
struct bkey_i *k;
......@@ -1708,9 +1708,16 @@ int bch2_btree_delete_at(struct btree_trans *trans,
bkey_init(&k->k);
k->k.p = iter->pos;
bch2_key_resize(&k->k, len);
return bch2_trans_update(trans, iter, k, update_flags);
}
int bch2_btree_delete_at(struct btree_trans *trans,
struct btree_iter *iter, unsigned update_flags)
{
return bch2_btree_delete_extent_at(trans, iter, 0, update_flags);
}
int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id,
struct bpos start, struct bpos end,
unsigned update_flags,
......
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