bcachefs: Delete duplicate code
Also rename for consistency Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
6fb076e60d
commit
58fbf80834
@ -841,7 +841,7 @@ struct btree *bch2_btree_node_get_sibling(struct bch_fs *c,
|
||||
}
|
||||
}
|
||||
|
||||
bch2_btree_trans_relock(trans);
|
||||
bch2_trans_relock(trans);
|
||||
}
|
||||
out:
|
||||
if (btree_lock_want(iter, level + 1) == BTREE_NODE_UNLOCKED)
|
||||
|
@ -408,7 +408,9 @@ void __bch2_btree_iter_downgrade(struct btree_iter *iter,
|
||||
bch2_btree_trans_verify_locks(iter->trans);
|
||||
}
|
||||
|
||||
bool bch2_btree_trans_relock(struct btree_trans *trans)
|
||||
/* Btree transaction locking: */
|
||||
|
||||
bool bch2_trans_relock(struct btree_trans *trans)
|
||||
{
|
||||
struct btree_iter *iter;
|
||||
bool ret = true;
|
||||
@ -419,7 +421,7 @@ bool bch2_btree_trans_relock(struct btree_trans *trans)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bch2_btree_trans_unlock(struct btree_trans *trans)
|
||||
void bch2_trans_unlock(struct btree_trans *trans)
|
||||
{
|
||||
struct btree_iter *iter;
|
||||
|
||||
@ -427,8 +429,6 @@ void bch2_btree_trans_unlock(struct btree_trans *trans)
|
||||
__bch2_btree_iter_unlock(iter);
|
||||
}
|
||||
|
||||
/* Btree transaction locking: */
|
||||
|
||||
/* Btree iterator: */
|
||||
|
||||
#ifdef CONFIG_BCACHEFS_DEBUG
|
||||
@ -982,7 +982,7 @@ static int __btree_iter_traverse_all(struct btree_trans *trans,
|
||||
#undef btree_iter_cmp_by_idx
|
||||
|
||||
retry_all:
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
if (unlikely(ret == -ENOMEM)) {
|
||||
struct closure cl;
|
||||
@ -1885,24 +1885,6 @@ void *bch2_trans_kmalloc(struct btree_trans *trans,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bch2_trans_unlock(struct btree_trans *trans)
|
||||
{
|
||||
u64 iters = trans->iters_linked;
|
||||
int ret = 0;
|
||||
|
||||
while (iters) {
|
||||
unsigned idx = __ffs64(iters);
|
||||
struct btree_iter *iter = &trans->iters[idx];
|
||||
|
||||
ret = ret ?: btree_iter_err(iter);
|
||||
|
||||
__bch2_btree_iter_unlock(iter);
|
||||
iters ^= 1ULL << idx;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline void bch2_trans_unlink_iters(struct btree_trans *trans, u64 iters)
|
||||
{
|
||||
iters &= trans->iters_linked;
|
||||
|
@ -103,8 +103,8 @@ void bch2_btree_node_iter_fix(struct btree_iter *, struct btree *,
|
||||
struct btree_node_iter *, struct bkey_packed *,
|
||||
unsigned, unsigned);
|
||||
|
||||
bool bch2_btree_trans_relock(struct btree_trans *);
|
||||
void bch2_btree_trans_unlock(struct btree_trans *);
|
||||
bool bch2_trans_relock(struct btree_trans *);
|
||||
void bch2_trans_unlock(struct btree_trans *);
|
||||
|
||||
bool __bch2_btree_iter_upgrade(struct btree_iter *, unsigned);
|
||||
bool __bch2_btree_iter_upgrade_nounlock(struct btree_iter *, unsigned);
|
||||
@ -191,8 +191,6 @@ static inline int btree_iter_cmp(const struct btree_iter *l,
|
||||
return __btree_iter_cmp(l->btree_id, l->pos, r);
|
||||
}
|
||||
|
||||
int bch2_trans_unlock(struct btree_trans *);
|
||||
|
||||
/*
|
||||
* Unlocks before scheduling
|
||||
* Note: does not revalidate iterator
|
||||
|
@ -1574,10 +1574,10 @@ int bch2_btree_split_leaf(struct bch_fs *c, struct btree_iter *iter,
|
||||
if (flags & BTREE_INSERT_NOUNLOCK)
|
||||
return -EINTR;
|
||||
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
down_read(&c->gc_lock);
|
||||
|
||||
if (!bch2_btree_trans_relock(trans))
|
||||
if (!bch2_trans_relock(trans))
|
||||
ret = -EINTR;
|
||||
}
|
||||
|
||||
@ -1598,7 +1598,7 @@ int bch2_btree_split_leaf(struct bch_fs *c, struct btree_iter *iter,
|
||||
ret = PTR_ERR(as);
|
||||
if (ret == -EAGAIN) {
|
||||
BUG_ON(flags & BTREE_INSERT_NOUNLOCK);
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
ret = -EINTR;
|
||||
}
|
||||
goto out;
|
||||
@ -1778,7 +1778,7 @@ err_cycle_gc_lock:
|
||||
if (flags & BTREE_INSERT_NOUNLOCK)
|
||||
goto out;
|
||||
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
down_read(&c->gc_lock);
|
||||
up_read(&c->gc_lock);
|
||||
@ -1794,7 +1794,7 @@ err:
|
||||
|
||||
if ((ret == -EAGAIN || ret == -EINTR) &&
|
||||
!(flags & BTREE_INSERT_NOUNLOCK)) {
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
closure_sync(&cl);
|
||||
ret = bch2_btree_iter_traverse(iter);
|
||||
if (ret)
|
||||
@ -1874,7 +1874,7 @@ int bch2_btree_node_rewrite(struct bch_fs *c, struct btree_iter *iter,
|
||||
|
||||
if (!(flags & BTREE_INSERT_GC_LOCK_HELD)) {
|
||||
if (!down_read_trylock(&c->gc_lock)) {
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
down_read(&c->gc_lock);
|
||||
}
|
||||
}
|
||||
@ -1893,7 +1893,7 @@ int bch2_btree_node_rewrite(struct bch_fs *c, struct btree_iter *iter,
|
||||
ret != -EINTR)
|
||||
break;
|
||||
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
closure_sync(&cl);
|
||||
}
|
||||
|
||||
@ -2046,10 +2046,10 @@ int bch2_btree_node_update_key(struct bch_fs *c, struct btree_iter *iter,
|
||||
return -EINTR;
|
||||
|
||||
if (!down_read_trylock(&c->gc_lock)) {
|
||||
bch2_btree_trans_unlock(iter->trans);
|
||||
bch2_trans_unlock(iter->trans);
|
||||
down_read(&c->gc_lock);
|
||||
|
||||
if (!bch2_btree_trans_relock(iter->trans)) {
|
||||
if (!bch2_trans_relock(iter->trans)) {
|
||||
ret = -EINTR;
|
||||
goto err;
|
||||
}
|
||||
@ -2060,12 +2060,12 @@ int bch2_btree_node_update_key(struct bch_fs *c, struct btree_iter *iter,
|
||||
/* bch2_btree_reserve_get will unlock */
|
||||
ret = bch2_btree_cache_cannibalize_lock(c, &cl);
|
||||
if (ret) {
|
||||
bch2_btree_trans_unlock(iter->trans);
|
||||
bch2_trans_unlock(iter->trans);
|
||||
up_read(&c->gc_lock);
|
||||
closure_sync(&cl);
|
||||
down_read(&c->gc_lock);
|
||||
|
||||
if (!bch2_btree_trans_relock(iter->trans)) {
|
||||
if (!bch2_trans_relock(iter->trans)) {
|
||||
ret = -EINTR;
|
||||
goto err;
|
||||
}
|
||||
@ -2089,12 +2089,12 @@ int bch2_btree_node_update_key(struct bch_fs *c, struct btree_iter *iter,
|
||||
if (ret != -EINTR)
|
||||
goto err;
|
||||
|
||||
bch2_btree_trans_unlock(iter->trans);
|
||||
bch2_trans_unlock(iter->trans);
|
||||
up_read(&c->gc_lock);
|
||||
closure_sync(&cl);
|
||||
down_read(&c->gc_lock);
|
||||
|
||||
if (!bch2_btree_trans_relock(iter->trans))
|
||||
if (!bch2_trans_relock(iter->trans))
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -431,14 +431,14 @@ static int bch2_trans_journal_preres_get(struct btree_trans *trans)
|
||||
if (ret != -EAGAIN)
|
||||
return ret;
|
||||
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
ret = bch2_journal_preres_get(&c->journal,
|
||||
&trans->journal_preres, u64s, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!bch2_btree_trans_relock(trans)) {
|
||||
if (!bch2_trans_relock(trans)) {
|
||||
trans_restart(" (iter relock after journal preres get blocked)");
|
||||
trace_trans_restart_journal_preres_get(c, trans->ip);
|
||||
return -EINTR;
|
||||
@ -736,7 +736,7 @@ int bch2_trans_commit_error(struct btree_trans *trans,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (bch2_btree_trans_relock(trans))
|
||||
if (bch2_trans_relock(trans))
|
||||
return 0;
|
||||
|
||||
trans_restart(" (iter relock after marking replicas)");
|
||||
@ -744,13 +744,13 @@ int bch2_trans_commit_error(struct btree_trans *trans,
|
||||
ret = -EINTR;
|
||||
break;
|
||||
case BTREE_INSERT_NEED_JOURNAL_RES:
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
ret = bch2_trans_journal_res_get(trans, JOURNAL_RES_GET_CHECK);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (bch2_btree_trans_relock(trans))
|
||||
if (bch2_trans_relock(trans))
|
||||
return 0;
|
||||
|
||||
trans_restart(" (iter relock after journal res get blocked)");
|
||||
@ -878,7 +878,7 @@ int bch2_trans_commit(struct btree_trans *trans,
|
||||
if (likely(!(trans->flags & BTREE_INSERT_LAZY_RW)))
|
||||
return -EROFS;
|
||||
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
ret = bch2_fs_read_write_early(c);
|
||||
if (ret)
|
||||
@ -886,7 +886,7 @@ int bch2_trans_commit(struct btree_trans *trans,
|
||||
|
||||
percpu_ref_get(&c->writes);
|
||||
|
||||
if (!bch2_btree_trans_relock(trans)) {
|
||||
if (!bch2_trans_relock(trans)) {
|
||||
ret = -EINTR;
|
||||
goto err;
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ static int ec_stripe_mem_alloc(struct bch_fs *c,
|
||||
if (!__ec_stripe_mem_alloc(c, idx, GFP_NOWAIT|__GFP_NOWARN))
|
||||
return ret;
|
||||
|
||||
bch2_btree_trans_unlock(iter->trans);
|
||||
bch2_trans_unlock(iter->trans);
|
||||
ret = -EINTR;
|
||||
|
||||
if (!__ec_stripe_mem_alloc(c, idx, GFP_KERNEL))
|
||||
|
@ -322,10 +322,10 @@ static int bch2_extent_update(struct btree_trans *trans,
|
||||
if (i_sectors_delta ||
|
||||
new_i_size > inode->ei_inode.bi_size) {
|
||||
if (c->opts.new_inode_updates) {
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
mutex_lock(&inode->ei_update_lock);
|
||||
|
||||
if (!bch2_btree_trans_relock(trans)) {
|
||||
if (!bch2_trans_relock(trans)) {
|
||||
mutex_unlock(&inode->ei_update_lock);
|
||||
return -EINTR;
|
||||
}
|
||||
@ -949,7 +949,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
|
||||
}
|
||||
|
||||
bkey_reassemble(&tmp.k, k);
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
k = bkey_i_to_s_c(&tmp.k);
|
||||
|
||||
if (readpages_iter) {
|
||||
|
@ -58,7 +58,7 @@ static int remove_dirent(struct btree_trans *trans,
|
||||
name.name = buf;
|
||||
|
||||
/* Unlock so we don't deadlock, after copying name: */
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
ret = bch2_inode_find_by_inum(c, dir_inum, &dir_inode);
|
||||
if (ret) {
|
||||
@ -1015,7 +1015,7 @@ retry:
|
||||
if (fsck_err_on(!inode_bitmap_test(&dirs_done, k.k->p.inode), c,
|
||||
"unreachable directory found (inum %llu)",
|
||||
k.k->p.inode)) {
|
||||
bch2_btree_trans_unlock(&trans);
|
||||
bch2_trans_unlock(&trans);
|
||||
|
||||
ret = reattach_inode(c, lostfound_inode, k.k->p.inode);
|
||||
if (ret) {
|
||||
@ -1229,7 +1229,7 @@ static int check_inode(struct btree_trans *trans,
|
||||
|
||||
ret = bch2_inode_unpack(inode, &u);
|
||||
|
||||
bch2_btree_trans_unlock(trans);
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
if (bch2_fs_inconsistent_on(ret, c,
|
||||
"error unpacking inode %llu in fsck",
|
||||
|
@ -1332,7 +1332,7 @@ retry:
|
||||
|
||||
bkey_reassemble(&tmp.k, k);
|
||||
k = bkey_i_to_s_c(&tmp.k);
|
||||
bch2_btree_trans_unlock(&trans);
|
||||
bch2_trans_unlock(&trans);
|
||||
|
||||
bytes = min_t(unsigned, bvec_iter.bi_size,
|
||||
(k.k->p.offset - bvec_iter.bi_sector) << 9);
|
||||
@ -1889,7 +1889,7 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode)
|
||||
*/
|
||||
bkey_reassemble(&tmp.k, k);
|
||||
k = bkey_i_to_s_c(&tmp.k);
|
||||
bch2_btree_trans_unlock(&trans);
|
||||
bch2_trans_unlock(&trans);
|
||||
|
||||
bytes = min_t(unsigned, rbio->bio.bi_iter.bi_size,
|
||||
(k.k->p.offset - rbio->bio.bi_iter.bi_sector) << 9);
|
||||
|
Loading…
x
Reference in New Issue
Block a user