]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/ec.h
Update bcachefs sources to 8dbfede1d9 fixup! bcachefs: More info on check_bucket_ref...
[bcachefs-tools-debian] / libbcachefs / ec.h
index 4dfaac0348869eb82640650c03d6709307d9fe1e..d47da7d86fe7d4162a21cb85405c90da43c36971 100644 (file)
@@ -3,17 +3,21 @@
 #define _BCACHEFS_EC_H
 
 #include "ec_types.h"
-#include "keylist_types.h"
+#include "buckets_types.h"
+#include "extents_types.h"
 
-const char *bch2_stripe_invalid(const struct bch_fs *, struct bkey_s_c);
+int bch2_stripe_invalid(const struct bch_fs *, struct bkey_s_c,
+                       unsigned, struct printbuf *);
 void bch2_stripe_to_text(struct printbuf *, struct bch_fs *,
                         struct bkey_s_c);
 
-#define bch2_bkey_ops_stripe (struct bkey_ops) {       \
+#define bch2_bkey_ops_stripe ((struct bkey_ops) {      \
        .key_invalid    = bch2_stripe_invalid,          \
        .val_to_text    = bch2_stripe_to_text,          \
        .swab           = bch2_ptr_swab,                \
-}
+       .trans_trigger  = bch2_trans_mark_stripe,       \
+       .atomic_trigger = bch2_mark_stripe,             \
+})
 
 static inline unsigned stripe_csums_per_device(const struct bch_stripe *s)
 {
@@ -59,9 +63,66 @@ static inline unsigned stripe_val_u64s(const struct bch_stripe *s)
 }
 
 static inline void *stripe_csum(struct bch_stripe *s,
-                               unsigned dev, unsigned csum_idx)
+                               unsigned block, unsigned csum_idx)
+{
+       EBUG_ON(block >= s->nr_blocks);
+       EBUG_ON(csum_idx >= stripe_csums_per_device(s));
+
+       return (void *) s + stripe_csum_offset(s, block, csum_idx);
+}
+
+static inline struct bch_csum stripe_csum_get(struct bch_stripe *s,
+                                  unsigned block, unsigned csum_idx)
 {
-       return (void *) s + stripe_csum_offset(s, dev, csum_idx);
+       struct bch_csum csum = { 0 };
+
+       memcpy(&csum, stripe_csum(s, block, csum_idx), bch_crc_bytes[s->csum_type]);
+       return csum;
+}
+
+static inline void stripe_csum_set(struct bch_stripe *s,
+                                  unsigned block, unsigned csum_idx,
+                                  struct bch_csum csum)
+{
+       memcpy(stripe_csum(s, block, csum_idx), &csum, bch_crc_bytes[s->csum_type]);
+}
+
+static inline bool __bch2_ptr_matches_stripe(const struct bch_extent_ptr *stripe_ptr,
+                                            const struct bch_extent_ptr *data_ptr,
+                                            unsigned sectors)
+{
+       return  data_ptr->dev    == stripe_ptr->dev &&
+               data_ptr->gen    == stripe_ptr->gen &&
+               data_ptr->offset >= stripe_ptr->offset &&
+               data_ptr->offset  < stripe_ptr->offset + sectors;
+}
+
+static inline bool bch2_ptr_matches_stripe(const struct bch_stripe *s,
+                                          struct extent_ptr_decoded p)
+{
+       unsigned nr_data = s->nr_blocks - s->nr_redundant;
+
+       BUG_ON(!p.has_ec);
+
+       if (p.ec.block >= nr_data)
+               return false;
+
+       return __bch2_ptr_matches_stripe(&s->ptrs[p.ec.block], &p.ptr,
+                                        le16_to_cpu(s->sectors));
+}
+
+static inline bool bch2_ptr_matches_stripe_m(const struct gc_stripe *m,
+                                            struct extent_ptr_decoded p)
+{
+       unsigned nr_data = m->nr_blocks - m->nr_redundant;
+
+       BUG_ON(!p.has_ec);
+
+       if (p.ec.block >= nr_data)
+               return false;
+
+       return __bch2_ptr_matches_stripe(&m->ptrs[p.ec.block], &p.ptr,
+                                        m->sectors);
 }
 
 struct bch_read_bio;
