diff --git a/src/common/Checksummer.h b/src/common/Checksummer.h index 28406540b37..eda44734ebf 100644 --- a/src/common/Checksummer.h +++ b/src/common/Checksummer.h @@ -28,6 +28,44 @@ public: } }; + struct crc32c_16 { + typedef __le16 value_t; + + // we have no execution context/state. + typedef int state_t; + static void init(state_t *state) { + } + static void fini(state_t *state) { + } + + static value_t calc( + state_t state, + size_t len, + bufferlist::const_iterator& p + ) { + return p.crc32c(len, -1) & 0xffff; + } + }; + + struct crc32c_8 { + typedef __u8 value_t; + + // we have no execution context/state. + typedef int state_t; + static void init(state_t *state) { + } + static void fini(state_t *state) { + } + + static value_t calc( + state_t state, + size_t len, + bufferlist::const_iterator& p + ) { + return p.crc32c(len, -1) & 0xff; + } + }; + struct xxhash32 { typedef __le32 value_t; diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index 7a649406944..2dbfec55e27 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -674,6 +674,14 @@ void bluestore_blob_t::calc_csum(uint64_t b_off, const bufferlist& bl) Checksummer::calculate( get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data); break; + case CSUM_CRC32C_16: + Checksummer::calculate( + get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data); + break; + case CSUM_CRC32C_8: + Checksummer::calculate( + get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data); + break; } } @@ -698,6 +706,14 @@ int bluestore_blob_t::verify_csum(uint64_t b_off, const bufferlist& bl, *b_bad_off = Checksummer::verify( get_csum_chunk_size(), b_off, bl.length(), bl, csum_data); break; + case CSUM_CRC32C_16: + *b_bad_off = Checksummer::verify( + get_csum_chunk_size(), b_off, bl.length(), bl, csum_data); + break; + case CSUM_CRC32C_8: + *b_bad_off = Checksummer::verify( + get_csum_chunk_size(), b_off, bl.length(), bl, csum_data); + break; default: r = -EOPNOTSUPP; break; diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 54b84a059ca..080ae1e8b8d 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -221,11 +221,12 @@ struct bluestore_blob_t { enum CSumType { CSUM_NONE = 0, - CSUM_CRC32C = 1, - CSUM_XXHASH32 = 2, - CSUM_XXHASH64 = 3, + CSUM_XXHASH32 = 1, + CSUM_XXHASH64 = 2, + CSUM_CRC32C = 3, + CSUM_CRC32C_16 = 4, // low 16 bits of crc32c + CSUM_CRC32C_8 = 5, // low 8 bits of crc32c CSUM_MAX, - CSUM_CRC16, // ** not yet implemented ** }; static const char *get_csum_type_string(unsigned t) { switch (t) { @@ -233,7 +234,8 @@ struct bluestore_blob_t { case CSUM_XXHASH32: return "xxhash32"; case CSUM_XXHASH64: return "xxhash64"; case CSUM_CRC32C: return "crc32c"; - case CSUM_CRC16: return "crc16"; + case CSUM_CRC32C_16: return "crc32c_16"; + case CSUM_CRC32C_8: return "crc32c_8"; default: return "???"; } } @@ -246,8 +248,10 @@ struct bluestore_blob_t { return CSUM_XXHASH64; if (s == "crc32c") return CSUM_CRC32C; - if (s == "crc16") - return CSUM_CRC16; + if (s == "crc32c_16") + return CSUM_CRC32C_16; + if (s == "crc32c_8") + return CSUM_CRC32C_8; return -EINVAL; } @@ -453,7 +457,8 @@ struct bluestore_blob_t { case CSUM_XXHASH32: return 4; case CSUM_XXHASH64: return 8; case CSUM_CRC32C: return 4; - case CSUM_CRC16: return 2; + case CSUM_CRC32C_16: return 2; + case CSUM_CRC32C_8: return 1; default: return 0; } }