Fix false negative NeedResize
BootControlAndroid did not call ResizePartitions when the
sizes were all correct to avoid storing metadata more than
once (after resuming from an update), and potentially writing
to incorrect extents. But, when the update starts, the target
metadata slot may contain metadata that happen to exactly
matches the size requirements, but have extents that maps to
currently running devices.
To do this correctly, DeltaPerformer uses PrefsInterface to
avoid calling into InitPartitionMetadata again when it is
initialized.
Hence, BootControlAndroid::InitPartitionMetadata ALWAYS write
metadata to the target slot. Also removed tests to reflect this.
Test: manual OTA
Test: update_engine_unittests
Bug: 117182932
Change-Id: I488ab369e42d582c94974791fdb988d12e695bc2
diff --git a/boot_control_android.cc b/boot_control_android.cc
index 622646e..61711d2 100644
--- a/boot_control_android.cc
+++ b/boot_control_android.cc
@@ -340,48 +340,6 @@
return true;
}
-// Return false if partition sizes are all correct in metadata slot
-// |target_slot|. If so, no need to resize. |logical_sizes| have format like
-// {vendor: size, ...}, and fail if a partition is not found.
-bool NeedResizePartitions(DynamicPartitionControlInterface* dynamic_control,
- const string& super_device,
- Slot target_slot,
- const string& suffix,
- const PartitionMetadata& logical_sizes) {
- auto target_metadata =
- dynamic_control->LoadMetadataBuilder(super_device, target_slot);
- if (target_metadata == nullptr) {
- LOG(INFO) << "Metadata slot " << BootControlInterface::SlotName(target_slot)
- << " in " << super_device
- << " is corrupted; attempt to recover from source slot.";
- return true;
- }
-
- for (const auto& pair : logical_sizes) {
- Partition* partition = target_metadata->FindPartition(pair.first + suffix);
- if (partition == nullptr) {
- LOG(INFO) << "Cannot find " << pair.first << suffix << " at slot "
- << BootControlInterface::SlotName(target_slot) << " in "
- << super_device << ". Need to resize.";
- return true;
- }
- if (partition->size() != pair.second) {
- LOG(INFO) << super_device << ":"
- << BootControlInterface::SlotName(target_slot) << ":"
- << pair.first << suffix << ": size == " << partition->size()
- << " but requested " << pair.second << ". Need to resize.";
- return true;
- }
- LOG(INFO) << super_device << ":"
- << BootControlInterface::SlotName(target_slot) << ":"
- << pair.first << suffix << ": size == " << partition->size()
- << " as requested.";
- }
- LOG(INFO) << "No need to resize at metadata slot "
- << BootControlInterface::SlotName(target_slot) << " in "
- << super_device;
- return false;
-}
} // namespace
bool BootControlAndroid::InitPartitionMetadata(
@@ -434,21 +392,13 @@
return false;
}
- // Read metadata from target slot to determine if the sizes are correct. Only
- // test logical partitions.
- if (NeedResizePartitions(dynamic_control_.get(),
- super_device,
- target_slot,
- target_suffix,
- logical_sizes)) {
- if (!ResizePartitions(dynamic_control_.get(),
- super_device,
- target_slot,
- target_suffix,
- logical_sizes,
- builder.get())) {
- return false;
- }
+ if (!ResizePartitions(dynamic_control_.get(),
+ super_device,
+ target_slot,
+ target_suffix,
+ logical_sizes,
+ builder.get())) {
+ return false;
}
// Unmap all partitions, and remap partitions if size is non-zero.