diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-11-25 20:53:51 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:15 -0400 |
commit | 61c8d7c8eb0e0169e04df64fab45c575aaad0739 (patch) | |
tree | ce46b86865189db93f925915d4a030254fd440d4 /fs/bcachefs/ec.h | |
parent | ed1646ca7412151dbdd81f4e4d05437cc99e9c8c (diff) |
bcachefs: Persist stripe blocks_used
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/ec.h')
-rw-r--r-- | fs/bcachefs/ec.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/fs/bcachefs/ec.h b/fs/bcachefs/ec.h index 4a8cade37c7a..7bcbb7e11377 100644 --- a/fs/bcachefs/ec.h +++ b/fs/bcachefs/ec.h @@ -14,6 +14,55 @@ void bch2_stripe_to_text(struct printbuf *, struct bch_fs *, .val_to_text = bch2_stripe_to_text, \ } +static inline unsigned stripe_csums_per_device(const struct bch_stripe *s) +{ + return DIV_ROUND_UP(le16_to_cpu(s->sectors), + 1 << s->csum_granularity_bits); +} + +static inline unsigned stripe_csum_offset(const struct bch_stripe *s, + unsigned dev, unsigned csum_idx) +{ + unsigned csum_bytes = bch_crc_bytes[s->csum_type]; + + return sizeof(struct bch_stripe) + + sizeof(struct bch_extent_ptr) * s->nr_blocks + + (dev * stripe_csums_per_device(s) + csum_idx) * csum_bytes; +} + +static inline unsigned stripe_blockcount_offset(const struct bch_stripe *s, + unsigned idx) +{ + return stripe_csum_offset(s, s->nr_blocks, 0) + + sizeof(u16) * idx; +} + +static inline unsigned stripe_blockcount_get(const struct bch_stripe *s, + unsigned idx) +{ + return le16_to_cpup((void *) s + stripe_blockcount_offset(s, idx)); +} + +static inline void stripe_blockcount_set(struct bch_stripe *s, + unsigned idx, unsigned v) +{ + __le16 *p = (void *) s + stripe_blockcount_offset(s, idx); + + *p = cpu_to_le16(v); +} + +static inline unsigned stripe_val_u64s(const struct bch_stripe *s) +{ + return DIV_ROUND_UP(stripe_blockcount_offset(s, s->nr_blocks), + sizeof(u64)); +} + +static inline void *stripe_csum(struct bch_stripe *s, + unsigned dev, unsigned csum_idx) +{ + return (void *) s + stripe_csum_offset(s, dev, csum_idx); +} + struct bch_read_bio; struct ec_stripe_buf { @@ -101,6 +150,9 @@ void bch2_ec_stop_dev(struct bch_fs *, struct bch_dev *); void bch2_ec_flush_new_stripes(struct bch_fs *); +int bch2_stripes_read(struct bch_fs *, struct list_head *); +int bch2_stripes_write(struct bch_fs *, bool *); + int bch2_ec_mem_alloc(struct bch_fs *, bool); int bch2_fs_ec_start(struct bch_fs *); |