Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 1 | // |
| 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 | |
| 19 | #include <memory> |
| 20 | #include <set> |
| 21 | #include <string> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 22 | #include <vector> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 23 | |
| 24 | #include <android-base/properties.h> |
| 25 | #include <android-base/strings.h> |
| 26 | #include <base/files/file_util.h> |
| 27 | #include <base/logging.h> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 28 | #include <base/strings/string_util.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 29 | #include <bootloader_message/bootloader_message.h> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 30 | #include <fs_mgr.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 31 | #include <fs_mgr_dm_linear.h> |
| 32 | |
| 33 | #include "update_engine/common/boot_control_interface.h" |
| 34 | #include "update_engine/common/utils.h" |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 35 | #include "update_engine/dynamic_partition_utils.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 36 | |
| 37 | using android::base::GetBoolProperty; |
| 38 | using android::base::Join; |
| 39 | using android::dm::DeviceMapper; |
| 40 | using android::dm::DmDeviceState; |
| 41 | using android::fs_mgr::CreateLogicalPartition; |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame^] | 42 | using android::fs_mgr::CreateLogicalPartitionParams; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 43 | using android::fs_mgr::DestroyLogicalPartition; |
| 44 | using android::fs_mgr::MetadataBuilder; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 45 | using android::fs_mgr::Partition; |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 46 | using android::fs_mgr::PartitionOpener; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 47 | using android::fs_mgr::SlotSuffixForSlotNumber; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 48 | |
| 49 | namespace chromeos_update_engine { |
| 50 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 51 | using PartitionMetadata = BootControlInterface::PartitionMetadata; |
| 52 | |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 53 | constexpr char kUseDynamicPartitions[] = "ro.boot.dynamic_partitions"; |
| 54 | constexpr char kRetrfoitDynamicPartitions[] = |
| 55 | "ro.boot.dynamic_partitions_retrofit"; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 56 | constexpr uint64_t kMapTimeoutMillis = 1000; |
| 57 | |
| 58 | DynamicPartitionControlAndroid::~DynamicPartitionControlAndroid() { |
| 59 | CleanupInternal(false /* wait */); |
| 60 | } |
| 61 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 62 | static FeatureFlag GetFeatureFlag(const char* enable_prop, |
| 63 | const char* retrofit_prop) { |
| 64 | bool retrofit = GetBoolProperty(retrofit_prop, false); |
| 65 | bool enabled = GetBoolProperty(enable_prop, false); |
| 66 | if (retrofit && !enabled) { |
| 67 | LOG(ERROR) << retrofit_prop << " is true but " << enable_prop |
| 68 | << " is not. These sysprops are inconsistent. Assume that " |
| 69 | << enable_prop << " is true from now on."; |
| 70 | } |
| 71 | if (retrofit) { |
| 72 | return FeatureFlag(FeatureFlag::Value::RETROFIT); |
| 73 | } |
| 74 | if (enabled) { |
| 75 | return FeatureFlag(FeatureFlag::Value::LAUNCH); |
| 76 | } |
| 77 | return FeatureFlag(FeatureFlag::Value::NONE); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 80 | FeatureFlag DynamicPartitionControlAndroid::GetDynamicPartitionsFeatureFlag() { |
| 81 | return GetFeatureFlag(kUseDynamicPartitions, kRetrfoitDynamicPartitions); |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 84 | bool DynamicPartitionControlAndroid::MapPartitionInternal( |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 85 | const std::string& super_device, |
| 86 | const std::string& target_partition_name, |
| 87 | uint32_t slot, |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 88 | bool force_writable, |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 89 | std::string* path) { |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame^] | 90 | CreateLogicalPartitionParams params = { |
| 91 | .block_device = super_device, |
| 92 | .metadata_slot = slot, |
| 93 | .partition_name = target_partition_name, |
| 94 | .force_writable = force_writable, |
| 95 | .timeout_ms = std::chrono::milliseconds(kMapTimeoutMillis), |
| 96 | }; |
| 97 | |
| 98 | if (!CreateLogicalPartition(params, path)) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 99 | LOG(ERROR) << "Cannot map " << target_partition_name << " in " |
| 100 | << super_device << " on device mapper."; |
| 101 | return false; |
| 102 | } |
| 103 | LOG(INFO) << "Succesfully mapped " << target_partition_name |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 104 | << " to device mapper (force_writable = " << force_writable |
| 105 | << "); device path at " << *path; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 106 | mapped_devices_.insert(target_partition_name); |
| 107 | return true; |
| 108 | } |
| 109 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 110 | bool DynamicPartitionControlAndroid::MapPartitionOnDeviceMapper( |
| 111 | const std::string& super_device, |
| 112 | const std::string& target_partition_name, |
| 113 | uint32_t slot, |
| 114 | bool force_writable, |
| 115 | std::string* path) { |
| 116 | DmDeviceState state = GetState(target_partition_name); |
| 117 | if (state == DmDeviceState::ACTIVE) { |
| 118 | if (mapped_devices_.find(target_partition_name) != mapped_devices_.end()) { |
| 119 | if (GetDmDevicePathByName(target_partition_name, path)) { |
| 120 | LOG(INFO) << target_partition_name |
| 121 | << " is mapped on device mapper: " << *path; |
| 122 | return true; |
| 123 | } |
| 124 | LOG(ERROR) << target_partition_name << " is mapped but path is unknown."; |
| 125 | return false; |
| 126 | } |
| 127 | // If target_partition_name is not in mapped_devices_ but state is ACTIVE, |
| 128 | // the device might be mapped incorrectly before. Attempt to unmap it. |
| 129 | // Note that for source partitions, if GetState() == ACTIVE, callers (e.g. |
| 130 | // BootControlAndroid) should not call MapPartitionOnDeviceMapper, but |
| 131 | // should directly call GetDmDevicePathByName. |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 132 | if (!UnmapPartitionOnDeviceMapper(target_partition_name)) { |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 133 | LOG(ERROR) << target_partition_name |
| 134 | << " is mapped before the update, and it cannot be unmapped."; |
| 135 | return false; |
| 136 | } |
| 137 | state = GetState(target_partition_name); |
| 138 | if (state != DmDeviceState::INVALID) { |
| 139 | LOG(ERROR) << target_partition_name << " is unmapped but state is " |
| 140 | << static_cast<std::underlying_type_t<DmDeviceState>>(state); |
| 141 | return false; |
| 142 | } |
| 143 | } |
| 144 | if (state == DmDeviceState::INVALID) { |
| 145 | return MapPartitionInternal( |
| 146 | super_device, target_partition_name, slot, force_writable, path); |
| 147 | } |
| 148 | |
| 149 | LOG(ERROR) << target_partition_name |
| 150 | << " is mapped on device mapper but state is unknown: " |
| 151 | << static_cast<std::underlying_type_t<DmDeviceState>>(state); |
| 152 | return false; |
| 153 | } |
| 154 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 155 | bool DynamicPartitionControlAndroid::UnmapPartitionOnDeviceMapper( |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 156 | const std::string& target_partition_name) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 157 | if (DeviceMapper::Instance().GetState(target_partition_name) != |
| 158 | DmDeviceState::INVALID) { |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 159 | if (!DestroyLogicalPartition(target_partition_name)) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 160 | LOG(ERROR) << "Cannot unmap " << target_partition_name |
| 161 | << " from device mapper."; |
| 162 | return false; |
| 163 | } |
| 164 | LOG(INFO) << "Successfully unmapped " << target_partition_name |
| 165 | << " from device mapper."; |
| 166 | } |
| 167 | mapped_devices_.erase(target_partition_name); |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | void DynamicPartitionControlAndroid::CleanupInternal(bool wait) { |
Tao Bao | 8c4d008 | 2019-08-08 08:56:16 -0700 | [diff] [blame] | 172 | if (mapped_devices_.empty()) { |
| 173 | return; |
| 174 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 175 | // UnmapPartitionOnDeviceMapper removes objects from mapped_devices_, hence |
| 176 | // a copy is needed for the loop. |
| 177 | std::set<std::string> mapped = mapped_devices_; |
| 178 | LOG(INFO) << "Destroying [" << Join(mapped, ", ") << "] from device mapper"; |
| 179 | for (const auto& partition_name : mapped) { |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 180 | ignore_result(UnmapPartitionOnDeviceMapper(partition_name)); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
| 184 | void DynamicPartitionControlAndroid::Cleanup() { |
| 185 | CleanupInternal(true /* wait */); |
| 186 | } |
| 187 | |
| 188 | bool DynamicPartitionControlAndroid::DeviceExists(const std::string& path) { |
| 189 | return base::PathExists(base::FilePath(path)); |
| 190 | } |
| 191 | |
| 192 | android::dm::DmDeviceState DynamicPartitionControlAndroid::GetState( |
| 193 | const std::string& name) { |
| 194 | return DeviceMapper::Instance().GetState(name); |
| 195 | } |
| 196 | |
| 197 | bool DynamicPartitionControlAndroid::GetDmDevicePathByName( |
| 198 | const std::string& name, std::string* path) { |
| 199 | return DeviceMapper::Instance().GetDmDevicePathByName(name, path); |
| 200 | } |
| 201 | |
| 202 | std::unique_ptr<MetadataBuilder> |
| 203 | DynamicPartitionControlAndroid::LoadMetadataBuilder( |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 204 | const std::string& super_device, uint32_t source_slot) { |
| 205 | return LoadMetadataBuilder( |
| 206 | super_device, source_slot, BootControlInterface::kInvalidSlot); |
| 207 | } |
| 208 | |
| 209 | std::unique_ptr<MetadataBuilder> |
| 210 | DynamicPartitionControlAndroid::LoadMetadataBuilder( |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 211 | const std::string& super_device, |
| 212 | uint32_t source_slot, |
| 213 | uint32_t target_slot) { |
Yifan Hong | 30fa5f5 | 2019-08-05 16:39:59 -0700 | [diff] [blame] | 214 | std::unique_ptr<MetadataBuilder> builder; |
| 215 | if (target_slot == BootControlInterface::kInvalidSlot) { |
| 216 | builder = |
| 217 | MetadataBuilder::New(PartitionOpener(), super_device, source_slot); |
| 218 | } else { |
| 219 | builder = MetadataBuilder::NewForUpdate( |
| 220 | PartitionOpener(), super_device, source_slot, target_slot); |
| 221 | } |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 222 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 223 | if (builder == nullptr) { |
| 224 | LOG(WARNING) << "No metadata slot " |
| 225 | << BootControlInterface::SlotName(source_slot) << " in " |
| 226 | << super_device; |
Yifan Hong | f48a005 | 2018-10-29 16:30:43 -0700 | [diff] [blame] | 227 | return nullptr; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 228 | } |
| 229 | LOG(INFO) << "Loaded metadata from slot " |
| 230 | << BootControlInterface::SlotName(source_slot) << " in " |
| 231 | << super_device; |
| 232 | return builder; |
| 233 | } |
| 234 | |
| 235 | bool DynamicPartitionControlAndroid::StoreMetadata( |
| 236 | const std::string& super_device, |
| 237 | MetadataBuilder* builder, |
| 238 | uint32_t target_slot) { |
| 239 | auto metadata = builder->Export(); |
| 240 | if (metadata == nullptr) { |
| 241 | LOG(ERROR) << "Cannot export metadata to slot " |
| 242 | << BootControlInterface::SlotName(target_slot) << " in " |
| 243 | << super_device; |
| 244 | return false; |
| 245 | } |
| 246 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 247 | if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) { |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 248 | if (!FlashPartitionTable(super_device, *metadata)) { |
| 249 | LOG(ERROR) << "Cannot write metadata to " << super_device; |
| 250 | return false; |
| 251 | } |
| 252 | LOG(INFO) << "Written metadata to " << super_device; |
| 253 | } else { |
| 254 | if (!UpdatePartitionTable(super_device, *metadata, target_slot)) { |
| 255 | LOG(ERROR) << "Cannot write metadata to slot " |
| 256 | << BootControlInterface::SlotName(target_slot) << " in " |
| 257 | << super_device; |
| 258 | return false; |
| 259 | } |
| 260 | LOG(INFO) << "Copied metadata to slot " |
| 261 | << BootControlInterface::SlotName(target_slot) << " in " |
| 262 | << super_device; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 265 | return true; |
| 266 | } |
| 267 | |
| 268 | bool DynamicPartitionControlAndroid::GetDeviceDir(std::string* out) { |
| 269 | // We can't use fs_mgr to look up |partition_name| because fstab |
| 270 | // doesn't list every slot partition (it uses the slotselect option |
| 271 | // to mask the suffix). |
| 272 | // |
| 273 | // We can however assume that there's an entry for the /misc mount |
| 274 | // point and use that to get the device file for the misc |
| 275 | // partition. This helps us locate the disk that |partition_name| |
| 276 | // resides on. From there we'll assume that a by-name scheme is used |
| 277 | // so we can just replace the trailing "misc" by the given |
| 278 | // |partition_name| and suffix corresponding to |slot|, e.g. |
| 279 | // |
| 280 | // /dev/block/platform/soc.0/7824900.sdhci/by-name/misc -> |
| 281 | // /dev/block/platform/soc.0/7824900.sdhci/by-name/boot_a |
| 282 | // |
| 283 | // If needed, it's possible to relax the by-name assumption in the |
| 284 | // future by trawling /sys/block looking for the appropriate sibling |
| 285 | // of misc and then finding an entry in /dev matching the sysfs |
| 286 | // entry. |
| 287 | |
| 288 | std::string err, misc_device = get_bootloader_message_blk_device(&err); |
| 289 | if (misc_device.empty()) { |
| 290 | LOG(ERROR) << "Unable to get misc block device: " << err; |
| 291 | return false; |
| 292 | } |
| 293 | |
| 294 | if (!utils::IsSymlink(misc_device.c_str())) { |
| 295 | LOG(ERROR) << "Device file " << misc_device << " for /misc " |
| 296 | << "is not a symlink."; |
| 297 | return false; |
| 298 | } |
| 299 | *out = base::FilePath(misc_device).DirName().value(); |
| 300 | return true; |
| 301 | } |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 302 | |
| 303 | bool DynamicPartitionControlAndroid::PreparePartitionsForUpdate( |
| 304 | uint32_t source_slot, |
| 305 | uint32_t target_slot, |
| 306 | const PartitionMetadata& partition_metadata) { |
| 307 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 308 | |
| 309 | // Unmap all the target dynamic partitions because they would become |
| 310 | // inconsistent with the new metadata. |
| 311 | for (const auto& group : partition_metadata.groups) { |
| 312 | for (const auto& partition : group.partitions) { |
| 313 | if (!UnmapPartitionOnDeviceMapper(partition.name + target_suffix)) { |
| 314 | return false; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | std::string device_dir_str; |
| 320 | if (!GetDeviceDir(&device_dir_str)) { |
| 321 | return false; |
| 322 | } |
| 323 | base::FilePath device_dir(device_dir_str); |
| 324 | auto source_device = |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 325 | device_dir.Append(GetSuperPartitionName(source_slot)).value(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 326 | |
| 327 | auto builder = LoadMetadataBuilder(source_device, source_slot, target_slot); |
| 328 | if (builder == nullptr) { |
| 329 | LOG(ERROR) << "No metadata at " |
| 330 | << BootControlInterface::SlotName(source_slot); |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | if (!UpdatePartitionMetadata( |
| 335 | builder.get(), target_slot, partition_metadata)) { |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | auto target_device = |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 340 | device_dir.Append(GetSuperPartitionName(target_slot)).value(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 341 | return StoreMetadata(target_device, builder.get(), target_slot); |
| 342 | } |
| 343 | |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 344 | std::string DynamicPartitionControlAndroid::GetSuperPartitionName( |
| 345 | uint32_t slot) { |
| 346 | return fs_mgr_get_super_partition_name(slot); |
| 347 | } |
| 348 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 349 | bool DynamicPartitionControlAndroid::UpdatePartitionMetadata( |
| 350 | MetadataBuilder* builder, |
| 351 | uint32_t target_slot, |
| 352 | const PartitionMetadata& partition_metadata) { |
| 353 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 354 | DeleteGroupsWithSuffix(builder, target_suffix); |
| 355 | |
| 356 | uint64_t total_size = 0; |
| 357 | for (const auto& group : partition_metadata.groups) { |
| 358 | total_size += group.size; |
| 359 | } |
| 360 | |
| 361 | std::string expr; |
| 362 | uint64_t allocatable_space = builder->AllocatableSpace(); |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 363 | if (!GetDynamicPartitionsFeatureFlag().IsRetrofit()) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 364 | allocatable_space /= 2; |
| 365 | expr = "half of "; |
| 366 | } |
| 367 | if (total_size > allocatable_space) { |
| 368 | LOG(ERROR) << "The maximum size of all groups with suffix " << target_suffix |
| 369 | << " (" << total_size << ") has exceeded " << expr |
| 370 | << "allocatable space for dynamic partitions " |
| 371 | << allocatable_space << "."; |
| 372 | return false; |
| 373 | } |
| 374 | |
| 375 | for (const auto& group : partition_metadata.groups) { |
| 376 | auto group_name_suffix = group.name + target_suffix; |
| 377 | if (!builder->AddGroup(group_name_suffix, group.size)) { |
| 378 | LOG(ERROR) << "Cannot add group " << group_name_suffix << " with size " |
| 379 | << group.size; |
| 380 | return false; |
| 381 | } |
| 382 | LOG(INFO) << "Added group " << group_name_suffix << " with size " |
| 383 | << group.size; |
| 384 | |
| 385 | for (const auto& partition : group.partitions) { |
| 386 | auto partition_name_suffix = partition.name + target_suffix; |
| 387 | Partition* p = builder->AddPartition( |
| 388 | partition_name_suffix, group_name_suffix, LP_PARTITION_ATTR_READONLY); |
| 389 | if (!p) { |
| 390 | LOG(ERROR) << "Cannot add partition " << partition_name_suffix |
| 391 | << " to group " << group_name_suffix; |
| 392 | return false; |
| 393 | } |
| 394 | if (!builder->ResizePartition(p, partition.size)) { |
| 395 | LOG(ERROR) << "Cannot resize partition " << partition_name_suffix |
| 396 | << " to size " << partition.size << ". Not enough space?"; |
| 397 | return false; |
| 398 | } |
| 399 | LOG(INFO) << "Added partition " << partition_name_suffix << " to group " |
| 400 | << group_name_suffix << " with size " << partition.size; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | return true; |
| 405 | } |
| 406 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 407 | } // namespace chromeos_update_engine |