Commit d5024b01 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_btree_node_lock_write_nofail()

Taking a write lock will be able to fail, with the new cycle detector -
unless we pass it nofail, which is possible but not preferred.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent ca7d8fca
......@@ -342,11 +342,12 @@ static int btree_key_cache_fill(struct btree_trans *trans,
}
}
/*
* XXX: not allowed to be holding read locks when we take a write lock,
* currently
*/
bch2_btree_node_lock_write(trans, ck_path, ck_path->l[0].b);
ret = bch2_btree_node_lock_write(trans, ck_path, ck_path->l[0].b);
if (ret) {
kfree(new_k);
goto err;
}
if (new_k) {
kfree(ck->k);
ck->u64s = new_u64s;
......
......@@ -281,7 +281,7 @@ static inline int btree_node_lock(struct btree_trans *trans,
void __bch2_btree_node_lock_write(struct btree_trans *, struct btree *);
static inline void bch2_btree_node_lock_write(struct btree_trans *trans,
static inline void bch2_btree_node_lock_write_nofail(struct btree_trans *trans,
struct btree_path *path,
struct btree *b)
{
......@@ -300,6 +300,15 @@ static inline void bch2_btree_node_lock_write(struct btree_trans *trans,
__bch2_btree_node_lock_write(trans, b);
}
static inline int __must_check
bch2_btree_node_lock_write(struct btree_trans *trans,
struct btree_path *path,
struct btree *b)
{
bch2_btree_node_lock_write_nofail(trans, path, b);
return 0;
}
/* relock: */
bool bch2_btree_path_relock_norestart(struct btree_trans *,
......
......@@ -1163,7 +1163,7 @@ static void bch2_btree_set_root(struct btree_update *as,
* Ensure no one is using the old root while we switch to the
* new root:
*/
bch2_btree_node_lock_write(trans, path, old);
bch2_btree_node_lock_write_nofail(trans, path, old);
bch2_btree_set_root_inmem(c, b);
......@@ -2002,7 +2002,7 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans,
if (ret)
goto err;
bch2_btree_node_lock_write(trans, iter->path, b);
bch2_btree_node_lock_write_nofail(trans, iter->path, b);
if (new_hash) {
mutex_lock(&c->btree_cache.lock);
......
......@@ -81,7 +81,7 @@ void bch2_btree_node_lock_for_insert(struct btree_trans *trans,
struct btree_path *path,
struct btree *b)
{
bch2_btree_node_lock_write(trans, path, b);
bch2_btree_node_lock_write_nofail(trans, path, b);
bch2_btree_node_prep_for_write(trans, path, b);
}
......
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