@@ -70,9 +131,9 @@ struct ec_stripe_buf {
        /* might not be buffering the entire stripe: */
        unsigned                offset;
        unsigned                size;
-       unsigned long           valid[BITS_TO_LONGS(EC_STRIPE_MAX)];
+       unsigned long           valid[BITS_TO_LONGS(BCH_BKEY_PTRS_MAX)];
 
-       void                    *data[EC_STRIPE_MAX];
+       void                    *data[BCH_BKEY_PTRS_MAX];
 
        union {
                struct bkey_i_stripe    key;
@@ -87,32 +148,36 @@ struct ec_stripe_new {
        struct ec_stripe_head   *h;
        struct mutex            lock;
        struct list_head        list;
+       struct closure          iodone;
 
        /* counts in flight writes, stripe is created when pin == 0 */
        atomic_t                pin;
 
        int                     err;
 
-       unsigned long           blocks_allocated[BITS_TO_LONGS(EC_STRIPE_MAX)];
+       u8                      nr_data;
+       u8                      nr_parity;
+       bool                    allocated;
+       bool                    pending;
+       bool                    have_existing_stripe;
 
-       struct open_buckets     blocks;
-       struct open_buckets     parity;
+       unsigned long           blocks_gotten[BITS_TO_LONGS(BCH_BKEY_PTRS_MAX)];
+       unsigned long           blocks_allocated[BITS_TO_LONGS(BCH_BKEY_PTRS_MAX)];
+       open_bucket_idx_t       blocks[BCH_BKEY_PTRS_MAX];
+       struct disk_reservation res;
 
-       struct keylist          keys;
-       u64                     inline_keys[BKEY_U64s * 8];
-
-       struct ec_stripe_buf    stripe;
+       struct ec_stripe_buf    new_stripe;
+       struct ec_stripe_buf    existing_stripe;
 };
 
 struct ec_stripe_head {
        struct list_head        list;
        struct mutex            lock;
 
-       struct list_head        stripes;
-
        unsigned                target;
        unsigned                algo;
        unsigned                redundancy;
+       bool                    copygc;
 
        struct bch_devs_mask    devs;
        unsigned                nr_active_devs;
@@ -122,42 +187,41 @@ struct ec_stripe_head {
        struct dev_stripe_state block_stripe;
        struct dev_stripe_state parity_stripe;
 
-       struct open_buckets     blocks;
-       struct open_buckets     parity;
-
        struct ec_stripe_new    *s;
 };
 
 int bch2_ec_read_extent(struct bch_fs *, struct bch_read_bio *);
 
 void *bch2_writepoint_ec_buf(struct bch_fs *, struct write_point *);
-void bch2_ec_add_backpointer(struct bch_fs *, struct write_point *,
-                            struct bpos, unsigned);
 
 void bch2_ec_bucket_written(struct bch_fs *, struct open_bucket *);
 void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *);
 
 int bch2_ec_stripe_new_alloc(struct bch_fs *, struct ec_stripe_head *);
 
-void bch2_ec_stripe_head_put(struct ec_stripe_head *);
-struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *, unsigned,
-                                              unsigned, unsigned);
+void bch2_ec_stripe_head_put(struct bch_fs *, struct ec_stripe_head *);
+struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *,
+                       unsigned, unsigned, unsigned, bool, struct closure *);
 
 void bch2_stripes_heap_update(struct bch_fs *, struct stripe *, size_t);
 void bch2_stripes_heap_del(struct bch_fs *, struct stripe *, size_t);
 void bch2_stripes_heap_insert(struct bch_fs *, struct stripe *, size_t);
 
+void bch2_do_stripe_deletes(struct bch_fs *);
+
 void bch2_ec_stop_dev(struct bch_fs *, struct bch_dev *);
 
 void bch2_ec_flush_new_stripes(struct bch_fs *);
 
-struct journal_keys;
-int bch2_stripes_read(struct bch_fs *, struct journal_keys *);
-int bch2_stripes_write(struct bch_fs *, unsigned, bool *);
+void bch2_stripes_heap_start(struct bch_fs *);
+
+int bch2_stripes_read(struct bch_fs *);
 
-int bch2_ec_mem_alloc(struct bch_fs *, bool);
+void bch2_stripes_heap_to_text(struct printbuf *, struct bch_fs *);
+void bch2_new_stripes_to_text(struct printbuf *, struct bch_fs *);
 
 void bch2_fs_ec_exit(struct bch_fs *);
+void bch2_fs_ec_init_early(struct bch_fs *);
 int bch2_fs_ec_init(struct bch_fs *);
 
 #endif /* _BCACHEFS_EC_H */