Add skeleton for zucchini patch
Also consolidates the code in partition writer to call patch functions
in one places.
Bug: 197361113
Test: TH
Change-Id: If6b5b9b6393888e67854b7130ae9a63e2fec482a
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index f067a82..274465c 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -389,12 +389,13 @@
return MetadataParseResult::kSuccess;
}
-#define OP_DURATION_HISTOGRAM(_op_name, _start_time) \
- LOCAL_HISTOGRAM_CUSTOM_TIMES( \
- "UpdateEngine.DownloadAction.InstallOperation::" _op_name ".Duration", \
- (base::TimeTicks::Now() - _start_time), \
- base::TimeDelta::FromMilliseconds(10), \
- base::TimeDelta::FromMinutes(5), \
+#define OP_DURATION_HISTOGRAM(_op_name, _start_time) \
+ LOCAL_HISTOGRAM_CUSTOM_TIMES( \
+ "UpdateEngine.DownloadAction.InstallOperation::" + string(_op_name) + \
+ ".Duration", \
+ (base::TimeTicks::Now() - _start_time), \
+ base::TimeDelta::FromMilliseconds(10), \
+ base::TimeDelta::FromMinutes(5), \
20);
// Wrapper around write. Returns true if all requested bytes
@@ -546,6 +547,7 @@
base::TimeTicks op_start_time = base::TimeTicks::Now();
bool op_result;
+ const string op_name = InstallOperationTypeName(op.type());
switch (op.type()) {
case InstallOperation::REPLACE:
case InstallOperation::REPLACE_BZ:
@@ -564,17 +566,15 @@
break;
case InstallOperation::SOURCE_BSDIFF:
case InstallOperation::BROTLI_BSDIFF:
- op_result = PerformSourceBsdiffOperation(op, error);
- OP_DURATION_HISTOGRAM("SOURCE_BSDIFF", op_start_time);
- break;
case InstallOperation::PUFFDIFF:
- op_result = PerformPuffDiffOperation(op, error);
- OP_DURATION_HISTOGRAM("PUFFDIFF", op_start_time);
+ case InstallOperation::ZUCCHINI:
+ op_result = PerformDiffOperation(op, error);
+ OP_DURATION_HISTOGRAM(op_name, op_start_time);
break;
default:
op_result = false;
}
- if (!HandleOpResult(op_result, InstallOperationTypeName(op.type()), error))
+ if (!HandleOpResult(op_result, op_name.c_str(), error))
return false;
next_operation_num_++;
@@ -824,8 +824,8 @@
return true;
}
-bool DeltaPerformer::PerformSourceBsdiffOperation(
- const InstallOperation& operation, ErrorCode* error) {
+bool DeltaPerformer::PerformDiffOperation(const InstallOperation& operation,
+ ErrorCode* error) {
// Since we delete data off the beginning of the buffer as we use it,
// the data we need should be exactly at the beginning of the buffer.
TEST_AND_RETURN_FALSE(buffer_offset_ == operation.data_offset());
@@ -835,19 +835,7 @@
if (operation.has_dst_length())
TEST_AND_RETURN_FALSE(operation.dst_length() % block_size_ == 0);
- TEST_AND_RETURN_FALSE(partition_writer_->PerformSourceBsdiffOperation(
- operation, error, buffer_.data(), buffer_.size()));
- DiscardBuffer(true, buffer_.size());
- return true;
-}
-
-bool DeltaPerformer::PerformPuffDiffOperation(const InstallOperation& operation,
- ErrorCode* error) {
- // Since we delete data off the beginning of the buffer as we use it,
- // the data we need should be exactly at the beginning of the buffer.
- TEST_AND_RETURN_FALSE(buffer_offset_ == operation.data_offset());
- TEST_AND_RETURN_FALSE(buffer_.size() >= operation.data_length());
- TEST_AND_RETURN_FALSE(partition_writer_->PerformPuffDiffOperation(
+ TEST_AND_RETURN_FALSE(partition_writer_->PerformDiffOperation(
operation, error, buffer_.data(), buffer_.size()));
DiscardBuffer(true, buffer_.size());
return true;
diff --git a/payload_consumer/delta_performer.h b/payload_consumer/delta_performer.h
index 30f5e9c..de6f448 100644
--- a/payload_consumer/delta_performer.h
+++ b/payload_consumer/delta_performer.h
@@ -267,10 +267,8 @@
bool PerformZeroOrDiscardOperation(const InstallOperation& operation);
bool PerformSourceCopyOperation(const InstallOperation& operation,
ErrorCode* error);
- bool PerformSourceBsdiffOperation(const InstallOperation& operation,
- ErrorCode* error);
- bool PerformPuffDiffOperation(const InstallOperation& operation,
- ErrorCode* error);
+ bool PerformDiffOperation(const InstallOperation& operation,
+ ErrorCode* error);
// Extracts the payload signature message from the current |buffer_| if the
// offset matches the one specified by the manifest. Returns whether the
diff --git a/payload_consumer/install_operation_executor.cc b/payload_consumer/install_operation_executor.cc
index ecd5dde..fa176da 100644
--- a/payload_consumer/install_operation_executor.cc
+++ b/payload_consumer/install_operation_executor.cc
@@ -170,36 +170,6 @@
DISALLOW_COPY_AND_ASSIGN(PuffinExtentStream);
};
-bool InstallOperationExecutor::ExecuteInstallOp(
- const InstallOperation& op,
- std::unique_ptr<ExtentWriter> writer,
- FileDescriptorPtr source_fd,
- const void* data,
- size_t size) {
- switch (op.type()) {
- case InstallOperation::REPLACE:
- case InstallOperation::REPLACE_BZ:
- case InstallOperation::REPLACE_XZ:
- return ExecuteReplaceOperation(op, std::move(writer), data, size);
- case InstallOperation::ZERO:
- case InstallOperation::DISCARD:
- return ExecuteZeroOrDiscardOperation(op, writer.get());
- case InstallOperation::SOURCE_COPY:
- return ExecuteSourceCopyOperation(op, writer.get(), source_fd);
- case InstallOperation::SOURCE_BSDIFF:
- case InstallOperation::BROTLI_BSDIFF:
- return ExecuteSourceBsdiffOperation(
- op, std::move(writer), source_fd, data, size);
- case InstallOperation::PUFFDIFF:
- return ExecutePuffDiffOperation(
- op, std::move(writer), source_fd, data, size);
- break;
- default:
- return false;
- }
- return false;
-}
-
bool InstallOperationExecutor::ExecuteReplaceOperation(
const InstallOperation& operation,
std::unique_ptr<ExtentWriter> writer,
@@ -254,17 +224,38 @@
source_fd, operation.src_extents(), writer, block_size_, nullptr);
}
+bool InstallOperationExecutor::ExecuteDiffOperation(
+ const InstallOperation& operation,
+ std::unique_ptr<ExtentWriter> writer,
+ FileDescriptorPtr source_fd,
+ const void* data,
+ size_t count) {
+ TEST_AND_RETURN_FALSE(source_fd != nullptr);
+ switch (operation.type()) {
+ case InstallOperation::SOURCE_BSDIFF:
+ case InstallOperation::BSDIFF:
+ case InstallOperation::BROTLI_BSDIFF:
+ return ExecuteSourceBsdiffOperation(
+ operation, std::move(writer), source_fd, data, count);
+ case InstallOperation::PUFFDIFF:
+ return ExecutePuffDiffOperation(
+ operation, std::move(writer), source_fd, data, count);
+ case InstallOperation::ZUCCHINI:
+ return ExecuteZucchiniOperation(
+ operation, std::move(writer), source_fd, data, count);
+ default:
+ LOG(ERROR) << "Unexpected operation type when executing diff ops "
+ << operation.type();
+ return false;
+ }
+}
+
bool InstallOperationExecutor::ExecuteSourceBsdiffOperation(
const InstallOperation& operation,
std::unique_ptr<ExtentWriter> writer,
FileDescriptorPtr source_fd,
const void* data,
size_t count) {
- TEST_AND_RETURN_FALSE(operation.type() == InstallOperation::SOURCE_BSDIFF ||
- operation.type() == InstallOperation::BROTLI_BSDIFF ||
- operation.type() == InstallOperation::BSDIFF);
- TEST_AND_RETURN_FALSE(source_fd != nullptr);
-
auto reader = std::make_unique<DirectExtentReader>();
TEST_AND_RETURN_FALSE(
reader->Init(source_fd, operation.src_extents(), block_size_));
@@ -290,9 +281,6 @@
FileDescriptorPtr source_fd,
const void* data,
size_t count) {
- TEST_AND_RETURN_FALSE(operation.type() == InstallOperation::PUFFDIFF);
- TEST_AND_RETURN_FALSE(source_fd != nullptr);
-
auto reader = std::make_unique<DirectExtentReader>();
TEST_AND_RETURN_FALSE(
reader->Init(source_fd, operation.src_extents(), block_size_));
@@ -314,4 +302,15 @@
kMaxCacheSize));
return true;
}
+
+bool InstallOperationExecutor::ExecuteZucchiniOperation(
+ const InstallOperation& operation,
+ std::unique_ptr<ExtentWriter> writer,
+ FileDescriptorPtr source_fd,
+ const void* data,
+ size_t count) {
+ LOG(ERROR) << "zucchini operation isn't supported";
+ return false;
+}
+
} // namespace chromeos_update_engine
diff --git a/payload_consumer/install_operation_executor.h b/payload_consumer/install_operation_executor.h
index a43139b..b064cc8 100644
--- a/payload_consumer/install_operation_executor.h
+++ b/payload_consumer/install_operation_executor.h
@@ -30,11 +30,6 @@
explicit InstallOperationExecutor(size_t block_size)
: block_size_(block_size) {}
- bool ExecuteInstallOp(const InstallOperation& op,
- std::unique_ptr<ExtentWriter> writer,
- FileDescriptorPtr source_fd,
- const void* data,
- size_t size);
bool ExecuteReplaceOperation(const InstallOperation& operation,
std::unique_ptr<ExtentWriter> writer,
const void* data,
@@ -44,6 +39,14 @@
bool ExecuteSourceCopyOperation(const InstallOperation& operation,
ExtentWriter* writer,
FileDescriptorPtr source_fd);
+
+ bool ExecuteDiffOperation(const InstallOperation& operation,
+ std::unique_ptr<ExtentWriter> writer,
+ FileDescriptorPtr source_fd,
+ const void* data,
+ size_t count);
+
+ private:
bool ExecuteSourceBsdiffOperation(const InstallOperation& operation,
std::unique_ptr<ExtentWriter> writer,
FileDescriptorPtr source_fd,
@@ -54,8 +57,12 @@
FileDescriptorPtr source_fd,
const void* data,
size_t count);
+ bool ExecuteZucchiniOperation(const InstallOperation& operation,
+ std::unique_ptr<ExtentWriter> writer,
+ FileDescriptorPtr source_fd,
+ const void* data,
+ size_t count);
- private:
size_t block_size_;
};
diff --git a/payload_consumer/mock_partition_writer.h b/payload_consumer/mock_partition_writer.h
index b056010..0f21337 100644
--- a/payload_consumer/mock_partition_writer.h
+++ b/payload_consumer/mock_partition_writer.h
@@ -54,11 +54,7 @@
(const InstallOperation&, ErrorCode*),
(override));
MOCK_METHOD(bool,
- PerformSourceBsdiffOperation,
- (const InstallOperation&, ErrorCode*, const void*, size_t),
- (override));
- MOCK_METHOD(bool,
- PerformPuffDiffOperation,
+ PerformDiffOperation,
(const InstallOperation&, ErrorCode*, const void*, size_t),
(override));
};
diff --git a/payload_consumer/partition_writer.cc b/payload_consumer/partition_writer.cc
index 7922eb2..75d738e 100644
--- a/payload_consumer/partition_writer.cc
+++ b/payload_consumer/partition_writer.cc
@@ -258,31 +258,16 @@
optimized, writer.get(), source_fd);
}
-bool PartitionWriter::PerformSourceBsdiffOperation(
- const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) {
+bool PartitionWriter::PerformDiffOperation(const InstallOperation& operation,
+ ErrorCode* error,
+ const void* data,
+ size_t count) {
FileDescriptorPtr source_fd = ChooseSourceFD(operation, error);
TEST_AND_RETURN_FALSE(source_fd != nullptr);
auto writer = CreateBaseExtentWriter();
writer->Init(operation.dst_extents(), block_size_);
- return install_op_executor_.ExecuteSourceBsdiffOperation(
- operation, std::move(writer), source_fd, data, count);
-}
-
-bool PartitionWriter::PerformPuffDiffOperation(
- const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) {
- FileDescriptorPtr source_fd = ChooseSourceFD(operation, error);
- TEST_AND_RETURN_FALSE(source_fd != nullptr);
-
- auto writer = CreateBaseExtentWriter();
- writer->Init(operation.dst_extents(), block_size_);
- return install_op_executor_.ExecutePuffDiffOperation(
+ return install_op_executor_.ExecuteDiffOperation(
operation, std::move(writer), source_fd, data, count);
}
diff --git a/payload_consumer/partition_writer.h b/payload_consumer/partition_writer.h
index e11d987..89e5884 100644
--- a/payload_consumer/partition_writer.h
+++ b/payload_consumer/partition_writer.h
@@ -76,15 +76,10 @@
[[nodiscard]] bool PerformSourceCopyOperation(
const InstallOperation& operation, ErrorCode* error) override;
- [[nodiscard]] bool PerformSourceBsdiffOperation(
- const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) override;
- [[nodiscard]] bool PerformPuffDiffOperation(const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) override;
+ [[nodiscard]] bool PerformDiffOperation(const InstallOperation& operation,
+ ErrorCode* error,
+ const void* data,
+ size_t count) override;
// |DeltaPerformer| calls this when all Install Ops are sent to partition
// writer. No |Perform*Operation| methods will be called in the future, and
diff --git a/payload_consumer/partition_writer_interface.h b/payload_consumer/partition_writer_interface.h
index f8d6b9c..e346292 100644
--- a/payload_consumer/partition_writer_interface.h
+++ b/payload_consumer/partition_writer_interface.h
@@ -62,12 +62,7 @@
[[nodiscard]] virtual bool PerformSourceCopyOperation(
const InstallOperation& operation, ErrorCode* error) = 0;
- [[nodiscard]] virtual bool PerformSourceBsdiffOperation(
- const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) = 0;
- [[nodiscard]] virtual bool PerformPuffDiffOperation(
+ [[nodiscard]] virtual bool PerformDiffOperation(
const InstallOperation& operation,
ErrorCode* error,
const void* data,
diff --git a/payload_consumer/vabc_partition_writer.cc b/payload_consumer/vabc_partition_writer.cc
index 5130d7a..3cdd4a4 100644
--- a/payload_consumer/vabc_partition_writer.cc
+++ b/payload_consumer/vabc_partition_writer.cc
@@ -221,7 +221,7 @@
return executor_.ExecuteReplaceOperation(op, std::move(writer), data, count);
}
-bool VABCPartitionWriter::PerformSourceBsdiffOperation(
+bool VABCPartitionWriter::PerformDiffOperation(
const InstallOperation& operation,
ErrorCode* error,
const void* data,
@@ -231,21 +231,7 @@
TEST_AND_RETURN_FALSE(source_fd != nullptr);
auto writer = CreateBaseExtentWriter();
- return executor_.ExecuteSourceBsdiffOperation(
- operation, std::move(writer), source_fd, data, count);
-}
-
-bool VABCPartitionWriter::PerformPuffDiffOperation(
- const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) {
- FileDescriptorPtr source_fd =
- verified_source_fd_.ChooseSourceFD(operation, error);
- TEST_AND_RETURN_FALSE(source_fd != nullptr);
-
- auto writer = CreateBaseExtentWriter();
- return executor_.ExecutePuffDiffOperation(
+ return executor_.ExecuteDiffOperation(
operation, std::move(writer), source_fd, data, count);
}
diff --git a/payload_consumer/vabc_partition_writer.h b/payload_consumer/vabc_partition_writer.h
index c73bd4d..fb63f8c 100644
--- a/payload_consumer/vabc_partition_writer.h
+++ b/payload_consumer/vabc_partition_writer.h
@@ -52,15 +52,10 @@
const void* data,
size_t count) override;
- [[nodiscard]] bool PerformSourceBsdiffOperation(
- const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) override;
- [[nodiscard]] bool PerformPuffDiffOperation(const InstallOperation& operation,
- ErrorCode* error,
- const void* data,
- size_t count) override;
+ [[nodiscard]] bool PerformDiffOperation(const InstallOperation& operation,
+ ErrorCode* error,
+ const void* data,
+ size_t count) override;
void CheckpointUpdateProgress(size_t next_op_index) override;