libsnapshot: use compression_factor in ota
Parse manifest compression_factor and set CowOptions appropriately. This
allows v3 writer to use compression factor in OTA. Updating some
comments about supported compression algorithms
Test: th
Change-Id: I88f254087e536d9e5925064f85317f0acce280ee
diff --git a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
index 7e97dc0..f2f7fc1 100644
--- a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
+++ b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
@@ -103,7 +103,7 @@
// The old partition size (if none existed, this will be zero).
uint64 old_partition_size = 10;
- // Compression algorithm (none, gz, or brotli).
+ // Compression algorithm (none, gz, lz4, zstd, or brotli).
string compression_algorithm = 11;
// Estimated COW size from OTA manifest.
@@ -117,6 +117,9 @@
// Size of v3 operation buffer. Needs to be determined during writer initialization
uint64 estimated_ops_buffer_size = 15;
+
+ // Max bytes to be compressed at once (4k, 8k, 16k, 32k, 64k, 128k)
+ uint64 compression_factor = 16;
}
// Next: 8
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h
index 7df976d..3bcee21 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h
@@ -60,6 +60,9 @@
// Size of the cow operation buffer; used in v3 only.
uint64_t op_count_max = 0;
+
+ // Compression factor
+ uint64_t compression_factor = 4096;
};
// Interface for writing to a snapuserd COW. All operations are ordered; merges
diff --git a/fs_mgr/libsnapshot/partition_cow_creator.h b/fs_mgr/libsnapshot/partition_cow_creator.h
index bd5c8cb..cbd664f 100644
--- a/fs_mgr/libsnapshot/partition_cow_creator.h
+++ b/fs_mgr/libsnapshot/partition_cow_creator.h
@@ -59,6 +59,7 @@
// True if snapuserd COWs are enabled.
bool using_snapuserd = false;
std::string compression_algorithm;
+ uint64_t compression_factor;
// True if multi-threaded compression should be enabled
bool enable_threading;
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index 9eb41b2..c12a9e2 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -420,6 +420,7 @@
status->set_metadata_sectors(0);
status->set_using_snapuserd(cow_creator->using_snapuserd);
status->set_compression_algorithm(cow_creator->compression_algorithm);
+ status->set_compression_factor(cow_creator->compression_factor);
if (cow_creator->enable_threading) {
status->set_enable_threading(cow_creator->enable_threading);
}
@@ -3233,8 +3234,10 @@
}
std::string compression_algorithm;
+ uint64_t compression_factor{};
if (using_snapuserd) {
compression_algorithm = dap_metadata.vabc_compression_param();
+ compression_factor = dap_metadata.compression_factor();
if (compression_algorithm.empty()) {
// Older OTAs don't set an explicit compression type, so default to gz.
compression_algorithm = "gz";
@@ -3251,7 +3254,9 @@
.extra_extents = {},
.using_snapuserd = using_snapuserd,
.compression_algorithm = compression_algorithm,
+ .compression_factor = compression_factor,
};
+
if (dap_metadata.vabc_feature_set().has_threaded()) {
cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded();
}
@@ -3666,6 +3671,7 @@
cow_options.batch_write = status.batched_writes();
cow_options.num_compress_threads = status.enable_threading() ? 2 : 1;
cow_options.op_count_max = status.estimated_ops_buffer_size();
+ cow_options.compression_factor = status.compression_factor();
// Disable scratch space for vts tests
if (device()->IsTestDevice()) {
cow_options.scratch_space = false;
@@ -3793,6 +3799,7 @@
ss << " allocated sectors: " << status.sectors_allocated() << std::endl;
ss << " metadata sectors: " << status.metadata_sectors() << std::endl;
ss << " compression: " << status.compression_algorithm() << std::endl;
+ ss << " compression factor: " << status.compression_factor() << std::endl;
ss << " merge phase: " << DecideMergePhase(status) << std::endl;
}
os << ss.rdbuf();