summaryrefslogtreecommitdiff
path: root/fs/bcachefs/ec.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-02-17 22:43:47 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:53 -0400
commit73d86dfd888541fd85f7e4d03c898f2ad8486196 (patch)
tree8f8008259cbcb45eb752c1c6d5b820c580cdb64b /fs/bcachefs/ec.c
parentaf0ee5bcf3012be753ab15ce9c27971e5b34bd74 (diff)
downloadlwn-73d86dfd888541fd85f7e4d03c898f2ad8486196.tar.gz
lwn-73d86dfd888541fd85f7e4d03c898f2ad8486196.zip
bcachefs: Fix erasure coding locking
This adds a new helper, bch2_trans_mutex_lock(), for locking a mutex - dropping and retaking btree locks as needed. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/ec.c')
-rw-r--r--fs/bcachefs/ec.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c
index 236e1bef5f02..6d0a49000bef 100644
--- a/fs/bcachefs/ec.c
+++ b/fs/bcachefs/ec.c
@@ -1231,7 +1231,7 @@ ec_new_stripe_head_alloc(struct bch_fs *c, unsigned target,
return NULL;
mutex_init(&h->lock);
- mutex_lock(&h->lock);
+ BUG_ON(!mutex_trylock(&h->lock));
h->target = target;
h->algo = algo;
@@ -1280,23 +1280,18 @@ struct ec_stripe_head *__bch2_ec_stripe_head_get(struct btree_trans *trans,
if (!redundancy)
return NULL;
- if (!mutex_trylock(&c->ec_stripe_head_lock)) {
- bch2_trans_unlock(trans);
- mutex_lock(&c->ec_stripe_head_lock);
-
- ret = bch2_trans_relock(trans);
- if (ret) {
- mutex_unlock(&c->ec_stripe_head_lock);
- return ERR_PTR(ret);
- }
- }
+ ret = bch2_trans_mutex_lock(trans, &c->ec_stripe_head_lock);
+ if (ret)
+ return ERR_PTR(ret);
list_for_each_entry(h, &c->ec_stripe_head_list, list)
if (h->target == target &&
h->algo == algo &&
h->redundancy == redundancy &&
h->copygc == copygc) {
- mutex_lock(&h->lock);
+ ret = bch2_trans_mutex_lock(trans, &h->lock);
+ if (ret)
+ h = ERR_PTR(ret);
goto found;
}