]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Limit pointers to being in only one stripe
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 8 Oct 2019 22:45:29 +0000 (18:45 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:29 +0000 (17:08 -0400)
This make the disk accounting code saner, and it's not clear why we'd
ever want the same data to be in multiple stripes simultaneously.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/buckets.c
fs/bcachefs/ec.c
fs/bcachefs/extents.c
fs/bcachefs/extents.h
fs/bcachefs/extents_types.h
fs/bcachefs/replicas.c

index 9beb4d4cf85da6f9f62bb32244721b440da509de..dc184de053ee408350712c880e4cc2a94fd30b56 100644 (file)
@@ -1027,7 +1027,6 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k,
        struct extent_ptr_decoded p;
        struct bch_replicas_padded r;
        s64 dirty_sectors = 0;
-       unsigned i;
        int ret;
 
        r.e.data_type   = data_type;
@@ -1047,17 +1046,15 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k,
                        if (!stale)
                                update_cached_sectors(c, fs_usage, p.ptr.dev,
                                                      disk_sectors);
-               } else if (!p.ec_nr) {
+               } else if (!p.has_ec) {
                        dirty_sectors          += disk_sectors;
                        r.e.devs[r.e.nr_devs++] = p.ptr.dev;
                } else {
-                       for (i = 0; i < p.ec_nr; i++) {
-                               ret = bch2_mark_stripe_ptr(c, p.ec[i],
-                                               data_type, fs_usage,
-                                               disk_sectors, flags);
-                               if (ret)
-                                       return ret;
-                       }
+                       ret = bch2_mark_stripe_ptr(c, p.ec,
+                                       data_type, fs_usage,
+                                       disk_sectors, flags);
+                       if (ret)
+                               return ret;
 
                        r.e.nr_required = 0;
                }
