summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2016-09-03 20:40:07 -0800
committerKent Overstreet <kent.overstreet@gmail.com>2016-09-11 17:16:30 -0800
commit46c4a2160c13d966897223b57cadefd6b8201082 (patch)
tree41d06663083da55a11c4c69cc871b1f9760fa6fc
parent8baf2a74bf1f47fce47685cb64a1876ab3166097 (diff)
bcache: new extent csum accessors
-rw-r--r--drivers/md/bcache/buckets.c25
-rw-r--r--drivers/md/bcache/extents.c52
-rw-r--r--drivers/md/bcache/extents.h36
-rw-r--r--drivers/md/bcache/fs.c4
-rw-r--r--drivers/md/bcache/sysfs.c8
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 fee985fcb27a..071dc0345dfd 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 */