Commit af0ee5bc authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Don't block on ec_stripe_head_lock with btree locks held

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 6623c0fc
...@@ -1267,18 +1267,30 @@ void bch2_ec_stripe_head_put(struct bch_fs *c, struct ec_stripe_head *h) ...@@ -1267,18 +1267,30 @@ void bch2_ec_stripe_head_put(struct bch_fs *c, struct ec_stripe_head *h)
mutex_unlock(&h->lock); mutex_unlock(&h->lock);
} }
struct ec_stripe_head *__bch2_ec_stripe_head_get(struct bch_fs *c, struct ec_stripe_head *__bch2_ec_stripe_head_get(struct btree_trans *trans,
unsigned target, unsigned target,
unsigned algo, unsigned algo,
unsigned redundancy, unsigned redundancy,
bool copygc) bool copygc)
{ {
struct bch_fs *c = trans->c;
struct ec_stripe_head *h; struct ec_stripe_head *h;
int ret;
if (!redundancy) if (!redundancy)
return NULL; return NULL;
mutex_lock(&c->ec_stripe_head_lock); 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);
}
}
list_for_each_entry(h, &c->ec_stripe_head_list, list) list_for_each_entry(h, &c->ec_stripe_head_list, list)
if (h->target == target && if (h->target == target &&
h->algo == algo && h->algo == algo &&
...@@ -1477,11 +1489,11 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *trans, ...@@ -1477,11 +1489,11 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *trans,
int ret; int ret;
bool needs_stripe_new; bool needs_stripe_new;
h = __bch2_ec_stripe_head_get(c, target, algo, redundancy, copygc); h = __bch2_ec_stripe_head_get(trans, target, algo, redundancy, copygc);
if (!h) { if (!h)
bch_err(c, "no stripe head"); bch_err(c, "no stripe head");
return NULL; if (IS_ERR_OR_NULL(h))
} return h;
needs_stripe_new = !h->s; needs_stripe_new = !h->s;
if (needs_stripe_new) { if (needs_stripe_new) {
......
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