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 | |
| 20 | #include <memory> |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 21 | #include <string> |
Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 22 | #include <vector> |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 23 | |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 24 | #include <libsnapshot/snapshot_writer.h> |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 25 | |
Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 26 | #include "update_engine/common/cow_operation_convert.h" |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 27 | #include "update_engine/payload_consumer/install_operation_executor.h" |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 28 | #include "update_engine/payload_consumer/install_plan.h" |
| 29 | #include "update_engine/payload_consumer/partition_writer.h" |
| 30 | |
| 31 | namespace chromeos_update_engine { |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 32 | class VABCPartitionWriter final : public PartitionWriterInterface { |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 33 | public: |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 34 | VABCPartitionWriter(const PartitionUpdate& partition_update, |
| 35 | const InstallPlan::Partition& install_part, |
| 36 | DynamicPartitionControlInterface* dynamic_control, |
Kelvin Zhang | a37aafc | 2021-06-14 13:21:37 -0400 | [diff] [blame] | 37 | size_t block_size); |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 38 | [[nodiscard]] bool Init(const InstallPlan* install_plan, |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 39 | bool source_may_exist, |
| 40 | size_t next_op_index) override; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 41 | ~VABCPartitionWriter() override; |
| 42 | |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 43 | // Only ZERO and SOURCE_COPY InstallOperations are treated special by VABC |
| 44 | // Partition Writer. These operations correspond to COW_ZERO and COW_COPY. All |
| 45 | // other operations just get converted to COW_REPLACE. |
| 46 | [[nodiscard]] bool PerformZeroOrDiscardOperation( |
| 47 | const InstallOperation& operation) override; |
| 48 | [[nodiscard]] bool PerformSourceCopyOperation( |
| 49 | const InstallOperation& operation, ErrorCode* error) override; |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 50 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 51 | [[nodiscard]] bool PerformReplaceOperation(const InstallOperation& operation, |
| 52 | const void* data, |
| 53 | size_t count) override; |
| 54 | |
Tianjie | 8e0090d | 2021-08-30 22:35:21 -0700 | [diff] [blame^] | 55 | [[nodiscard]] bool PerformDiffOperation(const InstallOperation& operation, |
| 56 | ErrorCode* error, |
| 57 | const void* data, |
| 58 | size_t count) override; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 59 | |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 60 | void CheckpointUpdateProgress(size_t next_op_index) override; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 61 | |
Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 62 | static bool WriteAllCowOps(size_t block_size, |
| 63 | const std::vector<CowOperation>& converted, |
| 64 | android::snapshot::ICowWriter* cow_writer, |
| 65 | FileDescriptorPtr source_fd); |
| 66 | |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 67 | [[nodiscard]] bool FinishedInstallOps() override; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 68 | int Close() override; |
Kelvin Zhang | a37aafc | 2021-06-14 13:21:37 -0400 | [diff] [blame] | 69 | // Send merge sequence data to cow writer |
| 70 | static bool WriteMergeSequence( |
| 71 | const ::google::protobuf::RepeatedPtrField<CowMergeOperation>& merge_ops, |
| 72 | android::snapshot::ICowWriter* cow_writer); |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 73 | |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 74 | private: |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 75 | std::unique_ptr<android::snapshot::ISnapshotWriter> cow_writer_; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 76 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 77 | [[nodiscard]] std::unique_ptr<ExtentWriter> CreateBaseExtentWriter(); |
| 78 | |
| 79 | const PartitionUpdate& partition_update_; |
| 80 | const InstallPlan::Partition& install_part_; |
| 81 | DynamicPartitionControlInterface* dynamic_control_; |
| 82 | // Path to source partition |
| 83 | std::string source_path_; |
| 84 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 85 | const size_t block_size_; |
| 86 | InstallOperationExecutor executor_; |
| 87 | VerifiedSourceFd verified_source_fd_; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace chromeos_update_engine |
| 91 | |
| 92 | #endif |