From 73d86dfd888541fd85f7e4d03c898f2ad8486196 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 17 Feb 2023 22:43:47 -0500 Subject: 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 --- fs/bcachefs/ec.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'fs/bcachefs/ec.c') 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; } -- cgit v1.2.3