From 3ad55a96906e2f4a8ff6dced1bcbb8e84bf6e601 Mon Sep 17 00:00:00 2001 From: Akilesh Kailash Date: Sun, 12 Sep 2021 12:31:33 +0000 Subject: [PATCH] libsnapshot: Error handling after QuerySnapshotStatus QuerySnapshotStatus will capture the error codes from dm-snapshot if there are any snapshot related failure. Handle the error codes and fail the QuerySnapshotStatus call. Validate snapshot status in MapSnapshot(). If the mode is set to Persistent and snapshot status is in Merging state, then forcefully set the mode to Merge state. Bug: 198265278 Test: Full/incremental OTA Signed-off-by: Akilesh Kailash Change-Id: I779184f1998b23edacd6e780acf2676442004340 --- fs_mgr/libsnapshot/snapshot.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 52324ba63..4eea88bcb 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -518,6 +518,13 @@ bool SnapshotManager::MapSnapshot(LockedFile* lock, const std::string& name, break; } + if (mode == SnapshotStorageMode::Persistent && status.state() == SnapshotState::MERGING) { + LOG(ERROR) << "Snapshot: " << name + << " has snapshot status Merging but mode set to Persistent." + << " Changing mode to Snapshot-Merge."; + mode = SnapshotStorageMode::Merge; + } + DmTable table; table.Emplace(0, snapshot_sectors, base_device, cow_device, mode, kSnapshotChunkSize); @@ -886,6 +893,10 @@ bool SnapshotManager::QuerySnapshotStatus(const std::string& dm_name, std::strin if (target_type) { *target_type = DeviceMapper::GetTargetType(target.spec); } + if (!status->error.empty()) { + LOG(ERROR) << "Snapshot: " << dm_name << " returned error code: " << status->error; + return false; + } return true; }