blob: c879375d265dddbcb1e818d9c80546f165d119d3 [file] [log] [blame]
Kelvin Zhang94f51cc2020-09-25 11:34:49 -04001//
2// Copyright (C) 2020 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/payload_consumer/vabc_partition_writer.h"
18
19#include <memory>
Kelvin Zhang3f60d532020-11-09 13:33:17 -050020#include <string>
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050021#include <utility>
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040022#include <vector>
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040023
Akilesh Kailash3e6e7df2021-11-18 23:29:15 +000024#include <android-base/properties.h>
Kelvin Zhang76f10b82021-06-25 18:45:46 -040025#include <brillo/secure_blob.h>
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040026#include <libsnapshot/cow_writer.h>
27
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040028#include "update_engine/common/cow_operation_convert.h"
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040029#include "update_engine/common/utils.h"
Kelvin Zhang76f10b82021-06-25 18:45:46 -040030#include "update_engine/payload_consumer/extent_map.h"
Kelvin Zhang7a265752020-10-29 15:51:35 -040031#include "update_engine/payload_consumer/file_descriptor.h"
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040032#include "update_engine/payload_consumer/install_plan.h"
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040033#include "update_engine/payload_consumer/snapshot_extent_writer.h"
Kelvin Zhang76f10b82021-06-25 18:45:46 -040034#include "update_engine/payload_consumer/xor_extent_writer.h"
Kelvin Zhanga37aafc2021-06-14 13:21:37 -040035#include "update_engine/payload_generator/extent_ranges.h"
36#include "update_engine/payload_generator/extent_utils.h"
37#include "update_engine/update_metadata.pb.h"
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040038
39namespace chromeos_update_engine {
Kelvin Zhang52cb1d72020-10-27 13:44:25 -040040// Expected layout of COW file:
41// === Beginning of Cow Image ===
42// All Source Copy Operations
43// ========== Label 0 ==========
44// Operation 0 in PartitionUpdate
45// ========== Label 1 ==========
46// Operation 1 in PartitionUpdate
47// ========== label 2 ==========
48// Operation 2 in PartitionUpdate
49// ========== label 3 ==========
50// .
51// .
52// .
53
54// When resuming, pass |next_op_index_| as label to
55// |InitializeWithAppend|.
56// For example, suppose we finished writing SOURCE_COPY, and we finished writing
57// operation 2 completely. Update is suspended when we are half way through
58// operation 3.
59// |cnext_op_index_| would be 3, so we pass 3 as
60// label to |InitializeWithAppend|. The CowWriter will retain all data before
61// label 3, Which contains all operation 2's data, but none of operation 3's
62// data.
63
Kelvin Zhanga37aafc2021-06-14 13:21:37 -040064using android::snapshot::ICowWriter;
65using ::google::protobuf::RepeatedPtrField;
66
Kelvin Zhang76f10b82021-06-25 18:45:46 -040067// Compute XOR map, a map from dst extent to corresponding merge operation
68static ExtentMap<const CowMergeOperation*, ExtentLess> ComputeXorMap(
69 const RepeatedPtrField<CowMergeOperation>& merge_ops) {
70 ExtentMap<const CowMergeOperation*, ExtentLess> xor_map;
71 for (const auto& merge_op : merge_ops) {
72 if (merge_op.type() == CowMergeOperation::COW_XOR) {
73 xor_map.AddExtent(merge_op.dst_extent(), &merge_op);
74 }
75 }
76 return xor_map;
77}
78
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050079VABCPartitionWriter::VABCPartitionWriter(
80 const PartitionUpdate& partition_update,
81 const InstallPlan::Partition& install_part,
82 DynamicPartitionControlInterface* dynamic_control,
Kelvin Zhanga37aafc2021-06-14 13:21:37 -040083 size_t block_size)
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050084 : partition_update_(partition_update),
85 install_part_(install_part),
86 dynamic_control_(dynamic_control),
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050087 block_size_(block_size),
88 executor_(block_size),
Kelvin Zhangd11e2fc2022-10-24 15:40:30 -070089 verified_source_fd_(block_size, install_part.source_path) {
90 for (const auto& cow_op : partition_update_.merge_operations()) {
91 if (cow_op.type() != CowMergeOperation::COW_COPY) {
92 continue;
93 }
94 copy_blocks_.AddExtent(cow_op.dst_extent());
95 }
Kelvin Zhang7dd5a5e2023-05-11 15:30:38 -070096 LOG(INFO) << "Partition `" << partition_update.partition_name() << "` has "
Kelvin Zhang67144e52023-04-03 18:17:07 -070097 << copy_blocks_.blocks() << " copy blocks";
Kelvin Zhangd11e2fc2022-10-24 15:40:30 -070098}
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050099
Daniel Zheng5a6e32b2024-02-26 14:09:06 -0800100bool VABCPartitionWriter::ProcessSourceCopyOperation(
101 const InstallOperation& operation,
102 const size_t block_size,
103 const ExtentRanges& copy_blocks,
104 const FileDescriptorPtr& source_fd,
105 android::snapshot::ICowWriter* cow_writer,
106 bool sequence_op_supported) {
107 // COPY ops are already handled during Init(), no need to do actual work, but
108 // we still want to verify that all blocks contain expected data.
109 TEST_AND_RETURN_FALSE(source_fd != nullptr);
110 std::vector<CowOperation> converted;
111
112 const auto& src_extents = operation.src_extents();
113 const auto& dst_extents = operation.dst_extents();
114 BlockIterator it1{src_extents};
115 BlockIterator it2{dst_extents};
116 const bool userSnapshots = android::base::GetBoolProperty(
117 "ro.virtual_ab.userspace.snapshots.enabled", false);
118 // For devices not supporting XOR, sequence op is not supported, so all COPY
119 // operations are written up front in strict merge order.
120 while (!it1.is_end() && !it2.is_end()) {
121 const auto src_block = *it1;
122 const auto dst_block = *it2;
123 ++it1;
124 ++it2;
125 if (src_block == dst_block) {
126 continue;
127 }
128 if (copy_blocks.ContainsBlock(dst_block)) {
129 if (sequence_op_supported) {
130 push_back(&converted, {CowOperation::CowCopy, src_block, dst_block, 1});
131 }
132 } else {
133 push_back(&converted,
134 {CowOperation::CowReplace, src_block, dst_block, 1});
135 }
136 }
137 std::vector<uint8_t> buffer;
138 for (const auto& cow_op : converted) {
139 if (cow_op.op == CowOperation::CowCopy) {
140 if (userSnapshots) {
141 cow_writer->AddCopy(
142 cow_op.dst_block, cow_op.src_block, cow_op.block_count);
143 } else {
144 // Add blocks in reverse order, because snapused specifically prefers
145 // this ordering. Since we already eliminated all self-overlapping
146 // SOURCE_COPY during delta generation, this should be safe to do.
147 for (size_t i = cow_op.block_count; i > 0; i--) {
148 TEST_AND_RETURN_FALSE(cow_writer->AddCopy(cow_op.dst_block + i - 1,
149 cow_op.src_block + i - 1));
150 }
151 }
152 continue;
153 }
154 buffer.resize(block_size * cow_op.block_count);
155 ssize_t bytes_read = 0;
156 TEST_AND_RETURN_FALSE(utils::ReadAll(source_fd,
157 buffer.data(),
158 block_size * cow_op.block_count,
159 cow_op.src_block * block_size,
160 &bytes_read));
161 if (bytes_read <= 0 || static_cast<size_t>(bytes_read) != buffer.size()) {
162 LOG(ERROR) << "source_fd->Read failed: " << bytes_read
163 << "\ncow op: " << cow_op.op;
164 return false;
165 }
166 TEST_AND_RETURN_FALSE(cow_writer->AddRawBlocks(
167 cow_op.dst_block, buffer.data(), buffer.size()));
168 }
169 return true;
170}
171
Kelvin Zhangd7958752023-03-23 12:23:47 -0700172bool VABCPartitionWriter::DoesDeviceSupportsXor() {
173 return dynamic_control_->GetVirtualAbCompressionXorFeatureFlag().IsEnabled();
174}
175
176bool VABCPartitionWriter::WriteAllCopyOps() {
177 const bool userSnapshots = android::base::GetBoolProperty(
178 "ro.virtual_ab.userspace.snapshots.enabled", false);
179 for (const auto& cow_op : partition_update_.merge_operations()) {
180 if (cow_op.type() != CowMergeOperation::COW_COPY) {
181 continue;
182 }
183 if (cow_op.dst_extent() == cow_op.src_extent()) {
184 continue;
185 }
186 if (userSnapshots) {
187 TEST_AND_RETURN_FALSE(cow_op.src_extent().num_blocks() != 0);
188 TEST_AND_RETURN_FALSE(
189 cow_writer_->AddCopy(cow_op.dst_extent().start_block(),
190 cow_op.src_extent().start_block(),
191 cow_op.src_extent().num_blocks()));
192 } else {
193 // Add blocks in reverse order, because snapused specifically prefers
194 // this ordering. Since we already eliminated all self-overlapping
195 // SOURCE_COPY during delta generation, this should be safe to do.
196 for (size_t i = cow_op.src_extent().num_blocks(); i > 0; i--) {
197 TEST_AND_RETURN_FALSE(
198 cow_writer_->AddCopy(cow_op.dst_extent().start_block() + i - 1,
199 cow_op.src_extent().start_block() + i - 1));
200 }
201 }
202 }
203 return true;
204}
205
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400206bool VABCPartitionWriter::Init(const InstallPlan* install_plan,
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400207 bool source_may_exist,
208 size_t next_op_index) {
Kelvin Zhang1c4b9812022-04-06 17:29:00 -0700209 if (dynamic_control_->GetVirtualAbCompressionXorFeatureFlag().IsEnabled()) {
210 xor_map_ = ComputeXorMap(partition_update_.merge_operations());
211 if (xor_map_.size() > 0) {
212 LOG(INFO) << "Virtual AB Compression with XOR is enabled";
213 } else {
214 LOG(INFO) << "Device supports Virtual AB compression with XOR, but OTA "
215 "package does not.";
216 }
217 } else {
218 LOG(INFO) << "Virtual AB Compression with XOR is disabled.";
219 }
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400220 TEST_AND_RETURN_FALSE(install_plan != nullptr);
Kelvin Zhangd1f90bc2021-09-15 21:12:34 -0700221 if (source_may_exist && install_part_.source_size > 0) {
222 TEST_AND_RETURN_FALSE(!install_part_.source_path.empty());
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500223 TEST_AND_RETURN_FALSE(verified_source_fd_.Open());
224 }
Kelvin Zhang3f60d532020-11-09 13:33:17 -0500225 std::optional<std::string> source_path;
226 if (!install_part_.source_path.empty()) {
227 // TODO(zhangkelvin) Make |source_path| a std::optional<std::string>
228 source_path = install_part_.source_path;
229 }
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400230
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400231 // ===== Resume case handling code goes here ====
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400232 // It is possible that the SOURCE_COPY are already written but
233 // |next_op_index_| is still 0. In this case we discard previously written
234 // SOURCE_COPY, and start over.
David Andersona4b7ba62023-05-10 21:41:37 -0700235 std::optional<uint64_t> label;
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400236 if (install_plan->is_resume && next_op_index > 0) {
237 LOG(INFO) << "Resuming update on partition `"
238 << partition_update_.partition_name() << "` op index "
239 << next_op_index;
David Andersona4b7ba62023-05-10 21:41:37 -0700240 label = {next_op_index};
241 }
242
243 cow_writer_ =
244 dynamic_control_->OpenCowWriter(install_part_.name, source_path, label);
245 TEST_AND_RETURN_FALSE(cow_writer_ != nullptr);
246
247 if (label) {
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400248 return true;
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400249 }
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400250
251 // ==============================================
Kelvin Zhanga37aafc2021-06-14 13:21:37 -0400252 if (!partition_update_.merge_operations().empty()) {
Kelvin Zhang5d74b722021-09-29 15:24:26 -0700253 if (IsXorEnabled()) {
254 LOG(INFO) << "VABC XOR enabled for partition "
255 << partition_update_.partition_name();
Kelvin Zhangd7958752023-03-23 12:23:47 -0700256 }
257 // When merge sequence is present in COW, snapuserd will merge blocks in
258 // order specified by the merge seuqnece op. Hence we have the freedom of
259 // writing COPY operations out of order. Delay processing of copy ops so
260 // that update_engine can be more responsive in progress updates.
261 if (DoesDeviceSupportsXor()) {
262 LOG(INFO) << "Snapuserd supports XOR and merge sequence, writing merge "
263 "sequence and delay writing COPY operations";
Kelvin Zhang5d74b722021-09-29 15:24:26 -0700264 TEST_AND_RETURN_FALSE(WriteMergeSequence(
265 partition_update_.merge_operations(), cow_writer_.get()));
Kelvin Zhangd7958752023-03-23 12:23:47 -0700266 } else {
267 LOG(INFO) << "Snapuserd does not support merge sequence, writing all "
268 "COPY operations up front, this may take few "
269 "minutes.";
270 TEST_AND_RETURN_FALSE(WriteAllCopyOps());
Kelvin Zhangd11e2fc2022-10-24 15:40:30 -0700271 }
Kelvin Zhanga37aafc2021-06-14 13:21:37 -0400272 cow_writer_->AddLabel(0);
Kelvin Zhangab3ce602021-02-24 14:46:40 -0500273 }
Kelvin Zhang7a265752020-10-29 15:51:35 -0400274 return true;
275}
276
Kelvin Zhanga37aafc2021-06-14 13:21:37 -0400277bool VABCPartitionWriter::WriteMergeSequence(
278 const RepeatedPtrField<CowMergeOperation>& merge_sequence,
279 ICowWriter* cow_writer) {
280 std::vector<uint32_t> blocks_merge_order;
281 for (const auto& merge_op : merge_sequence) {
282 const auto& dst_extent = merge_op.dst_extent();
Kelvin Zhangd1f90bc2021-09-15 21:12:34 -0700283 const auto& src_extent = merge_op.src_extent();
Kelvin Zhanga37aafc2021-06-14 13:21:37 -0400284 // In place copy are basically noops, they do not need to be "merged" at
285 // all, don't include them in merge sequence.
286 if (merge_op.type() == CowMergeOperation::COW_COPY &&
287 merge_op.src_extent() == merge_op.dst_extent()) {
288 continue;
289 }
Akilesh Kailash3e6e7df2021-11-18 23:29:15 +0000290
291 const bool extent_overlap =
292 ExtentRanges::ExtentsOverlap(src_extent, dst_extent);
293 // TODO(193863443) Remove this check once this feature
294 // lands on all pixel devices.
295 const bool is_ascending = android::base::GetBoolProperty(
296 "ro.virtual_ab.userspace.snapshots.enabled", false);
297
Kelvin Zhangd1f90bc2021-09-15 21:12:34 -0700298 // If this is a self-overlapping op and |dst_extent| comes after
299 // |src_extent|, we must write in reverse order for correctness.
Akilesh Kailash3e6e7df2021-11-18 23:29:15 +0000300 //
Kelvin Zhangd1f90bc2021-09-15 21:12:34 -0700301 // If this is self-overlapping op and |dst_extent| comes before
302 // |src_extent|, we must write in ascending order for correctness.
Akilesh Kailash3e6e7df2021-11-18 23:29:15 +0000303 //
304 // If this isn't a self overlapping op, write block in ascending order
305 // if userspace snapshots are enabled
306 if (extent_overlap) {
307 if (dst_extent.start_block() <= src_extent.start_block()) {
308 for (size_t i = 0; i < dst_extent.num_blocks(); i++) {
309 blocks_merge_order.push_back(dst_extent.start_block() + i);
310 }
311 } else {
312 for (int i = dst_extent.num_blocks() - 1; i >= 0; i--) {
313 blocks_merge_order.push_back(dst_extent.start_block() + i);
314 }
Kelvin Zhangd1f90bc2021-09-15 21:12:34 -0700315 }
316 } else {
Akilesh Kailash3e6e7df2021-11-18 23:29:15 +0000317 if (is_ascending) {
318 for (size_t i = 0; i < dst_extent.num_blocks(); i++) {
319 blocks_merge_order.push_back(dst_extent.start_block() + i);
320 }
321 } else {
322 for (int i = dst_extent.num_blocks() - 1; i >= 0; i--) {
323 blocks_merge_order.push_back(dst_extent.start_block() + i);
324 }
Kelvin Zhangd1f90bc2021-09-15 21:12:34 -0700325 }
Kelvin Zhanga37aafc2021-06-14 13:21:37 -0400326 }
327 }
328 return cow_writer->AddSequenceData(blocks_merge_order.size(),
329 blocks_merge_order.data());
330}
331
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400332std::unique_ptr<ExtentWriter> VABCPartitionWriter::CreateBaseExtentWriter() {
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400333 return std::make_unique<SnapshotExtentWriter>(cow_writer_.get());
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400334}
335
336[[nodiscard]] bool VABCPartitionWriter::PerformZeroOrDiscardOperation(
337 const InstallOperation& operation) {
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400338 for (const auto& extent : operation.dst_extents()) {
339 TEST_AND_RETURN_FALSE(
340 cow_writer_->AddZeroBlocks(extent.start_block(), extent.num_blocks()));
341 }
342 return true;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400343}
344
345[[nodiscard]] bool VABCPartitionWriter::PerformSourceCopyOperation(
346 const InstallOperation& operation, ErrorCode* error) {
Kelvin Zhangd11e2fc2022-10-24 15:40:30 -0700347 auto source_fd = verified_source_fd_.ChooseSourceFD(operation, error);
Kelvin Zhangd11e2fc2022-10-24 15:40:30 -0700348
Daniel Zheng5a6e32b2024-02-26 14:09:06 -0800349 return ProcessSourceCopyOperation(operation,
350 block_size_,
351 copy_blocks_,
352 source_fd,
353 cow_writer_.get(),
354 DoesDeviceSupportsXor());
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400355}
356
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500357bool VABCPartitionWriter::PerformReplaceOperation(const InstallOperation& op,
358 const void* data,
359 size_t count) {
360 // Setup the ExtentWriter stack based on the operation type.
361 std::unique_ptr<ExtentWriter> writer = CreateBaseExtentWriter();
362
Daniel Zheng17be0f92024-01-23 15:12:33 -0800363 return executor_.ExecuteReplaceOperation(op, std::move(writer), data);
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500364}
365
Tianjie8e0090d2021-08-30 22:35:21 -0700366bool VABCPartitionWriter::PerformDiffOperation(
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500367 const InstallOperation& operation,
368 ErrorCode* error,
369 const void* data,
370 size_t count) {
371 FileDescriptorPtr source_fd =
372 verified_source_fd_.ChooseSourceFD(operation, error);
373 TEST_AND_RETURN_FALSE(source_fd != nullptr);
Kelvin Zhang76f10b82021-06-25 18:45:46 -0400374 TEST_AND_RETURN_FALSE(source_fd->IsOpen());
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500375
Kelvin Zhang76f10b82021-06-25 18:45:46 -0400376 std::unique_ptr<ExtentWriter> writer =
377 IsXorEnabled() ? std::make_unique<XORExtentWriter>(
Kelvin Zhanga3a68a92023-04-05 13:17:18 -0700378 operation,
379 source_fd,
380 cow_writer_.get(),
381 xor_map_,
382 partition_update_.old_partition_info().size())
Kelvin Zhang76f10b82021-06-25 18:45:46 -0400383 : CreateBaseExtentWriter();
Tianjie8e0090d2021-08-30 22:35:21 -0700384 return executor_.ExecuteDiffOperation(
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500385 operation, std::move(writer), source_fd, data, count);
386}
387
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400388void VABCPartitionWriter::CheckpointUpdateProgress(size_t next_op_index) {
389 // No need to call fsync/sync, as CowWriter flushes after a label is added
390 // added.
Kelvin Zhang6a4d1ec2021-02-04 16:28:48 -0500391 // if cow_writer_ failed, that means Init() failed. This function shouldn't be
392 // called if Init() fails.
393 TEST_AND_RETURN(cow_writer_ != nullptr);
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400394 cow_writer_->AddLabel(next_op_index);
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400395}
396
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400397[[nodiscard]] bool VABCPartitionWriter::FinishedInstallOps() {
398 // Add a hardcoded magic label to indicate end of all install ops. This label
399 // is needed by filesystem verification, don't remove.
Kelvin Zhang6a4d1ec2021-02-04 16:28:48 -0500400 TEST_AND_RETURN_FALSE(cow_writer_ != nullptr);
Kelvin Zhang9e5e1ed2021-09-28 14:19:16 -0700401 TEST_AND_RETURN_FALSE(cow_writer_->AddLabel(kEndOfInstallLabel));
402 TEST_AND_RETURN_FALSE(cow_writer_->Finalize());
David Andersona4b7ba62023-05-10 21:41:37 -0700403
404 auto cow_reader = cow_writer_->OpenReader();
405 TEST_AND_RETURN_FALSE(cow_reader);
406 TEST_AND_RETURN_FALSE(cow_reader->VerifyMergeOps());
Kelvin Zhang02fe6622021-11-01 16:37:58 -0700407 return true;
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400408}
409
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400410VABCPartitionWriter::~VABCPartitionWriter() {
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500411 Close();
412}
413
414int VABCPartitionWriter::Close() {
Kelvin Zhang6a4d1ec2021-02-04 16:28:48 -0500415 if (cow_writer_) {
Kelvin Zhangd11e2fc2022-10-24 15:40:30 -0700416 LOG(INFO) << "Finalizing " << partition_update_.partition_name()
417 << " COW image";
Kelvin Zhangb1c05242023-12-14 13:49:53 -0800418 if (!cow_writer_->Finalize()) {
419 return -errno;
420 }
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500421 cow_writer_ = nullptr;
Kelvin Zhang6a4d1ec2021-02-04 16:28:48 -0500422 }
Kelvin Zhange52b6cd2021-02-09 15:28:40 -0500423 return 0;
Kelvin Zhang9b10dba2020-09-25 17:09:11 -0400424}
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400425
426} // namespace chromeos_update_engine