Commit 087c2019 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: bch2_btree_delete_range_trans()

This helps reduce stack usage by avoiding multiple btree_trans on the
stack.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 6584e84a
......@@ -67,8 +67,8 @@ int __bch2_btree_insert(struct btree_trans *, enum btree_id, struct bkey_i *);
int bch2_btree_insert(struct bch_fs *, enum btree_id, struct bkey_i *,
struct disk_reservation *, u64 *, int flags);
int bch2_btree_delete_at_range(struct btree_trans *, struct btree_iter *,
struct bpos, u64 *);
int bch2_btree_delete_range_trans(struct btree_trans *, enum btree_id,
struct bpos, struct bpos, u64 *);
int bch2_btree_delete_range(struct bch_fs *, enum btree_id,
struct bpos, struct bpos, u64 *);
......
......@@ -1094,13 +1094,32 @@ int bch2_btree_insert(struct bch_fs *c, enum btree_id id,
__bch2_btree_insert(&trans, id, k));
}
int bch2_btree_delete_at_range(struct btree_trans *trans,
struct btree_iter *iter,
struct bpos end,
u64 *journal_seq)
int bch2_btree_delete_at(struct btree_trans *trans,
struct btree_iter *iter, unsigned flags)
{
struct bkey_i k;
bkey_init(&k.k);
k.k.p = iter->pos;
bch2_trans_update(trans, iter, &k, 0);
return bch2_trans_commit(trans, NULL, NULL,
BTREE_INSERT_NOFAIL|
BTREE_INSERT_USE_RESERVE|flags);
}
int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id,
struct bpos start, struct bpos end,
u64 *journal_seq)
{
struct btree_iter *iter;
struct bkey_s_c k;
int ret = 0;
iter = bch2_trans_get_iter(trans, id, start, BTREE_ITER_INTENT);
ret = PTR_ERR_OR_ZERO(iter);
if (ret)
return ret;
retry:
while ((k = bch2_btree_iter_peek(iter)).k &&
!(ret = bkey_err(k)) &&
......@@ -1111,6 +1130,10 @@ int bch2_btree_delete_at_range(struct btree_trans *trans,
bkey_init(&delete.k);
/*
* This could probably be more efficient for extents:
*/
/*
* For extents, iter.pos won't necessarily be the same as
* bkey_start_pos(k.k) (for non extents they always will be the
......@@ -1150,22 +1173,8 @@ int bch2_btree_delete_at_range(struct btree_trans *trans,
goto retry;
}
bch2_trans_iter_put(trans, iter);
return ret;
}
int bch2_btree_delete_at(struct btree_trans *trans,
struct btree_iter *iter, unsigned flags)
{
struct bkey_i k;
bkey_init(&k.k);
k.k.p = iter->pos;
bch2_trans_update(trans, iter, &k, 0);
return bch2_trans_commit(trans, NULL, NULL,
BTREE_INSERT_NOFAIL|
BTREE_INSERT_USE_RESERVE|flags);
}
/*
......@@ -1177,21 +1186,6 @@ int bch2_btree_delete_range(struct bch_fs *c, enum btree_id id,
struct bpos start, struct bpos end,
u64 *journal_seq)
{
struct btree_trans trans;
struct btree_iter *iter;
int ret = 0;
/*
* XXX: whether we need mem/more iters depends on whether this btree id
* has triggers
*/
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 512);
iter = bch2_trans_get_iter(&trans, id, start, BTREE_ITER_INTENT);
ret = bch2_btree_delete_at_range(&trans, iter, end, journal_seq);
ret = bch2_trans_exit(&trans) ?: ret;
BUG_ON(ret == -EINTR);
return ret;
return bch2_trans_do(c, NULL, journal_seq, 0,
bch2_btree_delete_range_trans(&trans, id, start, end, journal_seq));
}
......@@ -553,6 +553,8 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
u64 bi_generation;
int ret;
bch2_trans_init(&trans, c, 0, 0);
/*
* If this was a directory, there shouldn't be any real dirents left -
* but there could be whiteouts (from hash collisions) that we should
......@@ -561,16 +563,14 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
* XXX: the dirent could ideally would delete whiteouts when they're no
* longer needed
*/
ret = bch2_btree_delete_range(c, BTREE_ID_EXTENTS,
start, end, NULL) ?:
bch2_btree_delete_range(c, BTREE_ID_XATTRS,
start, end, NULL) ?:
bch2_btree_delete_range(c, BTREE_ID_DIRENTS,
start, end, NULL);
ret = bch2_btree_delete_range_trans(&trans, BTREE_ID_EXTENTS,
start, end, NULL) ?:
bch2_btree_delete_range_trans(&trans, BTREE_ID_XATTRS,
start, end, NULL) ?:
bch2_btree_delete_range_trans(&trans, BTREE_ID_DIRENTS,
start, end, NULL);
if (ret)
return ret;
bch2_trans_init(&trans, c, 0, 0);
goto err;
retry:
bch2_trans_begin(&trans);
......@@ -590,7 +590,7 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
if (ret)
goto err;
bch2_fs_inconsistent_on(k.k->type != KEY_TYPE_inode, c,
bch2_fs_inconsistent_on(k.k->type != KEY_TYPE_inode, trans.c,
"inode %llu not found when deleting",
inode_nr);
......
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