Merge "libsnapshot: Communicate compression status to update_engine."

This commit is contained in:
Yifan Hong 2021-02-08 21:13:10 +00:00 committed by Gerrit Code Review
commit 3e6b93ca11
8 changed files with 36 additions and 6 deletions

View file

@ -156,7 +156,7 @@ message SnapshotUpdateStatus {
MergePhase merge_phase = 6;
}
// Next: 4
// Next: 5
message SnapshotMergeReport {
// Status of the update after the merge attempts.
UpdateState state = 1;
@ -167,4 +167,7 @@ message SnapshotMergeReport {
// Total size of all the COW images before the update.
uint64 cow_file_size = 3;
// Whether compression/dm-user was used for any snapshots.
bool compression_enabled = 4;
}

View file

@ -32,6 +32,7 @@ class MockSnapshotManager : public ISnapshotManager {
(const std::function<bool()>& callback, const std::function<bool()>& before_cancel),
(override));
MOCK_METHOD(UpdateState, GetUpdateState, (double* progress), (override));
MOCK_METHOD(bool, UpdateUsesCompression, (), (override));
MOCK_METHOD(Return, CreateUpdateSnapshots,
(const chromeos_update_engine::DeltaArchiveManifest& manifest), (override));
MOCK_METHOD(bool, MapUpdateSnapshot,

View file

@ -170,6 +170,10 @@ class ISnapshotManager {
// Other: 0
virtual UpdateState GetUpdateState(double* progress = nullptr) = 0;
// Returns true if compression is enabled for the current update. This always returns false if
// UpdateState is None, or no snapshots have been created.
virtual bool UpdateUsesCompression() = 0;
// Create necessary COW device / files for OTA clients. New logical partitions will be added to
// group "cow" in target_metadata. Regions of partitions of current_metadata will be
// "write-protected" and snapshotted.
@ -326,6 +330,7 @@ class SnapshotManager final : public ISnapshotManager {
UpdateState ProcessUpdateState(const std::function<bool()>& callback = {},
const std::function<bool()>& before_cancel = {}) override;
UpdateState GetUpdateState(double* progress = nullptr) override;
bool UpdateUsesCompression() override;
Return CreateUpdateSnapshots(const DeltaArchiveManifest& manifest) override;
bool MapUpdateSnapshot(const CreateLogicalPartitionParams& params,
std::string* snapshot_path) override;
@ -720,6 +725,9 @@ class SnapshotManager final : public ISnapshotManager {
SnapuserdClient* snapuserd_client() const { return snapuserd_client_.get(); }
// Helper of UpdateUsesCompression
bool UpdateUsesCompression(LockedFile* lock);
std::string gsid_dir_;
std::string metadata_dir_;
std::unique_ptr<IDeviceInfo> device_;

View file

@ -28,7 +28,7 @@ class ISnapshotMergeStats {
virtual ~ISnapshotMergeStats() = default;
// Called when merge starts or resumes.
virtual bool Start() = 0;
virtual void set_state(android::snapshot::UpdateState state) = 0;
virtual void set_state(android::snapshot::UpdateState state, bool using_compression) = 0;
virtual void set_cow_file_size(uint64_t cow_file_size) = 0;
virtual uint64_t cow_file_size() = 0;
@ -51,7 +51,7 @@ class SnapshotMergeStats : public ISnapshotMergeStats {
// ISnapshotMergeStats overrides
bool Start() override;
void set_state(android::snapshot::UpdateState state) override;
void set_state(android::snapshot::UpdateState state, bool using_compression) override;
void set_cow_file_size(uint64_t cow_file_size) override;
uint64_t cow_file_size() override;
std::unique_ptr<Result> Finish() override;

View file

@ -32,6 +32,7 @@ class SnapshotManagerStub : public ISnapshotManager {
UpdateState ProcessUpdateState(const std::function<bool()>& callback = {},
const std::function<bool()>& before_cancel = {}) override;
UpdateState GetUpdateState(double* progress = nullptr) override;
bool UpdateUsesCompression() override;
Return CreateUpdateSnapshots(
const chromeos_update_engine::DeltaArchiveManifest& manifest) override;
bool MapUpdateSnapshot(const android::fs_mgr::CreateLogicalPartitionParams& params,

View file

@ -1683,6 +1683,17 @@ UpdateState SnapshotManager::GetUpdateState(double* progress) {
return state;
}
bool SnapshotManager::UpdateUsesCompression() {
auto lock = LockShared();
if (!lock) return false;
return UpdateUsesCompression(lock.get());
}
bool SnapshotManager::UpdateUsesCompression(LockedFile* lock) {
SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
return update_status.compression_enabled();
}
bool SnapshotManager::ListSnapshots(LockedFile* lock, std::vector<std::string>* snapshots) {
CHECK(lock);
@ -2109,7 +2120,7 @@ bool SnapshotManager::UnmapCowDevices(LockedFile* lock, const std::string& name)
auto& dm = DeviceMapper::Instance();
if (IsCompressionEnabled() && !UnmapDmUserDevice(name)) {
if (UpdateUsesCompression(lock) && !UnmapDmUserDevice(name)) {
return false;
}

View file

@ -84,8 +84,9 @@ bool SnapshotMergeStats::Start() {
return WriteState();
}
void SnapshotMergeStats::set_state(android::snapshot::UpdateState state) {
void SnapshotMergeStats::set_state(android::snapshot::UpdateState state, bool using_compression) {
report_.set_state(state);
report_.set_compression_enabled(using_compression);
}
void SnapshotMergeStats::set_cow_file_size(uint64_t cow_file_size) {

View file

@ -116,9 +116,14 @@ std::unique_ptr<AutoDevice> SnapshotManagerStub::EnsureMetadataMounted() {
return nullptr;
}
bool SnapshotManagerStub::UpdateUsesCompression() {
LOG(ERROR) << __FUNCTION__ << " should never be called.";
return false;
}
class SnapshotMergeStatsStub : public ISnapshotMergeStats {
bool Start() override { return false; }
void set_state(android::snapshot::UpdateState) override {}
void set_state(android::snapshot::UpdateState, bool) override {}
void set_cow_file_size(uint64_t) override {}
uint64_t cow_file_size() override { return 0; }
std::unique_ptr<Result> Finish() override { return nullptr; }