From efcc9ae010c5f25f742939f22892a90564b9986f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 10 Mar 2023 12:50:59 -0800 Subject: [PATCH] snapshotctl: Display merge progress and phases. Bug: N/A Test: snapshotctl dump during merge phase Change-Id: Ife319450b28c8c58268a03127e9f58c47fc224d8 --- fs_mgr/libsnapshot/snapshot.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 15f025c9c..00da19f7a 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -2901,6 +2901,20 @@ std::ostream& operator<<(std::ostream& os, UpdateState state) { } } +std::ostream& operator<<(std::ostream& os, MergePhase phase) { + switch (phase) { + case MergePhase::NO_MERGE: + return os << "none"; + case MergePhase::FIRST_PHASE: + return os << "first"; + case MergePhase::SECOND_PHASE: + return os << "second"; + default: + LOG(ERROR) << "Unknown merge phase: " << static_cast(phase); + return os << "unknown(" << static_cast(phase) << ")"; + } +} + UpdateState SnapshotManager::ReadUpdateState(LockedFile* lock) { SnapshotUpdateStatus status = ReadSnapshotUpdateStatus(lock); return status.state(); @@ -3759,7 +3773,7 @@ bool SnapshotManager::Dump(std::ostream& os) { auto update_status = ReadSnapshotUpdateStatus(file.get()); - ss << "Update state: " << ReadUpdateState(file.get()) << std::endl; + ss << "Update state: " << update_status.state() << std::endl; ss << "Using snapuserd: " << update_status.using_snapuserd() << std::endl; ss << "Using userspace snapshots: " << update_status.userspace_snapshots() << std::endl; ss << "Using io_uring: " << update_status.io_uring_enabled() << std::endl; @@ -3774,6 +3788,17 @@ bool SnapshotManager::Dump(std::ostream& os) { << std::endl; ss << "Source build fingerprint: " << update_status.source_build_fingerprint() << std::endl; + if (update_status.state() == UpdateState::Merging) { + ss << "Merge completion: "; + if (!EnsureSnapuserdConnected()) { + ss << "N/A"; + } else { + ss << snapuserd_client_->GetMergePercent() << "%"; + } + ss << std::endl; + ss << "Merge phase: " << update_status.merge_phase() << std::endl; + } + bool ok = true; std::vector snapshots; if (!ListSnapshots(file.get(), &snapshots)) { @@ -3796,6 +3821,7 @@ bool SnapshotManager::Dump(std::ostream& os) { ss << " allocated sectors: " << status.sectors_allocated() << std::endl; ss << " metadata sectors: " << status.metadata_sectors() << std::endl; ss << " compression: " << status.compression_algorithm() << std::endl; + ss << " merge phase: " << DecideMergePhase(status) << std::endl; } os << ss.rdbuf(); return ok;