Commit 2c7dd446 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Erasure coding now uses bch2_bucket_alloc_trans

This code predates plumbing btree_trans through the bucket allocation
path: switching to it fixes a deadlock due to using multiple btree_trans
at the same time, which we never want to do.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 84ddb8b9
...@@ -713,7 +713,7 @@ static void add_new_bucket(struct bch_fs *c, ...@@ -713,7 +713,7 @@ static void add_new_bucket(struct bch_fs *c,
ob_push(c, ptrs, ob); ob_push(c, ptrs, ob);
} }
static int bch2_bucket_alloc_set_trans(struct btree_trans *trans, int bch2_bucket_alloc_set_trans(struct btree_trans *trans,
struct open_buckets *ptrs, struct open_buckets *ptrs,
struct dev_stripe_state *stripe, struct dev_stripe_state *stripe,
struct bch_devs_mask *devs_may_alloc, struct bch_devs_mask *devs_may_alloc,
...@@ -779,24 +779,6 @@ static int bch2_bucket_alloc_set_trans(struct btree_trans *trans, ...@@ -779,24 +779,6 @@ static int bch2_bucket_alloc_set_trans(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_bucket_alloc_set(struct bch_fs *c,
struct open_buckets *ptrs,
struct dev_stripe_state *stripe,
struct bch_devs_mask *devs_may_alloc,
unsigned nr_replicas,
unsigned *nr_effective,
bool *have_cache,
enum alloc_reserve reserve,
unsigned flags,
struct closure *cl)
{
return bch2_trans_do(c, NULL, NULL, 0,
bch2_bucket_alloc_set_trans(&trans, ptrs, stripe,
devs_may_alloc, nr_replicas,
nr_effective, have_cache, reserve,
flags, cl));
}
/* Allocate from stripes: */ /* Allocate from stripes: */
/* /*
...@@ -805,7 +787,7 @@ int bch2_bucket_alloc_set(struct bch_fs *c, ...@@ -805,7 +787,7 @@ int bch2_bucket_alloc_set(struct bch_fs *c,
* it's to a device we don't want: * it's to a device we don't want:
*/ */
static int bucket_alloc_from_stripe(struct bch_fs *c, static int bucket_alloc_from_stripe(struct btree_trans *trans,
struct open_buckets *ptrs, struct open_buckets *ptrs,
struct write_point *wp, struct write_point *wp,
struct bch_devs_mask *devs_may_alloc, struct bch_devs_mask *devs_may_alloc,
...@@ -817,6 +799,7 @@ static int bucket_alloc_from_stripe(struct bch_fs *c, ...@@ -817,6 +799,7 @@ static int bucket_alloc_from_stripe(struct bch_fs *c,
unsigned flags, unsigned flags,
struct closure *cl) struct closure *cl)
{ {
struct bch_fs *c = trans->c;
struct dev_alloc_list devs_sorted; struct dev_alloc_list devs_sorted;
struct ec_stripe_head *h; struct ec_stripe_head *h;
struct open_bucket *ob; struct open_bucket *ob;
...@@ -832,11 +815,11 @@ static int bucket_alloc_from_stripe(struct bch_fs *c, ...@@ -832,11 +815,11 @@ static int bucket_alloc_from_stripe(struct bch_fs *c,
if (ec_open_bucket(c, ptrs)) if (ec_open_bucket(c, ptrs))
return 0; return 0;
h = bch2_ec_stripe_head_get(c, target, 0, nr_replicas - 1, h = bch2_ec_stripe_head_get(trans, target, 0, nr_replicas - 1,
wp == &c->copygc_write_point, wp == &c->copygc_write_point,
cl); cl);
if (IS_ERR(h)) if (IS_ERR(h))
return -PTR_ERR(h); return PTR_ERR(h);
if (!h) if (!h)
return 0; return 0;
...@@ -942,7 +925,7 @@ static int open_bucket_add_buckets(struct btree_trans *trans, ...@@ -942,7 +925,7 @@ static int open_bucket_add_buckets(struct btree_trans *trans,
} }
if (!ec_open_bucket(c, ptrs)) { if (!ec_open_bucket(c, ptrs)) {
ret = bucket_alloc_from_stripe(c, ptrs, wp, &devs, ret = bucket_alloc_from_stripe(trans, ptrs, wp, &devs,
target, erasure_code, target, erasure_code,
nr_replicas, nr_effective, nr_replicas, nr_effective,
have_cache, flags, _cl); have_cache, flags, _cl);
......
...@@ -150,7 +150,7 @@ static inline bool bch2_bucket_is_open_safe(struct bch_fs *c, unsigned dev, u64 ...@@ -150,7 +150,7 @@ static inline bool bch2_bucket_is_open_safe(struct bch_fs *c, unsigned dev, u64
return ret; return ret;
} }
int bch2_bucket_alloc_set(struct bch_fs *, struct open_buckets *, int bch2_bucket_alloc_set_trans(struct btree_trans *, struct open_buckets *,
struct dev_stripe_state *, struct bch_devs_mask *, struct dev_stripe_state *, struct bch_devs_mask *,
unsigned, unsigned *, bool *, enum alloc_reserve, unsigned, unsigned *, bool *, enum alloc_reserve,
unsigned, struct closure *); unsigned, struct closure *);
......
...@@ -1294,9 +1294,10 @@ struct ec_stripe_head *__bch2_ec_stripe_head_get(struct bch_fs *c, ...@@ -1294,9 +1294,10 @@ struct ec_stripe_head *__bch2_ec_stripe_head_get(struct bch_fs *c,
return h; return h;
} }
static int new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h, static int new_stripe_alloc_buckets(struct btree_trans *trans, struct ec_stripe_head *h,
struct closure *cl) struct closure *cl)
{ {
struct bch_fs *c = trans->c;
struct bch_devs_mask devs = h->devs; struct bch_devs_mask devs = h->devs;
struct open_bucket *ob; struct open_bucket *ob;
struct open_buckets buckets; struct open_buckets buckets;
...@@ -1319,7 +1320,7 @@ static int new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h, ...@@ -1319,7 +1320,7 @@ static int new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h,
buckets.nr = 0; buckets.nr = 0;
if (nr_have_parity < h->s->nr_parity) { if (nr_have_parity < h->s->nr_parity) {
ret = bch2_bucket_alloc_set(c, &buckets, ret = bch2_bucket_alloc_set_trans(trans, &buckets,
&h->parity_stripe, &h->parity_stripe,
&devs, &devs,
h->s->nr_parity, h->s->nr_parity,
...@@ -1348,7 +1349,7 @@ static int new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h, ...@@ -1348,7 +1349,7 @@ static int new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h,
buckets.nr = 0; buckets.nr = 0;
if (nr_have_data < h->s->nr_data) { if (nr_have_data < h->s->nr_data) {
ret = bch2_bucket_alloc_set(c, &buckets, ret = bch2_bucket_alloc_set_trans(trans, &buckets,
&h->block_stripe, &h->block_stripe,
&devs, &devs,
h->s->nr_data, h->s->nr_data,
...@@ -1464,13 +1465,14 @@ static int __bch2_ec_stripe_head_reserve(struct bch_fs *c, ...@@ -1464,13 +1465,14 @@ static int __bch2_ec_stripe_head_reserve(struct bch_fs *c,
h->s->nr_parity, 0); h->s->nr_parity, 0);
} }
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 closure *cl) struct closure *cl)
{ {
struct bch_fs *c = trans->c;
struct ec_stripe_head *h; struct ec_stripe_head *h;
int ret; int ret;
bool needs_stripe_new; bool needs_stripe_new;
...@@ -1509,7 +1511,7 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *c, ...@@ -1509,7 +1511,7 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *c,
} }
if (!h->s->allocated) { if (!h->s->allocated) {
ret = new_stripe_alloc_buckets(c, h, cl); ret = new_stripe_alloc_buckets(trans, h, cl);
if (ret) if (ret)
goto err; goto err;
...@@ -1517,7 +1519,6 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *c, ...@@ -1517,7 +1519,6 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *c,
} }
return h; return h;
err: err:
bch2_ec_stripe_head_put(c, h); bch2_ec_stripe_head_put(c, h);
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -200,7 +200,7 @@ void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *); ...@@ -200,7 +200,7 @@ void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *);
int bch2_ec_stripe_new_alloc(struct bch_fs *, struct ec_stripe_head *); int bch2_ec_stripe_new_alloc(struct bch_fs *, struct ec_stripe_head *);
void bch2_ec_stripe_head_put(struct bch_fs *, struct ec_stripe_head *); void bch2_ec_stripe_head_put(struct bch_fs *, struct ec_stripe_head *);
struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *, struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *,
unsigned, unsigned, unsigned, bool, struct closure *); unsigned, unsigned, unsigned, bool, struct closure *);
void bch2_stripes_heap_update(struct bch_fs *, struct stripe *, size_t); void bch2_stripes_heap_update(struct bch_fs *, struct stripe *, size_t);
......
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