blob: e1f86d889dfdac50f2ab92d2fd9ba5d62abe8354 [file] [log] [blame]
Yifan Hong537802d2018-08-15 13:15:42 -07001//
2// Copyright (C) 2018 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#include "update_engine/aosp/dynamic_partition_control_android.h"
Yifan Hong537802d2018-08-15 13:15:42 -070018
Kelvin Zhang91d95fa2020-11-05 13:52:00 -050019#include <algorithm>
Yifan Hong420db9b2019-07-23 20:50:33 -070020#include <chrono> // NOLINT(build/c++11) - using libsnapshot / liblp API
Kelvin Zhang34618522020-09-28 09:21:02 -040021#include <cstdint>
Yifan Hong13d41cb2019-09-16 13:18:22 -070022#include <map>
Yifan Hong537802d2018-08-15 13:15:42 -070023#include <memory>
24#include <set>
25#include <string>
Tianjie99d570d2020-06-04 14:57:19 -070026#include <string_view>
27#include <utility>
Yifan Hong012508e2019-07-22 18:30:40 -070028#include <vector>
Yifan Hong537802d2018-08-15 13:15:42 -070029
30#include <android-base/properties.h>
31#include <android-base/strings.h>
32#include <base/files/file_util.h>
33#include <base/logging.h>
Yifan Hong012508e2019-07-22 18:30:40 -070034#include <base/strings/string_util.h>
Yifan Hong537802d2018-08-15 13:15:42 -070035#include <bootloader_message/bootloader_message.h>
Yifan Hong012508e2019-07-22 18:30:40 -070036#include <fs_mgr.h>
Yifan Hong537802d2018-08-15 13:15:42 -070037#include <fs_mgr_dm_linear.h>
Yifan Hong3a1a5612019-11-05 16:34:32 -080038#include <fs_mgr_overlayfs.h>
Yifan Hong29692902020-03-26 12:47:05 -070039#include <libavb/libavb.h>
Yifan Hong3a1a5612019-11-05 16:34:32 -080040#include <libdm/dm.h>
Kelvin Zhang34618522020-09-28 09:21:02 -040041#include <liblp/liblp.h>
42#include <libsnapshot/cow_writer.h>
Yifan Hong420db9b2019-07-23 20:50:33 -070043#include <libsnapshot/snapshot.h>
Yifan Hongf9cb4492020-04-15 13:00:20 -070044#include <libsnapshot/snapshot_stub.h>
Yifan Hong537802d2018-08-15 13:15:42 -070045
Amin Hassaniec7bc112020-10-29 16:47:58 -070046#include "update_engine/aosp/cleanup_previous_update_action.h"
47#include "update_engine/aosp/dynamic_partition_utils.h"
Yifan Hong537802d2018-08-15 13:15:42 -070048#include "update_engine/common/boot_control_interface.h"
Kelvin Zhangb9a5f612021-01-22 14:34:05 -050049#include "update_engine/common/dynamic_partition_control_interface.h"
50#include "update_engine/common/platform_constants.h"
Yifan Hong537802d2018-08-15 13:15:42 -070051#include "update_engine/common/utils.h"
Yifan Hong6a6d0f12020-03-11 13:20:52 -070052#include "update_engine/payload_consumer/delta_performer.h"
Yifan Hong537802d2018-08-15 13:15:42 -070053
54using android::base::GetBoolProperty;
Yifan Hong29692902020-03-26 12:47:05 -070055using android::base::GetProperty;
Yifan Hong537802d2018-08-15 13:15:42 -070056using android::base::Join;
57using android::dm::DeviceMapper;
58using android::dm::DmDeviceState;
59using android::fs_mgr::CreateLogicalPartition;
David Andersonbb90dfb2019-08-13 14:14:56 -070060using android::fs_mgr::CreateLogicalPartitionParams;
Yifan Hong537802d2018-08-15 13:15:42 -070061using android::fs_mgr::DestroyLogicalPartition;
Yifan Hong29692902020-03-26 12:47:05 -070062using android::fs_mgr::Fstab;
Yifan Hong537802d2018-08-15 13:15:42 -070063using android::fs_mgr::MetadataBuilder;
Yifan Hong012508e2019-07-22 18:30:40 -070064using android::fs_mgr::Partition;
Yifan Hong6e706b12018-11-09 16:50:51 -080065using android::fs_mgr::PartitionOpener;
Yifan Hong012508e2019-07-22 18:30:40 -070066using android::fs_mgr::SlotSuffixForSlotNumber;
Yifan Hongf5261562020-03-10 10:28:10 -070067using android::snapshot::OptimizeSourceCopyOperation;
Yifan Hong0850bca2020-01-16 15:14:07 -080068using android::snapshot::Return;
Yifan Hongf033ecb2020-01-07 18:13:56 -080069using android::snapshot::SnapshotManager;
Yifan Hongf9cb4492020-04-15 13:00:20 -070070using android::snapshot::SnapshotManagerStub;
Yifan Hong2257ee12020-01-13 18:33:00 -080071using android::snapshot::UpdateState;
Yifan Hong537802d2018-08-15 13:15:42 -070072
73namespace chromeos_update_engine {
74
Yifan Hong6e706b12018-11-09 16:50:51 -080075constexpr char kUseDynamicPartitions[] = "ro.boot.dynamic_partitions";
76constexpr char kRetrfoitDynamicPartitions[] =
77 "ro.boot.dynamic_partitions_retrofit";
Yifan Hong413d5722019-07-23 14:21:09 -070078constexpr char kVirtualAbEnabled[] = "ro.virtual_ab.enabled";
79constexpr char kVirtualAbRetrofit[] = "ro.virtual_ab.retrofit";
Kelvin Zhangda1b3142020-09-24 17:09:02 -040080constexpr char kVirtualAbCompressionEnabled[] =
81 "ro.virtual_ab.compression.enabled";
82
83// Currently, android doesn't have a retrofit prop for VAB Compression. However,
84// struct FeatureFlag forces us to determine if a feature is 'retrofit'. So this
85// is here just to simplify code. Replace it with real retrofit prop name once
86// there is one.
87constexpr char kVirtualAbCompressionRetrofit[] = "";
Yifan Hong29692902020-03-26 12:47:05 -070088constexpr char kPostinstallFstabPrefix[] = "ro.postinstall.fstab.prefix";
Yifan Hong420db9b2019-07-23 20:50:33 -070089// Map timeout for dynamic partitions.
90constexpr std::chrono::milliseconds kMapTimeout{1000};
91// Map timeout for dynamic partitions with snapshots. Since several devices
92// needs to be mapped, this timeout is longer than |kMapTimeout|.
93constexpr std::chrono::milliseconds kMapSnapshotTimeout{5000};
94
Yifan Hong537802d2018-08-15 13:15:42 -070095DynamicPartitionControlAndroid::~DynamicPartitionControlAndroid() {
Yifan Hongbae27842019-10-24 16:56:12 -070096 Cleanup();
Yifan Hong537802d2018-08-15 13:15:42 -070097}
98
Yifan Hong186bb682019-07-23 14:04:39 -070099static FeatureFlag GetFeatureFlag(const char* enable_prop,
100 const char* retrofit_prop) {
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400101 // Default retrofit to false if retrofit_prop is empty.
102 bool retrofit = retrofit_prop && retrofit_prop[0] != '\0' &&
103 GetBoolProperty(retrofit_prop, false);
Yifan Hong186bb682019-07-23 14:04:39 -0700104 bool enabled = GetBoolProperty(enable_prop, false);
105 if (retrofit && !enabled) {
106 LOG(ERROR) << retrofit_prop << " is true but " << enable_prop
107 << " is not. These sysprops are inconsistent. Assume that "
108 << enable_prop << " is true from now on.";
109 }
110 if (retrofit) {
111 return FeatureFlag(FeatureFlag::Value::RETROFIT);
112 }
113 if (enabled) {
114 return FeatureFlag(FeatureFlag::Value::LAUNCH);
115 }
116 return FeatureFlag(FeatureFlag::Value::NONE);
Yifan Hong537802d2018-08-15 13:15:42 -0700117}
118
Kelvin Zhangebd115e2021-03-08 16:10:25 -0500119DynamicPartitionControlAndroid::DynamicPartitionControlAndroid(
120 uint32_t source_slot)
Yifan Hongb38e1af2019-10-17 14:59:22 -0700121 : dynamic_partitions_(
122 GetFeatureFlag(kUseDynamicPartitions, kRetrfoitDynamicPartitions)),
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400123 virtual_ab_(GetFeatureFlag(kVirtualAbEnabled, kVirtualAbRetrofit)),
124 virtual_ab_compression_(GetFeatureFlag(kVirtualAbCompressionEnabled,
Kelvin Zhangebd115e2021-03-08 16:10:25 -0500125 kVirtualAbCompressionRetrofit)),
126 source_slot_(source_slot) {
Yifan Hongb38e1af2019-10-17 14:59:22 -0700127 if (GetVirtualAbFeatureFlag().IsEnabled()) {
Yifan Hongf033ecb2020-01-07 18:13:56 -0800128 snapshot_ = SnapshotManager::New();
Yifan Hongf9cb4492020-04-15 13:00:20 -0700129 } else {
130 snapshot_ = SnapshotManagerStub::New();
Yifan Hongb38e1af2019-10-17 14:59:22 -0700131 }
Yifan Hongf9cb4492020-04-15 13:00:20 -0700132 CHECK(snapshot_ != nullptr) << "Cannot initialize SnapshotManager.";
Yifan Hongb38e1af2019-10-17 14:59:22 -0700133}
134
Yifan Hong186bb682019-07-23 14:04:39 -0700135FeatureFlag DynamicPartitionControlAndroid::GetDynamicPartitionsFeatureFlag() {
Yifan Hongb38e1af2019-10-17 14:59:22 -0700136 return dynamic_partitions_;
Yifan Hong6e706b12018-11-09 16:50:51 -0800137}
138
Yifan Hong413d5722019-07-23 14:21:09 -0700139FeatureFlag DynamicPartitionControlAndroid::GetVirtualAbFeatureFlag() {
Yifan Hongb38e1af2019-10-17 14:59:22 -0700140 return virtual_ab_;
Yifan Hong413d5722019-07-23 14:21:09 -0700141}
142
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400143FeatureFlag
144DynamicPartitionControlAndroid::GetVirtualAbCompressionFeatureFlag() {
Kelvin Zhangb9a5f612021-01-22 14:34:05 -0500145 if constexpr (constants::kIsRecovery) {
146 // Don't attempt VABC in recovery
147 return FeatureFlag(FeatureFlag::Value::NONE);
148 }
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400149 return virtual_ab_compression_;
150}
151
Yifan Hongf5261562020-03-10 10:28:10 -0700152bool DynamicPartitionControlAndroid::OptimizeOperation(
153 const std::string& partition_name,
154 const InstallOperation& operation,
155 InstallOperation* optimized) {
Alessio Balsini2a3b4a22019-11-25 16:46:51 +0000156 switch (operation.type()) {
157 case InstallOperation::SOURCE_COPY:
158 return target_supports_snapshot_ &&
159 GetVirtualAbFeatureFlag().IsEnabled() &&
Yifan Hong6eec9952019-12-04 13:12:01 -0800160 mapped_devices_.count(partition_name +
161 SlotSuffixForSlotNumber(target_slot_)) > 0 &&
Yifan Hongf5261562020-03-10 10:28:10 -0700162 OptimizeSourceCopyOperation(operation, optimized);
Alessio Balsini2a3b4a22019-11-25 16:46:51 +0000163 break;
164 default:
165 break;
166 }
Alessio Balsini14980e22019-11-26 11:46:06 +0000167 return false;
168}
169
Yifan Hong8546a712019-03-28 14:42:53 -0700170bool DynamicPartitionControlAndroid::MapPartitionInternal(
Yifan Hong537802d2018-08-15 13:15:42 -0700171 const std::string& super_device,
172 const std::string& target_partition_name,
173 uint32_t slot,
Yifan Hongaf65ef12018-10-29 11:09:06 -0700174 bool force_writable,
Yifan Hong537802d2018-08-15 13:15:42 -0700175 std::string* path) {
David Andersonbb90dfb2019-08-13 14:14:56 -0700176 CreateLogicalPartitionParams params = {
177 .block_device = super_device,
178 .metadata_slot = slot,
179 .partition_name = target_partition_name,
180 .force_writable = force_writable,
David Andersonbb90dfb2019-08-13 14:14:56 -0700181 };
Yifan Hong420db9b2019-07-23 20:50:33 -0700182 bool success = false;
Yifan Hongf0f4a912019-09-26 17:51:33 -0700183 if (GetVirtualAbFeatureFlag().IsEnabled() && target_supports_snapshot_ &&
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700184 force_writable && ExpectMetadataMounted()) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700185 // Only target partitions are mapped with force_writable. On Virtual
186 // A/B devices, target partitions may overlap with source partitions, so
187 // they must be mapped with snapshot.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700188 // One exception is when /metadata is not mounted. Fallback to
189 // CreateLogicalPartition as snapshots are not created in the first place.
Yifan Hong420db9b2019-07-23 20:50:33 -0700190 params.timeout_ms = kMapSnapshotTimeout;
191 success = snapshot_->MapUpdateSnapshot(params, path);
192 } else {
193 params.timeout_ms = kMapTimeout;
194 success = CreateLogicalPartition(params, path);
195 }
David Andersonbb90dfb2019-08-13 14:14:56 -0700196
Yifan Hong420db9b2019-07-23 20:50:33 -0700197 if (!success) {
Yifan Hong537802d2018-08-15 13:15:42 -0700198 LOG(ERROR) << "Cannot map " << target_partition_name << " in "
199 << super_device << " on device mapper.";
200 return false;
201 }
202 LOG(INFO) << "Succesfully mapped " << target_partition_name
Yifan Hongaf65ef12018-10-29 11:09:06 -0700203 << " to device mapper (force_writable = " << force_writable
204 << "); device path at " << *path;
Yifan Hong537802d2018-08-15 13:15:42 -0700205 mapped_devices_.insert(target_partition_name);
206 return true;
207}
208
Yifan Hong8546a712019-03-28 14:42:53 -0700209bool DynamicPartitionControlAndroid::MapPartitionOnDeviceMapper(
210 const std::string& super_device,
211 const std::string& target_partition_name,
212 uint32_t slot,
213 bool force_writable,
214 std::string* path) {
215 DmDeviceState state = GetState(target_partition_name);
216 if (state == DmDeviceState::ACTIVE) {
217 if (mapped_devices_.find(target_partition_name) != mapped_devices_.end()) {
218 if (GetDmDevicePathByName(target_partition_name, path)) {
219 LOG(INFO) << target_partition_name
220 << " is mapped on device mapper: " << *path;
221 return true;
222 }
223 LOG(ERROR) << target_partition_name << " is mapped but path is unknown.";
224 return false;
225 }
226 // If target_partition_name is not in mapped_devices_ but state is ACTIVE,
227 // the device might be mapped incorrectly before. Attempt to unmap it.
228 // Note that for source partitions, if GetState() == ACTIVE, callers (e.g.
229 // BootControlAndroid) should not call MapPartitionOnDeviceMapper, but
230 // should directly call GetDmDevicePathByName.
David Anderson4c891c92019-06-21 17:45:23 -0700231 if (!UnmapPartitionOnDeviceMapper(target_partition_name)) {
Yifan Hong8546a712019-03-28 14:42:53 -0700232 LOG(ERROR) << target_partition_name
233 << " is mapped before the update, and it cannot be unmapped.";
234 return false;
235 }
236 state = GetState(target_partition_name);
237 if (state != DmDeviceState::INVALID) {
238 LOG(ERROR) << target_partition_name << " is unmapped but state is "
239 << static_cast<std::underlying_type_t<DmDeviceState>>(state);
240 return false;
241 }
242 }
243 if (state == DmDeviceState::INVALID) {
244 return MapPartitionInternal(
245 super_device, target_partition_name, slot, force_writable, path);
246 }
247
248 LOG(ERROR) << target_partition_name
249 << " is mapped on device mapper but state is unknown: "
250 << static_cast<std::underlying_type_t<DmDeviceState>>(state);
251 return false;
252}
253
Yifan Hong537802d2018-08-15 13:15:42 -0700254bool DynamicPartitionControlAndroid::UnmapPartitionOnDeviceMapper(
David Anderson4c891c92019-06-21 17:45:23 -0700255 const std::string& target_partition_name) {
Yifan Hong537802d2018-08-15 13:15:42 -0700256 if (DeviceMapper::Instance().GetState(target_partition_name) !=
257 DmDeviceState::INVALID) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700258 // Partitions at target slot on non-Virtual A/B devices are mapped as
259 // dm-linear. Also, on Virtual A/B devices, system_other may be mapped for
260 // preopt apps as dm-linear.
261 // Call DestroyLogicalPartition to handle these cases.
262 bool success = DestroyLogicalPartition(target_partition_name);
263
264 // On a Virtual A/B device, |target_partition_name| may be a leftover from
265 // a paused update. Clean up any underlying devices.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700266 if (ExpectMetadataMounted()) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700267 success &= snapshot_->UnmapUpdateSnapshot(target_partition_name);
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700268 } else {
269 LOG(INFO) << "Skip UnmapUpdateSnapshot(" << target_partition_name
270 << ") because metadata is not mounted";
Yifan Hong420db9b2019-07-23 20:50:33 -0700271 }
272
273 if (!success) {
Yifan Hong537802d2018-08-15 13:15:42 -0700274 LOG(ERROR) << "Cannot unmap " << target_partition_name
275 << " from device mapper.";
276 return false;
277 }
278 LOG(INFO) << "Successfully unmapped " << target_partition_name
279 << " from device mapper.";
280 }
281 mapped_devices_.erase(target_partition_name);
282 return true;
283}
284
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -0400285bool DynamicPartitionControlAndroid::UnmapAllPartitions() {
Kelvin Zhangf7ef12a2021-03-22 12:59:06 -0400286 snapshot_->UnmapAllSnapshots();
Tao Bao8c4d0082019-08-08 08:56:16 -0700287 if (mapped_devices_.empty()) {
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -0400288 return false;
Tao Bao8c4d0082019-08-08 08:56:16 -0700289 }
Yifan Hong537802d2018-08-15 13:15:42 -0700290 // UnmapPartitionOnDeviceMapper removes objects from mapped_devices_, hence
291 // a copy is needed for the loop.
292 std::set<std::string> mapped = mapped_devices_;
293 LOG(INFO) << "Destroying [" << Join(mapped, ", ") << "] from device mapper";
294 for (const auto& partition_name : mapped) {
David Anderson4c891c92019-06-21 17:45:23 -0700295 ignore_result(UnmapPartitionOnDeviceMapper(partition_name));
Yifan Hong537802d2018-08-15 13:15:42 -0700296 }
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -0400297 return true;
Yifan Hong537802d2018-08-15 13:15:42 -0700298}
299
300void DynamicPartitionControlAndroid::Cleanup() {
Yifan Hongbae27842019-10-24 16:56:12 -0700301 UnmapAllPartitions();
302 metadata_device_.reset();
Yifan Hong537802d2018-08-15 13:15:42 -0700303}
304
305bool DynamicPartitionControlAndroid::DeviceExists(const std::string& path) {
306 return base::PathExists(base::FilePath(path));
307}
308
309android::dm::DmDeviceState DynamicPartitionControlAndroid::GetState(
310 const std::string& name) {
311 return DeviceMapper::Instance().GetState(name);
312}
313
314bool DynamicPartitionControlAndroid::GetDmDevicePathByName(
315 const std::string& name, std::string* path) {
316 return DeviceMapper::Instance().GetDmDevicePathByName(name, path);
317}
318
319std::unique_ptr<MetadataBuilder>
320DynamicPartitionControlAndroid::LoadMetadataBuilder(
Tianjie24f96092020-06-30 12:26:25 -0700321 const std::string& super_device, uint32_t slot) {
322 auto builder = MetadataBuilder::New(PartitionOpener(), super_device, slot);
323 if (builder == nullptr) {
324 LOG(WARNING) << "No metadata slot " << BootControlInterface::SlotName(slot)
325 << " in " << super_device;
326 return nullptr;
327 }
328 LOG(INFO) << "Loaded metadata from slot "
329 << BootControlInterface::SlotName(slot) << " in " << super_device;
330 return builder;
Yifan Hong012508e2019-07-22 18:30:40 -0700331}
332
333std::unique_ptr<MetadataBuilder>
334DynamicPartitionControlAndroid::LoadMetadataBuilder(
Yifan Hong6e706b12018-11-09 16:50:51 -0800335 const std::string& super_device,
336 uint32_t source_slot,
337 uint32_t target_slot) {
Tianjie24f96092020-06-30 12:26:25 -0700338 bool always_keep_source_slot = !target_supports_snapshot_;
339 auto builder = MetadataBuilder::NewForUpdate(PartitionOpener(),
340 super_device,
341 source_slot,
342 target_slot,
343 always_keep_source_slot);
Yifan Hong537802d2018-08-15 13:15:42 -0700344 if (builder == nullptr) {
345 LOG(WARNING) << "No metadata slot "
346 << BootControlInterface::SlotName(source_slot) << " in "
347 << super_device;
Yifan Hongf48a0052018-10-29 16:30:43 -0700348 return nullptr;
Yifan Hong537802d2018-08-15 13:15:42 -0700349 }
Tianjie24f96092020-06-30 12:26:25 -0700350 LOG(INFO) << "Created metadata for new update from slot "
Yifan Hong537802d2018-08-15 13:15:42 -0700351 << BootControlInterface::SlotName(source_slot) << " in "
352 << super_device;
353 return builder;
354}
355
356bool DynamicPartitionControlAndroid::StoreMetadata(
357 const std::string& super_device,
358 MetadataBuilder* builder,
359 uint32_t target_slot) {
360 auto metadata = builder->Export();
361 if (metadata == nullptr) {
362 LOG(ERROR) << "Cannot export metadata to slot "
363 << BootControlInterface::SlotName(target_slot) << " in "
364 << super_device;
365 return false;
366 }
367
Yifan Hong186bb682019-07-23 14:04:39 -0700368 if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) {
Yifan Hong6e706b12018-11-09 16:50:51 -0800369 if (!FlashPartitionTable(super_device, *metadata)) {
370 LOG(ERROR) << "Cannot write metadata to " << super_device;
371 return false;
372 }
373 LOG(INFO) << "Written metadata to " << super_device;
374 } else {
375 if (!UpdatePartitionTable(super_device, *metadata, target_slot)) {
376 LOG(ERROR) << "Cannot write metadata to slot "
377 << BootControlInterface::SlotName(target_slot) << " in "
378 << super_device;
379 return false;
380 }
381 LOG(INFO) << "Copied metadata to slot "
382 << BootControlInterface::SlotName(target_slot) << " in "
383 << super_device;
Yifan Hong537802d2018-08-15 13:15:42 -0700384 }
385
Yifan Hong537802d2018-08-15 13:15:42 -0700386 return true;
387}
388
389bool DynamicPartitionControlAndroid::GetDeviceDir(std::string* out) {
390 // We can't use fs_mgr to look up |partition_name| because fstab
391 // doesn't list every slot partition (it uses the slotselect option
392 // to mask the suffix).
393 //
394 // We can however assume that there's an entry for the /misc mount
395 // point and use that to get the device file for the misc
396 // partition. This helps us locate the disk that |partition_name|
397 // resides on. From there we'll assume that a by-name scheme is used
398 // so we can just replace the trailing "misc" by the given
399 // |partition_name| and suffix corresponding to |slot|, e.g.
400 //
401 // /dev/block/platform/soc.0/7824900.sdhci/by-name/misc ->
402 // /dev/block/platform/soc.0/7824900.sdhci/by-name/boot_a
403 //
404 // If needed, it's possible to relax the by-name assumption in the
405 // future by trawling /sys/block looking for the appropriate sibling
406 // of misc and then finding an entry in /dev matching the sysfs
407 // entry.
408
409 std::string err, misc_device = get_bootloader_message_blk_device(&err);
410 if (misc_device.empty()) {
411 LOG(ERROR) << "Unable to get misc block device: " << err;
412 return false;
413 }
414
415 if (!utils::IsSymlink(misc_device.c_str())) {
416 LOG(ERROR) << "Device file " << misc_device << " for /misc "
417 << "is not a symlink.";
418 return false;
419 }
420 *out = base::FilePath(misc_device).DirName().value();
421 return true;
422}
Yifan Hong012508e2019-07-22 18:30:40 -0700423
424bool DynamicPartitionControlAndroid::PreparePartitionsForUpdate(
425 uint32_t source_slot,
426 uint32_t target_slot,
Yifan Hongf0f4a912019-09-26 17:51:33 -0700427 const DeltaArchiveManifest& manifest,
Yifan Hongf033ecb2020-01-07 18:13:56 -0800428 bool update,
429 uint64_t* required_size) {
Yifan Hong6eec9952019-12-04 13:12:01 -0800430 source_slot_ = source_slot;
431 target_slot_ = target_slot;
Yifan Hongf033ecb2020-01-07 18:13:56 -0800432 if (required_size != nullptr) {
433 *required_size = 0;
434 }
Yifan Hong6eec9952019-12-04 13:12:01 -0800435
Yifan Hong3a1a5612019-11-05 16:34:32 -0800436 if (fs_mgr_overlayfs_is_setup()) {
437 // Non DAP devices can use overlayfs as well.
438 LOG(WARNING)
439 << "overlayfs overrides are active and can interfere with our "
440 "resources.\n"
441 << "run adb enable-verity to deactivate if required and try again.";
442 }
443
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700444 // If metadata is erased but not formatted, it is possible to not mount
445 // it in recovery. It is acceptable to skip mounting and choose fallback path
446 // (PrepareDynamicPartitionsForUpdate) when sideloading full OTAs.
447 TEST_AND_RETURN_FALSE(EnsureMetadataMounted() || IsRecovery());
Yifan Hong29692902020-03-26 12:47:05 -0700448
449 if (update) {
450 TEST_AND_RETURN_FALSE(EraseSystemOtherAvbFooter(source_slot, target_slot));
451 }
452
Yifan Hong3a1a5612019-11-05 16:34:32 -0800453 if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) {
454 return true;
455 }
456
457 if (target_slot == source_slot) {
458 LOG(ERROR) << "Cannot call PreparePartitionsForUpdate on current slot.";
459 return false;
460 }
461
Yifan Hongf6f75c22020-07-31 15:20:25 -0700462 if (!SetTargetBuildVars(manifest)) {
463 return false;
464 }
465
Yifan Hong3a1a5612019-11-05 16:34:32 -0800466 // Although the current build supports dynamic partitions, the given payload
467 // doesn't use it for target partitions. This could happen when applying a
468 // retrofit update. Skip updating the partition metadata for the target slot.
Yifan Hong3a1a5612019-11-05 16:34:32 -0800469 if (!is_target_dynamic_) {
470 return true;
471 }
472
Yifan Hongf0f4a912019-09-26 17:51:33 -0700473 if (!update)
474 return true;
475
Yifan Hongbae27842019-10-24 16:56:12 -0700476 bool delete_source = false;
477
Yifan Hong6d888562019-10-01 13:00:31 -0700478 if (GetVirtualAbFeatureFlag().IsEnabled()) {
479 // On Virtual A/B device, either CancelUpdate() or BeginUpdate() must be
480 // called before calling UnmapUpdateSnapshot.
481 // - If target_supports_snapshot_, PrepareSnapshotPartitionsForUpdate()
482 // calls BeginUpdate() which resets update state
Yifan Hongbae27842019-10-24 16:56:12 -0700483 // - If !target_supports_snapshot_ or PrepareSnapshotPartitionsForUpdate
484 // failed in recovery, explicitly CancelUpdate().
Yifan Hong6d888562019-10-01 13:00:31 -0700485 if (target_supports_snapshot_) {
Yifan Hongbae27842019-10-24 16:56:12 -0700486 if (PrepareSnapshotPartitionsForUpdate(
487 source_slot, target_slot, manifest, required_size)) {
488 return true;
489 }
490
491 // Virtual A/B device doing Virtual A/B update in Android mode must use
492 // snapshots.
493 if (!IsRecovery()) {
494 LOG(ERROR) << "PrepareSnapshotPartitionsForUpdate failed in Android "
495 << "mode";
496 return false;
497 }
498
499 delete_source = true;
500 LOG(INFO) << "PrepareSnapshotPartitionsForUpdate failed in recovery. "
501 << "Attempt to overwrite existing partitions if possible";
502 } else {
503 // Downgrading to an non-Virtual A/B build or is secondary OTA.
504 LOG(INFO) << "Using regular A/B on Virtual A/B because package disabled "
505 << "snapshots.";
Yifan Hong6d888562019-10-01 13:00:31 -0700506 }
Yifan Hongbae27842019-10-24 16:56:12 -0700507
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700508 // In recovery, if /metadata is not mounted, it is likely that metadata
509 // partition is erased and not formatted yet. After sideloading, when
510 // rebooting into the new version, init will erase metadata partition,
511 // hence the failure of CancelUpdate() can be ignored here.
512 // However, if metadata is mounted and CancelUpdate fails, sideloading
513 // should not proceed because during next boot, snapshots will overlay on
514 // the devices incorrectly.
515 if (ExpectMetadataMounted()) {
516 TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate());
517 } else {
518 LOG(INFO) << "Skip canceling previous update because metadata is not "
519 << "mounted";
Yifan Hong6d888562019-10-01 13:00:31 -0700520 }
Yifan Hong420db9b2019-07-23 20:50:33 -0700521 }
Yifan Hongbae27842019-10-24 16:56:12 -0700522
Tianjie24f96092020-06-30 12:26:25 -0700523 // TODO(xunchang) support partial update on non VAB enabled devices.
Yifan Hong5c5743f2020-04-16 12:59:07 -0700524 TEST_AND_RETURN_FALSE(PrepareDynamicPartitionsForUpdate(
525 source_slot, target_slot, manifest, delete_source));
526
527 if (required_size != nullptr) {
528 *required_size = 0;
529 }
530 return true;
Yifan Hong420db9b2019-07-23 20:50:33 -0700531}
532
Yifan Hongf6f75c22020-07-31 15:20:25 -0700533bool DynamicPartitionControlAndroid::SetTargetBuildVars(
534 const DeltaArchiveManifest& manifest) {
535 // Precondition: current build supports dynamic partition.
536 CHECK(GetDynamicPartitionsFeatureFlag().IsEnabled());
537
538 bool is_target_dynamic =
539 !manifest.dynamic_partition_metadata().groups().empty();
540 bool target_supports_snapshot =
541 manifest.dynamic_partition_metadata().snapshot_enabled();
542
543 if (manifest.partial_update()) {
544 // Partial updates requires DAP. On partial updates that does not involve
545 // dynamic partitions, groups() can be empty, so also assume
546 // is_target_dynamic in this case. This assumption should be safe because we
547 // also check target_supports_snapshot below, which presumably also implies
548 // target build supports dynamic partition.
549 if (!is_target_dynamic) {
550 LOG(INFO) << "Assuming target build supports dynamic partitions for "
551 "partial updates.";
552 is_target_dynamic = true;
553 }
554
555 // Partial updates requires Virtual A/B. Double check that both current
556 // build and target build supports Virtual A/B.
557 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
558 LOG(ERROR) << "Partial update cannot be applied on a device that does "
559 "not support snapshots.";
560 return false;
561 }
562 if (!target_supports_snapshot) {
563 LOG(ERROR) << "Cannot apply partial update to a build that does not "
564 "support snapshots.";
565 return false;
566 }
567 }
568
569 // Store the flags.
570 is_target_dynamic_ = is_target_dynamic;
571 // If !is_target_dynamic_, leave target_supports_snapshot_ unset because
572 // snapshots would not work without dynamic partition.
573 if (is_target_dynamic_) {
574 target_supports_snapshot_ = target_supports_snapshot;
575 }
576 return true;
577}
578
Yifan Hong29692902020-03-26 12:47:05 -0700579namespace {
580// Try our best to erase AVB footer.
581class AvbFooterEraser {
582 public:
583 explicit AvbFooterEraser(const std::string& path) : path_(path) {}
584 bool Erase() {
585 // Try to mark the block device read-only. Ignore any
586 // failure since this won't work when passing regular files.
587 ignore_result(utils::SetBlockDeviceReadOnly(path_, false /* readonly */));
588
589 fd_.reset(new EintrSafeFileDescriptor());
590 int flags = O_WRONLY | O_TRUNC | O_CLOEXEC | O_SYNC;
591 TEST_AND_RETURN_FALSE(fd_->Open(path_.c_str(), flags));
592
593 // Need to write end-AVB_FOOTER_SIZE to end.
594 static_assert(AVB_FOOTER_SIZE > 0);
595 off64_t offset = fd_->Seek(-AVB_FOOTER_SIZE, SEEK_END);
596 TEST_AND_RETURN_FALSE_ERRNO(offset >= 0);
597 uint64_t write_size = AVB_FOOTER_SIZE;
598 LOG(INFO) << "Zeroing " << path_ << " @ [" << offset << ", "
599 << (offset + write_size) << "] (" << write_size << " bytes)";
600 brillo::Blob zeros(write_size);
601 TEST_AND_RETURN_FALSE(utils::WriteAll(fd_, zeros.data(), zeros.size()));
602 return true;
603 }
604 ~AvbFooterEraser() {
605 TEST_AND_RETURN(fd_ != nullptr && fd_->IsOpen());
606 if (!fd_->Close()) {
607 LOG(WARNING) << "Failed to close fd for " << path_;
608 }
609 }
610
611 private:
612 std::string path_;
613 FileDescriptorPtr fd_;
614};
615
616} // namespace
617
618std::optional<bool>
619DynamicPartitionControlAndroid::IsAvbEnabledOnSystemOther() {
620 auto prefix = GetProperty(kPostinstallFstabPrefix, "");
621 if (prefix.empty()) {
622 LOG(WARNING) << "Cannot get " << kPostinstallFstabPrefix;
623 return std::nullopt;
624 }
625 auto path = base::FilePath(prefix).Append("etc/fstab.postinstall").value();
626 return IsAvbEnabledInFstab(path);
627}
628
629std::optional<bool> DynamicPartitionControlAndroid::IsAvbEnabledInFstab(
630 const std::string& path) {
631 Fstab fstab;
632 if (!ReadFstabFromFile(path, &fstab)) {
Yifan Hong93cde302020-04-27 12:59:29 -0700633 PLOG(WARNING) << "Cannot read fstab from " << path;
634 if (errno == ENOENT) {
635 return false;
636 }
Yifan Hong29692902020-03-26 12:47:05 -0700637 return std::nullopt;
638 }
639 for (const auto& entry : fstab) {
640 if (!entry.avb_keys.empty()) {
641 return true;
642 }
643 }
644 return false;
645}
646
647bool DynamicPartitionControlAndroid::GetSystemOtherPath(
648 uint32_t source_slot,
649 uint32_t target_slot,
650 const std::string& partition_name_suffix,
651 std::string* path,
652 bool* should_unmap) {
653 path->clear();
654 *should_unmap = false;
655
P.Adarsh Reddy13e4195d2020-06-08 23:17:36 +0530656 // Check that AVB is enabled on system_other before erasing.
657 auto has_avb = IsAvbEnabledOnSystemOther();
658 TEST_AND_RETURN_FALSE(has_avb.has_value());
659 if (!has_avb.value()) {
660 LOG(INFO) << "AVB is not enabled on system_other. Skip erasing.";
661 return true;
662 }
Yifan Hong29692902020-03-26 12:47:05 -0700663
P.Adarsh Reddy13e4195d2020-06-08 23:17:36 +0530664 if (!IsRecovery()) {
Yifan Hong29692902020-03-26 12:47:05 -0700665 // Found unexpected avb_keys for system_other on devices retrofitting
666 // dynamic partitions. Previous crash in update_engine may leave logical
667 // partitions mapped on physical system_other partition. It is difficult to
668 // handle these cases. Just fail.
669 if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) {
670 LOG(ERROR) << "Cannot erase AVB footer on system_other on devices with "
671 << "retrofit dynamic partitions. They should not have AVB "
672 << "enabled on system_other.";
673 return false;
674 }
675 }
676
677 std::string device_dir_str;
678 TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str));
679 base::FilePath device_dir(device_dir_str);
680
681 // On devices without dynamic partition, search for static partitions.
682 if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) {
683 *path = device_dir.Append(partition_name_suffix).value();
684 TEST_AND_RETURN_FALSE(DeviceExists(*path));
685 return true;
686 }
687
688 auto source_super_device =
689 device_dir.Append(GetSuperPartitionName(source_slot)).value();
690
691 auto builder = LoadMetadataBuilder(source_super_device, source_slot);
692 if (builder == nullptr) {
693 if (IsRecovery()) {
694 // It might be corrupted for some reason. It should still be able to
695 // sideload.
696 LOG(WARNING) << "Super partition metadata cannot be read from the source "
697 << "slot, skip erasing.";
698 return true;
699 } else {
700 // Device has booted into Android mode, indicating that the super
701 // partition metadata should be there.
702 LOG(ERROR) << "Super partition metadata cannot be read from the source "
703 << "slot. This is unexpected on devices with dynamic "
704 << "partitions enabled.";
705 return false;
706 }
707 }
708 auto p = builder->FindPartition(partition_name_suffix);
709 if (p == nullptr) {
710 // If the source slot is flashed without system_other, it does not exist
711 // in super partition metadata at source slot. It is safe to skip it.
712 LOG(INFO) << "Can't find " << partition_name_suffix
713 << " in metadata source slot, skip erasing.";
714 return true;
715 }
716 // System_other created by flashing tools should be erased.
717 // If partition is created by update_engine (via NewForUpdate), it is a
718 // left-over partition from the previous update and does not contain
719 // system_other, hence there is no need to erase.
720 // Note the reverse is not necessary true. If the flag is not set, we don't
721 // know if the partition is created by update_engine or by flashing tools
722 // because older versions of super partition metadata does not contain this
723 // flag. It is okay to erase the AVB footer anyways.
724 if (p->attributes() & LP_PARTITION_ATTR_UPDATED) {
725 LOG(INFO) << partition_name_suffix
726 << " does not contain system_other, skip erasing.";
727 return true;
728 }
729
Yifan Hong64331b32020-05-13 16:50:40 -0700730 if (p->size() < AVB_FOOTER_SIZE) {
731 LOG(INFO) << partition_name_suffix << " has length " << p->size()
732 << "( < AVB_FOOTER_SIZE " << AVB_FOOTER_SIZE
733 << "), skip erasing.";
734 return true;
735 }
736
Yifan Hong29692902020-03-26 12:47:05 -0700737 // Delete any pre-existing device with name |partition_name_suffix| and
738 // also remove it from |mapped_devices_|.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700739 // In recovery, metadata might not be mounted, and
740 // UnmapPartitionOnDeviceMapper might fail. However,
741 // it is unusual that system_other has already been mapped. Hence, just skip.
Yifan Hong29692902020-03-26 12:47:05 -0700742 TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix));
743 // Use CreateLogicalPartition directly to avoid mapping with existing
744 // snapshots.
745 CreateLogicalPartitionParams params = {
746 .block_device = source_super_device,
747 .metadata_slot = source_slot,
748 .partition_name = partition_name_suffix,
749 .force_writable = true,
750 .timeout_ms = kMapTimeout,
751 };
752 TEST_AND_RETURN_FALSE(CreateLogicalPartition(params, path));
753 *should_unmap = true;
754 return true;
755}
756
757bool DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
758 uint32_t source_slot, uint32_t target_slot) {
759 LOG(INFO) << "Erasing AVB footer of system_other partition before update.";
760
761 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
762 const std::string partition_name_suffix = "system" + target_suffix;
763
764 std::string path;
765 bool should_unmap = false;
766
767 TEST_AND_RETURN_FALSE(GetSystemOtherPath(
768 source_slot, target_slot, partition_name_suffix, &path, &should_unmap));
769
770 if (path.empty()) {
771 return true;
772 }
773
774 bool ret = AvbFooterEraser(path).Erase();
775
776 // Delete |partition_name_suffix| from device mapper and from
777 // |mapped_devices_| again so that it does not interfere with update process.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700778 // In recovery, metadata might not be mounted, and
779 // UnmapPartitionOnDeviceMapper might fail. However, DestroyLogicalPartition
780 // should be called. If DestroyLogicalPartition does fail, it is still okay
781 // to skip the error here and let Prepare*() fail later.
Yifan Hong29692902020-03-26 12:47:05 -0700782 if (should_unmap) {
783 TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix));
784 }
785
786 return ret;
787}
788
Yifan Hong420db9b2019-07-23 20:50:33 -0700789bool DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
790 uint32_t source_slot,
791 uint32_t target_slot,
Yifan Hongbae27842019-10-24 16:56:12 -0700792 const DeltaArchiveManifest& manifest,
793 bool delete_source) {
Yifan Hong012508e2019-07-22 18:30:40 -0700794 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
795
796 // Unmap all the target dynamic partitions because they would become
797 // inconsistent with the new metadata.
Yifan Hong13d41cb2019-09-16 13:18:22 -0700798 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
799 for (const auto& partition_name : group.partition_names()) {
800 if (!UnmapPartitionOnDeviceMapper(partition_name + target_suffix)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700801 return false;
802 }
803 }
804 }
805
806 std::string device_dir_str;
807 if (!GetDeviceDir(&device_dir_str)) {
808 return false;
809 }
810 base::FilePath device_dir(device_dir_str);
811 auto source_device =
Yifan Hong700d7c12019-07-23 20:49:16 -0700812 device_dir.Append(GetSuperPartitionName(source_slot)).value();
Yifan Hong012508e2019-07-22 18:30:40 -0700813
814 auto builder = LoadMetadataBuilder(source_device, source_slot, target_slot);
815 if (builder == nullptr) {
816 LOG(ERROR) << "No metadata at "
817 << BootControlInterface::SlotName(source_slot);
818 return false;
819 }
820
Yifan Hongbae27842019-10-24 16:56:12 -0700821 if (delete_source) {
822 TEST_AND_RETURN_FALSE(
823 DeleteSourcePartitions(builder.get(), source_slot, manifest));
824 }
825
Yifan Hong13d41cb2019-09-16 13:18:22 -0700826 if (!UpdatePartitionMetadata(builder.get(), target_slot, manifest)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700827 return false;
828 }
829
830 auto target_device =
Yifan Hong700d7c12019-07-23 20:49:16 -0700831 device_dir.Append(GetSuperPartitionName(target_slot)).value();
Yifan Hong012508e2019-07-22 18:30:40 -0700832 return StoreMetadata(target_device, builder.get(), target_slot);
833}
834
Yifan Hong420db9b2019-07-23 20:50:33 -0700835bool DynamicPartitionControlAndroid::PrepareSnapshotPartitionsForUpdate(
836 uint32_t source_slot,
837 uint32_t target_slot,
Yifan Hongf033ecb2020-01-07 18:13:56 -0800838 const DeltaArchiveManifest& manifest,
839 uint64_t* required_size) {
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700840 TEST_AND_RETURN_FALSE(ExpectMetadataMounted());
Yifan Hong420db9b2019-07-23 20:50:33 -0700841 if (!snapshot_->BeginUpdate()) {
842 LOG(ERROR) << "Cannot begin new update.";
843 return false;
844 }
Yifan Hongf033ecb2020-01-07 18:13:56 -0800845 auto ret = snapshot_->CreateUpdateSnapshots(manifest);
846 if (!ret) {
847 LOG(ERROR) << "Cannot create update snapshots: " << ret.string();
848 if (required_size != nullptr &&
Yifan Hong0850bca2020-01-16 15:14:07 -0800849 ret.error_code() == Return::ErrorCode::NO_SPACE) {
Yifan Hongf033ecb2020-01-07 18:13:56 -0800850 *required_size = ret.required_size();
851 }
Yifan Hong420db9b2019-07-23 20:50:33 -0700852 return false;
853 }
854 return true;
855}
856
Yifan Hong700d7c12019-07-23 20:49:16 -0700857std::string DynamicPartitionControlAndroid::GetSuperPartitionName(
858 uint32_t slot) {
859 return fs_mgr_get_super_partition_name(slot);
860}
861
Yifan Hong012508e2019-07-22 18:30:40 -0700862bool DynamicPartitionControlAndroid::UpdatePartitionMetadata(
863 MetadataBuilder* builder,
864 uint32_t target_slot,
Yifan Hong13d41cb2019-09-16 13:18:22 -0700865 const DeltaArchiveManifest& manifest) {
Yifan Hong8d6df9a2020-08-13 13:59:54 -0700866 // Check preconditions.
Kelvin Zhang1c21eb82021-03-10 13:39:56 -0500867 LOG_IF(WARNING, !GetVirtualAbFeatureFlag().IsEnabled() || IsRecovery())
Yifan Hong8d6df9a2020-08-13 13:59:54 -0700868 << "UpdatePartitionMetadata is called on a Virtual A/B device "
869 "but source partitions is not deleted. This is not allowed.";
870
Yifan Honga4e7da32019-09-30 18:25:03 -0700871 // If applying downgrade from Virtual A/B to non-Virtual A/B, the left-over
872 // COW group needs to be deleted to ensure there are enough space to create
873 // target partitions.
874 builder->RemoveGroupAndPartitions(android::snapshot::kCowGroupName);
875
Yifan Hong012508e2019-07-22 18:30:40 -0700876 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
877 DeleteGroupsWithSuffix(builder, target_suffix);
878
879 uint64_t total_size = 0;
Yifan Hong13d41cb2019-09-16 13:18:22 -0700880 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
881 total_size += group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700882 }
883
884 std::string expr;
885 uint64_t allocatable_space = builder->AllocatableSpace();
Yifan Hong8d6df9a2020-08-13 13:59:54 -0700886 // On device retrofitting dynamic partitions, allocatable_space = super.
887 // On device launching dynamic partitions w/o VAB,
888 // allocatable_space = super / 2.
889 // On device launching dynamic partitions with VAB, allocatable_space = super.
890 if (!GetDynamicPartitionsFeatureFlag().IsRetrofit() &&
891 !GetVirtualAbFeatureFlag().IsEnabled()) {
Yifan Hong012508e2019-07-22 18:30:40 -0700892 allocatable_space /= 2;
893 expr = "half of ";
894 }
895 if (total_size > allocatable_space) {
896 LOG(ERROR) << "The maximum size of all groups with suffix " << target_suffix
897 << " (" << total_size << ") has exceeded " << expr
898 << "allocatable space for dynamic partitions "
899 << allocatable_space << ".";
900 return false;
901 }
902
Yifan Hong13d41cb2019-09-16 13:18:22 -0700903 // name of partition(e.g. "system") -> size in bytes
904 std::map<std::string, uint64_t> partition_sizes;
905 for (const auto& partition : manifest.partitions()) {
906 partition_sizes.emplace(partition.partition_name(),
907 partition.new_partition_info().size());
908 }
909
910 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
911 auto group_name_suffix = group.name() + target_suffix;
912 if (!builder->AddGroup(group_name_suffix, group.size())) {
Yifan Hong012508e2019-07-22 18:30:40 -0700913 LOG(ERROR) << "Cannot add group " << group_name_suffix << " with size "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700914 << group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700915 return false;
916 }
917 LOG(INFO) << "Added group " << group_name_suffix << " with size "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700918 << group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700919
Yifan Hong13d41cb2019-09-16 13:18:22 -0700920 for (const auto& partition_name : group.partition_names()) {
921 auto partition_sizes_it = partition_sizes.find(partition_name);
922 if (partition_sizes_it == partition_sizes.end()) {
923 // TODO(tbao): Support auto-filling partition info for framework-only
924 // OTA.
925 LOG(ERROR) << "dynamic_partition_metadata contains partition "
926 << partition_name << " but it is not part of the manifest. "
927 << "This is not supported.";
928 return false;
929 }
930 uint64_t partition_size = partition_sizes_it->second;
931
932 auto partition_name_suffix = partition_name + target_suffix;
Yifan Hong012508e2019-07-22 18:30:40 -0700933 Partition* p = builder->AddPartition(
934 partition_name_suffix, group_name_suffix, LP_PARTITION_ATTR_READONLY);
935 if (!p) {
936 LOG(ERROR) << "Cannot add partition " << partition_name_suffix
937 << " to group " << group_name_suffix;
938 return false;
939 }
Yifan Hong13d41cb2019-09-16 13:18:22 -0700940 if (!builder->ResizePartition(p, partition_size)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700941 LOG(ERROR) << "Cannot resize partition " << partition_name_suffix
Yifan Hong13d41cb2019-09-16 13:18:22 -0700942 << " to size " << partition_size << ". Not enough space?";
Yifan Hong012508e2019-07-22 18:30:40 -0700943 return false;
944 }
David Anderson0e1c7fd2021-03-08 19:01:59 -0800945 if (p->size() < partition_size) {
946 LOG(ERROR) << "Partition " << partition_name_suffix
947 << " was expected to have size " << partition_size
948 << ", but instead has size " << p->size();
949 return false;
950 }
Yifan Hong012508e2019-07-22 18:30:40 -0700951 LOG(INFO) << "Added partition " << partition_name_suffix << " to group "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700952 << group_name_suffix << " with size " << partition_size;
Yifan Hong012508e2019-07-22 18:30:40 -0700953 }
954 }
955
956 return true;
957}
958
Yifan Hong7b3910a2020-03-24 17:47:32 -0700959bool DynamicPartitionControlAndroid::FinishUpdate(bool powerwash_required) {
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700960 if (ExpectMetadataMounted()) {
961 if (snapshot_->GetUpdateState() == UpdateState::Initiated) {
962 LOG(INFO) << "Snapshot writes are done.";
963 return snapshot_->FinishedSnapshotWrites(powerwash_required);
964 }
965 } else {
966 LOG(INFO) << "Skip FinishedSnapshotWrites() because /metadata is not "
967 << "mounted";
Yifan Hongf0f4a912019-09-26 17:51:33 -0700968 }
969 return true;
Yifan Honga33bca42019-09-03 20:29:45 -0700970}
971
Yifan Hong3a1a5612019-11-05 16:34:32 -0800972bool DynamicPartitionControlAndroid::GetPartitionDevice(
973 const std::string& partition_name,
974 uint32_t slot,
975 uint32_t current_slot,
Tianjie51a5a392020-06-03 14:39:32 -0700976 bool not_in_payload,
977 std::string* device,
978 bool* is_dynamic) {
Kelvin Zhang66a9ebb2021-01-25 13:35:10 -0500979 auto partition_dev =
980 GetPartitionDevice(partition_name, slot, current_slot, not_in_payload);
Kelvin Zhang91d95fa2020-11-05 13:52:00 -0500981 if (!partition_dev.has_value()) {
Yifan Hong3a1a5612019-11-05 16:34:32 -0800982 return false;
983 }
Kelvin Zhang91d95fa2020-11-05 13:52:00 -0500984 if (device) {
985 *device = std::move(partition_dev->rw_device_path);
986 }
987 if (is_dynamic) {
988 *is_dynamic = partition_dev->is_dynamic;
989 }
Yifan Hong3a1a5612019-11-05 16:34:32 -0800990 return true;
991}
992
Tianjie51a5a392020-06-03 14:39:32 -0700993bool DynamicPartitionControlAndroid::GetPartitionDevice(
994 const std::string& partition_name,
995 uint32_t slot,
996 uint32_t current_slot,
997 std::string* device) {
998 return GetPartitionDevice(
999 partition_name, slot, current_slot, false, device, nullptr);
1000}
1001
Kelvin Zhang91d95fa2020-11-05 13:52:00 -05001002static std::string GetStaticDevicePath(
1003 const base::FilePath& device_dir,
1004 const std::string& partition_name_suffixed) {
1005 base::FilePath path = device_dir.Append(partition_name_suffixed);
1006 return path.value();
1007}
1008
1009std::optional<PartitionDevice>
1010DynamicPartitionControlAndroid::GetPartitionDevice(
1011 const std::string& partition_name,
1012 uint32_t slot,
1013 uint32_t current_slot,
1014 bool not_in_payload) {
1015 std::string device_dir_str;
1016 if (!GetDeviceDir(&device_dir_str)) {
1017 LOG(ERROR) << "Failed to GetDeviceDir()";
1018 return {};
1019 }
1020 const base::FilePath device_dir(device_dir_str);
1021 // When VABC is enabled, we can't get device path for dynamic partitions in
1022 // target slot.
1023 const auto& partition_name_suffix =
1024 partition_name + SlotSuffixForSlotNumber(slot);
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001025 if (UpdateUsesSnapshotCompression() && slot != current_slot &&
1026 IsDynamicPartition(partition_name, slot)) {
Kelvin Zhang91ad6622021-03-01 13:46:17 -05001027 return {
1028 {.mountable_device_path = base::FilePath{std::string{VABC_DEVICE_DIR}}
1029 .Append(partition_name_suffix)
1030 .value(),
1031 .is_dynamic = true}};
Kelvin Zhang91d95fa2020-11-05 13:52:00 -05001032 }
1033
1034 // When looking up target partition devices, treat them as static if the
1035 // current payload doesn't encode them as dynamic partitions. This may happen
1036 // when applying a retrofit update on top of a dynamic-partitions-enabled
1037 // build.
1038 std::string device;
1039 if (GetDynamicPartitionsFeatureFlag().IsEnabled() &&
1040 (slot == current_slot || is_target_dynamic_)) {
1041 switch (GetDynamicPartitionDevice(device_dir,
1042 partition_name_suffix,
1043 slot,
1044 current_slot,
1045 not_in_payload,
1046 &device)) {
1047 case DynamicPartitionDeviceStatus::SUCCESS:
1048 return {{.rw_device_path = device,
1049 .mountable_device_path = device,
1050 .is_dynamic = true}};
1051
1052 case DynamicPartitionDeviceStatus::TRY_STATIC:
1053 break;
1054 case DynamicPartitionDeviceStatus::ERROR: // fallthrough
1055 default:
1056 return {};
1057 }
1058 }
1059 // Try static partitions.
1060 auto static_path = GetStaticDevicePath(device_dir, partition_name_suffix);
1061 if (!DeviceExists(static_path)) {
1062 LOG(ERROR) << "Device file " << static_path << " does not exist.";
1063 return {};
1064 }
1065
1066 return {{.rw_device_path = static_path,
1067 .mountable_device_path = static_path,
1068 .is_dynamic = false}};
1069}
1070
Yifan Hong3a1a5612019-11-05 16:34:32 -08001071bool DynamicPartitionControlAndroid::IsSuperBlockDevice(
1072 const base::FilePath& device_dir,
1073 uint32_t current_slot,
1074 const std::string& partition_name_suffix) {
1075 std::string source_device =
1076 device_dir.Append(GetSuperPartitionName(current_slot)).value();
1077 auto source_metadata = LoadMetadataBuilder(source_device, current_slot);
1078 return source_metadata->HasBlockDevice(partition_name_suffix);
1079}
1080
1081DynamicPartitionControlAndroid::DynamicPartitionDeviceStatus
1082DynamicPartitionControlAndroid::GetDynamicPartitionDevice(
1083 const base::FilePath& device_dir,
1084 const std::string& partition_name_suffix,
1085 uint32_t slot,
1086 uint32_t current_slot,
Tianjie51a5a392020-06-03 14:39:32 -07001087 bool not_in_payload,
Yifan Hong3a1a5612019-11-05 16:34:32 -08001088 std::string* device) {
1089 std::string super_device =
1090 device_dir.Append(GetSuperPartitionName(slot)).value();
1091
1092 auto builder = LoadMetadataBuilder(super_device, slot);
1093 if (builder == nullptr) {
1094 LOG(ERROR) << "No metadata in slot "
1095 << BootControlInterface::SlotName(slot);
1096 return DynamicPartitionDeviceStatus::ERROR;
1097 }
1098 if (builder->FindPartition(partition_name_suffix) == nullptr) {
1099 LOG(INFO) << partition_name_suffix
1100 << " is not in super partition metadata.";
1101
1102 if (IsSuperBlockDevice(device_dir, current_slot, partition_name_suffix)) {
1103 LOG(ERROR) << "The static partition " << partition_name_suffix
1104 << " is a block device for current metadata."
1105 << "It cannot be used as a logical partition.";
1106 return DynamicPartitionDeviceStatus::ERROR;
1107 }
1108
1109 return DynamicPartitionDeviceStatus::TRY_STATIC;
1110 }
1111
1112 if (slot == current_slot) {
1113 if (GetState(partition_name_suffix) != DmDeviceState::ACTIVE) {
1114 LOG(WARNING) << partition_name_suffix << " is at current slot but it is "
1115 << "not mapped. Now try to map it.";
1116 } else {
1117 if (GetDmDevicePathByName(partition_name_suffix, device)) {
1118 LOG(INFO) << partition_name_suffix
1119 << " is mapped on device mapper: " << *device;
1120 return DynamicPartitionDeviceStatus::SUCCESS;
1121 }
1122 LOG(ERROR) << partition_name_suffix << "is mapped but path is unknown.";
1123 return DynamicPartitionDeviceStatus::ERROR;
1124 }
1125 }
1126
Tianjie51a5a392020-06-03 14:39:32 -07001127 bool force_writable = (slot != current_slot) && !not_in_payload;
Yifan Hong3a1a5612019-11-05 16:34:32 -08001128 if (MapPartitionOnDeviceMapper(
1129 super_device, partition_name_suffix, slot, force_writable, device)) {
1130 return DynamicPartitionDeviceStatus::SUCCESS;
1131 }
1132 return DynamicPartitionDeviceStatus::ERROR;
1133}
1134
Yifan Hong6eec9952019-12-04 13:12:01 -08001135void DynamicPartitionControlAndroid::set_fake_mapped_devices(
1136 const std::set<std::string>& fake) {
1137 mapped_devices_ = fake;
1138}
1139
Yifan Hongbae27842019-10-24 16:56:12 -07001140bool DynamicPartitionControlAndroid::IsRecovery() {
Kelvin Zhanga22ef552020-10-12 19:03:52 -04001141 return constants::kIsRecovery;
Yifan Hongbae27842019-10-24 16:56:12 -07001142}
1143
1144static bool IsIncrementalUpdate(const DeltaArchiveManifest& manifest) {
1145 const auto& partitions = manifest.partitions();
1146 return std::any_of(partitions.begin(), partitions.end(), [](const auto& p) {
1147 return p.has_old_partition_info();
1148 });
1149}
1150
1151bool DynamicPartitionControlAndroid::DeleteSourcePartitions(
1152 MetadataBuilder* builder,
1153 uint32_t source_slot,
1154 const DeltaArchiveManifest& manifest) {
1155 TEST_AND_RETURN_FALSE(IsRecovery());
1156
1157 if (IsIncrementalUpdate(manifest)) {
1158 LOG(ERROR) << "Cannot sideload incremental OTA because snapshots cannot "
1159 << "be created.";
1160 if (GetVirtualAbFeatureFlag().IsLaunch()) {
1161 LOG(ERROR) << "Sideloading incremental updates on devices launches "
1162 << " Virtual A/B is not supported.";
1163 }
1164 return false;
1165 }
1166
1167 LOG(INFO) << "Will overwrite existing partitions. Slot "
1168 << BootControlInterface::SlotName(source_slot)
1169 << "may be unbootable until update finishes!";
1170 const std::string source_suffix = SlotSuffixForSlotNumber(source_slot);
1171 DeleteGroupsWithSuffix(builder, source_suffix);
1172
1173 return true;
1174}
1175
Yifan Hong90965502020-02-19 15:22:47 -08001176std::unique_ptr<AbstractAction>
1177DynamicPartitionControlAndroid::GetCleanupPreviousUpdateAction(
1178 BootControlInterface* boot_control,
1179 PrefsInterface* prefs,
1180 CleanupPreviousUpdateActionDelegateInterface* delegate) {
1181 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1182 return std::make_unique<NoOpAction>();
1183 }
1184 return std::make_unique<CleanupPreviousUpdateAction>(
1185 prefs, boot_control, snapshot_.get(), delegate);
1186}
1187
Yifan Hong6a6d0f12020-03-11 13:20:52 -07001188bool DynamicPartitionControlAndroid::ResetUpdate(PrefsInterface* prefs) {
1189 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1190 return true;
1191 }
1192
1193 LOG(INFO) << __func__ << " resetting update state and deleting snapshots.";
1194 TEST_AND_RETURN_FALSE(prefs != nullptr);
1195
1196 // If the device has already booted into the target slot,
1197 // ResetUpdateProgress may pass but CancelUpdate fails.
1198 // This is expected. A scheduled CleanupPreviousUpdateAction should free
1199 // space when it is done.
1200 TEST_AND_RETURN_FALSE(DeltaPerformer::ResetUpdateProgress(
1201 prefs, false /* quick */, false /* skip dynamic partitions metadata */));
1202
Yifan Hong4d7c5eb2020-04-03 11:31:50 -07001203 if (ExpectMetadataMounted()) {
1204 TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate());
1205 } else {
1206 LOG(INFO) << "Skip cancelling update in ResetUpdate because /metadata is "
1207 << "not mounted";
1208 }
Yifan Hong6a6d0f12020-03-11 13:20:52 -07001209
1210 return true;
1211}
1212
Tianjie99d570d2020-06-04 14:57:19 -07001213bool DynamicPartitionControlAndroid::ListDynamicPartitionsForSlot(
Tianjie3a55fc22021-02-13 16:02:22 -08001214 uint32_t slot,
1215 uint32_t current_slot,
1216 std::vector<std::string>* partitions) {
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001217 CHECK(slot == source_slot_ || target_slot_ != UINT32_MAX)
1218 << " source slot: " << source_slot_ << " target slot: " << target_slot_
1219 << " slot: " << slot
1220 << " attempting to query dynamic partition metadata for target slot "
1221 "before PreparePartitionForUpdate() is called. The "
1222 "metadata in target slot isn't valid until "
1223 "PreparePartitionForUpdate() is called, contining execution would "
1224 "likely cause problems.";
Tianjie3a55fc22021-02-13 16:02:22 -08001225 bool slot_enables_dynamic_partitions =
1226 GetDynamicPartitionsFeatureFlag().IsEnabled();
1227 // Check if the target slot has dynamic partitions, this may happen when
1228 // applying a retrofit package.
1229 if (slot != current_slot) {
1230 slot_enables_dynamic_partitions =
1231 slot_enables_dynamic_partitions && is_target_dynamic_;
1232 }
1233
1234 if (!slot_enables_dynamic_partitions) {
1235 LOG(INFO) << "Dynamic partition is not enabled for slot " << slot;
1236 return true;
Tianjie99d570d2020-06-04 14:57:19 -07001237 }
1238
1239 std::string device_dir_str;
1240 TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str));
1241 base::FilePath device_dir(device_dir_str);
Tianjie3a55fc22021-02-13 16:02:22 -08001242 auto super_device = device_dir.Append(GetSuperPartitionName(slot)).value();
1243 auto builder = LoadMetadataBuilder(super_device, slot);
Tianjie99d570d2020-06-04 14:57:19 -07001244 TEST_AND_RETURN_FALSE(builder != nullptr);
1245
1246 std::vector<std::string> result;
Tianjie3a55fc22021-02-13 16:02:22 -08001247 auto suffix = SlotSuffixForSlotNumber(slot);
Tianjie99d570d2020-06-04 14:57:19 -07001248 for (const auto& group : builder->ListGroups()) {
1249 for (const auto& partition : builder->ListPartitionsInGroup(group)) {
1250 std::string_view partition_name = partition->name();
1251 if (!android::base::ConsumeSuffix(&partition_name, suffix)) {
1252 continue;
1253 }
1254 result.emplace_back(partition_name);
1255 }
1256 }
1257 *partitions = std::move(result);
1258 return true;
1259}
1260
Tianjie24f96092020-06-30 12:26:25 -07001261bool DynamicPartitionControlAndroid::VerifyExtentsForUntouchedPartitions(
1262 uint32_t source_slot,
1263 uint32_t target_slot,
1264 const std::vector<std::string>& partitions) {
1265 std::string device_dir_str;
1266 TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str));
1267 base::FilePath device_dir(device_dir_str);
1268
1269 auto source_super_device =
1270 device_dir.Append(GetSuperPartitionName(source_slot)).value();
1271 auto source_builder = LoadMetadataBuilder(source_super_device, source_slot);
1272 TEST_AND_RETURN_FALSE(source_builder != nullptr);
1273
1274 auto target_super_device =
1275 device_dir.Append(GetSuperPartitionName(target_slot)).value();
1276 auto target_builder = LoadMetadataBuilder(target_super_device, target_slot);
1277 TEST_AND_RETURN_FALSE(target_builder != nullptr);
1278
1279 return MetadataBuilder::VerifyExtentsAgainstSourceMetadata(
1280 *source_builder, source_slot, *target_builder, target_slot, partitions);
1281}
1282
Yifan Hong4d7c5eb2020-04-03 11:31:50 -07001283bool DynamicPartitionControlAndroid::ExpectMetadataMounted() {
1284 // No need to mount metadata for non-Virtual A/B devices.
1285 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1286 return false;
1287 }
1288 // Intentionally not checking |metadata_device_| in Android mode.
1289 // /metadata should always be mounted in Android mode. If it isn't, let caller
1290 // fails when calling into SnapshotManager.
1291 if (!IsRecovery()) {
1292 return true;
1293 }
1294 // In recovery mode, explicitly check |metadata_device_|.
1295 return metadata_device_ != nullptr;
1296}
1297
1298bool DynamicPartitionControlAndroid::EnsureMetadataMounted() {
1299 // No need to mount metadata for non-Virtual A/B devices.
1300 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1301 return true;
1302 }
1303
1304 if (metadata_device_ == nullptr) {
1305 metadata_device_ = snapshot_->EnsureMetadataMounted();
1306 }
1307 return metadata_device_ != nullptr;
1308}
1309
Kelvin Zhang34618522020-09-28 09:21:02 -04001310std::unique_ptr<android::snapshot::ISnapshotWriter>
1311DynamicPartitionControlAndroid::OpenCowWriter(
1312 const std::string& partition_name,
1313 const std::optional<std::string>& source_path,
1314 bool is_append) {
1315 auto suffix = SlotSuffixForSlotNumber(target_slot_);
1316
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001317 auto super_device = GetSuperDevice();
1318 if (!super_device.has_value()) {
Kelvin Zhang34618522020-09-28 09:21:02 -04001319 return nullptr;
1320 }
Kelvin Zhang34618522020-09-28 09:21:02 -04001321 CreateLogicalPartitionParams params = {
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001322 .block_device = super_device->value(),
Kelvin Zhang34618522020-09-28 09:21:02 -04001323 .metadata_slot = target_slot_,
1324 .partition_name = partition_name + suffix,
1325 .force_writable = true,
Kelvin Zhang877ddbe2020-11-09 13:37:56 -05001326 .timeout_ms = kMapSnapshotTimeout};
Kelvin Zhang34618522020-09-28 09:21:02 -04001327 // TODO(zhangkelvin) Open an APPEND mode CowWriter once there's an API to do
1328 // it.
1329 return snapshot_->OpenSnapshotWriter(params, std::move(source_path));
Kelvin Zhang877ddbe2020-11-09 13:37:56 -05001330} // namespace chromeos_update_engine
Kelvin Zhang34618522020-09-28 09:21:02 -04001331
Kelvin Zhangc82511c2020-11-06 16:01:24 -05001332FileDescriptorPtr DynamicPartitionControlAndroid::OpenCowReader(
1333 const std::string& unsuffixed_partition_name,
1334 const std::optional<std::string>& source_path,
1335 bool is_append) {
1336 auto cow_writer =
1337 OpenCowWriter(unsuffixed_partition_name, source_path, is_append);
1338 if (cow_writer == nullptr) {
1339 return nullptr;
1340 }
Kelvin Zhangec205cf2020-09-28 13:23:40 -04001341 cow_writer->InitializeAppend(kEndOfInstallLabel);
Kelvin Zhangc82511c2020-11-06 16:01:24 -05001342 return cow_writer->OpenReader();
1343}
1344
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001345std::optional<base::FilePath> DynamicPartitionControlAndroid::GetSuperDevice() {
1346 std::string device_dir_str;
1347 if (!GetDeviceDir(&device_dir_str)) {
1348 LOG(ERROR) << "Failed to get device dir!";
1349 return {};
1350 }
1351 base::FilePath device_dir(device_dir_str);
1352 auto super_device = device_dir.Append(GetSuperPartitionName(target_slot_));
1353 return super_device;
1354}
1355
1356bool DynamicPartitionControlAndroid::MapAllPartitions() {
Kelvin Zhang877ddbe2020-11-09 13:37:56 -05001357 return snapshot_->MapAllSnapshots(kMapSnapshotTimeout);
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001358}
1359
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001360bool DynamicPartitionControlAndroid::IsDynamicPartition(
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001361 const std::string& partition_name, uint32_t slot) {
1362 if (slot >= dynamic_partition_list_.size()) {
1363 LOG(ERROR) << "Seeing unexpected slot # " << slot << " currently assuming "
1364 << dynamic_partition_list_.size() << " slots";
1365 return false;
1366 }
1367 auto& dynamic_partition_list = dynamic_partition_list_[slot];
1368 if (dynamic_partition_list.empty() &&
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001369 GetDynamicPartitionsFeatureFlag().IsEnabled()) {
Tianjie3a55fc22021-02-13 16:02:22 -08001370 // Use the DAP config of the target slot.
1371 CHECK(ListDynamicPartitionsForSlot(
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001372 slot, source_slot_, &dynamic_partition_list));
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001373 }
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001374 return std::find(dynamic_partition_list.begin(),
1375 dynamic_partition_list.end(),
1376 partition_name) != dynamic_partition_list.end();
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001377}
Kelvin Zhang91d95fa2020-11-05 13:52:00 -05001378
Yifan Hongb0cbd392021-02-04 11:11:45 -08001379bool DynamicPartitionControlAndroid::UpdateUsesSnapshotCompression() {
1380 return snapshot_->UpdateUsesCompression();
1381}
1382
Yifan Hong537802d2018-08-15 13:15:42 -07001383} // namespace chromeos_update_engine