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

Commit 5fea7df8 authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "libsnapshot: Add a skeleton API for mapping and unmapping all snapshots."

parents a1a5fdc6 07ad1b35
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ class MockSnapshotManager : public ISnapshotManager {
    MOCK_METHOD(bool, CreateLogicalAndSnapshotPartitions,
                (const std::string& super_device, const std::chrono::milliseconds& timeout_ms),
                (override));
    MOCK_METHOD(bool, MapAllSnapshots, (const std::chrono::milliseconds& timeout_ms), (override));
    MOCK_METHOD(bool, UnmapAllSnapshots, (), (override));
    MOCK_METHOD(bool, HandleImminentDataWipe, (const std::function<void()>& callback), (override));
    MOCK_METHOD(bool, FinishMergeInRecovery, (), (override));
    MOCK_METHOD(CreateResult, RecoveryCreateSnapshotDevices, (), (override));
+10 −0
Original line number Diff line number Diff line
@@ -207,6 +207,14 @@ class ISnapshotManager {
    virtual bool CreateLogicalAndSnapshotPartitions(
            const std::string& super_device, const std::chrono::milliseconds& timeout_ms = {}) = 0;

    // Map all snapshots. This is analogous to CreateLogicalAndSnapshotPartitions, except it maps
    // the target slot rather than the current slot. It should only be used immediately after
    // applying an update, before rebooting to the new slot.
    virtual bool MapAllSnapshots(const std::chrono::milliseconds& timeout_ms = {}) = 0;

    // Unmap all snapshots. This should be called to undo MapAllSnapshots().
    virtual bool UnmapAllSnapshots() = 0;

    // This method should be called preceding any wipe or flash of metadata or
    // userdata. It is only valid in recovery or fastbootd, and it ensures that
    // a merge has been completed.
@@ -322,6 +330,8 @@ class SnapshotManager final : public ISnapshotManager {
    bool Dump(std::ostream& os) override;
    std::unique_ptr<AutoDevice> EnsureMetadataMounted() override;
    ISnapshotMergeStats* GetSnapshotMergeStatsInstance() override;
    bool MapAllSnapshots(const std::chrono::milliseconds& timeout_ms = {}) override;
    bool UnmapAllSnapshots() override;

  private:
    FRIEND_TEST(SnapshotTest, CleanFirstStageMount);
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ class SnapshotManagerStub : public ISnapshotManager {
    bool Dump(std::ostream& os) override;
    std::unique_ptr<AutoDevice> EnsureMetadataMounted() override;
    ISnapshotMergeStats* GetSnapshotMergeStatsInstance() override;
    bool MapAllSnapshots(const std::chrono::milliseconds& timeout_ms) override;
    bool UnmapAllSnapshots() override;
};

}  // namespace android::snapshot
+10 −0
Original line number Diff line number Diff line
@@ -1945,6 +1945,16 @@ bool SnapshotManager::UnmapCowDevices(LockedFile* lock, const std::string& name)
    return true;
}

bool SnapshotManager::MapAllSnapshots(const std::chrono::milliseconds&) {
    LOG(ERROR) << "Not yet implemented.";
    return false;
}

bool SnapshotManager::UnmapAllSnapshots() {
    LOG(ERROR) << "Not yet implemented.";
    return false;
}

auto SnapshotManager::OpenFile(const std::string& file, int lock_flags)
        -> std::unique_ptr<LockedFile> {
    unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
+10 −0
Original line number Diff line number Diff line
@@ -136,4 +136,14 @@ std::unique_ptr<ISnapshotWriter> SnapshotManagerStub::OpenSnapshotWriter(
    return nullptr;
}

bool SnapshotManagerStub::MapAllSnapshots(const std::chrono::milliseconds&) {
    LOG(ERROR) << __FUNCTION__ << " should never be called.";
    return false;
}

bool SnapshotManagerStub::UnmapAllSnapshots() {
    LOG(ERROR) << __FUNCTION__ << " should never be called.";
    return false;
}

}  // namespace android::snapshot