aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelvin Zhang <zhangkelvin@google.com>2022-03-19 01:08:47 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-03-19 01:08:47 +0000
commita949d23e78fa16bc04f78e5b6b39a71cbebbaae0 (patch)
tree6d6f3a72e24919d45ea90d4f5ffe560590d83efb
parentcad8b062f0b85bd6399df886098300486675986a (diff)
parentb936892050e662e1c514bb34af6fb14332cff4ce (diff)
downloadupdate_engine-a949d23e78fa16bc04f78e5b6b39a71cbebbaae0.tar.gz
pread() data into memory instead of lazily mmap everything am: b936892050
Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/2030887 Change-Id: I98b8d073e7a7ed4a81ad76844950987772c75176
-rw-r--r--aosp/ota_extractor.cc22
-rw-r--r--payload_consumer/delta_performer.cc8
2 files changed, 18 insertions, 12 deletions
diff --git a/aosp/ota_extractor.cc b/aosp/ota_extractor.cc
index 6fab44d2..f200fc81 100644
--- a/aosp/ota_extractor.cc
+++ b/aosp/ota_extractor.cc
@@ -49,14 +49,16 @@ namespace chromeos_update_engine {
bool ExtractImagesFromOTA(const DeltaArchiveManifest& manifest,
const PayloadMetadata& metadata,
- const uint8_t* payload,
- size_t size,
+ int payload_fd,
+ size_t payload_offset,
std::string_view output_dir) {
InstallOperationExecutor executor(manifest.block_size());
- const uint8_t* data_begin = payload + metadata.GetMetadataSize() +
- metadata.GetMetadataSignatureSize();
+ const size_t data_begin = metadata.GetMetadataSize() +
+ metadata.GetMetadataSignatureSize() +
+ payload_offset;
const base::FilePath path(
base::StringPiece(output_dir.data(), output_dir.size()));
+ std::vector<unsigned char> blob;
for (const auto& partition : manifest.partitions()) {
LOG(INFO) << "Extracting partition " << partition.partition_name()
<< " size: " << partition.new_partition_info().size();
@@ -67,10 +69,14 @@ bool ExtractImagesFromOTA(const DeltaArchiveManifest& manifest,
TEST_AND_RETURN_FALSE_ERRNO(
fd->Open(output_path.c_str(), O_RDWR | O_CREAT, 0644));
for (const auto& op : partition.operations()) {
+ blob.resize(op.data_length());
+ const auto op_data_offset = data_begin + op.data_offset();
+ ssize_t bytes_read = 0;
+ TEST_AND_RETURN_FALSE(utils::PReadAll(
+ payload_fd, blob.data(), blob.size(), op_data_offset, &bytes_read));
auto direct_writer = std::make_unique<DirectExtentWriter>(fd);
- const auto op_data = data_begin + op.data_offset();
TEST_AND_RETURN_FALSE(executor.ExecuteReplaceOperation(
- op, std::move(direct_writer), op_data, op.data_length()));
+ op, std::move(direct_writer), blob.data(), blob.size()));
}
int err =
truncate64(output_path.c_str(), partition.new_partition_info().size());
@@ -135,7 +141,7 @@ int main(int argc, char* argv[]) {
}
return !ExtractImagesFromOTA(manifest,
payload_metadata,
- payload + FLAGS_payload_offset,
- payload_size - FLAGS_payload_offset,
+ payload_fd,
+ FLAGS_payload_offset,
FLAGS_output_dir);
}
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index 19877db6..fc8858ff 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -1117,11 +1117,11 @@ ErrorCode DeltaPerformer::ValidateOperationHash(
if (calculated_op_hash != expected_op_hash) {
LOG(ERROR) << "Hash verification failed for operation "
- << next_operation_num_ << ". Expected hash = ";
- utils::HexDumpVector(expected_op_hash);
+ << next_operation_num_
+ << ". Expected hash = " << HexEncode(expected_op_hash);
LOG(ERROR) << "Calculated hash over " << operation.data_length()
- << " bytes at offset: " << operation.data_offset() << " = ";
- utils::HexDumpVector(calculated_op_hash);
+ << " bytes at offset: " << operation.data_offset() << " = "
+ << HexEncode(calculated_op_hash);
return ErrorCode::kDownloadOperationHashMismatch;
}