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>
This commit is contained in:
Kent Overstreet 2021-01-17 16:45:19 -05:00 committed by Kent Overstreet
parent a39c74be80
commit 6e53151b7b
3 changed files with 22 additions and 17 deletions

View File

@ -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]);
}
}

View File

@ -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,

View File

@ -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];