bcachefs: Kill stripe->dirty
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 17 Jan 2021 21:45:19 +0000 (16:45 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:51 +0000 (17:08 -0400)
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>
fs/bcachefs/btree_gc.c
fs/bcachefs/ec.c
fs/bcachefs/ec_types.h

index f2310f7f89c5660ad24bd39582cf238422a1fff8..5608d8a0ed618e872470ca836bd9c6107569be18 100644 (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]);
                }
        }
index 1f125ce77e4faeb23b98463e1b5a0a683f73cac9..0d9a27726c058a0e7c00bdb861361f8c546a41d8 100644 (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,
index 5b688b4394f788a8ec2accbce2365d1c7d45f76f..847770166223f6af2e93c391bb996d1750cc7866 100644 (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];