diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 5dc4b0c133ad..c9c7ffa9fa71 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -941,7 +941,7 @@ struct bch_fs { GENRADIX(struct gc_stripe) gc_stripes; ec_stripes_heap ec_stripes_heap; - spinlock_t ec_stripes_heap_lock; + struct mutex ec_stripes_heap_lock; /* ERASURE CODING */ struct list_head ec_stripe_head_list; diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 2e1751eeaef4..ddbf88a759f9 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -907,10 +907,10 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans, return -ENOMEM; } - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); if (!m || !m->alive) { - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); bch_err_ratelimited(c, "pointer to nonexistent stripe %llu", (u64) p.idx); bch2_inconsistent_error(c); @@ -920,7 +920,7 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans, m->block_sectors[p.block] += sectors; r = m->r; - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); r.e.data_type = data_type; update_replicas(c, k, &r.e, sectors, trans->journal_res.seq, true); @@ -1047,9 +1047,9 @@ int bch2_mark_stripe(struct btree_trans *trans, } if (!new_s) { - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); bch2_stripes_heap_del(c, m, idx); - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); memset(m, 0, sizeof(*m)); } else { @@ -1063,9 +1063,9 @@ int bch2_mark_stripe(struct btree_trans *trans, for (i = 0; i < new_s->nr_blocks; i++) m->blocks_nonempty += !!stripe_blockcount_get(new_s, i); - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); bch2_stripes_heap_update(c, m, idx); - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); } } else { struct gc_stripe *m = diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index 6d0a49000bef..7a6b962ae1fc 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -549,13 +549,13 @@ static int __ec_stripe_mem_alloc(struct bch_fs *c, size_t idx, gfp_t gfp) if (!init_heap(&n, max(1024UL, roundup_pow_of_two(idx + 1)), gfp)) return -ENOMEM; - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); if (n.size > h->size) { memcpy(n.data, h->data, h->used * sizeof(h->data[0])); n.used = h->used; swap(*h, n); } - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); free_heap(&n); } @@ -695,15 +695,15 @@ static void ec_stripe_delete_work(struct work_struct *work) ssize_t idx; while (1) { - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); idx = stripe_idx_to_delete(c); if (idx < 0) { - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); break; } bch2_stripes_heap_del(c, genradix_ptr(&c->stripes, idx), idx); - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); if (ec_stripe_delete(c, idx)) break; @@ -1013,12 +1013,13 @@ static void ec_stripe_create(struct ec_stripe_new *s) bch_err(c, "error creating stripe: error updating pointers: %s", bch2_err_str(ret)); - spin_lock(&c->ec_stripes_heap_lock); + + mutex_lock(&c->ec_stripes_heap_lock); m = genradix_ptr(&c->stripes, s->new_stripe.key.k.p.offset); BUG_ON(m->on_heap); bch2_stripes_heap_insert(c, m, s->new_stripe.key.k.p.offset); - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); err_put_writes: bch2_write_ref_put(c, BCH_WRITE_REF_stripe_create); err: @@ -1398,7 +1399,7 @@ static s64 get_existing_stripe(struct bch_fs *c, if (may_create_new_stripe(c)) return -1; - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); for (heap_idx = 0; heap_idx < h->used; heap_idx++) { /* No blocks worth reusing, stripe will just be deleted: */ if (!h->data[heap_idx].blocks_nonempty) @@ -1416,12 +1417,11 @@ static s64 get_existing_stripe(struct bch_fs *c, break; } } - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); return ret; } -static int __bch2_ec_stripe_head_reuse(struct bch_fs *c, - struct ec_stripe_head *h) +static int __bch2_ec_stripe_head_reuse(struct bch_fs *c, struct ec_stripe_head *h) { unsigned i; s64 idx; @@ -1464,8 +1464,7 @@ static int __bch2_ec_stripe_head_reuse(struct bch_fs *c, return 0; } -static int __bch2_ec_stripe_head_reserve(struct bch_fs *c, - struct ec_stripe_head *h) +static int __bch2_ec_stripe_head_reserve(struct bch_fs *c, struct ec_stripe_head *h) { return bch2_disk_reservation_get(c, &h->s->res, h->blocksize, @@ -1606,9 +1605,9 @@ int bch2_stripes_read(struct bch_fs *c) for (i = 0; i < s->nr_blocks; i++) m->blocks_nonempty += !!stripe_blockcount_get(s, i); - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); bch2_stripes_heap_update(c, m, k.k->p.offset); - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); } bch2_trans_iter_exit(&trans, &iter); @@ -1626,7 +1625,7 @@ void bch2_stripes_heap_to_text(struct printbuf *out, struct bch_fs *c) struct stripe *m; size_t i; - spin_lock(&c->ec_stripes_heap_lock); + mutex_lock(&c->ec_stripes_heap_lock); for (i = 0; i < min_t(size_t, h->used, 20); i++) { m = genradix_ptr(&c->stripes, h->data[i].idx); @@ -1635,7 +1634,7 @@ void bch2_stripes_heap_to_text(struct printbuf *out, struct bch_fs *c) m->nr_blocks - m->nr_redundant, m->nr_redundant); } - spin_unlock(&c->ec_stripes_heap_lock); + mutex_unlock(&c->ec_stripes_heap_lock); } void bch2_new_stripes_to_text(struct printbuf *out, struct bch_fs *c) diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index f703e41c7560..b030d0bb26e7 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -706,7 +706,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) INIT_LIST_HEAD(&c->data_progress_list); mutex_init(&c->data_progress_lock); - spin_lock_init(&c->ec_stripes_heap_lock); + mutex_init(&c->ec_stripes_heap_lock); seqcount_init(&c->gc_pos_lock);