diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2017-11-24 20:45:36 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-05-22 00:44:18 -0400 |
commit | 7f41527668271cd50e1f454282ad98f552fdc47d (patch) | |
tree | 8924ab57524cd882f6491f58ef21f7daaf5fa9a1 | |
parent | 8b278343fee9ddcce2ca1c93429138dd7d3e1229 (diff) |
bcachefs: struct bch_extent_crc_unpacked
-rw-r--r-- | fs/bcachefs/buckets.c | 14 | ||||
-rw-r--r-- | fs/bcachefs/compress.c | 22 | ||||
-rw-r--r-- | fs/bcachefs/compress.h | 6 | ||||
-rw-r--r-- | fs/bcachefs/extents.c | 261 | ||||
-rw-r--r-- | fs/bcachefs/extents.h | 314 | ||||
-rw-r--r-- | fs/bcachefs/extents_types.h | 23 | ||||
-rw-r--r-- | fs/bcachefs/fs-io.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/fs-io.h | 2 | ||||
-rw-r--r-- | fs/bcachefs/fs.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/io.c | 70 | ||||
-rw-r--r-- | fs/bcachefs/io_types.h | 9 | ||||
-rw-r--r-- | fs/bcachefs/sysfs.c | 8 |
12 files changed, 324 insertions, 415 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 6fdbb464069d..8953e9e29f11 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -405,13 +405,13 @@ void bch2_mark_metadata_bucket(struct bch_dev *ca, struct bucket *g, /* Reverting this until the copygc + compression issue is fixed: */ -static int __disk_sectors(const union bch_extent_crc *crc, unsigned sectors) +static int __disk_sectors(struct bch_extent_crc_unpacked crc, unsigned sectors) { if (!sectors) return 0; - return max(1U, DIV_ROUND_UP(sectors * crc_compressed_size(NULL, crc), - crc_uncompressed_size(NULL, crc))); + return max(1U, DIV_ROUND_UP(sectors * crc.compressed_size, + crc.uncompressed_size)); } /* @@ -421,8 +421,8 @@ static int __disk_sectors(const union bch_extent_crc *crc, unsigned sectors) */ static void bch2_mark_pointer(struct bch_fs *c, struct bkey_s_c_extent e, - const union bch_extent_crc *crc, const struct bch_extent_ptr *ptr, + struct bch_extent_crc_unpacked crc, s64 sectors, enum s_alloc type, struct bch_fs_usage *stats, u64 journal_seq, unsigned flags) @@ -435,7 +435,7 @@ static void bch2_mark_pointer(struct bch_fs *c, ? BUCKET_BTREE : BUCKET_DATA; u64 v; - if (crc_compression_type(crc)) { + if (crc.compression_type) { unsigned old_sectors, new_sectors; if (sectors > 0) { @@ -541,7 +541,7 @@ static void bch2_mark_extent(struct bch_fs *c, struct bkey_s_c_extent e, u64 journal_seq, unsigned flags) { const struct bch_extent_ptr *ptr; - const union bch_extent_crc *crc; + struct bch_extent_crc_unpacked crc; enum s_alloc type = metadata ? S_META : S_DIRTY; unsigned replicas = 0; @@ -549,7 +549,7 @@ static void bch2_mark_extent(struct bch_fs *c, struct bkey_s_c_extent e, BUG_ON(!sectors); extent_for_each_ptr_crc(e, ptr, crc) { - bch2_mark_pointer(c, e, crc, ptr, sectors, type, + bch2_mark_pointer(c, e, ptr, crc, sectors, type, stats, journal_seq, flags); replicas += !ptr->cached; } diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c index 7b45bb789b36..601fec1fed7e 100644 --- a/fs/bcachefs/compress.c +++ b/fs/bcachefs/compress.c @@ -145,11 +145,11 @@ static inline void zlib_set_workspace(z_stream *strm, void *workspace) } static int __bio_uncompress(struct bch_fs *c, struct bio *src, - void *dst_data, struct bch_extent_crc128 crc) + void *dst_data, struct bch_extent_crc_unpacked crc) { struct bbuf src_data = { NULL }; size_t src_len = src->bi_iter.bi_size; - size_t dst_len = crc_uncompressed_size(NULL, &crc) << 9; + size_t dst_len = crc.uncompressed_size << 9; int ret; src_data = bio_map_or_bounce(c, src, READ); @@ -212,17 +212,17 @@ err: } int bch2_bio_uncompress_inplace(struct bch_fs *c, struct bio *bio, - unsigned live_data_sectors, - struct bch_extent_crc128 crc) + unsigned live_data_sectors, + struct bch_extent_crc_unpacked crc) { struct bbuf dst_data = { NULL }; - size_t dst_len = crc_uncompressed_size(NULL, &crc) << 9; + size_t dst_len = crc.uncompressed_size << 9; int ret = -ENOMEM; BUG_ON(DIV_ROUND_UP(live_data_sectors, PAGE_SECTORS) > bio->bi_max_vecs); - if (crc_uncompressed_size(NULL, &crc) > c->sb.encoded_extent_max || - crc_compressed_size(NULL, &crc) > c->sb.encoded_extent_max) + if (crc.uncompressed_size > c->sb.encoded_extent_max || + crc.compressed_size > c->sb.encoded_extent_max) return -EIO; dst_data = __bounce_alloc(c, dst_len, WRITE); @@ -263,14 +263,14 @@ use_mempool: int bch2_bio_uncompress(struct bch_fs *c, struct bio *src, struct bio *dst, struct bvec_iter dst_iter, - struct bch_extent_crc128 crc) + struct bch_extent_crc_unpacked crc) { struct bbuf dst_data = { NULL }; - size_t dst_len = crc_uncompressed_size(NULL, &crc) << 9; + size_t dst_len = crc.uncompressed_size << 9; int ret = -ENOMEM; - if (crc_uncompressed_size(NULL, &crc) > c->sb.encoded_extent_max || - crc_compressed_size(NULL, &crc) > c->sb.encoded_extent_max) + if (crc.uncompressed_size > c->sb.encoded_extent_max || + crc.compressed_size > c->sb.encoded_extent_max) return -EIO; dst_data = dst_len == dst_iter.bi_size diff --git a/fs/bcachefs/compress.h b/fs/bcachefs/compress.h index ad1ba25defec..72c5d2f3d4f5 100644 --- a/fs/bcachefs/compress.h +++ b/fs/bcachefs/compress.h @@ -1,10 +1,12 @@ #ifndef _BCACHEFS_COMPRESS_H #define _BCACHEFS_COMPRESS_H +#include "extents_types.h" + int bch2_bio_uncompress_inplace(struct bch_fs *, struct bio *, - unsigned, struct bch_extent_crc128); + unsigned, struct bch_extent_crc_unpacked); int bch2_bio_uncompress(struct bch_fs *, struct bio *, struct bio *, - struct bvec_iter, struct bch_extent_crc128); + struct bvec_iter, struct bch_extent_crc_unpacked); void bch2_bio_compress(struct bch_fs *, struct bio *, size_t *, struct bio *, size_t *, unsigned *); diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c index 7d2f5ccbaad5..756054b7ee11 100644 --- a/fs/bcachefs/extents.c +++ b/fs/bcachefs/extents.c @@ -155,6 +155,28 @@ unsigned bch2_extent_nr_dirty_ptrs(struct bkey_s_c k) return nr_ptrs; } +unsigned bch2_extent_is_compressed(struct bkey_s_c k) +{ + struct bkey_s_c_extent e; + const struct bch_extent_ptr *ptr; + struct bch_extent_crc_unpacked crc; + unsigned ret = 0; + + switch (k.k->type) { + case BCH_EXTENT: + case BCH_EXTENT_CACHED: + e = bkey_s_c_to_extent(k); + + extent_for_each_ptr_crc(e, ptr, crc) + if (!ptr->cached && + crc.compression_type != BCH_COMPRESSION_NONE && + crc.compressed_size < k.k->size) + ret = max_t(unsigned, ret, crc.compressed_size); + } + + return ret; +} + /* Doesn't cleanup redundant crcs */ void __bch2_extent_drop_ptr(struct bkey_s_extent e, struct bch_extent_ptr *ptr) { @@ -194,15 +216,17 @@ static bool crc_cmp(union bch_extent_crc *l, union bch_extent_crc *r) } /* Increment pointers after @crc by crc's offset until the next crc entry: */ -void bch2_extent_crc_narrow_pointers(struct bkey_s_extent e, union bch_extent_crc *crc) +void bch2_extent_crc_narrow_pointers(struct bkey_s_extent e, + union bch_extent_entry *from, + struct bch_extent_crc_unpacked crc) { union bch_extent_entry *entry; - extent_for_each_entry_from(e, entry, extent_entry_next(to_entry(crc))) { + extent_for_each_entry_from(e, entry, extent_entry_next(from)) { if (!extent_entry_is_ptr(entry)) return; - entry->ptr.offset += crc_offset(crc); + entry->ptr.offset += crc.offset; } } @@ -231,33 +255,41 @@ void bch2_extent_crc_narrow_pointers(struct bkey_s_extent e, union bch_extent_cr */ void bch2_extent_narrow_crcs(struct bkey_s_extent e) { + struct bch_extent_crc_unpacked u; union bch_extent_crc *crc; + union bch_extent_entry *i; bool have_wide = false, have_narrow = false; struct bch_csum csum = { 0 }; unsigned csum_type = 0; - extent_for_each_crc(e, crc) { - if (crc_compression_type(crc) || - bch2_csum_type_is_encryption(crc_csum_type(crc))) + extent_for_each_crc(e, u, i) { + if (u.compression_type || + bch2_csum_type_is_encryption(u.csum_type)) continue; - if (crc_uncompressed_size(e.k, crc) != e.k->size) { + if (u.uncompressed_size != e.k->size) { have_wide = true; } else { have_narrow = true; - csum = crc_csum(crc); - csum_type = crc_csum_type(crc); + csum = u.csum; + csum_type = u.csum_type; } } if (!have_wide || !have_narrow) return; - extent_for_each_crc(e, crc) { - if (crc_compression_type(crc)) + extent_for_each_entry(e, i) { + if (!extent_entry_is_crc(i)) + continue; + + crc = entry_to_crc(i); + u = bch2_extent_crc_unpack(e.k, crc); + + if (u.compression_type) continue; - if (crc_uncompressed_size(e.k, crc) != e.k->size) { + if (u.uncompressed_size != e.k->size) { switch (extent_crc_type(crc)) { case BCH_EXTENT_CRC_NONE: BUG(); @@ -265,7 +297,7 @@ void bch2_extent_narrow_crcs(struct bkey_s_extent e) if (bch_crc_bytes[csum_type] > 4) continue; - bch2_extent_crc_narrow_pointers(e, crc); + bch2_extent_crc_narrow_pointers(e, i, u); crc->crc32._compressed_size = e.k->size - 1; crc->crc32._uncompressed_size = e.k->size - 1; crc->crc32.offset = 0; @@ -276,7 +308,7 @@ void bch2_extent_narrow_crcs(struct bkey_s_extent e) if (bch_crc_bytes[csum_type] > 10) continue; - bch2_extent_crc_narrow_pointers(e, crc); + bch2_extent_crc_narrow_pointers(e, i, u); crc->crc64._compressed_size = e.k->size - 1; crc->crc64._uncompressed_size = e.k->size - 1; crc->crc64.offset = 0; @@ -288,7 +320,7 @@ void bch2_extent_narrow_crcs(struct bkey_s_extent e) if (bch_crc_bytes[csum_type] > 16) continue; - bch2_extent_crc_narrow_pointers(e, crc); + bch2_extent_crc_narrow_pointers(e, i, u); crc->crc128._compressed_size = e.k->size - 1; crc->crc128._uncompressed_size = e.k->size - 1; crc->crc128.offset = 0; @@ -304,6 +336,7 @@ void bch2_extent_drop_redundant_crcs(struct bkey_s_extent e) { union bch_extent_entry *entry = e.v->start; union bch_extent_crc *crc, *prev = NULL; + struct bch_extent_crc_unpacked u; while (entry != extent_entry_last(e)) { union bch_extent_entry *next = extent_entry_next(entry); @@ -313,6 +346,7 @@ void bch2_extent_drop_redundant_crcs(struct bkey_s_extent e) goto next; crc = entry_to_crc(entry); + u = bch2_extent_crc_unpack(e.k, crc); if (next == extent_entry_last(e)) { /* crc entry with no pointers after it: */ @@ -330,10 +364,10 @@ void bch2_extent_drop_redundant_crcs(struct bkey_s_extent e) } if (!prev && - !crc_csum_type(crc) && - !crc_compression_type(crc)) { + !u.csum_type && + !u.compression_type) { /* null crc entry: */ - bch2_extent_crc_narrow_pointers(e, crc); + bch2_extent_crc_narrow_pointers(e, entry, u); goto drop; } @@ -453,7 +487,7 @@ static size_t extent_print_ptrs(struct bch_fs *c, char *buf, { char *out = buf, *end = buf + size; const union bch_extent_entry *entry; - const union bch_extent_crc *crc; + struct bch_extent_crc_unpacked crc; const struct bch_extent_ptr *ptr; struct bch_dev *ca; bool first = true; @@ -468,13 +502,13 @@ static size_t extent_print_ptrs(struct bch_fs *c, char *buf, case BCH_EXTENT_ENTRY_crc32: case BCH_EXTENT_ENTRY_crc64: case BCH_EXTENT_ENTRY_crc128: - crc = entry_to_crc(entry); + crc = bch2_extent_crc_unpack(e.k, entry_to_crc(entry)); p("crc: c_size %u size %u offset %u csum %u compress %u", - crc_compressed_size(e.k, crc), - crc_uncompressed_size(e.k, crc), - crc_offset(crc), crc_csum_type(crc), - crc_compression_type(crc)); + crc.compressed_size, + crc.uncompressed_size, + crc.offset, crc.csum_type, + crc.compression_type); break; case BCH_EXTENT_ENTRY_ptr: ptr = entry_to_ptr(entry); @@ -504,8 +538,8 @@ static void extent_pick_read_device(struct bch_fs *c, struct bch_devs_mask *avoid, struct extent_pick_ptr *pick) { - const union bch_extent_crc *crc; const struct bch_extent_ptr *ptr; + struct bch_extent_crc_unpacked crc; extent_for_each_ptr_crc(e, ptr, crc) { struct bch_dev *ca = c->devs[ptr->dev]; @@ -530,11 +564,9 @@ static void extent_pick_read_device(struct bch_fs *c, *pick = (struct extent_pick_ptr) { .ptr = *ptr, + .crc = crc, .ca = ca, }; - - if (e.k->size) - pick->crc = crc_to_128(e.k, crc); } } @@ -557,14 +589,17 @@ static const char *bch2_btree_ptr_invalid(const struct bch_fs *c, struct bkey_s_c_extent e = bkey_s_c_to_extent(k); const union bch_extent_entry *entry; const struct bch_extent_ptr *ptr; - const union bch_extent_crc *crc; const char *reason; - extent_for_each_entry(e, entry) + extent_for_each_entry(e, entry) { if (__extent_entry_type(entry) >= BCH_EXTENT_ENTRY_MAX) return "invalid extent entry type"; - extent_for_each_ptr_crc(e, ptr, crc) { + if (extent_entry_is_crc(entry)) + return "has crc field"; + } + + extent_for_each_ptr(e, ptr) { reason = extent_ptr_invalid(c, e, ptr, c->opts.btree_node_size, true); @@ -572,9 +607,6 @@ static const char *bch2_btree_ptr_invalid(const struct bch_fs *c, return reason; } - if (crc) - return "has crc field"; - return NULL; } @@ -699,28 +731,28 @@ static bool __bch2_cut_front(struct bpos where, struct bkey_s k) __set_bkey_deleted(k.k); else if (bkey_extent_is_data(k.k)) { struct bkey_s_extent e = bkey_s_to_extent(k); - struct bch_extent_ptr *ptr; - union bch_extent_crc *crc, *prev_crc = NULL; + union bch_extent_entry *entry; + bool seen_crc = false; - extent_for_each_ptr_crc(e, ptr, crc) { - switch (extent_crc_type(crc)) { - case BCH_EXTENT_CRC_NONE: - ptr->offset += e.k->size - len; + extent_for_each_entry(e, entry) { + switch (extent_entry_type(entry)) { + case BCH_EXTENT_ENTRY_ptr: + if (!seen_crc) + entry->ptr.offset += e.k->size - len; break; - case BCH_EXTENT_CRC32: - if (prev_crc != crc) - crc->crc32.offset += e.k->size - len; + case BCH_EXTENT_ENTRY_crc32: + entry->crc32.offset += e.k->size - len; break; - case BCH_EXTENT_CRC64: - if (prev_crc != crc) - crc->crc64.offset += e.k->size - len; + case BCH_EXTENT_ENTRY_crc64: + entry->crc64.offset += e.k->size - len; break; - case BCH_EXTENT_CRC128: - if (prev_crc != crc) - crc->crc128.offset += e.k->size - len; + case BCH_EXTENT_ENTRY_crc128: + entry->crc128.offset += e.k->size - len; break; } - prev_crc = crc; + + if (extent_entry_is_crc(entry)) + seen_crc = true; } } @@ -1123,7 +1155,7 @@ static void extent_insert_committed(struct extent_insert_state *s) if (!(s->trans->flags & BTREE_INSERT_JOURNAL_REPLAY) && bkey_cmp(s->committed, insert->k.p) && - bkey_extent_is_compressed(bkey_i_to_s_c(insert))) { + bch2_extent_is_compressed(bkey_i_to_s_c(insert))) { /* XXX: possibly need to increase our reservation? */ bch2_cut_subtract_back(s, s->committed, bkey_i_to_s(&split.k)); @@ -1245,7 +1277,7 @@ extent_insert_check_split_compressed(struct extent_insert_state *s, unsigned sectors; if (overlap == BCH_EXTENT_OVERLAP_MIDDLE && - (sectors = bkey_extent_is_compressed(k))) { + (sectors = bch2_extent_is_compressed(k))) { int flags = BCH_DISK_RESERVATION_BTREE_LOCKS_HELD; if (s->trans->flags & BTREE_INSERT_NOFAIL) @@ -1669,7 +1701,7 @@ static const char *bch2_extent_invalid(const struct bch_fs *c, case BCH_EXTENT_CACHED: { struct bkey_s_c_extent e = bkey_s_c_to_extent(k); const union bch_extent_entry *entry; - const union bch_extent_crc *crc; + struct bch_extent_crc_unpacked crc; const struct bch_extent_ptr *ptr; unsigned size_ondisk = e.k->size; const char *reason; @@ -1679,18 +1711,18 @@ static const char *bch2_extent_invalid(const struct bch_fs *c, return "invalid extent entry type"; if (extent_entry_is_crc(entry)) { - crc = entry_to_crc(entry); + crc = bch2_extent_crc_unpack(e.k, entry_to_crc(entry)); - if (crc_offset(crc) + e.k->size > - crc_uncompressed_size(e.k, crc)) + if (crc.offset + e.k->size > + crc.uncompressed_size) return "checksum offset + key size > uncompressed size"; - size_ondisk = crc_compressed_size(e.k, crc); + size_ondisk = crc.compressed_size; - if (!bch2_checksum_type_valid(c, crc_csum_type(crc))) + if (!bch2_checksum_type_valid(c, crc.csum_type)) return "invalid checksum type"; - if (crc_compression_type(crc) >= BCH_COMPRESSION_NR) + if (crc.compression_type >= BCH_COMPRESSION_NR) return "invalid compression type"; } else { ptr = entry_to_ptr(entry); @@ -1864,56 +1896,52 @@ static unsigned PTR_TIER(struct bch_fs *c, } static void bch2_extent_crc_init(union bch_extent_crc *crc, - unsigned compressed_size, - unsigned uncompressed_size, - unsigned compression_type, - unsigned nonce, - struct bch_csum csum, unsigned csum_type) -{ - if (bch_crc_bytes[csum_type] <= 4 && - uncompressed_size <= CRC32_SIZE_MAX && - nonce <= CRC32_NONCE_MAX) { + struct bch_extent_crc_unpacked new) +{ + if (bch_crc_bytes[new.csum_type] <= 4 && + new.uncompressed_size <= CRC32_SIZE_MAX && + new.nonce <= CRC32_NONCE_MAX) { crc->crc32 = (struct bch_extent_crc32) { .type = 1 << BCH_EXTENT_ENTRY_crc32, - ._compressed_size = compressed_size - 1, - ._uncompressed_size = uncompressed_size - 1, - .offset = 0, - .compression_type = compression_type, - .csum_type = csum_type, - .csum = *((__le32 *) &csum.lo), + .csum_type = new.csum_type, + .compression_type = new.compression_type, + ._compressed_size = new.compressed_size - 1, + ._uncompressed_size = new.uncompressed_size - 1, + .offset = new.offset, + .csum = *((__le32 *) &new.csum.lo), }; return; } - if (bch_crc_bytes[csum_type] <= 10 && - uncompressed_size <= CRC64_SIZE_MAX && - nonce <= CRC64_NONCE_MAX) { + if (bch_crc_bytes[new.csum_type] <= 10 && + new.uncompressed_size <= CRC64_SIZE_MAX && + new.nonce <= CRC64_NONCE_MAX) { crc->crc64 = (struct bch_extent_crc64) { .type = 1 << BCH_EXTENT_ENTRY_crc64, - ._compressed_size = compressed_size - 1, - ._uncompressed_size = uncompressed_size - 1, - .offset = 0, - .nonce = nonce, - .compression_type = compression_type, - .csum_type = csum_type, - .csum_lo = csum.lo, - .csum_hi = *((__le16 *) &csum.hi), + .csum_type = new.csum_type, + .compression_type = new.compression_type, + ._compressed_size = new.compressed_size - 1, + ._uncompressed_size = new.uncompressed_size - 1, + .offset = new.offset, + .nonce = new.nonce, + .csum_lo = new.csum.lo, + .csum_hi = *((__le16 *) &new.csum.hi), }; return; } - if (bch_crc_bytes[csum_type] <= 16 && - uncompressed_size <= CRC128_SIZE_MAX && - nonce <= CRC128_NONCE_MAX) { + if (bch_crc_bytes[new.csum_type] <= 16 && + new.uncompressed_size <= CRC128_SIZE_MAX && + new.nonce <= CRC128_NONCE_MAX) { crc->crc128 = (struct bch_extent_crc128) { .type = 1 << BCH_EXTENT_ENTRY_crc128, - ._compressed_size = compressed_size - 1, - ._uncompressed_size = uncompressed_size - 1, - .offset = 0, - .nonce = nonce, - .compression_type = compression_type, - .csum_type = csum_type, - .csum = csum, + .csum_type = new.csum_type, + .compression_type = new.compression_type, + ._compressed_size = new.compressed_size - 1, + ._uncompressed_size = new.uncompressed_size - 1, + .offset = new.offset, + .nonce = new.nonce, + .csum = new.csum, }; return; } @@ -1922,44 +1950,33 @@ static void bch2_extent_crc_init(union bch_extent_crc *crc, } void bch2_extent_crc_append(struct bkey_i_extent *e, - unsigned compressed_size, - unsigned uncompressed_size, - unsigned compression_type, - unsigned nonce, - struct bch_csum csum, unsigned csum_type) + struct bch_extent_crc_unpacked new) { - union bch_extent_crc *crc; + struct bch_extent_crc_unpacked crc; + const union bch_extent_entry *i; - BUG_ON(compressed_size > uncompressed_size); - BUG_ON(uncompressed_size != e->k.size); - BUG_ON(!compressed_size || !uncompressed_size); + BUG_ON(new.compressed_size > new.uncompressed_size); + BUG_ON(new.offset); + BUG_ON(new.uncompressed_size != e->k.size); + BUG_ON(!new.compressed_size || !new.uncompressed_size); /* * Look up the last crc entry, so we can check if we need to add * another: */ - extent_for_each_crc(extent_i_to_s(e), crc) + extent_for_each_crc(extent_i_to_s(e), crc, i) ; - if (!crc && !csum_type && !compression_type) - return; - - if (crc && - crc_compressed_size(&e->k, crc) == compressed_size && - crc_uncompressed_size(&e->k, crc) == uncompressed_size && - crc_offset(crc) == 0 && - crc_nonce(crc) == nonce && - crc_csum_type(crc) == csum_type && - crc_compression_type(crc) == compression_type && - crc_csum(crc).lo == csum.lo && - crc_csum(crc).hi == csum.hi) + if (crc.csum_type == new.csum_type && + crc.compression_type == new.compression_type && + crc.compressed_size == new.compressed_size && + crc.uncompressed_size == new.uncompressed_size && + crc.offset == new.offset && + crc.nonce == new.nonce && + !bch2_crc_cmp(crc.csum, new.csum)) return; - bch2_extent_crc_init((void *) extent_entry_last(extent_i_to_s(e)), - compressed_size, - uncompressed_size, - compression_type, - nonce, csum, csum_type); + bch2_extent_crc_init((void *) extent_entry_last(extent_i_to_s(e)), new); __extent_entry_push(e); } diff --git a/fs/bcachefs/extents.h b/fs/bcachefs/extents.h index 634159f27958..32f820c451d4 100644 --- a/fs/bcachefs/extents.h +++ b/fs/bcachefs/extents.h @@ -3,7 +3,7 @@ #include "bcachefs.h" #include "bkey.h" -#include "io_types.h" +#include "extents_types.h" struct bch_fs; struct journal_res; @@ -43,6 +43,7 @@ void bch2_extent_mark_replicas_cached(struct bch_fs *, unsigned bch2_extent_nr_ptrs(struct bkey_s_c_extent); unsigned bch2_extent_nr_dirty_ptrs(struct bkey_s_c); +unsigned bch2_extent_is_compressed(struct bkey_s_c); static inline bool bkey_extent_is_data(const struct bkey *k) { @@ -170,6 +171,8 @@ union bch_extent_crc { (struct bch_extent_ptr *) (_entry)); \ }) +/* checksum entries: */ + enum bch_extent_crc_type { BCH_EXTENT_CRC_NONE, BCH_EXTENT_CRC32, @@ -208,6 +211,52 @@ __extent_crc_type(const union bch_extent_crc *crc) : __extent_crc_type((union bch_extent_crc *) _crc); \ }) +static inline struct bch_extent_crc_unpacked +bch2_extent_crc_unpack(const struct bkey *k, const union bch_extent_crc *crc) +{ + switch (extent_crc_type(crc)) { + case BCH_EXTENT_CRC_NONE: + return (struct bch_extent_crc_unpacked) { + .compressed_size = k->size, + .uncompressed_size = k->size, + }; + case BCH_EXTENT_CRC32: + return (struct bch_extent_crc_unpacked) { + .csum_type = crc->crc32.csum_type, + .compression_type = crc->crc32.compression_type, + .compressed_size = crc->crc32._compressed_size + 1, + .uncompressed_size = crc->crc32._uncompressed_size + 1, + .offset = crc->crc32.offset, + .csum.lo = crc->crc32.csum, + }; + case BCH_EXTENT_CRC64: + return (struct bch_extent_crc_unpacked) { + .csum_type = crc->crc64.csum_type, + .compression_type = crc->crc64.compression_type, + .compressed_size = crc->crc64._compressed_size + 1, + .uncompressed_size = crc->crc64._uncompressed_size + 1, + .offset = crc->crc64.offset, + .nonce = crc->crc64.nonce, + .csum.lo = crc->crc64.csum_lo, + .csum.hi = crc->crc64.csum_hi, + }; + case BCH_EXTENT_CRC128: + return (struct bch_extent_crc_unpacked) { + .csum_type = crc->crc128.csum_type, + .compression_type = crc->crc128.compression_type, + .compressed_size = crc->crc128._compressed_size + 1, + .uncompressed_size = crc->crc128._uncompressed_size + 1, + .offset = crc->crc128.offset, + .nonce = crc->crc128.nonce, + .csum = crc->crc128.csum, + }; + default: + BUG(); + } +} + +/* Extent entry iteration: */ + #define extent_entry_next(_entry) \ ((typeof(_entry)) ((void *) (_entry) + extent_entry_bytes(_entry))) @@ -226,7 +275,7 @@ __extent_crc_type(const union bch_extent_crc *crc) /* Iterate over crcs only: */ -#define extent_crc_next(_e, _p) \ +#define __extent_crc_next(_e, _p) \ ({ \ typeof(&(_e).v->start[0]) _entry = _p; \ \ @@ -237,25 +286,41 @@ __extent_crc_type(const union bch_extent_crc *crc) entry_to_crc(_entry < extent_entry_last(_e) ? _entry : NULL); \ }) -#define extent_for_each_crc(_e, _crc) \ - for ((_crc) = extent_crc_next(_e, (_e).v->start); \ +#define __extent_for_each_crc(_e, _crc) \ + for ((_crc) = __extent_crc_next(_e, (_e).v->start); \ (_crc); \ - (_crc) = extent_crc_next(_e, extent_entry_next(to_entry(_crc)))) + (_crc) = __extent_crc_next(_e, extent_entry_next(to_entry(_crc)))) + +#define extent_crc_next(_e, _crc, _iter) \ +({ \ + extent_for_each_entry_from(_e, _iter, _iter) \ + if (extent_entry_is_crc(_iter)) { \ + (_crc) = bch2_extent_crc_unpack((_e).k, entry_to_crc(_iter));\ + break; \ + } \ + \ + (_iter) < extent_entry_last(_e); \ +}) + +#define extent_for_each_crc(_e, _crc, _iter) \ + for ((_crc) = bch2_extent_crc_unpack((_e).k, NULL), \ + (_iter) = (_e).v->start; \ + extent_crc_next(_e, _crc, _iter); \ + (_iter) = extent_entry_next(_iter)) /* Iterate over pointers, with crcs: */ -#define extent_ptr_crc_next_filter(_e, _crc, _ptr, _filter) \ +#define extent_ptr_crc_next(_e, _ptr, _crc) \ ({ \ __label__ out; \ typeof(&(_e).v->start[0]) _entry; \ \ extent_for_each_entry_from(_e, _entry, to_entry(_ptr)) \ if (extent_entry_is_crc(_entry)) { \ - (_crc) = entry_to_crc(_entry); \ + (_crc) = bch2_extent_crc_unpack((_e).k, entry_to_crc(_entry));\ } else { \ _ptr = entry_to_ptr(_entry); \ - if (_filter) \ - goto out; \ + goto out; \ } \ \ _ptr = NULL; \ @@ -263,35 +328,26 @@ out: \ _ptr; \ }) -#define extent_for_each_ptr_crc_filter(_e, _ptr, _crc, _filter) \ - for ((_crc) = NULL, \ +#define extent_for_each_ptr_crc(_e, _ptr, _crc) \ + for ((_crc) = bch2_extent_crc_unpack((_e).k, NULL), \ (_ptr) = &(_e).v->start->ptr; \ - ((_ptr) = extent_ptr_crc_next_filter(_e, _crc, _ptr, _filter));\ + ((_ptr) = extent_ptr_crc_next(_e, _ptr, _crc)); \ (_ptr)++) -#define extent_for_each_ptr_crc(_e, _ptr, _crc) \ - extent_for_each_ptr_crc_filter(_e, _ptr, _crc, true) - /* Iterate over pointers only, and from a given position: */ -#define extent_ptr_next_filter(_e, _ptr, _filter) \ +#define extent_ptr_next(_e, _ptr) \ ({ \ - typeof(__entry_to_crc(&(_e).v->start[0])) _crc; \ + struct bch_extent_crc_unpacked _crc; \ \ - extent_ptr_crc_next_filter(_e, _crc, _ptr, _filter); \ + extent_ptr_crc_next(_e, _ptr, _crc); \ }) -#define extent_ptr_next(_e, _ptr) \ - extent_ptr_next_filter(_e, _ptr, true) - -#define extent_for_each_ptr_filter(_e, _ptr, _filter) \ +#define extent_for_each_ptr(_e, _ptr) \ for ((_ptr) = &(_e).v->start->ptr; \ - ((_ptr) = extent_ptr_next_filter(_e, _ptr, _filter)); \ + ((_ptr) = extent_ptr_next(_e, _ptr)); \ (_ptr)++) -#define extent_for_each_ptr(_e, _ptr) \ - extent_for_each_ptr_filter(_e, _ptr, true) - #define extent_ptr_prev(_e, _ptr) \ ({ \ typeof(&(_e).v->start->ptr) _p; \ @@ -315,8 +371,8 @@ out: \ (_ptr); \ (_ptr) = extent_ptr_prev(_e, _ptr)) -void bch2_extent_crc_append(struct bkey_i_extent *, unsigned, unsigned, - unsigned, unsigned, struct bch_csum, unsigned); +void bch2_extent_crc_append(struct bkey_i_extent *, + struct bch_extent_crc_unpacked); static inline void __extent_entry_push(struct bkey_i_extent *e) { @@ -336,206 +392,14 @@ static inline void extent_ptr_append(struct bkey_i_extent *e, __extent_entry_push(e); } -static inline struct bch_extent_crc128 crc_to_128(const struct bkey *k, - const union bch_extent_crc *crc) -{ - EBUG_ON(!k->size); - - switch (extent_crc_type(crc)) { - case BCH_EXTENT_CRC_NONE: - return (struct bch_extent_crc128) { - ._compressed_size = k->size - 1, - ._uncompressed_size = k->size - 1, - }; - case BCH_EXTENT_CRC32: - return (struct bch_extent_crc128) { - .type = 1 << BCH_EXTENT_ENTRY_crc128, - ._compressed_size = crc->crc32._compressed_size, - ._uncompressed_size = crc->crc32._uncompressed_size, - .offset = crc->crc32.offset, - .csum_type = crc->crc32.csum_type, - .compression_type = crc->crc32.compression_type, - .csum.lo = crc->crc32.csum, - }; - case BCH_EXTENT_CRC64: - return (struct bch_extent_crc128) { - .type = 1 << BCH_EXTENT_ENTRY_crc128, - ._compressed_size = crc->crc64._compressed_size, - ._uncompressed_size = crc->crc64._uncompressed_size, - .offset = crc->crc64.offset, - .nonce = crc->crc64.nonce, - .csum_type = crc->crc64.csum_type, - .compression_type = crc->crc64.compression_type, - .csum.lo = crc->crc64.csum_lo, - .csum.hi = crc->crc64.csum_hi, - }; - case BCH_EXTENT_CRC128: - return crc->crc128; - default: - BUG(); - } -} - -#define crc_compressed_size(_k, _crc) \ -({ \ - unsigned _size = 0; \ - \ - switch (extent_crc_type(_crc)) { \ - case BCH_EXTENT_CRC_NONE: \ - _size = ((const struct bkey *) (_k))->size; \ - break; \ - case BCH_EXTENT_CRC32: \ - _size = ((struct bch_extent_crc32 *) _crc) \ - ->_compressed_size + 1; \ - break; \ - case BCH_EXTENT_CRC64: \ - _size = ((struct bch_extent_crc64 *) _crc) \ - ->_compressed_size + 1; \ - break; \ - case BCH_EXTENT_CRC128: \ - _size = ((struct bch_extent_crc128 *) _crc) \ - ->_compressed_size + 1; \ - break; \ - } \ - _size; \ -}) - -#define crc_uncompressed_size(_k, _crc) \ -({ \ - unsigned _size = 0; \ - \ - switch (extent_crc_type(_crc)) { \ - case BCH_EXTENT_CRC_NONE: \ - _size = ((const struct bkey *) (_k))->size; \ - break; \ - case BCH_EXTENT_CRC32: \ - _size = ((struct bch_extent_crc32 *) _crc) \ - ->_uncompressed_size + 1; \ - break; \ - case BCH_EXTENT_CRC64: \ - _size = ((struct bch_extent_crc64 *) _crc) \ - ->_uncompressed_size + 1; \ - break; \ - case BCH_EXTENT_CRC128: \ - _size = ((struct bch_extent_crc128 *) _crc) \ - ->_uncompressed_size + 1; \ - break; \ - } \ - _size; \ -}) - -static inline unsigned crc_offset(const union bch_extent_crc *crc) -{ - switch (extent_crc_type(crc)) { - case BCH_EXTENT_CRC_NONE: - return 0; - case BCH_EXTENT_CRC32: - return crc->crc32.offset; - case BCH_EXTENT_CRC64: - return crc->crc64.offset; - case BCH_EXTENT_CRC128: - return crc->crc128.offset; - default: - BUG(); - } -} - -static inline unsigned crc_nonce(const union bch_extent_crc *crc) -{ - switch (extent_crc_type(crc)) { - case BCH_EXTENT_CRC_NONE: - case BCH_EXTENT_CRC32: - return 0; - case BCH_EXTENT_CRC64: - return crc->crc64.nonce; - case BCH_EXTENT_CRC128: - return crc->crc128.nonce; - default: - BUG(); - } -} - -static inline unsigned crc_csum_type(const union bch_extent_crc *crc) -{ - switch (extent_crc_type(crc)) { - case BCH_EXTENT_CRC_NONE: - return 0; - case BCH_EXTENT_CRC32: - return crc->crc32.csum_type; - case BCH_EXTENT_CRC64: - return crc->crc64.csum_type; - case BCH_EXTENT_CRC128: - return crc->crc128.csum_type; - default: - BUG(); - } -} - -static inline unsigned crc_compression_type(const union bch_extent_crc *crc) -{ - switch (extent_crc_type(crc)) { - case BCH_EXTENT_CRC_NONE: - return 0; - case BCH_EXTENT_CRC32: - return crc->crc32.compression_type; - case BCH_EXTENT_CRC64: - return crc->crc64.compression_type; - case BCH_EXTENT_CRC128: - return crc->crc128.compression_type; - default: - BUG(); - } -} - -static inline struct bch_csum crc_csum(const union bch_extent_crc *crc) -{ - switch (extent_crc_type(crc)) { - case BCH_EXTENT_CRC_NONE: - return (struct bch_csum) { 0 }; - case BCH_EXTENT_CRC32: - return (struct bch_csum) { .lo = crc->crc32.csum }; - case BCH_EXTENT_CRC64: - return (struct bch_csum) { - .lo = crc->crc64.csum_lo, - .hi = crc->crc64.csum_hi, - }; - case BCH_EXTENT_CRC128: - return crc->crc128.csum; - default: - BUG(); - } -} - -static inline unsigned bkey_extent_is_compressed(struct bkey_s_c k) -{ - struct bkey_s_c_extent e; - const struct bch_extent_ptr *ptr; - const union bch_extent_crc *crc; - unsigned ret = 0; - - switch (k.k->type) { - case BCH_EXTENT: - case BCH_EXTENT_CACHED: - e = bkey_s_c_to_extent(k); - - extent_for_each_ptr_crc(e, ptr, crc) - if (!ptr->cached && - crc_compression_type(crc) != BCH_COMPRESSION_NONE && - crc_compressed_size(e.k, crc) < k.k->size) - ret = max_t(unsigned, ret, - crc_compressed_size(e.k, crc)); - } - - return ret; -} - static inline unsigned extent_current_nonce(struct bkey_s_c_extent e) { - const union bch_extent_crc *crc; + struct bch_extent_crc_unpacked crc; + const union bch_extent_entry *i; - extent_for_each_crc(e, crc) - if (bch2_csum_type_is_encryption(crc_csum_type(crc))) - return crc_offset(crc) + crc_nonce(crc); + extent_for_each_crc(e, crc, i) + if (bch2_csum_type_is_encryption(crc.csum_type)) + return crc.offset + crc.nonce; return 0; } diff --git a/fs/bcachefs/extents_types.h b/fs/bcachefs/extents_types.h new file mode 100644 index 000000000000..8b229929750d --- /dev/null +++ b/fs/bcachefs/extents_types.h @@ -0,0 +1,23 @@ +#ifndef _BCACHEFS_EXTENTS_TYPES_H +#define _BCACHEFS_EXTENTS_TYPES_H + +#include "bcachefs_format.h" + +struct bch_extent_crc_unpacked { + __u64 csum_type:4, + compression_type:4, + compressed_size:14, + uncompressed_size:14, + offset:14, + nonce:14; + + struct bch_csum csum; +}; + +struct extent_pick_ptr { + struct bch_extent_ptr ptr; + struct bch_extent_crc_unpacked crc; + struct bch_dev *ca; +}; + +#endif /* _BCACHEFS_EXTENTS_TYPES_H */ diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c index 5764bbb34460..f2cd874f8867 100644 --- a/fs/bcachefs/fs-io.c +++ b/fs/bcachefs/fs-io.c @@ -749,7 +749,7 @@ static void bchfs_read(struct bch_fs *c, struct btree_iter *iter, bch2_add_page_sectors(bio, k); if (!bkey_extent_is_allocation(k.k) || - bkey_extent_is_compressed(k)) + bch2_extent_is_compressed(k)) bch2_mark_pages_unalloc(bio); if (pick.ca) { @@ -2318,7 +2318,7 @@ static long bch2_fallocate(struct bch_inode_info *inode, int mode, reservation.v.nr_replicas = bch2_extent_nr_dirty_ptrs(k); if (reservation.v.nr_replicas < replicas || - bkey_extent_is_compressed(k)) { + bch2_extent_is_compressed(k)) { ret = bch2_disk_reservation_get(c, &disk_res, sectors, 0); if (ret) diff --git a/fs/bcachefs/fs-io.h b/fs/bcachefs/fs-io.h index 505cea733f3b..b5a397d4711b 100644 --- a/fs/bcachefs/fs-io.h +++ b/fs/bcachefs/fs-io.h @@ -2,6 +2,8 @@ #define _BCACHEFS_FS_IO_H #include "buckets.h" +#include "io_types.h" + #include <linux/uio.h> int bch2_set_page_dirty(struct page *); diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c index 901be5143af1..923cb569a9ea 100644 --- a/fs/bcachefs/fs.c +++ b/fs/bcachefs/fs.c @@ -654,17 +654,17 @@ static int bch2_fill_extent(struct fiemap_extent_info *info, if (bkey_extent_is_data(&k->k)) { struct bkey_s_c_extent e = bkey_i_to_s_c_extent(k); const struct bch_extent_ptr *ptr; - const union bch_extent_crc *crc; + struct bch_extent_crc_unpacked crc; int ret; extent_for_each_ptr_crc(e, ptr, crc) { int flags2 = 0; u64 offset = ptr->offset; - if (crc_compression_type(crc)) + if (crc.compression_type) flags2 |= FIEMAP_EXTENT_ENCODED; else - offset += crc_offset(crc); + offset += crc.offset; if ((offset & (PAGE_SECTORS - 1)) || (e.k->size & (PAGE_SECTORS - 1))) diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index 88f490a0a1aa..d6004ac300c2 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -324,34 +324,46 @@ static struct nonce extent_nonce(struct bversion version, }}; } -static void init_append_extent(struct bch_write_op *op, - unsigned compressed_size, - unsigned uncompressed_size, - unsigned compression_type, - unsigned nonce, - struct bch_csum csum, unsigned csum_type, - struct open_bucket *ob) +static void __init_append_extent(struct bch_write_op *op, + struct bch_extent_crc_unpacked crc, + struct open_bucket *ob) { struct bkey_i_extent *e = bkey_extent_init(op->insert_keys.top); - op->pos.offset += uncompressed_size; + op->pos.offset += crc.uncompressed_size; e->k.p = op->pos; - e->k.size = uncompressed_size; + e->k.size = crc.uncompressed_size; e->k.version = op->version; bkey_extent_set_cached(&e->k, op->flags & BCH_WRITE_CACHED); - bch2_extent_crc_append(e, compressed_size, - uncompressed_size, - compression_type, - nonce, csum, csum_type); - + bch2_extent_crc_append(e, crc); bch2_alloc_sectors_append_ptrs(op->c, e, op->nr_replicas, - ob, compressed_size); + ob, crc.compressed_size); bkey_extent_set_cached(&e->k, (op->flags & BCH_WRITE_CACHED)); bch2_keylist_push(&op->insert_keys); } +static void init_append_extent(struct bch_write_op *op, + unsigned compressed_size, + unsigned uncompressed_size, + unsigned compression_type, + unsigned nonce, + struct bch_csum csum, unsigned csum_type, + struct open_bucket *ob) +{ + struct bch_extent_crc_unpacked crc = { + .csum_type = csum_type, + .compression_type = compression_type, + .compressed_size = compressed_size, + .uncompressed_size = uncompressed_size, + .nonce = nonce, + .csum = csum, + }; + + __init_append_extent(op, crc, ob); +} + static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp) { struct bch_fs *c = op->c; @@ -372,8 +384,8 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp) /* Need to decompress data? */ if ((op->flags & BCH_WRITE_DATA_COMPRESSED) && - (crc_uncompressed_size(NULL, &op->crc) != op->size || - crc_compressed_size(NULL, &op->crc) > wp->sectors_free)) { + (op->crc.uncompressed_size != op->size || + op->crc.compressed_size > wp->sectors_free)) { int ret; ret = bch2_bio_uncompress_inplace(c, orig, op->size, op->crc); @@ -384,14 +396,9 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp) } if (op->flags & BCH_WRITE_DATA_COMPRESSED) { - init_append_extent(op, - crc_compressed_size(NULL, &op->crc), - crc_uncompressed_size(NULL, &op->crc), - op->crc.compression_type, - op->crc.nonce, - op->crc.csum, - op->crc.csum_type, - wp->ob); + __init_append_extent(op, + op->crc, + wp->ob); bio = orig; wbio = wbio_init(bio); @@ -827,8 +834,7 @@ static struct promote_op *promote_alloc(struct bch_fs *c, * biovec needs to be big enough to hold decompressed data, if * bch2_write_extent() has to decompress/recompress it: */ - unsigned sectors = max_t(unsigned, k.k->size, - crc_uncompressed_size(NULL, &pick->crc)); + unsigned sectors = pick->crc.uncompressed_size; unsigned pages = DIV_ROUND_UP(sectors, PAGE_SECTORS); op = kmalloc(sizeof(*op) + sizeof(struct bio_vec) * pages, GFP_NOIO); @@ -990,7 +996,7 @@ static int bch2_rbio_checksum_uncompress(struct bio *dst, struct bvec_iter dst_iter = rbio->bvec_iter; struct nonce nonce = extent_nonce(rbio->version, rbio->pick.crc.nonce, - crc_uncompressed_size(NULL, &rbio->pick.crc), + rbio->pick.crc.uncompressed_size, rbio->pick.crc.compression_type); struct bch_csum csum; int ret = 0; @@ -1002,7 +1008,7 @@ static int bch2_rbio_checksum_uncompress(struct bio *dst, * in order to promote */ if (rbio->bounce) { - src->bi_iter.bi_size = crc_compressed_size(NULL, &rbio->pick.crc) << 9; + src->bi_iter.bi_size = rbio->pick.crc.compressed_size << 9; src->bi_iter.bi_idx = 0; src->bi_iter.bi_bvec_done = 0; } else { @@ -1142,7 +1148,7 @@ int __bch2_read_extent(struct bch_fs *c, struct bch_read_bio *orig, */ if (pick->crc.compression_type != BCH_COMPRESSION_NONE || (pick->crc.csum_type != BCH_CSUM_NONE && - (bvec_iter_sectors(iter) != crc_uncompressed_size(NULL, &pick->crc) || + (bvec_iter_sectors(iter) != pick->crc.uncompressed_size || (bch2_csum_type_is_encryption(pick->crc.csum_type) && (flags & BCH_READ_USER_MAPPED)) || (flags & BCH_READ_MUST_BOUNCE)))) { @@ -1159,7 +1165,7 @@ int __bch2_read_extent(struct bch_fs *c, struct bch_read_bio *orig, if (bounce) { unsigned sectors = read_full - ? (crc_compressed_size(NULL, &pick->crc) ?: k.k->size) + ? pick->crc.compressed_size : bvec_iter_sectors(iter); rbio = rbio_init(bio_alloc_bioset(GFP_NOIO, @@ -1208,7 +1214,7 @@ int __bch2_read_extent(struct bch_fs *c, struct bch_read_bio *orig, * bounced (which isn't necessarily the original key size, if we bounced * only for promoting) */ - rbio->pick.crc._compressed_size = bio_sectors(&rbio->bio) - 1; + rbio->pick.crc.compressed_size = bio_sectors(&rbio->bio); rbio->version = k.k->version; rbio->promote = promote_op; rbio->inode = k.k->p.inode; diff --git a/fs/bcachefs/io_types.h b/fs/bcachefs/io_types.h index f77106be398a..9bf6229240ff 100644 --- a/fs/bcachefs/io_types.h +++ b/fs/bcachefs/io_types.h @@ -3,18 +3,13 @@ #include "btree_types.h" #include "buckets_types.h" +#include "extents_types.h" #include "keylist_types.h" #include "super_types.h" #include <linux/llist.h> #include <linux/workqueue.h> -struct extent_pick_ptr { - struct bch_extent_crc128 crc; - struct bch_extent_ptr ptr; - struct bch_dev *ca; -}; - struct bch_read_bio { struct bch_fs *c; @@ -113,7 +108,7 @@ struct bch_write_op { struct bversion version; /* For BCH_WRITE_DATA_COMPRESSED: */ - struct bch_extent_crc128 crc; + struct bch_extent_crc_unpacked crc; unsigned size; struct bch_devs_mask *devs; diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index c20769b7ca06..801e8771f723 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -272,18 +272,18 @@ static ssize_t bch2_compression_stats(struct bch_fs *c, char *buf) if (k.k->type == BCH_EXTENT) { struct bkey_s_c_extent e = bkey_s_c_to_extent(k); const struct bch_extent_ptr *ptr; - const union bch_extent_crc *crc; + struct bch_extent_crc_unpacked crc; extent_for_each_ptr_crc(e, ptr, crc) { - if (crc_compression_type(crc) == BCH_COMPRESSION_NONE) { + if (crc.compression_type == BCH_COMPRESSION_NONE) { nr_uncompressed_extents++; uncompressed_sectors += e.k->size; } else { nr_compressed_extents++; compressed_sectors_compressed += - crc_compressed_size(e.k, crc); + crc.compressed_size; compressed_sectors_uncompressed += - crc_uncompressed_size(e.k, crc); + crc.uncompressed_size; } /* only looking at the first ptr */ |