SOURCE_COPY operation: implement src == dst

Helper function to compare the source and destination extents of a
SOURCE_COPY InstallOperation.
The function returns true iff source and destination are identical with
the use of std::equal().

Bug: 141207436
Test: build
Change-Id: I146aeba1c8ede35f21cfef8e21d4af62274bda84
Signed-off-by: Alessio Balsini <balsini@google.com>
This commit is contained in:
Alessio Balsini 2019-11-28 13:30:27 +00:00 committed by Yifan Hong
parent adb98df120
commit ef2c39bd6b
2 changed files with 20 additions and 0 deletions

View File

@ -72,6 +72,8 @@ class SnapshotStatus;
static constexpr const std::string_view kCowGroupName = "cow";
bool SourceCopyOperationIsClone(const chromeos_update_engine::InstallOperation& operation);
enum class UpdateState : unsigned int {
// No update or merge is in progress.
None,

View File

@ -62,6 +62,19 @@ bool PartitionCowCreator::HasExtent(Partition* p, Extent* e) {
return false;
}
bool SourceCopyOperationIsClone(const InstallOperation& operation) {
using ChromeOSExtent = chromeos_update_engine::Extent;
if (operation.src_extents().size() != operation.dst_extents().size()) {
return false;
}
return std::equal(operation.src_extents().begin(), operation.src_extents().end(),
operation.dst_extents().begin(),
[](const ChromeOSExtent& src, const ChromeOSExtent& dst) {
return src.start_block() == dst.start_block() &&
src.num_blocks() == dst.num_blocks();
});
}
void WriteExtent(DmSnapCowSizeCalculator* sc, const chromeos_update_engine::Extent& de,
unsigned int sectors_per_block) {
const auto block_boundary = de.start_block() + de.num_blocks();
@ -88,6 +101,11 @@ uint64_t PartitionCowCreator::GetCowSize() {
if (operations == nullptr) return sc.cow_size_bytes();
for (const auto& iop : *operations) {
// Do not allocate space for operations that are going to be skipped
// during OTA application.
if (iop.type() == InstallOperation::SOURCE_COPY && SourceCopyOperationIsClone(iop))
continue;
for (const auto& de : iop.dst_extents()) {
WriteExtent(&sc, de, sectors_per_block);
}