diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2016-09-03 20:40:07 -0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2017-01-18 21:40:17 -0900 |
commit | 8bfa943b48c282f970b620c2a71929aab8020227 (patch) | |
tree | 9d68f8167d496a3ca3d91f5858a3bad4deb325a8 | |
parent | a9abff6f8cf2620cecb017c664be79aef4dabd2d (diff) |
bcache: new extent csum accessors
-rw-r--r-- | drivers/md/bcache/buckets.c | 25 | ||||
-rw-r--r-- | drivers/md/bcache/extents.c | 52 | ||||
-rw-r--r-- | drivers/md/bcache/extents.h | 36 | ||||
-rw-r--r-- | drivers/md/bcache/fs.c | 4 | ||||
-rw-r--r-- | drivers/md/bcache/sysfs.c | 8 |
5 files changed, 76 insertions, 49 deletions
diff --git a/drivers/md/bcache/buckets.c b/drivers/md/bcache/buckets.c index 818491c46317..89874a361611 100644 --- a/drivers/md/bcache/buckets.c +++ b/drivers/md/bcache/buckets.c @@ -360,26 +360,26 @@ do { \ #if 0 /* Reverting this until the copygc + compression issue is fixed: */ -static unsigned __disk_sectors(struct bch_extent_crc64 crc, unsigned sectors) +static unsigned __disk_sectors(const union bch_extent_crc *crc, unsigned sectors) { - return crc.compression_type - ? sectors * crc.compressed_size / crc.uncompressed_size + return crc_compression_type(crc) + ? sectors * crc_compressed_size(crc) / crc_uncompressed_size(crc) : sectors; } -static unsigned __compressed_sectors(struct bch_extent_crc64 crc, unsigned sectors) +static unsigned __compressed_sectors(const union bch_extent_crc *crc, unsigned sectors) { - return crc.compression_type - ? min_t(unsigned, crc.compressed_size, sectors) + return crc_compression_type(crc) + ? min_t(unsigned, crc_compressed_size(crc), sectors) : sectors; } #else -static unsigned __disk_sectors(struct bch_extent_crc64 crc, unsigned sectors) +static unsigned __disk_sectors(const union bch_extent_crc *crc, unsigned sectors) { return sectors; } -static unsigned __compressed_sectors(struct bch_extent_crc64 crc, unsigned sectors) +static unsigned __compressed_sectors(const union bch_extent_crc *crc, unsigned sectors) { return sectors; } @@ -404,7 +404,6 @@ static void bch_mark_pointer(struct cache_set *c, unsigned saturated; struct bucket *g = ca->buckets + PTR_BUCKET_NR(ca, ptr); u32 v = READ_ONCE(g->mark.counter); - struct bch_extent_crc64 crc64 = crc_to_64(crc); unsigned old_sectors, new_sectors; int disk_sectors, compressed_sectors; @@ -416,10 +415,10 @@ static void bch_mark_pointer(struct cache_set *c, new_sectors = e.k->size + sectors; } - disk_sectors = -__disk_sectors(crc64, old_sectors) - + __disk_sectors(crc64, new_sectors); - compressed_sectors = -__compressed_sectors(crc64, old_sectors) - + __compressed_sectors(crc64, new_sectors); + disk_sectors = -__disk_sectors(crc, old_sectors) + + __disk_sectors(crc, new_sectors); + compressed_sectors = -__compressed_sectors(crc, old_sectors) + + __compressed_sectors(crc, new_sectors); do { new.counter = old.counter = v; diff --git a/drivers/md/bcache/extents.c b/drivers/md/bcache/extents.c index ec7482df32de..5e30607242f7 100644 --- a/drivers/md/bcache/extents.c +++ b/drivers/md/bcache/extents.c @@ -172,7 +172,7 @@ void bch_extent_crc_narrow_pointers(struct bkey_s_extent e, union bch_extent_crc if (!extent_entry_is_ptr(entry)) return; - entry->ptr.offset += crc_to_64(crc).offset; + entry->ptr.offset += crc_offset(crc); } } @@ -205,15 +205,15 @@ void bch_extent_narrow_crcs(struct bkey_s_extent e) unsigned csum_type = 0; extent_for_each_crc(e, crc) { - if (crc_to_64(crc).compression_type) + if (crc_compression_type(crc)) continue; - if (crc_to_64(crc).uncompressed_size != e.k->size) { + if (crc_uncompressed_size(crc) != e.k->size) { have_wide = true; } else { have_narrow = true; - csum = crc_to_64(crc).csum; - csum_type = crc_to_64(crc).csum_type; + csum = crc_csum(crc); + csum_type = crc_csum_type(crc); } } @@ -221,10 +221,10 @@ void bch_extent_narrow_crcs(struct bkey_s_extent e) return; extent_for_each_crc(e, crc) { - if (crc_to_64(crc).compression_type) + if (crc_compression_type(crc)) continue; - if (crc_to_64(crc).uncompressed_size != e.k->size) { + if (crc_uncompressed_size(crc) != e.k->size) { switch (extent_crc_type(crc)) { case BCH_EXTENT_CRC_NONE: BUG(); @@ -285,8 +285,8 @@ void bch_extent_drop_redundant_crcs(struct bkey_s_extent e) } if (!prev && - !crc_to_64(crc).csum_type && - !crc_to_64(crc).compression_type){ + !crc_csum_type(crc) && + !crc_compression_type(crc)) { /* null crc entry: */ bch_extent_crc_narrow_pointers(e, crc); goto drop; @@ -385,8 +385,8 @@ static size_t extent_print_ptrs(struct cache_set *c, char *buf, { char *out = buf, *end = buf + size; const union bch_extent_entry *entry; + const union bch_extent_crc *crc; const struct bch_extent_ptr *ptr; - struct bch_extent_crc64 crc; struct cache *ca; bool first = true; @@ -400,10 +400,10 @@ static size_t extent_print_ptrs(struct cache_set *c, char *buf, switch (extent_entry_type(entry)) { case BCH_EXTENT_ENTRY_crc32: case BCH_EXTENT_ENTRY_crc64: - crc = crc_to_64(entry_to_crc(entry)); + crc = entry_to_crc(entry); p("crc: c_size %u size %u offset %u csum %u compress %u", - crc.compressed_size, crc.uncompressed_size, - crc.offset, crc.csum_type, crc.compression_type); + crc_compressed_size(crc), crc_uncompressed_size(crc), + crc_offset(crc), crc_csum_type(crc), crc_compression_type(crc)); break; case BCH_EXTENT_ENTRY_ptr: ptr = &entry->ptr; @@ -1518,7 +1518,7 @@ static const char *bch_extent_invalid(const struct cache_set *c, case BCH_EXTENT_CACHED: { struct bkey_s_c_extent e = bkey_s_c_to_extent(k); const union bch_extent_entry *entry; - struct bch_extent_crc64 crc64; + const union bch_extent_crc *crc; struct cache_member_rcu *mi = cache_member_info_get(c); unsigned size_ondisk = e.k->size; const char *reason; @@ -1531,24 +1531,24 @@ static const char *bch_extent_invalid(const struct cache_set *c, switch (extent_entry_type(entry)) { case BCH_EXTENT_ENTRY_crc32: case BCH_EXTENT_ENTRY_crc64: - crc64 = crc_to_64(entry_to_crc(entry)); + crc = entry_to_crc(entry); reason = "checksum uncompressed size < key size"; - if (crc64.uncompressed_size < e.k->size) + if (crc_uncompressed_size(crc) < e.k->size) goto invalid; reason = "checksum offset > uncompressed size"; - if (crc64.offset >= crc64.uncompressed_size) + if (crc_offset(crc) >= crc_uncompressed_size(crc)) goto invalid; - size_ondisk = crc64.compressed_size; + size_ondisk = crc_compressed_size(crc); reason = "invalid checksum type"; - if (crc64.csum_type >= BCH_CSUM_NR) + if (crc_csum_type(crc) >= BCH_CSUM_NR) goto invalid; reason = "invalid compression type"; - if (crc64.compression_type >= BCH_COMPRESSION_NR) + if (crc_compression_type(crc) >= BCH_COMPRESSION_NR) goto invalid; break; case BCH_EXTENT_ENTRY_ptr: @@ -1819,12 +1819,12 @@ void bch_extent_crc_append(struct bkey_i_extent *e, break; case BCH_EXTENT_CRC32: case BCH_EXTENT_CRC64: - if (crc_to_64(crc).compressed_size == compressed_size && - crc_to_64(crc).uncompressed_size == uncompressed_size && - crc_to_64(crc).offset == 0 && - crc_to_64(crc).compression_type == compression_type && - crc_to_64(crc).csum_type == csum_type && - crc_to_64(crc).csum == csum) + if (crc_compressed_size(crc) == compressed_size && + crc_uncompressed_size(crc) == uncompressed_size && + crc_offset(crc) == 0 && + crc_compression_type(crc) == compression_type && + crc_csum_type(crc) == csum_type && + crc_csum(crc) == csum) return; break; } diff --git a/drivers/md/bcache/extents.h b/drivers/md/bcache/extents.h index c87630f50111..b94d14b61c0f 100644 --- a/drivers/md/bcache/extents.h +++ b/drivers/md/bcache/extents.h @@ -375,6 +375,36 @@ static inline struct bch_extent_crc64 crc_to_64(const union bch_extent_crc *crc) } } +static inline unsigned crc_compressed_size(const union bch_extent_crc *crc) +{ + return crc_to_64(crc).compressed_size; +} + +static inline unsigned crc_uncompressed_size(const union bch_extent_crc *crc) +{ + return crc_to_64(crc).uncompressed_size; +} + +static inline unsigned crc_offset(const union bch_extent_crc *crc) +{ + return crc_to_64(crc).offset; +} + +static inline unsigned crc_csum_type(const union bch_extent_crc *crc) +{ + return crc_to_64(crc).csum_type; +} + +static inline unsigned crc_compression_type(const union bch_extent_crc *crc) +{ + return crc_to_64(crc).compression_type; +} + +static inline u64 crc_csum(const union bch_extent_crc *crc) +{ + return crc_to_64(crc).csum; +} + static inline unsigned bkey_extent_is_compressed(struct cache_set *c, struct bkey_s_c k) { @@ -390,10 +420,10 @@ static inline unsigned bkey_extent_is_compressed(struct cache_set *c, extent_for_each_ptr_crc(e, ptr, crc) if (bch_extent_ptr_is_dirty(c, e, ptr) && - crc_to_64(crc).compression_type != BCH_COMPRESSION_NONE && - crc_to_64(crc).compressed_size < k.k->size) + crc_compression_type(crc) != BCH_COMPRESSION_NONE && + crc_compressed_size(crc) < k.k->size) ret = max_t(unsigned, ret, - crc_to_64(crc).compressed_size); + crc_compressed_size(crc)); } return ret; diff --git a/drivers/md/bcache/fs.c b/drivers/md/bcache/fs.c index 3732404abbb9..8cd541a2b746 100644 --- a/drivers/md/bcache/fs.c +++ b/drivers/md/bcache/fs.c @@ -634,10 +634,10 @@ static int bch_fill_extent(struct fiemap_extent_info *info, int flags2 = 0; u64 offset = ptr->offset; - if (crc_to_64(crc).compression_type) + if (crc_compression_type(crc)) flags2 |= FIEMAP_EXTENT_ENCODED; else - offset += crc_to_64(crc).offset; + offset += crc_offset(crc); if ((offset & (PAGE_SECTORS - 1)) || (e.k->size & (PAGE_SECTORS - 1))) diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 1652c09b7fb6..52ebb718e376 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -612,17 +612,15 @@ static ssize_t bch_compression_stats(struct cache_set *c, char *buf) const union bch_extent_crc *crc; extent_for_each_ptr_crc(e, ptr, crc) { - struct bch_extent_crc64 crc64 = crc_to_64(crc); - - if (crc64.compression_type == BCH_COMPRESSION_NONE) { + if (crc_compression_type(crc) == BCH_COMPRESSION_NONE) { nr_uncompressed_extents++; uncompressed_sectors += e.k->size; } else { nr_compressed_extents++; compressed_sectors_compressed += - crc64.compressed_size; + crc_compressed_size(crc); compressed_sectors_uncompressed += - crc64.uncompressed_size; + crc_uncompressed_size(crc); } /* only looking at the first ptr */ |