From 07ad1b3566ae58655a9bf3a126afd458c0a9e3a7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 26 Oct 2020 22:41:13 -0700 Subject: [PATCH] libsnapshot: Add a skeleton API for mapping and unmapping all snapshots. Bug: 168554689 Test: builds Change-Id: I0da50275cc4d0a85bd6b176b5c1286659d51a25c --- fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot.h | 2 ++ fs_mgr/libsnapshot/include/libsnapshot/snapshot.h | 10 ++++++++++ fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h | 2 ++ fs_mgr/libsnapshot/snapshot.cpp | 10 ++++++++++ fs_mgr/libsnapshot/snapshot_stub.cpp | 10 ++++++++++ 5 files changed, 34 insertions(+) diff --git a/fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot.h index 6dee3d43d..92e79107a 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot.h @@ -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& callback), (override)); MOCK_METHOD(bool, FinishMergeInRecovery, (), (override)); MOCK_METHOD(CreateResult, RecoveryCreateSnapshotDevices, (), (override)); diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h index 5b50ca97b..0764bc767 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h @@ -206,6 +206,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. @@ -321,6 +329,8 @@ class SnapshotManager final : public ISnapshotManager { bool Dump(std::ostream& os) override; std::unique_ptr EnsureMetadataMounted() override; ISnapshotMergeStats* GetSnapshotMergeStatsInstance() override; + bool MapAllSnapshots(const std::chrono::milliseconds& timeout_ms = {}) override; + bool UnmapAllSnapshots() override; private: FRIEND_TEST(SnapshotTest, CleanFirstStageMount); diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h index ed790a0f9..cba356005 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h @@ -52,6 +52,8 @@ class SnapshotManagerStub : public ISnapshotManager { bool Dump(std::ostream& os) override; std::unique_ptr EnsureMetadataMounted() override; ISnapshotMergeStats* GetSnapshotMergeStatsInstance() override; + bool MapAllSnapshots(const std::chrono::milliseconds& timeout_ms) override; + bool UnmapAllSnapshots() override; }; } // namespace android::snapshot diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 6574457db..e42e66874 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -1861,6 +1861,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 { unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW)); diff --git a/fs_mgr/libsnapshot/snapshot_stub.cpp b/fs_mgr/libsnapshot/snapshot_stub.cpp index 5be3c10c8..26b9129b8 100644 --- a/fs_mgr/libsnapshot/snapshot_stub.cpp +++ b/fs_mgr/libsnapshot/snapshot_stub.cpp @@ -136,4 +136,14 @@ std::unique_ptr 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