X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libbcachefs%2Fec.h;h=7d0237c9819f1a42561f5ec81512e1c4278d12fd;hb=7fd6c3ffe45b3b42c0bc8a8c5d1387a5e3316a54;hp=78d468c7680a2f167070297392dbcabba1204f95;hpb=38f8daa2b17627488c51f2e0c150213bd1636e00;p=bcachefs-tools-debian diff --git a/libbcachefs/ec.h b/libbcachefs/ec.h index 78d468c..7d0237c 100644 --- a/libbcachefs/ec.h +++ b/libbcachefs/ec.h @@ -4,17 +4,23 @@ #include "ec_types.h" #include "buckets_types.h" -#include "keylist_types.h" +#include "extents_types.h" -const char *bch2_stripe_invalid(const struct bch_fs *, struct bkey_s_c); +enum bkey_invalid_flags; + +int bch2_stripe_invalid(struct bch_fs *, struct bkey_s_c, + enum bkey_invalid_flags, 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, \ + .min_val_size = 8, \ +}) static inline unsigned stripe_csums_per_device(const struct bch_stripe *s) { @@ -132,23 +138,29 @@ struct ec_stripe_buf { void *data[BCH_BKEY_PTRS_MAX]; - union { - struct bkey_i_stripe key; - u64 pad[255]; - }; + __BKEY_PADDED(key, 255); }; 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; struct mutex lock; struct list_head list; + + struct hlist_node hash; + u64 idx; + struct closure iodone; - /* counts in flight writes, stripe is created when pin == 0 */ - atomic_t pin; + atomic_t ref[STRIPE_REF_NR]; int err; @@ -163,9 +175,6 @@ struct ec_stripe_new { 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 new_stripe; struct ec_stripe_buf existing_stripe; }; @@ -177,7 +186,7 @@ struct ec_stripe_head { unsigned target; unsigned algo; unsigned redundancy; - bool copygc; + enum bch_watermark watermark; struct bch_devs_mask devs; unsigned nr_active_devs; @@ -190,30 +199,54 @@ struct ec_stripe_head { struct ec_stripe_new *s; }; -int bch2_ec_read_extent(struct bch_fs *, struct bch_read_bio *); +int bch2_ec_read_extent(struct btree_trans *, struct bch_read_bio *); void *bch2_writepoint_ec_buf(struct bch_fs *, struct write_point *); -void bch2_ob_add_backpointer(struct bch_fs *, struct open_bucket *, - struct bkey *); -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 bch_fs *, struct ec_stripe_head *); -struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *, - unsigned, unsigned, unsigned, bool, struct closure *); +struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *, + unsigned, unsigned, unsigned, + enum bch_watermark, 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_ec_stop_dev(struct bch_fs *, struct bch_dev *); +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 *); -void bch2_ec_flush_new_stripes(struct bch_fs *); +static inline void ec_stripe_new_get(struct ec_stripe_new *s, + enum ec_stripe_ref ref) +{ + atomic_inc(&s->ref[ref]); +} -void bch2_stripes_heap_start(struct bch_fs *); +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->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: + BUG(); + } +} + +void bch2_ec_stop_dev(struct bch_fs *, struct bch_dev *); +void bch2_fs_ec_stop(struct bch_fs *); +void bch2_fs_ec_flush(struct bch_fs *); int bch2_stripes_read(struct bch_fs *); @@ -221,6 +254,7 @@ 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 */