Merge "Adding block sz to compressors" into main
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_compress.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_compress.h
index cf65615..fd12b84 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/cow_compress.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_compress.h
@@ -24,24 +24,26 @@
class ICompressor {
public:
- explicit ICompressor(uint32_t compression_level) : compression_level_(compression_level) {}
+ explicit ICompressor(uint32_t compression_level, uint32_t block_size)
+ : compression_level_(compression_level), block_size_(block_size) {}
virtual ~ICompressor() {}
// Factory methods for compression methods.
- static std::unique_ptr<ICompressor> Gz(uint32_t compression_level);
- static std::unique_ptr<ICompressor> Brotli(uint32_t compression_level);
- static std::unique_ptr<ICompressor> Lz4(uint32_t compression_level);
+ static std::unique_ptr<ICompressor> Gz(uint32_t compression_level, const int32_t BLOCK_SZ);
+ static std::unique_ptr<ICompressor> Brotli(uint32_t compression_level, const int32_t BLOCK_SZ);
+ static std::unique_ptr<ICompressor> Lz4(uint32_t compression_level, const int32_t BLOCK_SZ);
static std::unique_ptr<ICompressor> Zstd(uint32_t compression_level, const int32_t BLOCK_SZ);
static std::unique_ptr<ICompressor> Create(CowCompression compression, const int32_t BLOCK_SZ);
uint32_t GetCompressionLevel() const { return compression_level_; }
-
+ uint32_t GetBlockSize() const { return block_size_; }
[[nodiscard]] virtual std::basic_string<uint8_t> Compress(const void* data,
size_t length) const = 0;
private:
uint32_t compression_level_;
+ uint32_t block_size_;
};
} // namespace snapshot
} // namespace android
\ No newline at end of file
diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/cow_compress.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/cow_compress.cpp
index 71ac59f..abc7d33 100644
--- a/fs_mgr/libsnapshot/libsnapshot_cow/cow_compress.cpp
+++ b/fs_mgr/libsnapshot/libsnapshot_cow/cow_compress.cpp
@@ -56,16 +56,16 @@
}
std::unique_ptr<ICompressor> ICompressor::Create(CowCompression compression,
- const int32_t BLOCK_SZ) {
+ const int32_t block_size) {
switch (compression.algorithm) {
case kCowCompressLz4:
- return ICompressor::Lz4(compression.compression_level);
+ return ICompressor::Lz4(compression.compression_level, block_size);
case kCowCompressBrotli:
- return ICompressor::Brotli(compression.compression_level);
+ return ICompressor::Brotli(compression.compression_level, block_size);
case kCowCompressGz:
- return ICompressor::Gz(compression.compression_level);
+ return ICompressor::Gz(compression.compression_level, block_size);
case kCowCompressZstd:
- return ICompressor::Zstd(compression.compression_level, BLOCK_SZ);
+ return ICompressor::Zstd(compression.compression_level, block_size);
case kCowCompressNone:
return nullptr;
}
@@ -100,7 +100,8 @@
class GzCompressor final : public ICompressor {
public:
- GzCompressor(uint32_t compression_level) : ICompressor(compression_level){};
+ GzCompressor(uint32_t compression_level, const uint32_t block_size)
+ : ICompressor(compression_level, block_size){};
std::basic_string<uint8_t> Compress(const void* data, size_t length) const override {
const auto bound = compressBound(length);
@@ -120,7 +121,8 @@
class Lz4Compressor final : public ICompressor {
public:
- Lz4Compressor(uint32_t compression_level) : ICompressor(compression_level){};
+ Lz4Compressor(uint32_t compression_level, const uint32_t block_size)
+ : ICompressor(compression_level, block_size){};
std::basic_string<uint8_t> Compress(const void* data, size_t length) const override {
const auto bound = LZ4_compressBound(length);
@@ -151,7 +153,8 @@
class BrotliCompressor final : public ICompressor {
public:
- BrotliCompressor(uint32_t compression_level) : ICompressor(compression_level){};
+ BrotliCompressor(uint32_t compression_level, const uint32_t block_size)
+ : ICompressor(compression_level, block_size){};
std::basic_string<uint8_t> Compress(const void* data, size_t length) const override {
const auto bound = BrotliEncoderMaxCompressedSize(length);
@@ -176,10 +179,11 @@
class ZstdCompressor final : public ICompressor {
public:
- ZstdCompressor(uint32_t compression_level, const uint32_t MAX_BLOCK_SIZE)
- : ICompressor(compression_level), zstd_context_(ZSTD_createCCtx(), ZSTD_freeCCtx) {
+ ZstdCompressor(uint32_t compression_level, const uint32_t block_size)
+ : ICompressor(compression_level, block_size),
+ zstd_context_(ZSTD_createCCtx(), ZSTD_freeCCtx) {
ZSTD_CCtx_setParameter(zstd_context_.get(), ZSTD_c_compressionLevel, compression_level);
- ZSTD_CCtx_setParameter(zstd_context_.get(), ZSTD_c_windowLog, log2(MAX_BLOCK_SIZE));
+ ZSTD_CCtx_setParameter(zstd_context_.get(), ZSTD_c_windowLog, log2(GetBlockSize()));
};
std::basic_string<uint8_t> Compress(const void* data, size_t length) const override {
@@ -313,20 +317,23 @@
return true;
}
-std::unique_ptr<ICompressor> ICompressor::Brotli(uint32_t compression_level) {
- return std::make_unique<BrotliCompressor>(compression_level);
+std::unique_ptr<ICompressor> ICompressor::Brotli(uint32_t compression_level,
+ const int32_t block_size) {
+ return std::make_unique<BrotliCompressor>(compression_level, block_size);
}
-std::unique_ptr<ICompressor> ICompressor::Gz(uint32_t compression_level) {
- return std::make_unique<GzCompressor>(compression_level);
+std::unique_ptr<ICompressor> ICompressor::Gz(uint32_t compression_level, const int32_t block_size) {
+ return std::make_unique<GzCompressor>(compression_level, block_size);
}
-std::unique_ptr<ICompressor> ICompressor::Lz4(uint32_t compression_level) {
- return std::make_unique<Lz4Compressor>(compression_level);
+std::unique_ptr<ICompressor> ICompressor::Lz4(uint32_t compression_level,
+ const int32_t block_size) {
+ return std::make_unique<Lz4Compressor>(compression_level, block_size);
}
-std::unique_ptr<ICompressor> ICompressor::Zstd(uint32_t compression_level, const int32_t BLOCK_SZ) {
- return std::make_unique<ZstdCompressor>(compression_level, BLOCK_SZ);
+std::unique_ptr<ICompressor> ICompressor::Zstd(uint32_t compression_level,
+ const int32_t block_size) {
+ return std::make_unique<ZstdCompressor>(compression_level, block_size);
}
void CompressWorker::Finalize() {