]> git.dujemihanovic.xyz Git - linux.git/commitdiff
bcachefs: stripe_to_mem()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 1 Sep 2024 18:51:45 +0000 (14:51 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Sep 2024 15:39:48 +0000 (11:39 -0400)
factor out a common helper

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

index 0812d2c76384c7138737a1abd55af9f3759b164a..9efffc43406dbec768d244ea01454fcd879a8339 100644 (file)
@@ -352,6 +352,18 @@ static int mark_stripe_buckets(struct btree_trans *trans,
        return 0;
 }
 
+static inline void stripe_to_mem(struct stripe *m, const struct bch_stripe *s)
+{
+       m->sectors      = le16_to_cpu(s->sectors);
+       m->algorithm    = s->algorithm;
+       m->nr_blocks    = s->nr_blocks;
+       m->nr_redundant = s->nr_redundant;
+       m->blocks_nonempty = 0;
+
+       for (unsigned i = 0; i < s->nr_blocks; i++)
+               m->blocks_nonempty += !!stripe_blockcount_get(s, i);
+}
+
 int bch2_trigger_stripe(struct btree_trans *trans,
                        enum btree_id btree, unsigned level,
                        struct bkey_s_c old, struct bkey_s _new,
@@ -468,14 +480,7 @@ int bch2_trigger_stripe(struct btree_trans *trans,
 
                        memset(m, 0, sizeof(*m));
                } else {
-                       m->sectors      = le16_to_cpu(new_s->sectors);
-                       m->algorithm    = new_s->algorithm;
-                       m->nr_blocks    = new_s->nr_blocks;
-                       m->nr_redundant = new_s->nr_redundant;
-                       m->blocks_nonempty = 0;
-
-                       for (unsigned i = 0; i < new_s->nr_blocks; i++)
-                               m->blocks_nonempty += !!stripe_blockcount_get(new_s, i);
+                       stripe_to_mem(m, new_s);
 
                        if (!old_s)
                                bch2_stripes_heap_insert(c, m, idx);
@@ -2198,17 +2203,9 @@ int bch2_stripes_read(struct bch_fs *c)
                        if (ret)
                                break;
 
-                       const struct bch_stripe *s = bkey_s_c_to_stripe(k).v;
-
                        struct stripe *m = genradix_ptr(&c->stripes, k.k->p.offset);
-                       m->sectors      = le16_to_cpu(s->sectors);
-                       m->algorithm    = s->algorithm;
-                       m->nr_blocks    = s->nr_blocks;
-                       m->nr_redundant = s->nr_redundant;
-                       m->blocks_nonempty = 0;
-
-                       for (unsigned i = 0; i < s->nr_blocks; i++)
-                               m->blocks_nonempty += !!stripe_blockcount_get(s, i);
+
+                       stripe_to_mem(m, bkey_s_c_to_stripe(k).v);
 
                        bch2_stripes_heap_insert(c, m, k.k->p.offset);
                        0;