@@ -1564,7 +1561,6 @@ static int bch2_trans_mark_extent(struct btree_trans *trans,
        struct bch_replicas_padded r;
        s64 dirty_sectors = 0;
        bool stale;
-       unsigned i;
        int ret;
 
        r.e.data_type   = data_type;
@@ -1589,16 +1585,14 @@ static int bch2_trans_mark_extent(struct btree_trans *trans,
                        if (!stale)
                                update_cached_sectors_list(trans, p.ptr.dev,
                                                           disk_sectors);
-               } else if (!p.ec_nr) {
+               } else if (!p.has_ec) {
                        dirty_sectors          += disk_sectors;
                        r.e.devs[r.e.nr_devs++] = p.ptr.dev;
                } else {
-                       for (i = 0; i < p.ec_nr; i++) {
-                               ret = bch2_trans_mark_stripe_ptr(trans, p.ec[i],
-                                               disk_sectors, data_type);
-                               if (ret)
-                                       return ret;
-                       }
+                       ret = bch2_trans_mark_stripe_ptr(trans, p.ec,
+                                       disk_sectors, data_type);
+                       if (ret)
+                               return ret;
 
                        r.e.nr_required = 0;
                }
index 424d5cf48893a1befc1023bcff6a46ea0a9a6843..316dd82809ffc66618a3a7d871e99565e570c883 100644 (file)
@@ -433,10 +433,9 @@ int bch2_ec_read_extent(struct bch_fs *c, struct bch_read_bio *rbio)
 
        closure_init_stack(&cl);
 
-       BUG_ON(!rbio->pick.idx ||
-              rbio->pick.idx - 1 >= rbio->pick.ec_nr);
+       BUG_ON(!rbio->pick.has_ec);
 
-       stripe_idx = rbio->pick.ec[rbio->pick.idx - 1].idx;
+       stripe_idx = rbio->pick.ec.idx;
 
        buf = kzalloc(sizeof(*buf), GFP_NOIO);
        if (!buf)
index a8c2081cdd250e5cac0a6fe6aa40ae8ef55af95b..50cad6725c1b608c184cc3bede760d5f2325e543 100644 (file)
@@ -66,7 +66,7 @@ unsigned bch2_bkey_nr_dirty_ptrs(struct bkey_s_c k)
 static unsigned bch2_extent_ptr_durability(struct bch_fs *c,
                                           struct extent_ptr_decoded p)
 {
-       unsigned i, durability = 0;
+       unsigned durability = 0;
        struct bch_dev *ca;
 
        if (p.ptr.cached)
@@ -77,16 +77,16 @@ static unsigned bch2_extent_ptr_durability(struct bch_fs *c,
        if (ca->mi.state != BCH_MEMBER_STATE_FAILED)
                durability = max_t(unsigned, durability, ca->mi.durability);
 
-       for (i = 0; i < p.ec_nr; i++) {
+       if (p.has_ec) {
                struct stripe *s =
-                       genradix_ptr(&c->stripes[0], p.ec[i].idx);
+                       genradix_ptr(&c->stripes[0], p.ec.idx);
 
                if (WARN_ON(!s))
-                       continue;
+                       goto out;
 
                durability = max_t(unsigned, durability, s->nr_redundant);
        }
-
+out:
        return durability;
 }
 
@@ -205,10 +205,10 @@ int bch2_bkey_pick_read_device(struct bch_fs *c, struct bkey_s_c k,
                        p.idx++;
 
                if (force_reconstruct_read(c) &&
-                   !p.idx && p.ec_nr)
+                   !p.idx && p.has_ec)
                        p.idx++;
 
-               if (p.idx >= p.ec_nr + 1)
+               if (p.idx >= (unsigned) p.has_ec + 1)
                        continue;
 
                if (ret > 0 && !ptr_better(c, p, *pick))
@@ -1543,7 +1543,6 @@ void bch2_extent_ptr_decoded_append(struct bkey_i *k,
        struct bch_extent_crc_unpacked crc =
                bch2_extent_crc_unpack(&k->k, NULL);
        union bch_extent_entry *pos;
-       unsigned i;
 
        if (!bch2_crc_unpacked_cmp(crc, p->crc)) {
                pos = ptrs.start;
@@ -1562,9 +1561,9 @@ found:
        p->ptr.type = 1 << BCH_EXTENT_ENTRY_ptr;
        __extent_entry_insert(k, pos, to_entry(&p->ptr));
 
-       for (i = 0; i < p->ec_nr; i++) {
-               p->ec[i].type = 1 << BCH_EXTENT_ENTRY_stripe_ptr;
-               __extent_entry_insert(k, pos, to_entry(&p->ec[i]));
+       if (p->has_ec) {
+               p->ec.type = 1 << BCH_EXTENT_ENTRY_stripe_ptr;
+               __extent_entry_insert(k, pos, to_entry(&p->ec));
        }
 }
 
index 7253cd01db6aea69df495c5d0c02255cea50e35b..cc7ee9067b50a7ee69bc65f7d053d1f9b60a614d 100644 (file)
@@ -228,7 +228,7 @@ struct bkey_ptrs {
        __label__ out;                                                  \
                                                                        \
        (_ptr).idx      = 0;                                            \
-       (_ptr).ec_nr    = 0;                                            \
+       (_ptr).has_ec   = false;                                        \
                                                                        \
        __bkey_extent_entry_for_each_from(_entry, _end, _entry)         \
                switch (extent_entry_type(_entry)) {                    \
@@ -242,7 +242,8 @@ struct bkey_ptrs {
                                        entry_to_crc(_entry));          \
                        break;                                          \
                case BCH_EXTENT_ENTRY_stripe_ptr:                       \
-                       (_ptr).ec[(_ptr).ec_nr++] = _entry->stripe_ptr; \
+                       (_ptr).ec = _entry->stripe_ptr;                 \
+                       (_ptr).has_ec   = true;                         \
                        break;                                          \
                }                                                       \
 out:                                                                   \
index a8dd6952d9895cddd2f13c350db500966454cc94..43d6c341eccabb86be8c5395fef5b558bb52004a 100644 (file)
@@ -21,10 +21,10 @@ struct bch_extent_crc_unpacked {
 
 struct extent_ptr_decoded {
        unsigned                        idx;
-       unsigned                        ec_nr;
+       bool                            has_ec;
        struct bch_extent_crc_unpacked  crc;
        struct bch_extent_ptr           ptr;
-       struct bch_extent_stripe_ptr    ec[4];
+       struct bch_extent_stripe_ptr    ec;
 };
 
 struct bch_io_failures {
index afd226f3c8e7d7e2744189246ba5de36a97b9c7e..eef9f54808fb118883b2da3631b45af7cb1e6943 100644 (file)
@@ -84,10 +84,8 @@ static void extent_to_replicas(struct bkey_s_c k,
                if (p.ptr.cached)
                        continue;
 
-               if (p.ec_nr) {
+               if (p.has_ec)
                        r->nr_required = 0;
-                       break;
-               }
 
                r->devs[r->nr_devs++] = p.ptr.dev;
        }