blob: 8dcf343db3a7f3b61727887920d029f8397e0118 [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
17#include "update_engine/dynamic_partition_control_android.h"
18
Yifan Hong420db9b2019-07-23 20:50:33 -070019#include <chrono> // NOLINT(build/c++11) - using libsnapshot / liblp API
Yifan Hong13d41cb2019-09-16 13:18:22 -070020#include <map>
Yifan Hong537802d2018-08-15 13:15:42 -070021#include <memory>
22#include <set>
23#include <string>
Yifan Hong012508e2019-07-22 18:30:40 -070024#include <vector>
Yifan Hong537802d2018-08-15 13:15:42 -070025
26#include <android-base/properties.h>
27#include <android-base/strings.h>
28#include <base/files/file_util.h>
29#include <base/logging.h>
Yifan Hong012508e2019-07-22 18:30:40 -070030#include <base/strings/string_util.h>
Yifan Hong537802d2018-08-15 13:15:42 -070031#include <bootloader_message/bootloader_message.h>
Yifan Hong012508e2019-07-22 18:30:40 -070032#include <fs_mgr.h>
Yifan Hong537802d2018-08-15 13:15:42 -070033#include <fs_mgr_dm_linear.h>
Yifan Hong420db9b2019-07-23 20:50:33 -070034#include <libsnapshot/snapshot.h>
Yifan Hong537802d2018-08-15 13:15:42 -070035
36#include "update_engine/common/boot_control_interface.h"
37#include "update_engine/common/utils.h"
Yifan Hong012508e2019-07-22 18:30:40 -070038#include "update_engine/dynamic_partition_utils.h"
Yifan Hong537802d2018-08-15 13:15:42 -070039
40using android::base::GetBoolProperty;
41using android::base::Join;
42using android::dm::DeviceMapper;
43using android::dm::DmDeviceState;
44using android::fs_mgr::CreateLogicalPartition;
David Andersonbb90dfb2019-08-13 14:14:56 -070045using android::fs_mgr::CreateLogicalPartitionParams;
Yifan Hong537802d2018-08-15 13:15:42 -070046using android::fs_mgr::DestroyLogicalPartition;
47using android::fs_mgr::MetadataBuilder;
Yifan Hong012508e2019-07-22 18:30:40 -070048using android::fs_mgr::Partition;
Yifan Hong6e706b12018-11-09 16:50:51 -080049using android::fs_mgr::PartitionOpener;
Yifan Hong012508e2019-07-22 18:30:40 -070050using android::fs_mgr::SlotSuffixForSlotNumber;
Yifan Hong537802d2018-08-15 13:15:42 -070051
52namespace chromeos_update_engine {
53
Yifan Hong6e706b12018-11-09 16:50:51 -080054constexpr char kUseDynamicPartitions[] = "ro.boot.dynamic_partitions";
55constexpr char kRetrfoitDynamicPartitions[] =
56 "ro.boot.dynamic_partitions_retrofit";
Yifan Hong413d5722019-07-23 14:21:09 -070057constexpr char kVirtualAbEnabled[] = "ro.virtual_ab.enabled";
58constexpr char kVirtualAbRetrofit[] = "ro.virtual_ab.retrofit";
Yifan Hong420db9b2019-07-23 20:50:33 -070059// Map timeout for dynamic partitions.
60constexpr std::chrono::milliseconds kMapTimeout{1000};
61// Map timeout for dynamic partitions with snapshots. Since several devices
62// needs to be mapped, this timeout is longer than |kMapTimeout|.
63constexpr std::chrono::milliseconds kMapSnapshotTimeout{5000};
64
65DynamicPartitionControlAndroid::DynamicPartitionControlAndroid() {
66 if (GetVirtualAbFeatureFlag().IsEnabled()) {
67 snapshot_ = android::snapshot::SnapshotManager::New();
68 CHECK(snapshot_ != nullptr) << "Cannot initialize SnapshotManager.";
69 }
70}
Yifan Hong537802d2018-08-15 13:15:42 -070071
72DynamicPartitionControlAndroid::~DynamicPartitionControlAndroid() {
73 CleanupInternal(false /* wait */);
74}
75
Yifan Hong186bb682019-07-23 14:04:39 -070076static FeatureFlag GetFeatureFlag(const char* enable_prop,
77 const char* retrofit_prop) {
78 bool retrofit = GetBoolProperty(retrofit_prop, false);
79 bool enabled = GetBoolProperty(enable_prop, false);
80 if (retrofit && !enabled) {
81 LOG(ERROR) << retrofit_prop << " is true but " << enable_prop
82 << " is not. These sysprops are inconsistent. Assume that "
83 << enable_prop << " is true from now on.";
84 }
85 if (retrofit) {
86 return FeatureFlag(FeatureFlag::Value::RETROFIT);
87 }
88 if (enabled) {
89 return FeatureFlag(FeatureFlag::Value::LAUNCH);
90 }
91 return FeatureFlag(FeatureFlag::Value::NONE);
Yifan Hong537802d2018-08-15 13:15:42 -070092}
93
Yifan Hong186bb682019-07-23 14:04:39 -070094FeatureFlag DynamicPartitionControlAndroid::GetDynamicPartitionsFeatureFlag() {
95 return GetFeatureFlag(kUseDynamicPartitions, kRetrfoitDynamicPartitions);
Yifan Hong6e706b12018-11-09 16:50:51 -080096}
97
Yifan Hong413d5722019-07-23 14:21:09 -070098FeatureFlag DynamicPartitionControlAndroid::GetVirtualAbFeatureFlag() {
99 return GetFeatureFlag(kVirtualAbEnabled, kVirtualAbRetrofit);
100}
101
Yifan Hong8546a712019-03-28 14:42:53 -0700102bool DynamicPartitionControlAndroid::MapPartitionInternal(
Yifan Hong537802d2018-08-15 13:15:42 -0700103 const std::string& super_device,
104 const std::string& target_partition_name,
105 uint32_t slot,
Yifan Hongaf65ef12018-10-29 11:09:06 -0700106 bool force_writable,
Yifan Hong537802d2018-08-15 13:15:42 -0700107 std::string* path) {
David Andersonbb90dfb2019-08-13 14:14:56 -0700108 CreateLogicalPartitionParams params = {
109 .block_device = super_device,
110 .metadata_slot = slot,
111 .partition_name = target_partition_name,
112 .force_writable = force_writable,
David Andersonbb90dfb2019-08-13 14:14:56 -0700113 };
Yifan Hong420db9b2019-07-23 20:50:33 -0700114 bool success = false;
115 if (GetVirtualAbFeatureFlag().IsEnabled() && force_writable) {
116 // Only target partitions are mapped with force_writable. On Virtual
117 // A/B devices, target partitions may overlap with source partitions, so
118 // they must be mapped with snapshot.
119 params.timeout_ms = kMapSnapshotTimeout;
120 success = snapshot_->MapUpdateSnapshot(params, path);
121 } else {
122 params.timeout_ms = kMapTimeout;
123 success = CreateLogicalPartition(params, path);
124 }
David Andersonbb90dfb2019-08-13 14:14:56 -0700125
Yifan Hong420db9b2019-07-23 20:50:33 -0700126 if (!success) {
Yifan Hong537802d2018-08-15 13:15:42 -0700127 LOG(ERROR) << "Cannot map " << target_partition_name << " in "
128 << super_device << " on device mapper.";
129 return false;
130 }
131 LOG(INFO) << "Succesfully mapped " << target_partition_name
Yifan Hongaf65ef12018-10-29 11:09:06 -0700132 << " to device mapper (force_writable = " << force_writable
133 << "); device path at " << *path;
Yifan Hong537802d2018-08-15 13:15:42 -0700134 mapped_devices_.insert(target_partition_name);
135 return true;
136}
137
Yifan Hong8546a712019-03-28 14:42:53 -0700138bool DynamicPartitionControlAndroid::MapPartitionOnDeviceMapper(
139 const std::string& super_device,
140 const std::string& target_partition_name,
141 uint32_t slot,
142 bool force_writable,
143 std::string* path) {
144 DmDeviceState state = GetState(target_partition_name);
145 if (state == DmDeviceState::ACTIVE) {
146 if (mapped_devices_.find(target_partition_name) != mapped_devices_.end()) {
147 if (GetDmDevicePathByName(target_partition_name, path)) {
148 LOG(INFO) << target_partition_name
149 << " is mapped on device mapper: " << *path;
150 return true;
151 }
152 LOG(ERROR) << target_partition_name << " is mapped but path is unknown.";
153 return false;
154 }
155 // If target_partition_name is not in mapped_devices_ but state is ACTIVE,
156 // the device might be mapped incorrectly before. Attempt to unmap it.
157 // Note that for source partitions, if GetState() == ACTIVE, callers (e.g.
158 // BootControlAndroid) should not call MapPartitionOnDeviceMapper, but
159 // should directly call GetDmDevicePathByName.
David Anderson4c891c92019-06-21 17:45:23 -0700160 if (!UnmapPartitionOnDeviceMapper(target_partition_name)) {
Yifan Hong8546a712019-03-28 14:42:53 -0700161 LOG(ERROR) << target_partition_name
162 << " is mapped before the update, and it cannot be unmapped.";
163 return false;
164 }
165 state = GetState(target_partition_name);
166 if (state != DmDeviceState::INVALID) {
167 LOG(ERROR) << target_partition_name << " is unmapped but state is "
168 << static_cast<std::underlying_type_t<DmDeviceState>>(state);
169 return false;
170 }
171 }
172 if (state == DmDeviceState::INVALID) {
173 return MapPartitionInternal(
174 super_device, target_partition_name, slot, force_writable, path);
175 }
176
177 LOG(ERROR) << target_partition_name
178 << " is mapped on device mapper but state is unknown: "
179 << static_cast<std::underlying_type_t<DmDeviceState>>(state);
180 return false;
181}
182
Yifan Hong537802d2018-08-15 13:15:42 -0700183bool DynamicPartitionControlAndroid::UnmapPartitionOnDeviceMapper(
David Anderson4c891c92019-06-21 17:45:23 -0700184 const std::string& target_partition_name) {
Yifan Hong537802d2018-08-15 13:15:42 -0700185 if (DeviceMapper::Instance().GetState(target_partition_name) !=
186 DmDeviceState::INVALID) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700187 // Partitions at target slot on non-Virtual A/B devices are mapped as
188 // dm-linear. Also, on Virtual A/B devices, system_other may be mapped for
189 // preopt apps as dm-linear.
190 // Call DestroyLogicalPartition to handle these cases.
191 bool success = DestroyLogicalPartition(target_partition_name);
192
193 // On a Virtual A/B device, |target_partition_name| may be a leftover from
194 // a paused update. Clean up any underlying devices.
195 if (GetVirtualAbFeatureFlag().IsEnabled()) {
196 success &= snapshot_->UnmapUpdateSnapshot(target_partition_name);
197 }
198
199 if (!success) {
Yifan Hong537802d2018-08-15 13:15:42 -0700200 LOG(ERROR) << "Cannot unmap " << target_partition_name
201 << " from device mapper.";
202 return false;
203 }
204 LOG(INFO) << "Successfully unmapped " << target_partition_name
205 << " from device mapper.";
206 }
207 mapped_devices_.erase(target_partition_name);
208 return true;
209}
210
211void DynamicPartitionControlAndroid::CleanupInternal(bool wait) {
Tao Bao8c4d0082019-08-08 08:56:16 -0700212 if (mapped_devices_.empty()) {
213 return;
214 }
Yifan Hong537802d2018-08-15 13:15:42 -0700215 // UnmapPartitionOnDeviceMapper removes objects from mapped_devices_, hence
216 // a copy is needed for the loop.
217 std::set<std::string> mapped = mapped_devices_;
218 LOG(INFO) << "Destroying [" << Join(mapped, ", ") << "] from device mapper";
219 for (const auto& partition_name : mapped) {
David Anderson4c891c92019-06-21 17:45:23 -0700220 ignore_result(UnmapPartitionOnDeviceMapper(partition_name));
Yifan Hong537802d2018-08-15 13:15:42 -0700221 }
222}
223
224void DynamicPartitionControlAndroid::Cleanup() {
225 CleanupInternal(true /* wait */);
226}
227
228bool DynamicPartitionControlAndroid::DeviceExists(const std::string& path) {
229 return base::PathExists(base::FilePath(path));
230}
231
232android::dm::DmDeviceState DynamicPartitionControlAndroid::GetState(
233 const std::string& name) {
234 return DeviceMapper::Instance().GetState(name);
235}
236
237bool DynamicPartitionControlAndroid::GetDmDevicePathByName(
238 const std::string& name, std::string* path) {
239 return DeviceMapper::Instance().GetDmDevicePathByName(name, path);
240}
241
242std::unique_ptr<MetadataBuilder>
243DynamicPartitionControlAndroid::LoadMetadataBuilder(
Yifan Hong012508e2019-07-22 18:30:40 -0700244 const std::string& super_device, uint32_t source_slot) {
245 return LoadMetadataBuilder(
246 super_device, source_slot, BootControlInterface::kInvalidSlot);
247}
248
249std::unique_ptr<MetadataBuilder>
250DynamicPartitionControlAndroid::LoadMetadataBuilder(
Yifan Hong6e706b12018-11-09 16:50:51 -0800251 const std::string& super_device,
252 uint32_t source_slot,
253 uint32_t target_slot) {
Yifan Hong30fa5f52019-08-05 16:39:59 -0700254 std::unique_ptr<MetadataBuilder> builder;
255 if (target_slot == BootControlInterface::kInvalidSlot) {
256 builder =
257 MetadataBuilder::New(PartitionOpener(), super_device, source_slot);
258 } else {
259 builder = MetadataBuilder::NewForUpdate(
260 PartitionOpener(), super_device, source_slot, target_slot);
261 }
Yifan Hong6e706b12018-11-09 16:50:51 -0800262
Yifan Hong537802d2018-08-15 13:15:42 -0700263 if (builder == nullptr) {
264 LOG(WARNING) << "No metadata slot "
265 << BootControlInterface::SlotName(source_slot) << " in "
266 << super_device;
Yifan Hongf48a0052018-10-29 16:30:43 -0700267 return nullptr;
Yifan Hong537802d2018-08-15 13:15:42 -0700268 }
269 LOG(INFO) << "Loaded metadata from slot "
270 << BootControlInterface::SlotName(source_slot) << " in "
271 << super_device;
272 return builder;
273}
274
275bool DynamicPartitionControlAndroid::StoreMetadata(
276 const std::string& super_device,
277 MetadataBuilder* builder,
278 uint32_t target_slot) {
279 auto metadata = builder->Export();
280 if (metadata == nullptr) {
281 LOG(ERROR) << "Cannot export metadata to slot "
282 << BootControlInterface::SlotName(target_slot) << " in "
283 << super_device;
284 return false;
285 }
286
Yifan Hong186bb682019-07-23 14:04:39 -0700287 if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) {
Yifan Hong6e706b12018-11-09 16:50:51 -0800288 if (!FlashPartitionTable(super_device, *metadata)) {
289 LOG(ERROR) << "Cannot write metadata to " << super_device;
290 return false;
291 }
292 LOG(INFO) << "Written metadata to " << super_device;
293 } else {
294 if (!UpdatePartitionTable(super_device, *metadata, target_slot)) {
295 LOG(ERROR) << "Cannot write metadata to slot "
296 << BootControlInterface::SlotName(target_slot) << " in "
297 << super_device;
298 return false;
299 }
300 LOG(INFO) << "Copied metadata to slot "
301 << BootControlInterface::SlotName(target_slot) << " in "
302 << super_device;
Yifan Hong537802d2018-08-15 13:15:42 -0700303 }
304
Yifan Hong537802d2018-08-15 13:15:42 -0700305 return true;
306}
307
308bool DynamicPartitionControlAndroid::GetDeviceDir(std::string* out) {
309 // We can't use fs_mgr to look up |partition_name| because fstab
310 // doesn't list every slot partition (it uses the slotselect option
311 // to mask the suffix).
312 //
313 // We can however assume that there's an entry for the /misc mount
314 // point and use that to get the device file for the misc
315 // partition. This helps us locate the disk that |partition_name|
316 // resides on. From there we'll assume that a by-name scheme is used
317 // so we can just replace the trailing "misc" by the given
318 // |partition_name| and suffix corresponding to |slot|, e.g.
319 //
320 // /dev/block/platform/soc.0/7824900.sdhci/by-name/misc ->
321 // /dev/block/platform/soc.0/7824900.sdhci/by-name/boot_a
322 //
323 // If needed, it's possible to relax the by-name assumption in the
324 // future by trawling /sys/block looking for the appropriate sibling
325 // of misc and then finding an entry in /dev matching the sysfs
326 // entry.
327
328 std::string err, misc_device = get_bootloader_message_blk_device(&err);
329 if (misc_device.empty()) {
330 LOG(ERROR) << "Unable to get misc block device: " << err;
331 return false;
332 }
333
334 if (!utils::IsSymlink(misc_device.c_str())) {
335 LOG(ERROR) << "Device file " << misc_device << " for /misc "
336 << "is not a symlink.";
337 return false;
338 }
339 *out = base::FilePath(misc_device).DirName().value();
340 return true;
341}
Yifan Hong012508e2019-07-22 18:30:40 -0700342
343bool DynamicPartitionControlAndroid::PreparePartitionsForUpdate(
344 uint32_t source_slot,
345 uint32_t target_slot,
Yifan Hong13d41cb2019-09-16 13:18:22 -0700346 const DeltaArchiveManifest& manifest) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700347 // TODO(elsk): Also call PrepareDynamicPartitionsForUpdate when applying
348 // downgrade packages on retrofit Virtual A/B devices and when applying
349 // secondary OTA. b/138258570
350 if (GetVirtualAbFeatureFlag().IsEnabled()) {
351 return PrepareSnapshotPartitionsForUpdate(
352 source_slot, target_slot, manifest);
353 }
354 return PrepareDynamicPartitionsForUpdate(source_slot, target_slot, manifest);
355}
356
357bool DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
358 uint32_t source_slot,
359 uint32_t target_slot,
360 const DeltaArchiveManifest& manifest) {
Yifan Hong012508e2019-07-22 18:30:40 -0700361 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
362
363 // Unmap all the target dynamic partitions because they would become
364 // inconsistent with the new metadata.
Yifan Hong13d41cb2019-09-16 13:18:22 -0700365 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
366 for (const auto& partition_name : group.partition_names()) {
367 if (!UnmapPartitionOnDeviceMapper(partition_name + target_suffix)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700368 return false;
369 }
370 }
371 }
372
373 std::string device_dir_str;
374 if (!GetDeviceDir(&device_dir_str)) {
375 return false;
376 }
377 base::FilePath device_dir(device_dir_str);
378 auto source_device =
Yifan Hong700d7c12019-07-23 20:49:16 -0700379 device_dir.Append(GetSuperPartitionName(source_slot)).value();
Yifan Hong012508e2019-07-22 18:30:40 -0700380
381 auto builder = LoadMetadataBuilder(source_device, source_slot, target_slot);
382 if (builder == nullptr) {
383 LOG(ERROR) << "No metadata at "
384 << BootControlInterface::SlotName(source_slot);
385 return false;
386 }
387
Yifan Hong13d41cb2019-09-16 13:18:22 -0700388 if (!UpdatePartitionMetadata(builder.get(), target_slot, manifest)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700389 return false;
390 }
391
392 auto target_device =
Yifan Hong700d7c12019-07-23 20:49:16 -0700393 device_dir.Append(GetSuperPartitionName(target_slot)).value();
Yifan Hong012508e2019-07-22 18:30:40 -0700394 return StoreMetadata(target_device, builder.get(), target_slot);
395}
396
Yifan Hong420db9b2019-07-23 20:50:33 -0700397bool DynamicPartitionControlAndroid::PrepareSnapshotPartitionsForUpdate(
398 uint32_t source_slot,
399 uint32_t target_slot,
400 const DeltaArchiveManifest& manifest) {
401 if (!snapshot_->BeginUpdate()) {
402 LOG(ERROR) << "Cannot begin new update.";
403 return false;
404 }
405 if (!snapshot_->CreateUpdateSnapshots(manifest)) {
406 LOG(ERROR) << "Cannot create update snapshots.";
407 return false;
408 }
409 return true;
410}
411
Yifan Hong700d7c12019-07-23 20:49:16 -0700412std::string DynamicPartitionControlAndroid::GetSuperPartitionName(
413 uint32_t slot) {
414 return fs_mgr_get_super_partition_name(slot);
415}
416
Yifan Hong012508e2019-07-22 18:30:40 -0700417bool DynamicPartitionControlAndroid::UpdatePartitionMetadata(
418 MetadataBuilder* builder,
419 uint32_t target_slot,
Yifan Hong13d41cb2019-09-16 13:18:22 -0700420 const DeltaArchiveManifest& manifest) {
Yifan Hong012508e2019-07-22 18:30:40 -0700421 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
422 DeleteGroupsWithSuffix(builder, target_suffix);
423
424 uint64_t total_size = 0;
Yifan Hong13d41cb2019-09-16 13:18:22 -0700425 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
426 total_size += group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700427 }
428
429 std::string expr;
430 uint64_t allocatable_space = builder->AllocatableSpace();
Yifan Hong186bb682019-07-23 14:04:39 -0700431 if (!GetDynamicPartitionsFeatureFlag().IsRetrofit()) {
Yifan Hong012508e2019-07-22 18:30:40 -0700432 allocatable_space /= 2;
433 expr = "half of ";
434 }
435 if (total_size > allocatable_space) {
436 LOG(ERROR) << "The maximum size of all groups with suffix " << target_suffix
437 << " (" << total_size << ") has exceeded " << expr
438 << "allocatable space for dynamic partitions "
439 << allocatable_space << ".";
440 return false;
441 }
442
Yifan Hong13d41cb2019-09-16 13:18:22 -0700443 // name of partition(e.g. "system") -> size in bytes
444 std::map<std::string, uint64_t> partition_sizes;
445 for (const auto& partition : manifest.partitions()) {
446 partition_sizes.emplace(partition.partition_name(),
447 partition.new_partition_info().size());
448 }
449
450 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
451 auto group_name_suffix = group.name() + target_suffix;
452 if (!builder->AddGroup(group_name_suffix, group.size())) {
Yifan Hong012508e2019-07-22 18:30:40 -0700453 LOG(ERROR) << "Cannot add group " << group_name_suffix << " with size "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700454 << group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700455 return false;
456 }
457 LOG(INFO) << "Added group " << group_name_suffix << " with size "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700458 << group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700459
Yifan Hong13d41cb2019-09-16 13:18:22 -0700460 for (const auto& partition_name : group.partition_names()) {
461 auto partition_sizes_it = partition_sizes.find(partition_name);
462 if (partition_sizes_it == partition_sizes.end()) {
463 // TODO(tbao): Support auto-filling partition info for framework-only
464 // OTA.
465 LOG(ERROR) << "dynamic_partition_metadata contains partition "
466 << partition_name << " but it is not part of the manifest. "
467 << "This is not supported.";
468 return false;
469 }
470 uint64_t partition_size = partition_sizes_it->second;
471
472 auto partition_name_suffix = partition_name + target_suffix;
Yifan Hong012508e2019-07-22 18:30:40 -0700473 Partition* p = builder->AddPartition(
474 partition_name_suffix, group_name_suffix, LP_PARTITION_ATTR_READONLY);
475 if (!p) {
476 LOG(ERROR) << "Cannot add partition " << partition_name_suffix
477 << " to group " << group_name_suffix;
478 return false;
479 }
Yifan Hong13d41cb2019-09-16 13:18:22 -0700480 if (!builder->ResizePartition(p, partition_size)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700481 LOG(ERROR) << "Cannot resize partition " << partition_name_suffix
Yifan Hong13d41cb2019-09-16 13:18:22 -0700482 << " to size " << partition_size << ". Not enough space?";
Yifan Hong012508e2019-07-22 18:30:40 -0700483 return false;
484 }
485 LOG(INFO) << "Added partition " << partition_name_suffix << " to group "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700486 << group_name_suffix << " with size " << partition_size;
Yifan Hong012508e2019-07-22 18:30:40 -0700487 }
488 }
489
490 return true;
491}
492
Yifan Honga33bca42019-09-03 20:29:45 -0700493bool DynamicPartitionControlAndroid::FinishUpdate() {
494 if (!GetVirtualAbFeatureFlag().IsEnabled())
495 return true;
496 LOG(INFO) << "Snapshot writes are done.";
497 return snapshot_->FinishedSnapshotWrites();
498}
499
Yifan Hong537802d2018-08-15 13:15:42 -0700500} // namespace chromeos_update_engine