summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2016-08-26 21:20:20 -0800
committerKent Overstreet <kent.overstreet@gmail.com>2016-08-27 05:27:02 -0800
commitc820493652e830dc050e1418301e1bdec5691a1e (patch)
tree158986878321231b2f63937dc986eea53c40b01e
parentcf5d9245a12234f156a3534fc50db07705223eb4 (diff)
bcache: bch_extent refactoring
improve the casts to/from bch_extent_entry, this caught a few const correctness things
-rw-r--r--drivers/md/bcache/buckets.c4
-rw-r--r--drivers/md/bcache/extents.c161
-rw-r--r--drivers/md/bcache/extents.h161
-rw-r--r--drivers/md/bcache/io.c94
-rw-r--r--drivers/md/bcache/util.h5
5 files changed, 232 insertions, 193 deletions
diff --git a/drivers/md/bcache/buckets.c b/drivers/md/bcache/buckets.c
index c742e520b4a5..e45f128d1635 100644
--- a/drivers/md/bcache/buckets.c
+++ b/drivers/md/bcache/buckets.c
@@ -393,7 +393,7 @@ static unsigned __compressed_sectors(struct bch_extent_crc64 crc, unsigned secto
static void bch_mark_pointer(struct cache_set *c,
struct bkey_s_c_extent e,
struct cache *ca,
- union bch_extent_crc *crc,
+ const union bch_extent_crc *crc,
const struct bch_extent_ptr *ptr,
int sectors, enum s_alloc type,
bool may_make_unavailable,
@@ -510,7 +510,7 @@ static void bch_mark_extent(struct cache_set *c, struct bkey_s_c_extent e,
bool is_gc, struct gc_pos gc_pos)
{
const struct bch_extent_ptr *ptr;
- union bch_extent_crc *crc;
+ const union bch_extent_crc *crc;
struct cache *ca;
enum s_alloc type = metadata ? S_META : S_DIRTY;
diff --git a/drivers/md/bcache/extents.c b/drivers/md/bcache/extents.c
index 558142c679c5..8310b8cb898a 100644
--- a/drivers/md/bcache/extents.c
+++ b/drivers/md/bcache/extents.c
@@ -157,37 +157,39 @@ unsigned bch_extent_nr_ptrs(struct bkey_s_c_extent e)
}
/* returns true if equal */
-static bool crc_cmp(union bch_extent_entry *l, union bch_extent_entry *r)
+static bool crc_cmp(union bch_extent_crc *l, union bch_extent_crc *r)
{
- return extent_entry_type(l) == extent_entry_type(r) &&
- !memcmp(l, r, extent_entry_bytes(l));
+ return extent_crc_type(l) == extent_crc_type(r) &&
+ !memcmp(l, r, extent_entry_bytes(to_entry(l)));
}
/* Increment pointers after @crc by crc's offset until the next crc entry: */
-void extent_adjust_pointers(struct bkey_s_extent e, union bch_extent_entry *crc)
+void extent_adjust_pointers(struct bkey_s_extent e, union bch_extent_crc *crc)
{
union bch_extent_entry *entry;
- unsigned offset = crc_to_64((void *) crc).offset;
- extent_for_each_entry_from(e, entry, extent_entry_next(crc)) {
+ extent_for_each_entry_from(e, entry, extent_entry_next(to_entry(crc))) {
if (!extent_entry_is_ptr(entry))
return;
- entry->ptr.offset += offset;
+ entry->ptr.offset += crc_to_64(crc).offset;
}
}
static void extent_cleanup_crcs(struct bkey_s_extent e)
{
- union bch_extent_entry *crc = e.v->start, *prev = NULL;
+ union bch_extent_entry *entry = e.v->start;
+ union bch_extent_crc *crc, *prev = NULL;
- while (crc != extent_entry_last(e)) {
- union bch_extent_entry *next = extent_entry_next(crc);
- size_t crc_u64s = extent_entry_u64s(crc);
+ while (entry != extent_entry_last(e)) {
+ union bch_extent_entry *next = extent_entry_next(entry);
+ size_t crc_u64s = extent_entry_u64s(entry);
- if (!extent_entry_is_crc(crc))
+ if (!extent_entry_is_crc(entry))
goto next;
+ crc = entry_to_crc(entry);
+
if (next == extent_entry_last(e)) {
/* crc entry with no pointers after it: */
goto drop;
@@ -204,8 +206,8 @@ static void extent_cleanup_crcs(struct bkey_s_extent e)
}
if (!prev &&
- !crc_to_64((void *) crc).csum_type &&
- !crc_to_64((void *) crc).compression_type){
+ !crc_to_64(crc).csum_type &&
+ !crc_to_64(crc).compression_type){
/* null crc entry: */
extent_adjust_pointers(e, crc);
goto drop;
@@ -213,7 +215,7 @@ static void extent_cleanup_crcs(struct bkey_s_extent e)
prev = crc;
next:
- crc = next;
+ entry = next;
continue;
drop:
memmove(crc, next,
@@ -325,7 +327,7 @@ 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((void *) entry);
+ crc = crc_to_64(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);
@@ -481,7 +483,7 @@ struct extent_pick_ptr
bch_btree_pick_ptr(struct cache_set *c, const struct btree *b)
{
struct bkey_s_c_extent e = bkey_i_to_s_c_extent(&b->key);
- union bch_extent_crc *crc;
+ const union bch_extent_crc *crc;
const struct bch_extent_ptr *ptr;
struct cache *ca;
@@ -550,7 +552,7 @@ static bool __bch_cut_front(struct bpos where, struct bkey_s k)
union bch_extent_crc *crc, *prev_crc = NULL;
extent_for_each_ptr_crc(e, ptr, crc) {
- switch (bch_extent_crc_type(crc)) {
+ switch (extent_crc_type(crc)) {
case BCH_EXTENT_CRC_NONE:
ptr->offset += e.k->size - len;
break;
@@ -1437,7 +1439,7 @@ 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((void *) entry);
+ crc64 = crc_to_64(entry_to_crc(entry));
reason = "checksum uncompressed size < key size";
if (crc64.uncompressed_size < e.k->size)
@@ -1648,11 +1650,107 @@ static unsigned PTR_TIER(struct cache_member_rcu *mi,
: UINT_MAX;
}
+void bch_extent_entry_append(struct bkey_i_extent *e,
+ union bch_extent_entry *entry)
+{
+ BUG_ON(bkey_val_u64s(&e->k) + extent_entry_u64s(entry) >
+ BKEY_EXTENT_VAL_U64s_MAX);
+
+ memcpy(extent_entry_last(extent_i_to_s(e)),
+ entry,
+ extent_entry_bytes(entry));
+ e->k.u64s += extent_entry_u64s(entry);
+}
+
+const unsigned bch_crc_size[] = {
+ [BCH_CSUM_NONE] = 0,
+ [BCH_CSUM_CRC32C] = 4,
+ [BCH_CSUM_CRC64] = 8,
+};
+
+static void bch_extent_crc_init(union bch_extent_crc *crc,
+ unsigned compressed_size,
+ unsigned uncompressed_size,
+ unsigned compression_type,
+ u64 csum, unsigned csum_type)
+{
+ if (bch_crc_size[csum_type] <= 4 &&
+ uncompressed_size <= CRC32_EXTENT_SIZE_MAX) {
+ crc->crc32 = (struct bch_extent_crc32) {
+ .type = 1 << BCH_EXTENT_ENTRY_crc32,
+ .compressed_size = compressed_size,
+ .uncompressed_size = uncompressed_size,
+ .offset = 0,
+ .compression_type = compression_type,
+ .csum_type = csum_type,
+ .csum = csum,
+ };
+ } else {
+ BUG_ON(uncompressed_size > CRC64_EXTENT_SIZE_MAX);
+
+ crc->crc64 = (struct bch_extent_crc64) {
+ .type = 1 << BCH_EXTENT_ENTRY_crc64,
+ .compressed_size = compressed_size,
+ .uncompressed_size = uncompressed_size,
+ .offset = 0,
+ .compression_type = compression_type,
+ .csum_type = csum_type,
+ .csum = csum,
+ };
+ }
+}
+
+void bch_extent_crc_append(struct bkey_i_extent *e,
+ unsigned compressed_size,
+ unsigned uncompressed_size,
+ unsigned compression_type,
+ u64 csum, unsigned csum_type)
+{
+ union bch_extent_crc *crc;
+ union bch_extent_crc new;
+
+ BUG_ON(compressed_size > uncompressed_size);
+ BUG_ON(uncompressed_size != e->k.size);
+ BUG_ON(!compressed_size || !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)
+ ;
+
+ switch (extent_crc_type(crc)) {
+ case BCH_EXTENT_CRC_NONE:
+ if (!csum_type && !compression_type)
+ return;
+ 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)
+ return;
+ break;
+ }
+
+ bch_extent_crc_init(&new,
+ compressed_size,
+ uncompressed_size,
+ compression_type,
+ csum, csum_type);
+ bch_extent_entry_append(e, to_entry(&new));
+}
+
static void __extent_sort_ptrs(struct cache_member_rcu *mi,
struct bkey_s_extent src)
{
struct bch_extent_ptr *src_ptr, *dst_ptr;
- union bch_extent_entry *src_crc, *dst_crc;
+ union bch_extent_crc *src_crc, *dst_crc;
+ union bch_extent_crc _src;
BKEY_PADDED(k) tmp;
struct bkey_s_extent dst;
size_t u64s, crc_u64s;
@@ -1681,24 +1779,21 @@ static void __extent_sort_ptrs(struct cache_member_rcu *mi,
* dst_ptr points to a pointer it better have a crc:
*/
BUG_ON(dst_ptr != &extent_entry_last(dst)->ptr && !dst_crc);
- BUG_ON(dst_crc && extent_entry_next(dst_crc) != (void *) dst_ptr);
+ BUG_ON(dst_crc &&
+ (extent_entry_next(to_entry(dst_crc)) !=
+ to_entry(dst_ptr)));
+
+ if (!src_crc) {
+ bch_extent_crc_init(&_src, src.k->size,
+ src.k->size, 0, 0, 0);
+ src_crc = &_src;
+ }
p = dst_ptr != &extent_entry_last(dst)->ptr
? (void *) dst_crc
: (void *) dst_ptr;
- if (!src_crc)
- src_crc = (void *) &((struct bch_extent_crc32) {
- .type = 1 << BCH_EXTENT_ENTRY_crc32,
- .compressed_size = src.k->size,
- .uncompressed_size = src.k->size,
- .offset = 0,
- .compression_type = BCH_COMPRESSION_NONE,
- .csum_type = BCH_CSUM_NONE,
- .csum = 0,
- });
-
- crc_u64s = extent_entry_u64s((void *) src_crc);
+ crc_u64s = extent_entry_u64s(to_entry(src_crc));
u64s = crc_u64s + sizeof(*dst_ptr) / sizeof(u64);
memmove(p + u64s, p,
diff --git a/drivers/md/bcache/extents.h b/drivers/md/bcache/extents.h
index c2108ac4d287..70f04235a110 100644
--- a/drivers/md/bcache/extents.h
+++ b/drivers/md/bcache/extents.h
@@ -119,9 +119,9 @@ extent_entry_type(const union bch_extent_entry *e)
return ret;
}
-static inline size_t __extent_entry_bytes(enum bch_extent_entry_type type)
+static inline size_t extent_entry_bytes(const union bch_extent_entry *entry)
{
- switch (type) {
+ switch (extent_entry_type(entry)) {
case BCH_EXTENT_ENTRY_crc32:
return sizeof(struct bch_extent_crc32);
case BCH_EXTENT_ENTRY_crc64:
@@ -133,19 +133,9 @@ static inline size_t __extent_entry_bytes(enum bch_extent_entry_type type)
}
}
-static inline size_t __extent_entry_u64s(enum bch_extent_entry_type type)
+static inline size_t extent_entry_u64s(const union bch_extent_entry *entry)
{
- return __extent_entry_bytes(type) / sizeof(u64);
-}
-
-static inline size_t extent_entry_bytes(const union bch_extent_entry *e)
-{
- return __extent_entry_bytes(extent_entry_type(e));
-}
-
-static inline size_t extent_entry_u64s(const union bch_extent_entry *e)
-{
- return extent_entry_bytes(e) / sizeof(u64);
+ return extent_entry_bytes(entry) / sizeof(u64);
}
static inline bool extent_entry_is_ptr(const union bch_extent_entry *e)
@@ -164,6 +154,42 @@ union bch_extent_crc {
struct bch_extent_crc64 crc64;
};
+/* downcast, preserves const */
+#define to_entry(_entry) \
+({ \
+ BUILD_BUG_ON(!type_is(_entry, union bch_extent_crc *) && \
+ !type_is(_entry, struct bch_extent_ptr *)); \
+ \
+ __builtin_choose_expr( \
+ (type_is_exact(_entry, const union bch_extent_crc *) || \
+ type_is_exact(_entry, const struct bch_extent_ptr *)), \
+ (const union bch_extent_entry *) (_entry), \
+ (union bch_extent_entry *) (_entry)); \
+})
+
+#define __entry_to_crc(_entry) \
+ __builtin_choose_expr( \
+ type_is_exact(_entry, const union bch_extent_entry *), \
+ (const union bch_extent_crc *) (_entry), \
+ (union bch_extent_crc *) (_entry))
+
+#define entry_to_crc(_entry) \
+({ \
+ EBUG_ON((_entry) && !extent_entry_is_crc(_entry)); \
+ \
+ __entry_to_crc(_entry); \
+})
+
+#define entry_to_ptr(_entry) \
+({ \
+ EBUG_ON((_entry) && !extent_entry_is_ptr(_entry)); \
+ \
+ __builtin_choose_expr( \
+ type_is_exact(_entry, const union bch_extent_entry *), \
+ (const struct bch_extent_ptr *) (_entry), \
+ (struct bch_extent_ptr *) (_entry)); \
+})
+
enum bch_extent_crc_type {
BCH_EXTENT_CRC_NONE,
BCH_EXTENT_CRC32,
@@ -171,12 +197,12 @@ enum bch_extent_crc_type {
};
static inline enum bch_extent_crc_type
-bch_extent_crc_type(const union bch_extent_crc *crc)
+extent_crc_type(const union bch_extent_crc *crc)
{
if (!crc)
return BCH_EXTENT_CRC_NONE;
- switch (extent_entry_type((void *) crc)) {
+ switch (extent_entry_type(to_entry(crc))) {
case BCH_EXTENT_ENTRY_crc32:
return BCH_EXTENT_CRC32;
case BCH_EXTENT_ENTRY_crc64:
@@ -192,6 +218,8 @@ bch_extent_crc_type(const union bch_extent_crc *crc)
#define extent_entry_last(_e) \
bkey_idx((_e).v, bkey_val_u64s((_e).k))
+/* Iterate over all entries: */
+
#define extent_for_each_entry_from(_e, _entry, _start) \
for ((_entry) = _start; \
(_entry) < extent_entry_last(_e); \
@@ -200,33 +228,36 @@ bch_extent_crc_type(const union bch_extent_crc *crc)
#define extent_for_each_entry(_e, _entry) \
extent_for_each_entry_from(_e, _entry, (_e).v->start)
+/* Iterate over crcs only: */
+
#define extent_crc_next(_e, _p) \
({ \
- union bch_extent_entry *_entry = _p; \
+ typeof(&(_e).v->start[0]) _entry = _p; \
\
while ((_entry) < extent_entry_last(_e) && \
!extent_entry_is_crc(_entry)) \
(_entry) = extent_entry_next(_entry); \
\
- _entry < extent_entry_last(_e) ? (void *) _entry : NULL; \
+ 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); \
(_crc); \
- (_crc) = extent_crc_next(_e, extent_entry_next((void *) (_crc))))
+ (_crc) = extent_crc_next(_e, extent_entry_next(to_entry(_crc))))
+
+/* Iterate over pointers, with crcs: */
-/* Iterates through entries until it hits a pointer: */
#define extent_ptr_crc_next_filter(_e, _crc, _ptr, _filter) \
({ \
__label__ out; \
- const union bch_extent_entry *_entry; \
+ typeof(&(_e).v->start[0]) _entry; \
\
- extent_for_each_entry_from(_e, _entry, (void *) _ptr) \
+ extent_for_each_entry_from(_e, _entry, to_entry(_ptr)) \
if (extent_entry_is_crc(_entry)) { \
- (_crc) = (void *) _entry; \
+ (_crc) = entry_to_crc(_entry); \
} else { \
- _ptr = (typeof(_ptr)) &_entry->ptr; \
+ _ptr = entry_to_ptr(_entry); \
if (_filter) \
goto out; \
} \
@@ -236,49 +267,45 @@ out: \
_ptr; \
})
+#define extent_for_each_ptr_crc_filter(_e, _ptr, _crc, _filter) \
+ for ((_crc) = NULL, \
+ (_ptr) = &(_e).v->start->ptr; \
+ ((_ptr) = extent_ptr_crc_next_filter(_e, _crc, _ptr, _filter));\
+ (_ptr)++)
+
+#define extent_for_each_ptr_crc(_e, _ptr, _crc) \
+ extent_for_each_ptr_crc_filter(_e, _ptr, _crc, true)
+
+#define extent_for_each_online_device_crc(_c, _e, _crc, _ptr, _ca) \
+ extent_for_each_ptr_crc_filter(_e, _ptr, _crc, \
+ ((_ca) = PTR_CACHE(_c, _ptr)))
+
+/* Iterate over pointers only, and from a given position: */
+
#define extent_ptr_next_filter(_e, _ptr, _filter) \
({ \
- union bch_extent_crc *_crc; \
+ typeof(__entry_to_crc(&(_e).v->start[0])) _crc; \
\
extent_ptr_crc_next_filter(_e, _crc, _ptr, _filter); \
})
-#define extent_ptr_crc_next(_e, _crc, _ptr) \
- extent_ptr_crc_next_filter(_e, _crc, _ptr, true)
-
#define extent_ptr_next(_e, _ptr) \
extent_ptr_next_filter(_e, _ptr, true)
-#define extent_for_each_ptr_crc_filter(_e, _ptr, _crc, _filter) \
- for ((_crc) = NULL, \
- (_ptr) = &(_e).v->start->ptr; \
- ((_ptr) = extent_ptr_crc_next_filter(_e, _crc, _ptr, _filter));\
- (_ptr)++)
-
#define extent_for_each_ptr_from_filter(_e, _ptr, _start, _filter) \
for ((_ptr) = (_start); \
((_ptr) = extent_ptr_next_filter(_e, _ptr, _filter)); \
(_ptr)++)
-#define extent_for_each_ptr_filter(_e, _ptr, _filter) \
- extent_for_each_ptr_from_filter(_e, _ptr, &(_e).v->start->ptr, _filter)
-
-#define extent_for_each_ptr_crc(_e, _ptr, _crc) \
- extent_for_each_ptr_crc_filter(_e, _ptr, _crc, true)
-
#define extent_for_each_ptr_from(_e, _ptr, _start) \
extent_for_each_ptr_from_filter(_e, _ptr, _start, true)
#define extent_for_each_ptr(_e, _ptr) \
- extent_for_each_ptr_filter(_e, _ptr, true)
-
-#define extent_for_each_online_device_crc(_c, _e, _crc, _ptr, _ca) \
- extent_for_each_ptr_crc_filter(_e, _ptr, _crc, \
- ((_ca) = PTR_CACHE(_c, _ptr)))
+ extent_for_each_ptr_from_filter(_e, _ptr, &(_e).v->start->ptr, true)
#define extent_for_each_online_device(_c, _e, _ptr, _ca) \
- extent_for_each_ptr_filter(_e, _ptr, \
- ((_ca) = PTR_CACHE(_c, _ptr)))
+ extent_for_each_ptr_from_filter(_e, _ptr, &(_e).v->start->ptr, \
+ ((_ca) = PTR_CACHE(_c, _ptr)))
#define extent_ptr_prev(_e, _ptr) \
({ \
@@ -303,39 +330,15 @@ out: \
(_ptr); \
(_ptr) = extent_ptr_prev(_e, _ptr))
-/*
- * make sure the type field gets set correctly:
- */
-#define __extent_entry_append(_e, _type, _val) \
-do { \
- union bch_extent_entry *_new = \
- extent_entry_last(extent_i_to_s((_e))); \
- \
- (_e)->k.u64s += __extent_entry_u64s(BCH_EXTENT_ENTRY_##_type); \
- BUG_ON(bkey_val_u64s(&(_e)->k) > BKEY_EXTENT_VAL_U64s_MAX); \
- \
- _new->_type = _val; \
- _new->_type.type = 1 << BCH_EXTENT_ENTRY_##_type; \
- \
- BUG_ON(extent_entry_type(_new) != BCH_EXTENT_ENTRY_##_type); \
-} while (0)
-
-static inline void extent_crc32_append(struct bkey_i_extent *e,
- struct bch_extent_crc32 crc)
-{
- __extent_entry_append(e, crc32, crc);
-}
-
-static inline void extent_crc64_append(struct bkey_i_extent *e,
- struct bch_extent_crc64 crc)
-{
- __extent_entry_append(e, crc64, crc);
-}
+void bch_extent_entry_append(struct bkey_i_extent *, union bch_extent_entry *);
+void bch_extent_crc_append(struct bkey_i_extent *, unsigned, unsigned,
+ unsigned, u64, unsigned);
static inline void extent_ptr_append(struct bkey_i_extent *e,
struct bch_extent_ptr ptr)
{
- __extent_entry_append(e, ptr, ptr);
+ ptr.type = 1 << BCH_EXTENT_ENTRY_ptr;
+ bch_extent_entry_append(e, to_entry(&ptr));
}
/* XXX: inefficient */
@@ -350,9 +353,11 @@ static inline bool bch_extent_ptr_is_dirty(const struct cache_set *c,
return bch_extent_nr_ptrs_from(e, ptr) <= c->opts.data_replicas;
}
+extern const unsigned bch_crc_size[];
+
static inline struct bch_extent_crc64 crc_to_64(const union bch_extent_crc *crc)
{
- switch (bch_extent_crc_type(crc)) {
+ switch (extent_crc_type(crc)) {
case BCH_EXTENT_CRC_NONE:
return (struct bch_extent_crc64) { 0 };
case BCH_EXTENT_CRC32:
@@ -395,7 +400,7 @@ static inline unsigned bkey_extent_is_compressed(struct cache_set *c,
return ret;
}
-void extent_adjust_pointers(struct bkey_s_extent, union bch_extent_entry *);
+void extent_adjust_pointers(struct bkey_s_extent, union bch_extent_crc *);
/* Doesn't cleanup redundant crcs */
static inline void __bch_extent_drop_ptr(struct bkey_s_extent e,
diff --git a/drivers/md/bcache/io.c b/drivers/md/bcache/io.c
index e899a8658a20..cd3dbe76ceca 100644
--- a/drivers/md/bcache/io.c
+++ b/drivers/md/bcache/io.c
@@ -806,12 +806,6 @@ static void bch_write_endio(struct bio *bio)
closure_put(cl);
}
-static const unsigned bch_crc_size[] = {
- [BCH_CSUM_NONE] = 0,
- [BCH_CSUM_CRC32C] = 4,
- [BCH_CSUM_CRC64] = 8,
-};
-
/*
* We're writing another replica for this extent, so while we've got the data in
* memory we'll be computing a new checksum for the currently live data.
@@ -839,7 +833,7 @@ static void extent_cleanup_checksums(struct bkey_s_extent e,
union bch_extent_crc *crc;
extent_for_each_crc(e, crc)
- switch (bch_extent_crc_type(crc)) {
+ switch (extent_crc_type(crc)) {
case BCH_EXTENT_CRC_NONE:
BUG();
case BCH_EXTENT_CRC32:
@@ -847,7 +841,7 @@ static void extent_cleanup_checksums(struct bkey_s_extent e,
bch_crc_size[csum_type] > sizeof(crc->crc32.csum))
continue;
- extent_adjust_pointers(e, (void *) crc);
+ extent_adjust_pointers(e, crc);
crc->crc32.compressed_size = e.k->size;
crc->crc32.uncompressed_size = e.k->size;
crc->crc32.offset = 0;
@@ -859,7 +853,7 @@ static void extent_cleanup_checksums(struct bkey_s_extent e,
bch_crc_size[csum_type] > sizeof(crc->crc64.csum))
continue;
- extent_adjust_pointers(e, (void *) crc);
+ extent_adjust_pointers(e, crc);
crc->crc64.compressed_size = e.k->size;
crc->crc64.uncompressed_size = e.k->size;
crc->crc64.offset = 0;
@@ -869,66 +863,6 @@ static void extent_cleanup_checksums(struct bkey_s_extent e,
}
}
-static void extent_checksum_append(struct bkey_i_extent *e,
- unsigned compressed_size,
- unsigned uncompressed_size,
- unsigned compression_type,
- u64 csum, unsigned csum_type)
-{
- union bch_extent_crc *crc;
-
- BUG_ON(compressed_size > uncompressed_size);
- BUG_ON(uncompressed_size != e->k.size);
- BUG_ON(!compressed_size || !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)
- ;
-
- switch (bch_extent_crc_type(crc)) {
- case BCH_EXTENT_CRC_NONE:
- if (!csum_type && !compression_type)
- return;
- 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)
- return;
- break;
- }
-
- if (bch_crc_size[csum_type] <= 4 &&
- uncompressed_size <= CRC32_EXTENT_SIZE_MAX) {
- extent_crc32_append(e, (struct bch_extent_crc32) {
- .compressed_size = compressed_size,
- .uncompressed_size = uncompressed_size,
- .offset = 0,
- .compression_type = compression_type,
- .csum_type = csum_type,
- .csum = csum,
- });
- } else {
- BUG_ON(uncompressed_size > CRC64_EXTENT_SIZE_MAX);
-
- extent_crc64_append(e, (struct bch_extent_crc64) {
- .compressed_size = compressed_size,
- .uncompressed_size = uncompressed_size,
- .offset = 0,
- .compression_type = compression_type,
- .csum_type = csum_type,
- .csum = csum,
- });
- }
-}
-
static int bch_write_extent(struct bch_write_op *op,
struct open_bucket *ob,
struct bkey_i_extent *e,
@@ -958,12 +892,12 @@ static int bch_write_extent(struct bch_write_op *op,
}
if (op->flags & BCH_WRITE_DATA_COMPRESSED) {
- extent_checksum_append(e,
- op->crc.compressed_size,
- op->crc.uncompressed_size,
- op->crc.compression_type,
- op->crc.csum,
- op->crc.csum_type);
+ bch_extent_crc_append(e,
+ op->crc.compressed_size,
+ op->crc.uncompressed_size,
+ op->crc.compression_type,
+ op->crc.csum,
+ op->crc.csum_type);
bch_alloc_sectors_done(op->c, op->wp,
e, op->nr_replicas,
ob, bio_sectors(orig));
@@ -1036,9 +970,9 @@ static int bch_write_extent(struct bch_write_op *op,
* Add a bch_extent_crc header for the pointers that
* bch_alloc_sectors_done() is going to append:
*/
- extent_checksum_append(e, bio_sectors(bio), e->k.size,
- compression_type,
- csum, csum_type);
+ bch_extent_crc_append(e, bio_sectors(bio), e->k.size,
+ compression_type,
+ csum, csum_type);
bch_alloc_sectors_done(op->c, op->wp,
e, op->nr_replicas,
ob, bio_sectors(bio));
@@ -1051,8 +985,8 @@ static int bch_write_extent(struct bch_write_op *op,
* We might need a checksum entry, if there's a previous
* checksum entry we need to override:
*/
- extent_checksum_append(e, e->k.size, e->k.size,
- compression_type, 0, csum_type);
+ bch_extent_crc_append(e, e->k.size, e->k.size,
+ compression_type, 0, csum_type);
bch_alloc_sectors_done(op->c, op->wp,
e, op->nr_replicas,
ob, e->k.size);
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
index 9f52ba08b943..c79b55fc08ed 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -61,6 +61,11 @@ struct closure;
#define CPU_BIG_ENDIAN 1
#endif
+/* type hackery */
+
+#define type_is_exact(_val, _type) \
+ __builtin_types_compatible_p(typeof(_val), _type)
+
#define type_is(_val, _type) \
(__builtin_types_compatible_p(typeof(_val), _type) || \
__builtin_types_compatible_p(typeof(_val), const _type))