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

bcachefs: Improve inode deletion code

It had some silly redundancies.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent fad7cfed
...@@ -542,12 +542,12 @@ int bch2_inode_create(struct btree_trans *trans, ...@@ -542,12 +542,12 @@ int bch2_inode_create(struct btree_trans *trans,
int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached) int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
{ {
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter = NULL;
struct bkey_i_inode_generation delete; struct bkey_i_inode_generation delete;
struct bpos start = POS(inode_nr, 0); struct bpos start = POS(inode_nr, 0);
struct bpos end = POS(inode_nr + 1, 0); struct bpos end = POS(inode_nr + 1, 0);
struct bch_inode_unpacked inode_u;
struct bkey_s_c k; struct bkey_s_c k;
u64 bi_generation;
int ret; int ret;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
...@@ -571,8 +571,6 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached) ...@@ -571,8 +571,6 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
retry: retry:
bch2_trans_begin(&trans); bch2_trans_begin(&trans);
bi_generation = 0;
if (cached) { if (cached) {
iter = bch2_trans_get_iter(&trans, BTREE_ID_inodes, POS(0, inode_nr), iter = bch2_trans_get_iter(&trans, BTREE_ID_inodes, POS(0, inode_nr),
BTREE_ITER_CACHED|BTREE_ITER_INTENT); BTREE_ITER_CACHED|BTREE_ITER_INTENT);
...@@ -587,41 +585,26 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached) ...@@ -587,41 +585,26 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
if (ret) if (ret)
goto err; goto err;
bch2_fs_inconsistent_on(k.k->type != KEY_TYPE_inode, trans.c, if (k.k->type != KEY_TYPE_inode) {
"inode %llu not found when deleting", bch2_fs_inconsistent(trans.c,
inode_nr); "inode %llu not found when deleting",
inode_nr);
switch (k.k->type) { ret = -EIO;
case KEY_TYPE_inode: { goto err;
struct bch_inode_unpacked inode_u;
if (!bch2_inode_unpack(bkey_s_c_to_inode(k), &inode_u))
bi_generation = inode_u.bi_generation + 1;
break;
}
case KEY_TYPE_inode_generation: {
struct bkey_s_c_inode_generation g =
bkey_s_c_to_inode_generation(k);
bi_generation = le32_to_cpu(g.v->bi_generation);
break;
}
} }
if (!bi_generation) { bch2_inode_unpack(bkey_s_c_to_inode(k), &inode_u);
bkey_init(&delete.k);
delete.k.p.offset = inode_nr; bkey_inode_generation_init(&delete.k_i);
} else { delete.k.p = iter->pos;
bkey_inode_generation_init(&delete.k_i); delete.v.bi_generation = cpu_to_le32(inode_u.bi_generation + 1);
delete.k.p.offset = inode_nr;
delete.v.bi_generation = cpu_to_le32(bi_generation);
}
bch2_trans_update(&trans, iter, &delete.k_i, 0); bch2_trans_update(&trans, iter, &delete.k_i, 0);
ret = bch2_trans_commit(&trans, NULL, NULL, ret = bch2_trans_commit(&trans, NULL, NULL,
BTREE_INSERT_NOFAIL); BTREE_INSERT_NOFAIL);
bch2_trans_iter_put(&trans, iter);
err: err:
bch2_trans_iter_put(&trans, iter);
if (ret == -EINTR) if (ret == -EINTR)
goto retry; goto retry;
......
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