@@ -359,6 +359,7 @@ bool SnapshotManager::CreateSnapshot(LockedFile* lock, PartitionCowCreator* cow_
359
359
status->set_sectors_allocated (0 );
360
360
status->set_metadata_sectors (0 );
361
361
status->set_compression_enabled (cow_creator->compression_enabled );
362
+ status->set_compression_algorithm (cow_creator->compression_algorithm );
362
363
363
364
if (!WriteSnapshotStatus (lock, *status)) {
364
365
PLOG (ERROR) << " Could not write snapshot status: " << status->name ();
@@ -2660,9 +2661,20 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
2660
2661
// these devices.
2661
2662
AutoDeviceList created_devices;
2662
2663
2663
- bool use_compression = IsCompressionEnabled () &&
2664
- manifest.dynamic_partition_metadata ().vabc_enabled () &&
2665
- !device_->IsRecovery ();
2664
+ const auto & dap_metadata = manifest.dynamic_partition_metadata ();
2665
+ bool use_compression =
2666
+ IsCompressionEnabled () && dap_metadata.vabc_enabled () && !device_->IsRecovery ();
2667
+
2668
+ std::string compression_algorithm;
2669
+ if (use_compression) {
2670
+ compression_algorithm = dap_metadata.vabc_compression_param ();
2671
+ if (compression_algorithm.empty ()) {
2672
+ // Older OTAs don't set an explicit compression type, so default to gz.
2673
+ compression_algorithm = " gz" ;
2674
+ }
2675
+ } else {
2676
+ compression_algorithm = " none" ;
2677
+ }
2666
2678
2667
2679
PartitionCowCreator cow_creator{
2668
2680
.target_metadata = target_metadata.get (),
@@ -2673,6 +2685,7 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
2673
2685
.update = nullptr ,
2674
2686
.extra_extents = {},
2675
2687
.compression_enabled = use_compression,
2688
+ .compression_algorithm = compression_algorithm,
2676
2689
};
2677
2690
2678
2691
auto ret = CreateUpdateSnapshotsInternal (lock.get (), manifest, &cow_creator, &created_devices,
@@ -2917,7 +2930,7 @@ Return SnapshotManager::InitializeUpdateSnapshots(
2917
2930
return Return::Error ();
2918
2931
}
2919
2932
2920
- CowWriter writer (CowOptions{});
2933
+ CowWriter writer (CowOptions{. compression = it-> second . compression_algorithm () });
2921
2934
if (!writer.Initialize (fd) || !writer.Finalize ()) {
2922
2935
LOG (ERROR) << " Could not initialize COW device for " << target_partition->name ();
2923
2936
return Return::Error ();
@@ -3024,7 +3037,7 @@ std::unique_ptr<ISnapshotWriter> SnapshotManager::OpenCompressedSnapshotWriter(
3024
3037
CHECK (lock);
3025
3038
3026
3039
CowOptions cow_options;
3027
- cow_options.compression = " gz " ;
3040
+ cow_options.compression = status. compression_algorithm () ;
3028
3041
cow_options.max_blocks = {status.device_size () / cow_options.block_size };
3029
3042
3030
3043
// Currently we don't support partial snapshots, since partition_cow_creator
@@ -3163,6 +3176,7 @@ bool SnapshotManager::Dump(std::ostream& os) {
3163
3176
ss << " cow file size (bytes): " << status.cow_file_size () << std::endl;
3164
3177
ss << " allocated sectors: " << status.sectors_allocated () << std::endl;
3165
3178
ss << " metadata sectors: " << status.metadata_sectors () << std::endl;
3179
+ ss << " compression: " << status.compression_algorithm () << std::endl;
3166
3180
}
3167
3181
os << ss.rdbuf ();
3168
3182
return ok;
0 commit comments