Commit 253ba178 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix ca->oldest_gen allocation

The ca->oldest_gen array needs to be the same size as the bucket_gens
array; ca->mi.nbuckets is updated with only state_lock held, not
gc_lock, so bch2_gc_gens() could race with device resize and allocate
too small of an oldest_gens array.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a1d97d84
...@@ -1954,19 +1954,17 @@ int bch2_gc_gens(struct bch_fs *c) ...@@ -1954,19 +1954,17 @@ int bch2_gc_gens(struct bch_fs *c)
trans = bch2_trans_get(c); trans = bch2_trans_get(c);
for_each_member_device(ca, c, i) { for_each_member_device(ca, c, i) {
struct bucket_gens *gens; struct bucket_gens *gens = bucket_gens(ca);
BUG_ON(ca->oldest_gen); BUG_ON(ca->oldest_gen);
ca->oldest_gen = kvmalloc(ca->mi.nbuckets, GFP_KERNEL); ca->oldest_gen = kvmalloc(gens->nbuckets, GFP_KERNEL);
if (!ca->oldest_gen) { if (!ca->oldest_gen) {
percpu_ref_put(&ca->ref); percpu_ref_put(&ca->ref);
ret = -BCH_ERR_ENOMEM_gc_gens; ret = -BCH_ERR_ENOMEM_gc_gens;
goto err; goto err;
} }
gens = bucket_gens(ca);
for (b = gens->first_bucket; for (b = gens->first_bucket;
b < gens->nbuckets; b++) b < gens->nbuckets; b++)
ca->oldest_gen[b] = gens->b[b]; ca->oldest_gen[b] = gens->b[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