From 0d05b7a8fa0367edf30862bd6bf2ccb1f61d9f5c Mon Sep 17 00:00:00 2001 From: Tianjie Date: Mon, 8 Jun 2020 21:12:49 -0700 Subject: [PATCH] Update libsnapshot to handle partial update For partial update, the payload will not include all dynamic partitions on the device, update the logic libsnapshot to better handle such case. Bug: 157778739 Test: run a partial OTA, unit tests pass Change-Id: I4339a81ed31161bab3ba9666c1d05fb8bf57dbf9 --- fs_mgr/libsnapshot/snapshot.cpp | 4 ++++ .../libsnapshot/snapshot_metadata_updater.cpp | 19 +++++++++++++++++++ .../libsnapshot/snapshot_metadata_updater.h | 1 + .../update_engine/update_metadata.proto | 1 + 4 files changed, 25 insertions(+) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 5909cff79..55214f545 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -2277,6 +2277,10 @@ Return SnapshotManager::CreateUpdateSnapshotsInternal( auto operations_it = install_operation_map.find(target_partition->name()); if (operations_it != install_operation_map.end()) { cow_creator->operations = operations_it->second; + } else { + LOG(INFO) << target_partition->name() + << " isn't included in the payload, skipping the cow creation."; + continue; } cow_creator->extra_extents.clear(); diff --git a/fs_mgr/libsnapshot/snapshot_metadata_updater.cpp b/fs_mgr/libsnapshot/snapshot_metadata_updater.cpp index 60bf79647..051584c34 100644 --- a/fs_mgr/libsnapshot/snapshot_metadata_updater.cpp +++ b/fs_mgr/libsnapshot/snapshot_metadata_updater.cpp @@ -62,6 +62,8 @@ SnapshotMetadataUpdater::SnapshotMetadataUpdater(MetadataBuilder* builder, uint3 std::string(it->second) + target_suffix_, &p}); } } + + partial_update_ = manifest.partial_update(); } bool SnapshotMetadataUpdater::ShrinkPartitions() const { @@ -82,6 +84,18 @@ bool SnapshotMetadataUpdater::ShrinkPartitions() const { } bool SnapshotMetadataUpdater::DeletePartitions() const { + // For partial update, not all dynamic partitions are included in the payload. + // TODO(xunchang) delete the untouched partitions whose group is in the payload. + // e.g. Delete vendor in the following scenario + // On device: + // Group A: system, vendor + // In payload: + // Group A: system + if (partial_update_) { + LOG(INFO) << "Skip deleting partitions for partial update"; + return true; + } + std::vector partitions_to_delete; // Don't delete partitions in groups where the group name doesn't have target_suffix, // e.g. default. @@ -139,6 +153,11 @@ bool SnapshotMetadataUpdater::ShrinkGroups() const { } bool SnapshotMetadataUpdater::DeleteGroups() const { + if (partial_update_) { + LOG(INFO) << "Skip deleting groups for partial update"; + return true; + } + std::vector existing_groups = builder_->ListGroups(); for (const auto& existing_group_name : existing_groups) { // Don't delete groups without target suffix, e.g. default. diff --git a/fs_mgr/libsnapshot/snapshot_metadata_updater.h b/fs_mgr/libsnapshot/snapshot_metadata_updater.h index 83c94607d..5b1cbf91a 100644 --- a/fs_mgr/libsnapshot/snapshot_metadata_updater.h +++ b/fs_mgr/libsnapshot/snapshot_metadata_updater.h @@ -79,6 +79,7 @@ class SnapshotMetadataUpdater { const std::string target_suffix_; std::vector groups_; std::vector partitions_; + bool partial_update_{false}; }; } // namespace snapshot diff --git a/fs_mgr/libsnapshot/update_engine/update_metadata.proto b/fs_mgr/libsnapshot/update_engine/update_metadata.proto index 8a11eaa95..202e39be1 100644 --- a/fs_mgr/libsnapshot/update_engine/update_metadata.proto +++ b/fs_mgr/libsnapshot/update_engine/update_metadata.proto @@ -77,4 +77,5 @@ message DynamicPartitionMetadata { message DeltaArchiveManifest { repeated PartitionUpdate partitions = 13; optional DynamicPartitionMetadata dynamic_partition_metadata = 15; + optional bool partial_update = 16; }