Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 1 | // |
| 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 | #ifndef UPDATE_ENGINE_VABC_PARTITION_WRITER_H_ |
| 18 | #define UPDATE_ENGINE_VABC_PARTITION_WRITER_H_ |
| 19 | |
Kelvin Zhang | 76f10b8 | 2021-06-25 18:45:46 -0400 | [diff] [blame] | 20 | #include <map> |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 21 | #include <memory> |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 22 | #include <string> |
Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 23 | #include <vector> |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 24 | |
David Anderson | a4b7ba6 | 2023-05-10 21:41:37 -0700 | [diff] [blame] | 25 | #include <libsnapshot/cow_writer.h> |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 26 | |
Kelvin Zhang | 76f10b8 | 2021-06-25 18:45:46 -0400 | [diff] [blame] | 27 | #include "update_engine/payload_consumer/extent_map.h" |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 28 | #include "update_engine/payload_consumer/install_operation_executor.h" |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 29 | #include "update_engine/payload_consumer/install_plan.h" |
Kelvin Zhang | d11e2fc | 2022-10-24 15:40:30 -0700 | [diff] [blame] | 30 | #include "update_engine/payload_consumer/partition_writer_interface.h" |
| 31 | #include "update_engine/payload_consumer/verified_source_fd.h" |
Kelvin Zhang | 76f10b8 | 2021-06-25 18:45:46 -0400 | [diff] [blame] | 32 | #include "update_engine/payload_generator/extent_ranges.h" |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 33 | |
| 34 | namespace chromeos_update_engine { |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 35 | class VABCPartitionWriter final : public PartitionWriterInterface { |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 36 | public: |
Daniel Zheng | 5a6e32b | 2024-02-26 14:09:06 -0800 | [diff] [blame^] | 37 | static bool ProcessSourceCopyOperation( |
| 38 | const InstallOperation& operation, |
| 39 | const size_t block_size, |
| 40 | const ExtentRanges& copy_blocks, |
| 41 | const FileDescriptorPtr& source_fd, |
| 42 | android::snapshot::ICowWriter* cow_writer, |
| 43 | bool sequence_op_supported); |
| 44 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 45 | VABCPartitionWriter(const PartitionUpdate& partition_update, |
| 46 | const InstallPlan::Partition& install_part, |
| 47 | DynamicPartitionControlInterface* dynamic_control, |
Kelvin Zhang | a37aafc | 2021-06-14 13:21:37 -0400 | [diff] [blame] | 48 | size_t block_size); |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 49 | [[nodiscard]] bool Init(const InstallPlan* install_plan, |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 50 | bool source_may_exist, |
| 51 | size_t next_op_index) override; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 52 | ~VABCPartitionWriter() override; |
| 53 | |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 54 | // Only ZERO and SOURCE_COPY InstallOperations are treated special by VABC |
| 55 | // Partition Writer. These operations correspond to COW_ZERO and COW_COPY. All |
| 56 | // other operations just get converted to COW_REPLACE. |
| 57 | [[nodiscard]] bool PerformZeroOrDiscardOperation( |
| 58 | const InstallOperation& operation) override; |
| 59 | [[nodiscard]] bool PerformSourceCopyOperation( |
| 60 | const InstallOperation& operation, ErrorCode* error) override; |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 61 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 62 | [[nodiscard]] bool PerformReplaceOperation(const InstallOperation& operation, |
| 63 | const void* data, |
| 64 | size_t count) override; |
| 65 | |
Tianjie | 8e0090d | 2021-08-30 22:35:21 -0700 | [diff] [blame] | 66 | [[nodiscard]] bool PerformDiffOperation(const InstallOperation& operation, |
| 67 | ErrorCode* error, |
| 68 | const void* data, |
| 69 | size_t count) override; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 70 | |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 71 | void CheckpointUpdateProgress(size_t next_op_index) override; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 72 | |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 73 | [[nodiscard]] bool FinishedInstallOps() override; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 74 | int Close() override; |
Kelvin Zhang | a37aafc | 2021-06-14 13:21:37 -0400 | [diff] [blame] | 75 | // Send merge sequence data to cow writer |
| 76 | static bool WriteMergeSequence( |
| 77 | const ::google::protobuf::RepeatedPtrField<CowMergeOperation>& merge_ops, |
| 78 | android::snapshot::ICowWriter* cow_writer); |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 79 | |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 80 | private: |
Kelvin Zhang | d795875 | 2023-03-23 12:23:47 -0700 | [diff] [blame] | 81 | [[nodiscard]] bool DoesDeviceSupportsXor(); |
Kelvin Zhang | 76f10b8 | 2021-06-25 18:45:46 -0400 | [diff] [blame] | 82 | bool IsXorEnabled() const noexcept { return xor_map_.size() > 0; } |
Kelvin Zhang | d795875 | 2023-03-23 12:23:47 -0700 | [diff] [blame] | 83 | [[nodiscard]] bool WriteAllCopyOps(); |
David Anderson | a4b7ba6 | 2023-05-10 21:41:37 -0700 | [diff] [blame] | 84 | std::unique_ptr<android::snapshot::ICowWriter> cow_writer_; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 85 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 86 | [[nodiscard]] std::unique_ptr<ExtentWriter> CreateBaseExtentWriter(); |
| 87 | |
| 88 | const PartitionUpdate& partition_update_; |
| 89 | const InstallPlan::Partition& install_part_; |
Kelvin Zhang | 76f10b8 | 2021-06-25 18:45:46 -0400 | [diff] [blame] | 90 | DynamicPartitionControlInterface* const dynamic_control_; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 91 | // Path to source partition |
Kelvin Zhang | 76f10b8 | 2021-06-25 18:45:46 -0400 | [diff] [blame] | 92 | const std::string source_path_; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 93 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 94 | const size_t block_size_; |
| 95 | InstallOperationExecutor executor_; |
| 96 | VerifiedSourceFd verified_source_fd_; |
Kelvin Zhang | 76f10b8 | 2021-06-25 18:45:46 -0400 | [diff] [blame] | 97 | ExtentMap<const CowMergeOperation*, ExtentLess> xor_map_; |
Kelvin Zhang | d11e2fc | 2022-10-24 15:40:30 -0700 | [diff] [blame] | 98 | ExtentRanges copy_blocks_; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace chromeos_update_engine |
| 102 | |
| 103 | #endif |