Merge changes I845d2250,I4faa0785

* changes:
  libsnapshot: proto use correct index
  libsnapshot: Export COW image size
This commit is contained in:
Yifan Hong 2020-05-30 01:06:56 +00:00 committed by Gerrit Code Review
commit 51b127c71e
8 changed files with 36 additions and 7 deletions

View file

@ -132,7 +132,7 @@ message SnapshotUpdateStatus {
uint64 metadata_sectors = 4; uint64 metadata_sectors = 4;
} }
// Next: 2 // Next: 4
message SnapshotMergeReport { message SnapshotMergeReport {
// Status of the update after the merge attempts. // Status of the update after the merge attempts.
UpdateState state = 1; UpdateState state = 1;
@ -140,4 +140,7 @@ message SnapshotMergeReport {
// Number of reboots that occurred after issuing and before completeing the // Number of reboots that occurred after issuing and before completeing the
// merge of all the snapshot devices. // merge of all the snapshot devices.
int32 resume_count = 2; int32 resume_count = 2;
// Total size of all the COW images before the update.
uint64 cow_file_size = 3;
} }

View file

@ -25,7 +25,7 @@ class MockSnapshotManager : public ISnapshotManager {
MOCK_METHOD(bool, BeginUpdate, (), (override)); MOCK_METHOD(bool, BeginUpdate, (), (override));
MOCK_METHOD(bool, CancelUpdate, (), (override)); MOCK_METHOD(bool, CancelUpdate, (), (override));
MOCK_METHOD(bool, FinishedSnapshotWrites, (bool wipe), (override)); MOCK_METHOD(bool, FinishedSnapshotWrites, (bool wipe), (override));
MOCK_METHOD(bool, InitiateMerge, (), (override)); MOCK_METHOD(bool, InitiateMerge, (uint64_t * cow_file_size), (override));
MOCK_METHOD(UpdateState, ProcessUpdateState, MOCK_METHOD(UpdateState, ProcessUpdateState,
(const std::function<bool()>& callback, const std::function<bool()>& before_cancel), (const std::function<bool()>& callback, const std::function<bool()>& before_cancel),

View file

@ -124,7 +124,7 @@ class ISnapshotManager {
// Initiate a merge on all snapshot devices. This should only be used after an // Initiate a merge on all snapshot devices. This should only be used after an
// update has been marked successful after booting. // update has been marked successful after booting.
virtual bool InitiateMerge() = 0; virtual bool InitiateMerge(uint64_t* cow_file_size = nullptr) = 0;
// Perform any necessary post-boot actions. This should be run soon after // Perform any necessary post-boot actions. This should be run soon after
// /data is mounted. // /data is mounted.
@ -281,7 +281,7 @@ class SnapshotManager final : public ISnapshotManager {
bool BeginUpdate() override; bool BeginUpdate() override;
bool CancelUpdate() override; bool CancelUpdate() override;
bool FinishedSnapshotWrites(bool wipe) override; bool FinishedSnapshotWrites(bool wipe) override;
bool InitiateMerge() override; bool InitiateMerge(uint64_t* cow_file_size = nullptr) override;
UpdateState ProcessUpdateState(const std::function<bool()>& callback = {}, UpdateState ProcessUpdateState(const std::function<bool()>& callback = {},
const std::function<bool()>& before_cancel = {}) override; const std::function<bool()>& before_cancel = {}) override;
UpdateState GetUpdateState(double* progress = nullptr) override; UpdateState GetUpdateState(double* progress = nullptr) override;

View file

@ -29,6 +29,8 @@ class ISnapshotMergeStats {
// Called when merge starts or resumes. // Called when merge starts or resumes.
virtual bool Start() = 0; virtual bool Start() = 0;
virtual void set_state(android::snapshot::UpdateState state) = 0; virtual void set_state(android::snapshot::UpdateState state) = 0;
virtual void set_cow_file_size(uint64_t cow_file_size) = 0;
virtual uint64_t cow_file_size() = 0;
// Called when merge ends. Properly clean up permanent storage. // Called when merge ends. Properly clean up permanent storage.
class Result { class Result {
@ -50,6 +52,8 @@ class SnapshotMergeStats : public ISnapshotMergeStats {
// ISnapshotMergeStats overrides // ISnapshotMergeStats overrides
bool Start() override; bool Start() override;
void set_state(android::snapshot::UpdateState state) override; void set_state(android::snapshot::UpdateState state) override;
void set_cow_file_size(uint64_t cow_file_size) override;
uint64_t cow_file_size() override;
std::unique_ptr<Result> Finish() override; std::unique_ptr<Result> Finish() override;
private: private:

View file

@ -27,7 +27,7 @@ class SnapshotManagerStub : public ISnapshotManager {
bool BeginUpdate() override; bool BeginUpdate() override;
bool CancelUpdate() override; bool CancelUpdate() override;
bool FinishedSnapshotWrites(bool wipe) override; bool FinishedSnapshotWrites(bool wipe) override;
bool InitiateMerge() override; bool InitiateMerge(uint64_t* cow_file_size = nullptr) override;
UpdateState ProcessUpdateState(const std::function<bool()>& callback = {}, UpdateState ProcessUpdateState(const std::function<bool()>& callback = {},
const std::function<bool()>& before_cancel = {}) override; const std::function<bool()>& before_cancel = {}) override;
UpdateState GetUpdateState(double* progress = nullptr) override; UpdateState GetUpdateState(double* progress = nullptr) override;

View file

@ -555,7 +555,7 @@ bool SnapshotManager::DeleteSnapshot(LockedFile* lock, const std::string& name)
return true; return true;
} }
bool SnapshotManager::InitiateMerge() { bool SnapshotManager::InitiateMerge(uint64_t* cow_file_size) {
auto lock = LockExclusive(); auto lock = LockExclusive();
if (!lock) return false; if (!lock) return false;
@ -618,6 +618,7 @@ bool SnapshotManager::InitiateMerge() {
} }
} }
uint64_t total_cow_file_size = 0;
DmTargetSnapshot::Status initial_target_values = {}; DmTargetSnapshot::Status initial_target_values = {};
for (const auto& snapshot : snapshots) { for (const auto& snapshot : snapshots) {
DmTargetSnapshot::Status current_status; DmTargetSnapshot::Status current_status;
@ -627,6 +628,16 @@ bool SnapshotManager::InitiateMerge() {
initial_target_values.sectors_allocated += current_status.sectors_allocated; initial_target_values.sectors_allocated += current_status.sectors_allocated;
initial_target_values.total_sectors += current_status.total_sectors; initial_target_values.total_sectors += current_status.total_sectors;
initial_target_values.metadata_sectors += current_status.metadata_sectors; initial_target_values.metadata_sectors += current_status.metadata_sectors;
SnapshotStatus snapshot_status;
if (!ReadSnapshotStatus(lock.get(), snapshot, &snapshot_status)) {
return false;
}
total_cow_file_size += snapshot_status.cow_file_size();
}
if (cow_file_size) {
*cow_file_size = total_cow_file_size;
} }
SnapshotUpdateStatus initial_status; SnapshotUpdateStatus initial_status;

View file

@ -88,6 +88,15 @@ void SnapshotMergeStats::set_state(android::snapshot::UpdateState state) {
report_.set_state(state); report_.set_state(state);
} }
void SnapshotMergeStats::set_cow_file_size(uint64_t cow_file_size) {
report_.set_cow_file_size(cow_file_size);
WriteState();
}
uint64_t SnapshotMergeStats::cow_file_size() {
return report_.cow_file_size();
}
class SnapshotMergeStatsResultImpl : public SnapshotMergeStats::Result { class SnapshotMergeStatsResultImpl : public SnapshotMergeStats::Result {
public: public:
SnapshotMergeStatsResultImpl(const SnapshotMergeReport& report, SnapshotMergeStatsResultImpl(const SnapshotMergeReport& report,

View file

@ -42,7 +42,7 @@ bool SnapshotManagerStub::FinishedSnapshotWrites(bool) {
return false; return false;
} }
bool SnapshotManagerStub::InitiateMerge() { bool SnapshotManagerStub::InitiateMerge(uint64_t*) {
LOG(ERROR) << __FUNCTION__ << " should never be called."; LOG(ERROR) << __FUNCTION__ << " should never be called.";
return false; return false;
} }
@ -118,6 +118,8 @@ std::unique_ptr<AutoDevice> SnapshotManagerStub::EnsureMetadataMounted() {
class SnapshotMergeStatsStub : public ISnapshotMergeStats { class SnapshotMergeStatsStub : public ISnapshotMergeStats {
bool Start() override { return false; } bool Start() override { return false; }
void set_state(android::snapshot::UpdateState) override {} void set_state(android::snapshot::UpdateState) 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; } std::unique_ptr<Result> Finish() override { return nullptr; }
}; };