libsnapshot: Only enable compression when the corresponding bit is set in DeltaArchiveManifest.
Test: vts_libsnapshot_test Change-Id: I43bab4a823d61c56596e1fd5b1522de08b9674f2
This commit is contained in:
parent
4787c1fa28
commit
3ee2475061
4 changed files with 33 additions and 13 deletions
|
|
@ -441,7 +441,7 @@ class SnapshotManager final : public ISnapshotManager {
|
|||
//
|
||||
// All sizes are specified in bytes, and the device, snapshot, COW partition and COW file sizes
|
||||
// must be a multiple of the sector size (512 bytes).
|
||||
bool CreateSnapshot(LockedFile* lock, SnapshotStatus* status);
|
||||
bool CreateSnapshot(LockedFile* lock, PartitionCowCreator* cow_creator, SnapshotStatus* status);
|
||||
|
||||
// |name| should be the base partition name (e.g. "system_a"). Create the
|
||||
// backing COW image using the size previously passed to CreateSnapshot().
|
||||
|
|
|
|||
|
|
@ -312,7 +312,8 @@ bool SnapshotManager::FinishedSnapshotWrites(bool wipe) {
|
|||
return WriteUpdateState(lock.get(), UpdateState::Unverified);
|
||||
}
|
||||
|
||||
bool SnapshotManager::CreateSnapshot(LockedFile* lock, SnapshotStatus* status) {
|
||||
bool SnapshotManager::CreateSnapshot(LockedFile* lock, PartitionCowCreator* cow_creator,
|
||||
SnapshotStatus* status) {
|
||||
CHECK(lock);
|
||||
CHECK(lock->lock_mode() == LOCK_EX);
|
||||
CHECK(status);
|
||||
|
|
@ -353,7 +354,7 @@ bool SnapshotManager::CreateSnapshot(LockedFile* lock, SnapshotStatus* status) {
|
|||
status->set_state(SnapshotState::CREATED);
|
||||
status->set_sectors_allocated(0);
|
||||
status->set_metadata_sectors(0);
|
||||
status->set_compression_enabled(IsCompressionEnabled());
|
||||
status->set_compression_enabled(cow_creator->compression_enabled);
|
||||
|
||||
if (!WriteSnapshotStatus(lock, *status)) {
|
||||
PLOG(ERROR) << "Could not write snapshot status: " << status->name();
|
||||
|
|
@ -2584,6 +2585,9 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
|
|||
// these devices.
|
||||
AutoDeviceList created_devices;
|
||||
|
||||
bool use_compression =
|
||||
IsCompressionEnabled() && manifest.dynamic_partition_metadata().vabc_enabled();
|
||||
|
||||
PartitionCowCreator cow_creator{
|
||||
.target_metadata = target_metadata.get(),
|
||||
.target_suffix = target_suffix,
|
||||
|
|
@ -2592,7 +2596,7 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
|
|||
.current_suffix = current_suffix,
|
||||
.update = nullptr,
|
||||
.extra_extents = {},
|
||||
.compression_enabled = IsCompressionEnabled(),
|
||||
.compression_enabled = use_compression,
|
||||
};
|
||||
|
||||
auto ret = CreateUpdateSnapshotsInternal(lock.get(), manifest, &cow_creator, &created_devices,
|
||||
|
|
@ -2744,7 +2748,7 @@ Return SnapshotManager::CreateUpdateSnapshotsInternal(
|
|||
}
|
||||
|
||||
// Store these device sizes to snapshot status file.
|
||||
if (!CreateSnapshot(lock, &cow_creator_ret->snapshot_status)) {
|
||||
if (!CreateSnapshot(lock, cow_creator, &cow_creator_ret->snapshot_status)) {
|
||||
return Return::Error();
|
||||
}
|
||||
created_devices->EmplaceBack<AutoDeleteSnapshot>(this, lock, target_partition->name());
|
||||
|
|
@ -2857,11 +2861,6 @@ Return SnapshotManager::InitializeUpdateSnapshots(
|
|||
|
||||
bool SnapshotManager::MapUpdateSnapshot(const CreateLogicalPartitionParams& params,
|
||||
std::string* snapshot_path) {
|
||||
if (IsCompressionEnabled()) {
|
||||
LOG(ERROR) << "MapUpdateSnapshot cannot be used in compression mode.";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lock = LockShared();
|
||||
if (!lock) return false;
|
||||
if (!UnmapPartitionWithSnapshot(lock.get(), params.GetPartitionName())) {
|
||||
|
|
@ -2870,6 +2869,15 @@ bool SnapshotManager::MapUpdateSnapshot(const CreateLogicalPartitionParams& para
|
|||
return false;
|
||||
}
|
||||
|
||||
SnapshotStatus status;
|
||||
if (!ReadSnapshotStatus(lock.get(), params.GetPartitionName(), &status)) {
|
||||
return false;
|
||||
}
|
||||
if (status.compression_enabled()) {
|
||||
LOG(ERROR) << "Cannot use MapUpdateSnapshot with compressed snapshots";
|
||||
return false;
|
||||
}
|
||||
|
||||
SnapshotPaths paths;
|
||||
if (!MapPartitionWithSnapshot(lock.get(), params, SnapshotContext::Update, &paths)) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include <android/snapshot/snapshot.pb.h>
|
||||
#include <libsnapshot/test_helpers.h>
|
||||
#include "partition_cow_creator.h"
|
||||
#include "utility.h"
|
||||
|
||||
// Mock classes are not used. Header included to ensure mocked class definition aligns with the
|
||||
|
|
@ -323,7 +324,10 @@ class SnapshotTest : public ::testing::Test {
|
|||
|
||||
DeltaArchiveManifest manifest;
|
||||
|
||||
auto group = manifest.mutable_dynamic_partition_metadata()->add_groups();
|
||||
auto dynamic_partition_metadata = manifest.mutable_dynamic_partition_metadata();
|
||||
dynamic_partition_metadata->set_vabc_enabled(IsCompressionEnabled());
|
||||
|
||||
auto group = dynamic_partition_metadata->add_groups();
|
||||
group->set_name("group");
|
||||
group->set_size(device_size * 2);
|
||||
group->add_partition_names("test_partition");
|
||||
|
|
@ -416,13 +420,16 @@ class SnapshotTest : public ::testing::Test {
|
|||
TEST_F(SnapshotTest, CreateSnapshot) {
|
||||
ASSERT_TRUE(AcquireLock());
|
||||
|
||||
PartitionCowCreator cow_creator;
|
||||
cow_creator.compression_enabled = IsCompressionEnabled();
|
||||
|
||||
static const uint64_t kDeviceSize = 1024 * 1024;
|
||||
SnapshotStatus status;
|
||||
status.set_name("test-snapshot");
|
||||
status.set_device_size(kDeviceSize);
|
||||
status.set_snapshot_size(kDeviceSize);
|
||||
status.set_cow_file_size(kDeviceSize);
|
||||
ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &status));
|
||||
ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &cow_creator, &status));
|
||||
ASSERT_TRUE(CreateCowImage("test-snapshot"));
|
||||
|
||||
std::vector<std::string> snapshots;
|
||||
|
|
@ -437,6 +444,7 @@ TEST_F(SnapshotTest, CreateSnapshot) {
|
|||
ASSERT_EQ(status.state(), SnapshotState::CREATED);
|
||||
ASSERT_EQ(status.device_size(), kDeviceSize);
|
||||
ASSERT_EQ(status.snapshot_size(), kDeviceSize);
|
||||
ASSERT_EQ(status.compression_enabled(), cow_creator.compression_enabled);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(sm->UnmapSnapshot(lock_.get(), "test-snapshot"));
|
||||
|
|
@ -447,13 +455,16 @@ TEST_F(SnapshotTest, CreateSnapshot) {
|
|||
TEST_F(SnapshotTest, MapSnapshot) {
|
||||
ASSERT_TRUE(AcquireLock());
|
||||
|
||||
PartitionCowCreator cow_creator;
|
||||
cow_creator.compression_enabled = IsCompressionEnabled();
|
||||
|
||||
static const uint64_t kDeviceSize = 1024 * 1024;
|
||||
SnapshotStatus status;
|
||||
status.set_name("test-snapshot");
|
||||
status.set_device_size(kDeviceSize);
|
||||
status.set_snapshot_size(kDeviceSize);
|
||||
status.set_cow_file_size(kDeviceSize);
|
||||
ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &status));
|
||||
ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &cow_creator, &status));
|
||||
ASSERT_TRUE(CreateCowImage("test-snapshot"));
|
||||
|
||||
std::string base_device;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ message DynamicPartitionGroup {
|
|||
|
||||
message DynamicPartitionMetadata {
|
||||
repeated DynamicPartitionGroup groups = 1;
|
||||
optional bool vabc_enabled = 3;
|
||||
}
|
||||
|
||||
message DeltaArchiveManifest {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue