From f1f06f86786794ede887a8608f2dd2e0bf95de6a Mon Sep 17 00:00:00 2001 From: Akilesh Kailash Date: Mon, 13 Nov 2023 22:06:37 -0800 Subject: [PATCH] libsnapshot: Check if OTA update in progress during reboot If any of the read-only partitions are mounted off dm-user then certainly update is in-progress. Bug: 308900853 Test: OTA on Pixel, reboot during OTA. Change-Id: I36121e1d99ec7c1f1110a65fc67996190875af18 Signed-off-by: Akilesh Kailash --- fs_mgr/libsnapshot/snapshot.cpp | 44 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index c639e43d3..e91e3b73c 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -4339,32 +4339,30 @@ std::string SnapshotManager::ReadSourceBuildFingerprint() { } bool SnapshotManager::IsUserspaceSnapshotUpdateInProgress() { - auto slot = GetCurrentSlot(); - if (slot == Slot::Target) { - // Merge in-progress - if (IsSnapuserdRequired()) { + // We cannot grab /metadata/ota lock here as this + // is in reboot path. See b/308900853 + // + // Check if any of the partitions are mounted + // off dm-user block device. If so, then we are certain + // that OTA update in progress. + auto current_suffix = device_->GetSlotSuffix(); + auto& dm = DeviceMapper::Instance(); + auto dm_block_devices = dm.FindDmPartitions(); + if (dm_block_devices.empty()) { + LOG(ERROR) << "No dm-enabled block device is found."; + return false; + } + for (auto& partition : dm_block_devices) { + std::string partition_name = partition.first + current_suffix; + DeviceMapper::TargetInfo snap_target; + if (!GetSingleTarget(partition_name, TableQuery::Status, &snap_target)) { + return false; + } + auto type = DeviceMapper::GetTargetType(snap_target.spec); + if (type == "user") { return true; } } - - // Let's check more deeper to see if snapshots are mounted - auto lock = LockExclusive(); - if (!lock) { - return false; - } - - std::vector snapshots; - if (!ListSnapshots(lock.get(), &snapshots)) { - return false; - } - - for (const auto& snapshot : snapshots) { - // Active snapshot and daemon is alive - if (IsSnapshotDevice(snapshot) && EnsureSnapuserdConnected(2s)) { - return true; - } - } - return false; }