Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9865e47e authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "libsnapshot: Collect more COW size data in snapshot merge stats."

parents f0e39a9d cdf3b398
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ enum MergePhase {
    SECOND_PHASE = 2;
}

// Next: 12
// Next: 13
message SnapshotStatus {
    // Name of the snapshot. This is usually the name of the snapshotted
    // logical partition; for example, "system_b".
@@ -105,6 +105,9 @@ message SnapshotStatus {

    // Compression algorithm (none, gz, or brotli).
    string compression_algorithm = 11;

    // Estimated COW size from OTA manifest.
    uint64 estimated_cow_size = 12;
}

// Next: 8
@@ -159,7 +162,7 @@ message SnapshotUpdateStatus {
    MergePhase merge_phase = 6;
}

// Next: 5
// Next: 7
message SnapshotMergeReport {
    // Status of the update after the merge attempts.
    UpdateState state = 1;
@@ -173,4 +176,10 @@ message SnapshotMergeReport {

    // Whether compression/dm-user was used for any snapshots.
    bool compression_enabled = 4;

    // Total size used by COWs, including /data and the super partition.
    uint64 total_cow_size_bytes = 5;

    // Sum of the estimated COW fields in the OTA manifest.
    uint64 estimated_cow_size_bytes = 6;
}
+2 −1
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@ class MockSnapshotManager : public ISnapshotManager {
    MOCK_METHOD(bool, BeginUpdate, (), (override));
    MOCK_METHOD(bool, CancelUpdate, (), (override));
    MOCK_METHOD(bool, FinishedSnapshotWrites, (bool wipe), (override));
    MOCK_METHOD(bool, InitiateMerge, (uint64_t * cow_file_size), (override));
    MOCK_METHOD(void, UpdateCowStats, (ISnapshotMergeStats * stats), (override));
    MOCK_METHOD(bool, InitiateMerge, (), (override));

    MOCK_METHOD(UpdateState, ProcessUpdateState,
                (const std::function<bool()>& callback, const std::function<bool()>& before_cancel),
+13 −3
Original line number Diff line number Diff line
@@ -127,9 +127,14 @@ class ISnapshotManager {
    // may need to be merged before wiping.
    virtual bool FinishedSnapshotWrites(bool wipe) = 0;

    // Update an ISnapshotMergeStats object with statistics about COW usage.
    // This should be called before the merge begins as otherwise snapshots
    // may be deleted.
    virtual void UpdateCowStats(ISnapshotMergeStats* stats) = 0;

    // Initiate a merge on all snapshot devices. This should only be used after an
    // update has been marked successful after booting.
    virtual bool InitiateMerge(uint64_t* cow_file_size = nullptr) = 0;
    virtual bool InitiateMerge() = 0;

    // Perform any necessary post-boot actions. This should be run soon after
    // /data is mounted.
@@ -326,7 +331,8 @@ class SnapshotManager final : public ISnapshotManager {
    bool BeginUpdate() override;
    bool CancelUpdate() override;
    bool FinishedSnapshotWrites(bool wipe) override;
    bool InitiateMerge(uint64_t* cow_file_size = nullptr) override;
    void UpdateCowStats(ISnapshotMergeStats* stats) override;
    bool InitiateMerge() override;
    UpdateState ProcessUpdateState(const std::function<bool()>& callback = {},
                                   const std::function<bool()>& before_cancel = {}) override;
    UpdateState GetUpdateState(double* progress = nullptr) override;
@@ -491,7 +497,8 @@ class SnapshotManager final : public ISnapshotManager {
    bool RemoveAllSnapshots(LockedFile* lock);

    // List the known snapshot names.
    bool ListSnapshots(LockedFile* lock, std::vector<std::string>* snapshots);
    bool ListSnapshots(LockedFile* lock, std::vector<std::string>* snapshots,
                       const std::string& suffix = "");

    // Check for a cancelled or rolled back merge, returning true if such a
    // condition was detected and handled.
@@ -679,6 +686,9 @@ class SnapshotManager final : public ISnapshotManager {
    friend std::ostream& operator<<(std::ostream& os, SnapshotManager::Slot slot);
    Slot GetCurrentSlot();

    // Return the suffix we expect snapshots to have.
    std::string GetSnapshotSlotSuffix();

    std::string ReadUpdateSourceSlotSuffix();

    // Helper for RemoveAllSnapshots.
+8 −0
Original line number Diff line number Diff line
@@ -30,7 +30,11 @@ class ISnapshotMergeStats {
    virtual bool Start() = 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 void set_total_cow_size_bytes(uint64_t bytes) = 0;
    virtual void set_estimated_cow_size_bytes(uint64_t bytes) = 0;
    virtual uint64_t cow_file_size() = 0;
    virtual uint64_t total_cow_size_bytes() = 0;
    virtual uint64_t estimated_cow_size_bytes() = 0;

    // Called when merge ends. Properly clean up permanent storage.
    class Result {
@@ -54,6 +58,10 @@ class SnapshotMergeStats : public ISnapshotMergeStats {
    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;
    void set_total_cow_size_bytes(uint64_t bytes) override;
    void set_estimated_cow_size_bytes(uint64_t bytes) override;
    uint64_t total_cow_size_bytes() override;
    uint64_t estimated_cow_size_bytes() override;
    std::unique_ptr<Result> Finish() override;

  private:
+2 −1
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ class SnapshotManagerStub : public ISnapshotManager {
    bool BeginUpdate() override;
    bool CancelUpdate() override;
    bool FinishedSnapshotWrites(bool wipe) override;
    bool InitiateMerge(uint64_t* cow_file_size = nullptr) override;
    void UpdateCowStats(ISnapshotMergeStats* stats) override;
    bool InitiateMerge() override;
    UpdateState ProcessUpdateState(const std::function<bool()>& callback = {},
                                   const std::function<bool()>& before_cancel = {}) override;
    UpdateState GetUpdateState(double* progress = nullptr) override;
Loading