]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/ec.h
Update bcachefs sources to 72405e7ff8 bcachefs: Fix bch2_check_extents_to_backpointers()
[bcachefs-tools-debian] / libbcachefs / ec.h
index d112aea9ec5632f0339532fd39c3e2407fceedc2..7c08a49d741956534a229e92e2d787ceacb3b407 100644 (file)
@@ -143,6 +143,12 @@ struct ec_stripe_buf {
 
 struct ec_stripe_head;
 
+enum ec_stripe_ref {
+       STRIPE_REF_io,
+       STRIPE_REF_stripe,
+       STRIPE_REF_NR
+};
+
 struct ec_stripe_new {
        struct bch_fs           *c;
        struct ec_stripe_head   *h;
@@ -154,8 +160,7 @@ struct ec_stripe_new {
 
        struct closure          iodone;
 
-       /* counts in flight writes, stripe is created when pin == 0 */
-       atomic_t                pin;
+       atomic_t                ref[STRIPE_REF_NR];
 
        int                     err;
 
@@ -213,24 +218,35 @@ void bch2_stripes_heap_insert(struct bch_fs *, struct stripe *, size_t);
 
 void bch2_do_stripe_deletes(struct bch_fs *);
 void bch2_ec_do_stripe_creates(struct bch_fs *);
+void bch2_ec_stripe_new_free(struct bch_fs *, struct ec_stripe_new *);
 
-static inline void ec_stripe_new_get(struct ec_stripe_new *s)
+static inline void ec_stripe_new_get(struct ec_stripe_new *s,
+                                    enum ec_stripe_ref ref)
 {
-       atomic_inc(&s->pin);
+       atomic_inc(&s->ref[ref]);
 }
 
-static inline void ec_stripe_new_put(struct bch_fs *c, struct ec_stripe_new *s)
+static inline void ec_stripe_new_put(struct bch_fs *c, struct ec_stripe_new *s,
+                                    enum ec_stripe_ref ref)
 {
-       BUG_ON(atomic_read(&s->pin) <= 0);
-       BUG_ON(!s->err && !s->idx);
-
-       if (atomic_dec_and_test(&s->pin))
-               bch2_ec_do_stripe_creates(c);
+       BUG_ON(atomic_read(&s->ref[ref]) <= 0);
+
+       if (atomic_dec_and_test(&s->ref[ref]))
+               switch (ref) {
+               case STRIPE_REF_stripe:
+                       bch2_ec_stripe_new_free(c, s);
+                       break;
+               case STRIPE_REF_io:
+                       bch2_ec_do_stripe_creates(c);
+                       break;
+               default:
+                       unreachable();
+               }
 }
 
 void bch2_ec_stop_dev(struct bch_fs *, struct bch_dev *);
-
-void bch2_ec_flush_new_stripes(struct bch_fs *);
+void bch2_fs_ec_stop(struct bch_fs *);
+void bch2_fs_ec_flush(struct bch_fs *);
 
 int bch2_stripes_read(struct bch_fs *);