libsnapshot: Only mount snapshots in MapAllSnapshots().
By accident, this was mounting partitions as well, which caused
conflicts in partial updates where some partitions don't have snapshots.
Test: update_device.py with partial OTA
Change-Id: I2db0e6269f0a02cbe8164fa2a72b887c352f56d8
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index 34c684c..9329725 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -2172,12 +2172,44 @@
return false;
}
- if (!UnmapAllSnapshots(lock.get())) {
+ std::vector<std::string> snapshots;
+ if (!ListSnapshots(lock.get(), &snapshots)) {
return false;
}
- uint32_t slot = SlotNumberForSlotSuffix(device_->GetOtherSlotSuffix());
- return MapAllPartitions(lock.get(), device_->GetSuperDevice(slot), slot, timeout_ms);
+ const auto& opener = device_->GetPartitionOpener();
+ auto slot_suffix = device_->GetOtherSlotSuffix();
+ auto slot_number = SlotNumberForSlotSuffix(slot_suffix);
+ auto super_device = device_->GetSuperDevice(slot_number);
+ auto metadata = android::fs_mgr::ReadMetadata(opener, super_device, slot_number);
+ if (!metadata) {
+ LOG(ERROR) << "MapAllSnapshots could not read dynamic partition metadata for device: "
+ << super_device;
+ return false;
+ }
+
+ for (const auto& snapshot : snapshots) {
+ if (!UnmapPartitionWithSnapshot(lock.get(), snapshot)) {
+ LOG(ERROR) << "MapAllSnapshots could not unmap snapshot: " << snapshot;
+ return false;
+ }
+
+ CreateLogicalPartitionParams params = {
+ .block_device = super_device,
+ .metadata = metadata.get(),
+ .partition_name = snapshot,
+ .partition_opener = &opener,
+ .timeout_ms = timeout_ms,
+ };
+ if (!MapPartitionWithSnapshot(lock.get(), std::move(params), SnapshotContext::Mount,
+ nullptr)) {
+ LOG(ERROR) << "MapAllSnapshots failed to map: " << snapshot;
+ return false;
+ }
+ }
+
+ LOG(INFO) << "MapAllSnapshots succeeded.";
+ return true;
}
bool SnapshotManager::UnmapAllSnapshots() {