From a7c9c84eac8003737bcefbb7a77b11e5f99b6b5e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 23 May 2016 15:01:40 -0400 Subject: [PATCH] os/bluestore/bluestore_types: add length to the compression_header_t Snappy fails to decompress if there are extra zeros in the input buffer. So, store the length explicitly in the header to avoid feeding them into the decompressor. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 4 +++- src/os/bluestore/bluestore_types.cc | 4 ++++ src/os/bluestore/bluestore_types.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 907e7010f35e7..a429ee4191891 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -3132,7 +3132,9 @@ int BlueStore::_decompress(bufferlist& source, bufferlist* result) derr << __func__ << " can't load decompressor " << chdr.type << dendl; r = -EIO; } else { - r = compressor->decompress(i, *result); + bufferlist t; + i.copy(chdr.length, t); + r = compressor->decompress(t, *result); if (r < 0) { derr << __func__ << " decompression failed with exit code " << r << dendl; r = -EIO; diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index f3de90eb70904..5f1f0ae397d46 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -1018,6 +1018,7 @@ void bluestore_compression_header_t::encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); ::encode(type, bl); + ::encode(length, bl); ENCODE_FINISH(bl); } @@ -1025,12 +1026,14 @@ void bluestore_compression_header_t::decode(bufferlist::iterator& p) { DECODE_START(1, p); ::decode(type, p); + ::decode(length, p); DECODE_FINISH(p); } void bluestore_compression_header_t::dump(Formatter *f) const { f->dump_string("type", type); + f->dump_unsigned("length", length); } void bluestore_compression_header_t::generate_test_instances( @@ -1038,4 +1041,5 @@ void bluestore_compression_header_t::generate_test_instances( { o.push_back(new bluestore_compression_header_t); o.push_back(new bluestore_compression_header_t("some_header")); + o.back()->length = 1234; } diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 3382c6254af30..efc971cb1f243 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -704,6 +704,8 @@ WRITE_CLASS_ENCODER(bluestore_wal_transaction_t) struct bluestore_compression_header_t { std::string type; + uint32_t length = 0; + bluestore_compression_header_t() {} bluestore_compression_header_t(const std::string& _type) : type(_type) {} -- 2.39.5