summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2020-04-15 13:47:34 -0700
committerYifan Hong <elsk@google.com>2020-04-16 13:12:41 -0700
commitee5032a4365e203b3555f524ac63f91c0dabd77c (patch)
tree9834bf6068796939b5b94bcecae4163afd83d3c6
parentfedb2709083a02674d45e2c20bb2bf4767dcce64 (diff)
downloadcore-ee5032a4365e203b3555f524ac63f91c0dabd77c.tar.gz
libsnapshot: Add GetSnapshotMergeStatsInstance
This is preferred over SnapshotMergeStats::GetInstance because the latter needs a concrete SnapshotManager, not the ISnapshotManager interface. SnapshotManagerStub::GetSnapshotMergeStatsInstance returns a SnapshotMergeStatsStub instance. Test: vts_libsnapshot_test Bug: 148956645 Change-Id: Ife0ad6d3ce85333cbf395d07f74dedc9ca3fe675
-rw-r--r--fs_mgr/libsnapshot/include/libsnapshot/snapshot.h6
-rw-r--r--fs_mgr/libsnapshot/include/libsnapshot/snapshot_stats.h24
-rw-r--r--fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h1
-rw-r--r--fs_mgr/libsnapshot/snapshot.cpp4
-rw-r--r--fs_mgr/libsnapshot/snapshot_stub.cpp14
5 files changed, 42 insertions, 7 deletions
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
index c73ed2c33..fff667ee5 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
@@ -70,6 +70,8 @@ struct AutoDeleteCowImage;
struct AutoDeleteSnapshot;
struct AutoDeviceList;
struct PartitionCowCreator;
+class ISnapshotMergeStats;
+class SnapshotMergeStats;
class SnapshotStatus;
static constexpr const std::string_view kCowGroupName = "cow";
@@ -235,6 +237,9 @@ class ISnapshotManager {
// b.reset() // unmounts
// a.reset() // does nothing
virtual std::unique_ptr<AutoDevice> EnsureMetadataMounted() = 0;
+
+ // Return the associated ISnapshotMergeStats instance. Never null.
+ virtual ISnapshotMergeStats* GetSnapshotMergeStatsInstance() = 0;
};
class SnapshotManager final : public ISnapshotManager {
@@ -289,6 +294,7 @@ class SnapshotManager final : public ISnapshotManager {
const std::unique_ptr<AutoDevice>& metadata_device) override;
bool Dump(std::ostream& os) override;
std::unique_ptr<AutoDevice> EnsureMetadataMounted() override;
+ ISnapshotMergeStats* GetSnapshotMergeStatsInstance() override;
private:
FRIEND_TEST(SnapshotTest, CleanFirstStageMount);
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stats.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stats.h
index 91dd34f80..4caf63231 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stats.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stats.h
@@ -23,14 +23,12 @@
namespace android {
namespace snapshot {
-class SnapshotMergeStats {
+class ISnapshotMergeStats {
public:
- // Not thread safe.
- static SnapshotMergeStats* GetInstance(SnapshotManager& manager);
-
+ virtual ~ISnapshotMergeStats() = default;
// Called when merge starts or resumes.
- bool Start();
- void set_state(android::snapshot::UpdateState state);
+ virtual bool Start() = 0;
+ virtual void set_state(android::snapshot::UpdateState state) = 0;
// Called when merge ends. Properly clean up permanent storage.
class Result {
@@ -40,7 +38,19 @@ class SnapshotMergeStats {
// Time between successful Start() / Resume() to Finish().
virtual std::chrono::steady_clock::duration merge_time() const = 0;
};
- std::unique_ptr<Result> Finish();
+ // Return nullptr if any failure.
+ virtual std::unique_ptr<Result> Finish() = 0;
+};
+
+class SnapshotMergeStats : public ISnapshotMergeStats {
+ public:
+ // Not thread safe.
+ static SnapshotMergeStats* GetInstance(SnapshotManager& manager);
+
+ // ISnapshotMergeStats overrides
+ bool Start() override;
+ void set_state(android::snapshot::UpdateState state) override;
+ std::unique_ptr<Result> Finish() override;
private:
bool ReadState();
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h
index 924f26d49..9b2590ccd 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot_stub.h
@@ -46,6 +46,7 @@ class SnapshotManagerStub : public ISnapshotManager {
const std::unique_ptr<AutoDevice>& metadata_device) override;
bool Dump(std::ostream& os) override;
std::unique_ptr<AutoDevice> EnsureMetadataMounted() override;
+ ISnapshotMergeStats* GetSnapshotMergeStatsInstance() override;
};
} // namespace android::snapshot
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index c9fa28e9f..eafeea215 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -2685,5 +2685,9 @@ bool SnapshotManager::UpdateForwardMergeIndicator(bool wipe) {
return true;
}
+ISnapshotMergeStats* SnapshotManager::GetSnapshotMergeStatsInstance() {
+ return SnapshotMergeStats::GetInstance(*this);
+}
+
} // namespace snapshot
} // namespace android
diff --git a/fs_mgr/libsnapshot/snapshot_stub.cpp b/fs_mgr/libsnapshot/snapshot_stub.cpp
index 6c82f61ee..2747b037f 100644
--- a/fs_mgr/libsnapshot/snapshot_stub.cpp
+++ b/fs_mgr/libsnapshot/snapshot_stub.cpp
@@ -16,6 +16,8 @@
#include <android-base/logging.h>
+#include <libsnapshot/snapshot_stats.h>
+
using android::fs_mgr::CreateLogicalPartitionParams;
using chromeos_update_engine::DeltaArchiveManifest;
@@ -108,4 +110,16 @@ std::unique_ptr<AutoDevice> SnapshotManagerStub::EnsureMetadataMounted() {
return nullptr;
}
+class SnapshotMergeStatsStub : public ISnapshotMergeStats {
+ bool Start() override { return false; }
+ void set_state(android::snapshot::UpdateState) override {}
+ std::unique_ptr<Result> Finish() override { return nullptr; }
+};
+
+ISnapshotMergeStats* SnapshotManagerStub::GetSnapshotMergeStatsInstance() {
+ static SnapshotMergeStatsStub snapshot_merge_stats;
+ LOG(ERROR) << __FUNCTION__ << " should never be called.";
+ return &snapshot_merge_stats;
+}
+
} // namespace android::snapshot