summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-05-15 09:47:40 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2019-06-10 14:08:06 -0400
commit53b0b3a1beb00d9eb2129cfbee545f7ae75f851f (patch)
tree969a8ab40edc049a92190083218354f9f426f7ef
parent1e2d2c109f2def21eff947643ead27c6a761dbd2 (diff)
bcachefs: Delete duplicate code
Also rename for consistency Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/btree_cache.c2
-rw-r--r--fs/bcachefs/btree_iter.c28
-rw-r--r--fs/bcachefs/btree_iter.h6
-rw-r--r--fs/bcachefs/btree_update_interior.c26
-rw-r--r--fs/bcachefs/btree_update_leaf.c14
-rw-r--r--fs/bcachefs/ec.c2
-rw-r--r--fs/bcachefs/fs-io.c6
-rw-r--r--fs/bcachefs/fsck.c6
-rw-r--r--fs/bcachefs/io.c4
9 files changed, 37 insertions, 57 deletions
diff --git a/fs/bcachefs/btree_cache.c b/fs/bcachefs/btree_cache.c
index 170938772e38..dda99a75f549 100644
--- a/fs/bcachefs/btree_cache.c
+++ b/fs/bcachefs/btree_cache.c
@@ -840,7 +840,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)
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c
index fb036c26e79c..a8ff1d2754ef 100644
--- a/fs/bcachefs/btree_iter.c
+++ b/fs/bcachefs/btree_iter.c
@@ -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;
@@ -1884,24 +1884,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;
diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h
index 4dd8b01c597e..b21ca4180caa 100644
--- a/fs/bcachefs/btree_iter.h
+++ b/fs/bcachefs/btree_iter.h
@@ -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
diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c
index 1a0adaeaae46..a5d5d4fbe764 100644
--- a/fs/bcachefs/btree_update_interior.c
+++ b/fs/bcachefs/btree_update_interior.c
@@ -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;
}
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c
index 07580f57985d..d45b8a980096 100644
--- a/fs/bcachefs/btree_update_leaf.c
+++ b/fs/bcachefs/btree_update_leaf.c
@@ -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;
}
diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c
index 72aa11c0e4fb..dabc849d87bb 100644
--- a/fs/bcachefs/ec.c
+++ b/fs/bcachefs/ec.c
@@ -563,7 +563,7 @@ static int ec_stripe_mem_alloc(struct bch_fs *c,
if (!__ec_stripe_mem_alloc(c, idx, GFP_NOWAIT))
return ret;
- bch2_btree_trans_unlock(iter->trans);
+ bch2_trans_unlock(iter->trans);
ret = -EINTR;
if (!__ec_stripe_mem_alloc(c, idx, GFP_KERNEL))
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index 81b0a3fac2dd..601719d551f9 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -323,10 +323,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;
}
@@ -967,7 +967,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) {
diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c
index 61569e4e1c77..2dfa87edb116 100644
--- a/fs/bcachefs/fsck.c
+++ b/fs/bcachefs/fsck.c
@@ -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",
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c
index 5a34463ec349..72babfd4e10d 100644
--- a/fs/bcachefs/io.c
+++ b/fs/bcachefs/io.c
@@ -1326,7 +1326,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);
@@ -1881,7 +1881,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);