summaryrefslogtreecommitdiff
path: root/fs/bcachefs/btree_update_leaf.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-03-27 22:03:30 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:18 -0400
commit0f2383677172176691bbc760c5af4d87f67f78fc (patch)
tree880ad6e20a36b1d6408a80e9995b5f3fed269138 /fs/bcachefs/btree_update_leaf.c
parent7c26ecae326aee84bb53cfb163108a20fb3094d1 (diff)
downloadlwn-0f2383677172176691bbc760c5af4d87f67f78fc.tar.gz
lwn-0f2383677172176691bbc760c5af4d87f67f78fc.zip
bcachefs: trans_for_each_iter()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/btree_update_leaf.c')
-rw-r--r--fs/bcachefs/btree_update_leaf.c64
1 files changed, 17 insertions, 47 deletions
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c
index 45838db7b991..8b043d3c19ad 100644
--- a/fs/bcachefs/btree_update_leaf.c
+++ b/fs/bcachefs/btree_update_leaf.c
@@ -51,25 +51,6 @@ static void btree_trans_unlock_write(struct btree_trans *trans)
bch2_btree_node_unlock_write(i->iter->l[0].b, i->iter);
}
-static bool btree_trans_relock(struct btree_trans *trans)
-{
- struct btree_insert_entry *i;
-
- trans_for_each_update_iter(trans, i)
- return bch2_btree_iter_relock(i->iter);
- return true;
-}
-
-static void btree_trans_unlock(struct btree_trans *trans)
-{
- struct btree_insert_entry *i;
-
- trans_for_each_update_iter(trans, i) {
- bch2_btree_iter_unlock(i->iter);
- break;
- }
-}
-
static inline int btree_trans_cmp(struct btree_insert_entry l,
struct btree_insert_entry r)
{
@@ -422,8 +403,6 @@ static inline void btree_insert_entry_checks(struct btree_trans *trans,
EBUG_ON((i->iter->flags & BTREE_ITER_IS_EXTENTS) &&
!(trans->flags & BTREE_INSERT_ATOMIC));
-
- bch2_btree_iter_verify_locks(i->iter);
}
BUG_ON(debug_check_bkeys(c) &&
@@ -451,14 +430,14 @@ static int bch2_trans_journal_preres_get(struct btree_trans *trans)
if (ret != -EAGAIN)
return ret;
- btree_trans_unlock(trans);
+ bch2_btree_trans_unlock(trans);
ret = bch2_journal_preres_get(&c->journal,
&trans->journal_preres, u64s, 0);
if (ret)
return ret;
- if (!btree_trans_relock(trans)) {
+ if (!bch2_btree_trans_relock(trans)) {
trans_restart(" (iter relock after journal preres get blocked)");
return -EINTR;
}
@@ -617,12 +596,9 @@ static inline int do_btree_insert_at(struct btree_trans *trans,
* have been traversed/locked, depending on what the caller was
* doing:
*/
- trans_for_each_update_iter(trans, i) {
- for_each_btree_iter(i->iter, linked)
- if (linked->uptodate < BTREE_ITER_NEED_RELOCK)
- linked->flags |= BTREE_ITER_NOUNLOCK;
- break;
- }
+ trans_for_each_iter(trans, linked)
+ if (linked->uptodate < BTREE_ITER_NEED_RELOCK)
+ linked->flags |= BTREE_ITER_NOUNLOCK;
}
trans_for_each_update_iter(trans, i)
@@ -707,20 +683,20 @@ int bch2_trans_commit_error(struct btree_trans *trans,
return ret;
}
- if (btree_trans_relock(trans))
+ if (bch2_btree_trans_relock(trans))
return 0;
trans_restart(" (iter relock after marking replicas)");
ret = -EINTR;
break;
case BTREE_INSERT_NEED_JOURNAL_RES:
- btree_trans_unlock(trans);
+ bch2_btree_trans_unlock(trans);
ret = bch2_trans_journal_res_get(trans, JOURNAL_RES_GET_CHECK);
if (ret)
return ret;
- if (btree_trans_relock(trans))
+ if (bch2_btree_trans_relock(trans))
return 0;
trans_restart(" (iter relock after journal res get blocked)");
@@ -785,10 +761,9 @@ static int __bch2_trans_commit(struct btree_trans *trans,
goto err;
}
- if (i->iter->flags & BTREE_ITER_ERROR) {
- ret = -EIO;
+ ret = btree_iter_err(i->iter);
+ if (ret)
goto err;
- }
}
ret = do_btree_insert_at(trans, stopped_at);
@@ -802,16 +777,10 @@ static int __bch2_trans_commit(struct btree_trans *trans,
bch2_btree_iter_downgrade(i->iter);
err:
/* make sure we didn't drop or screw up locks: */
- trans_for_each_update_iter(trans, i) {
- bch2_btree_iter_verify_locks(i->iter);
- break;
- }
+ bch2_btree_trans_verify_locks(trans);
- trans_for_each_update_iter(trans, i) {
- for_each_btree_iter(i->iter, linked)
- linked->flags &= ~BTREE_ITER_NOUNLOCK;
- break;
- }
+ trans_for_each_iter(trans, linked)
+ linked->flags &= ~BTREE_ITER_NOUNLOCK;
return ret;
}
@@ -847,13 +816,14 @@ int bch2_trans_commit(struct btree_trans *trans,
trans_for_each_update(trans, i)
btree_insert_entry_checks(trans, i);
+ bch2_btree_trans_verify_locks(trans);
if (unlikely(!(trans->flags & BTREE_INSERT_NOCHECK_RW) &&
!percpu_ref_tryget(&c->writes))) {
if (likely(!(trans->flags & BTREE_INSERT_LAZY_RW)))
return -EROFS;
- btree_trans_unlock(trans);
+ bch2_btree_trans_unlock(trans);
ret = bch2_fs_read_write_early(c);
if (ret)
@@ -861,7 +831,7 @@ int bch2_trans_commit(struct btree_trans *trans,
percpu_ref_get(&c->writes);
- if (!btree_trans_relock(trans)) {
+ if (!bch2_btree_trans_relock(trans)) {
ret = -EINTR;
goto err;
}
@@ -962,7 +932,7 @@ int bch2_btree_delete_range(struct bch_fs *c, enum btree_id id,
iter = bch2_trans_get_iter(&trans, id, start, BTREE_ITER_INTENT);
while ((k = bch2_btree_iter_peek(iter)).k &&
- !(ret = btree_iter_err(k)) &&
+ !(ret = bkey_err(k)) &&
bkey_cmp(iter->pos, end) < 0) {
unsigned max_sectors = KEY_SIZE_MAX & (~0 << c->block_bits);
/* really shouldn't be using a bare, unpadded bkey_i */