diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-01-18 00:45:19 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:08:51 +0300 |
commit | 6e53151b7b738fe60b9295c2ff47e6b2092718b1 (patch) | |
tree | cd7f04741e5638fa69dd33aba36b2d9538400ea6 | |
parent | a39c74be8059be72fcf6c7cc2f827c38076a25db (diff) | |
download | linux-6e53151b7b738fe60b9295c2ff47e6b2092718b1.tar.xz |
bcachefs: Kill stripe->dirty
This makes bch2_stripes_write() work more like bch2_alloc_write().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/btree_gc.c | 21 | ||||
-rw-r--r-- | fs/bcachefs/ec.c | 15 | ||||
-rw-r--r-- | fs/bcachefs/ec_types.h | 3 |
3 files changed, 22 insertions, 17 deletions
diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index f2310f7f89c5..5608d8a0ed61 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -583,7 +583,6 @@ static int bch2_gc_done(struct bch_fs *c, iter.pos, ##__VA_ARGS__, \ dst->_f, src->_f); \ dst->_f = src->_f; \ - dst->dirty = true; \ set_bit(BCH_FS_NEED_ALLOC_WRITE, &c->flags); \ } #define copy_bucket_field(_f) \ @@ -609,18 +608,24 @@ static int bch2_gc_done(struct bch_fs *c, while ((src = genradix_iter_peek(&iter, &c->stripes[1]))) { dst = genradix_ptr_alloc(&c->stripes[0], iter.pos, GFP_KERNEL); - copy_stripe_field(alive, "alive"); - copy_stripe_field(sectors, "sectors"); - copy_stripe_field(algorithm, "algorithm"); - copy_stripe_field(nr_blocks, "nr_blocks"); - copy_stripe_field(nr_redundant, "nr_redundant"); - copy_stripe_field(blocks_nonempty, - "blocks_nonempty"); + if (dst->alive != src->alive || + dst->sectors != src->sectors || + dst->algorithm != src->algorithm || + dst->nr_blocks != src->nr_blocks || + dst->nr_redundant != src->nr_redundant) { + bch_err(c, "unexpected stripe inconsistency at bch2_gc_done, confused"); + ret = -EINVAL; + goto fsck_err; + } for (i = 0; i < ARRAY_SIZE(dst->block_sectors); i++) copy_stripe_field(block_sectors[i], "block_sectors[%u]", i); + dst->blocks_nonempty = 0; + for (i = 0; i < dst->nr_blocks; i++) + dst->blocks_nonempty += dst->block_sectors[i] != 0; + genradix_iter_advance(&iter, &c->stripes[1]); } } diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index 1f125ce77e4f..0d9a27726c05 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -1466,7 +1466,7 @@ static int __bch2_stripe_write_key(struct btree_trans *trans, size_t idx, struct bkey_i_stripe *new_key) { - struct bch_fs *c = trans->c; + const struct bch_stripe *v; struct bkey_s_c k; unsigned i; int ret; @@ -1481,16 +1481,17 @@ static int __bch2_stripe_write_key(struct btree_trans *trans, if (k.k->type != KEY_TYPE_stripe) return -EIO; + v = bkey_s_c_to_stripe(k).v; + for (i = 0; i < v->nr_blocks; i++) + if (m->block_sectors[i] != stripe_blockcount_get(v, i)) + goto write; + return 0; +write: bkey_reassemble(&new_key->k_i, k); - spin_lock(&c->ec_stripes_heap_lock); - for (i = 0; i < new_key->v.nr_blocks; i++) stripe_blockcount_set(&new_key->v, i, m->block_sectors[i]); - m->dirty = false; - - spin_unlock(&c->ec_stripes_heap_lock); bch2_trans_update(trans, iter, &new_key->k_i, 0); return 0; @@ -1514,7 +1515,7 @@ int bch2_stripes_write(struct bch_fs *c, unsigned flags) BTREE_ITER_SLOTS|BTREE_ITER_INTENT); genradix_for_each(&c->stripes[0], giter, m) { - if (!m->dirty) + if (!m->alive) continue; ret = __bch2_trans_do(&trans, NULL, NULL, diff --git a/fs/bcachefs/ec_types.h b/fs/bcachefs/ec_types.h index 5b688b4394f7..847770166223 100644 --- a/fs/bcachefs/ec_types.h +++ b/fs/bcachefs/ec_types.h @@ -18,8 +18,7 @@ struct stripe { u8 nr_blocks; u8 nr_redundant; - unsigned alive:1; - unsigned dirty:1; + unsigned alive:1; /* does a corresponding key exist in stripes btree? */ unsigned on_heap:1; u8 blocks_nonempty; u16 block_sectors[BCH_BKEY_PTRS_MAX]; |