1// Copyright (C) 2019 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15syntax = "proto3"; 16package android.snapshot; 17 18option optimize_for = LITE_RUNTIME; 19 20// Next: 4 21enum SnapshotState { 22 // No snapshot is found. 23 NONE = 0; 24 25 // The snapshot has been created and possibly written to. Rollbacks are 26 // possible by destroying the snapshot. 27 CREATED = 1; 28 29 // Changes are being merged. No rollbacks are possible beyond this point. 30 MERGING = 2; 31 32 // Changes have been merged, Future reboots may map the base device 33 // directly. 34 MERGE_COMPLETED = 3; 35} 36 37// Next: 3 38enum MergePhase { 39 // No merge is in progress. 40 NO_MERGE = 0; 41 42 // Shrunk partitions can merge. 43 FIRST_PHASE = 1; 44 45 // Grown partitions can merge. 46 SECOND_PHASE = 2; 47} 48 49// Next: 13 50message SnapshotStatus { 51 // Name of the snapshot. This is usually the name of the snapshotted 52 // logical partition; for example, "system_b". 53 string name = 1; 54 55 SnapshotState state = 2; 56 57 // Size of the full (base) device. 58 uint64 device_size = 3; 59 60 // Size of the snapshot. This is the sum of lengths of ranges in the base 61 // device that needs to be snapshotted during the update. 62 // This must be less than or equal to |device_size|. 63 // This value is 0 if no snapshot is needed for this device because 64 // no changes 65 uint64 snapshot_size = 4; 66 67 // Size of the "COW partition". A COW partition is a special logical 68 // partition represented in the super partition metadata. This partition and 69 // the "COW image" form the "COW device" that supports the snapshot device. 70 // 71 // When SnapshotManager creates a COW device, it first searches for unused 72 // blocks in the super partition, and use those before creating the COW 73 // image if the COW partition is not big enough. 74 // 75 // This value is 0 if no space in super is left for the COW partition. 76 // |cow_partition_size + cow_file_size| must not be zero if |snapshot_size| 77 // is non-zero. 78 uint64 cow_partition_size = 5; 79 80 // Size of the "COW file", or "COW image". A COW file / image is created 81 // when the "COW partition" is not big enough to store changes to the 82 // snapshot device. 83 // 84 // This value is 0 if |cow_partition_size| is big enough to hold all changes 85 // to the snapshot device. 86 uint64 cow_file_size = 6; 87 88 // Sectors allocated for the COW device. Recording this value right after 89 // the update and before the merge allows us to infer the progress of the 90 // merge process. 91 // This is non-zero when |state| == MERGING or MERGE_COMPLETED. 92 uint64 sectors_allocated = 7; 93 94 // Metadata sectors allocated for the COW device. Recording this value right 95 // before the update and before the merge allows us to infer the progress of 96 // the merge process. 97 // This is non-zero when |state| == MERGING or MERGE_COMPLETED. 98 uint64 metadata_sectors = 8; 99 100 // True if using snapuserd, false otherwise. 101 bool using_snapuserd = 9; 102 103 // The old partition size (if none existed, this will be zero). 104 uint64 old_partition_size = 10; 105 106 // Compression algorithm (none, lz4, zstd). 107 string compression_algorithm = 11; 108 109 // Estimated COW size from OTA manifest. 110 uint64 estimated_cow_size = 12; 111 112 // Enable multi-threaded compression 113 bool enable_threading = 13; 114 115 // Enable batching for COW writes 116 bool batched_writes = 14; 117 118 // Size of v3 operation buffer. Needs to be determined during writer initialization 119 uint64 estimated_ops_buffer_size = 15; 120 121 // Max bytes to be compressed at once (4k, 8k, 16k, 32k, 64k, 128k) 122 uint64 compression_factor = 16; 123 124 // Default value is 32, can be set lower for low mem devices 125 uint32 read_ahead_size = 17; 126 127 reserved 18; 128 129 // Blocks size to be verified at once 130 uint64 verify_block_size = 19; 131 132 // Default value is 2, configures threads to do verification phase 133 uint32 num_verify_threads = 20; 134} 135 136// Next: 8 137enum UpdateState { 138 // No update or merge is in progress. 139 None = 0; 140 141 // An update is applying; snapshots may already exist. 142 Initiated = 1; 143 144 // An update is pending, but has not been successfully booted yet. 145 Unverified = 2; 146 147 // The kernel is merging in the background. 148 Merging = 3; 149 150 // Post-merge cleanup steps could not be completed due to a transient 151 // error, but the next reboot will finish any pending operations. 152 MergeNeedsReboot = 4; 153 154 // Merging is complete, and needs to be acknowledged. 155 MergeCompleted = 5; 156 157 // Merging failed due to an unrecoverable error. 158 MergeFailed = 6; 159 160 // The update was implicitly cancelled, either by a rollback or a flash 161 // operation via fastboot. This state can only be returned by WaitForMerge. 162 Cancelled = 7; 163}; 164 165// Next 14: 166// 167// To understand the source of each failure, read snapshot.cpp. To handle new 168// sources of failure, avoid reusing an existing code; add a new code instead. 169enum MergeFailureCode { 170 Ok = 0; 171 ReadStatus = 1; 172 GetTableInfo = 2; 173 UnknownTable = 3; 174 GetTableParams = 4; 175 ActivateNewTable = 5; 176 AcquireLock = 6; 177 ListSnapshots = 7; 178 WriteStatus = 8; 179 UnknownTargetType = 9; 180 QuerySnapshotStatus = 10; 181 ExpectedMergeTarget = 11; 182 UnmergedSectorsAfterCompletion = 12; 183 UnexpectedMergeState = 13; 184 GetCowPathConsistencyCheck = 14; 185 OpenCowConsistencyCheck = 15; 186 ParseCowConsistencyCheck = 16; 187 OpenCowDirectConsistencyCheck = 17; 188 MemAlignConsistencyCheck = 18; 189 DirectReadConsistencyCheck = 19; 190 WrongMergeCountConsistencyCheck = 20; 191}; 192 193// Next: 8 194message SnapshotUpdateStatus { 195 UpdateState state = 1; 196 197 // Total number of sectors allocated in the COW files before performing the 198 // merge operation. This field is used to keep track of the total number 199 // of sectors modified to monitor and show the progress of the merge during 200 // an update. 201 uint64 sectors_allocated = 2; 202 203 // Total number of sectors of all the snapshot devices. 204 uint64 total_sectors = 3; 205 206 // Sectors allocated for metadata in all the snapshot devices. 207 uint64 metadata_sectors = 4; 208 209 // Whether compression/dm-user was used for any snapshots. 210 bool using_snapuserd = 5; 211 212 // Merge phase (if state == MERGING). 213 MergePhase merge_phase = 6; 214 215 // Merge failure code, filled if state == MergeFailed. 216 MergeFailureCode merge_failure_code = 7; 217 218 // Source build fingerprint. 219 string source_build_fingerprint = 8; 220 221 // user-space snapshots 222 bool userspace_snapshots = 9; 223 224 // io_uring support 225 bool io_uring_enabled = 10; 226 227 // legacy dm-snapshot based snapuserd 228 bool legacy_snapuserd = 11; 229 230 // Enable direct reads from source device 231 bool o_direct = 12; 232} 233 234// Next: 10 235message SnapshotMergeReport { 236 // Status of the update after the merge attempts. 237 UpdateState state = 1; 238 239 // Number of reboots that occurred after issuing and before completeing the 240 // merge of all the snapshot devices. 241 int32 resume_count = 2; 242 243 // Total size of all the COW images before the update. 244 uint64 cow_file_size = 3; 245 246 // Whether compression/dm-user was used for any snapshots. 247 bool compression_enabled = 4; 248 249 // Total size used by COWs, including /data and the super partition. 250 uint64 total_cow_size_bytes = 5; 251 252 // Sum of the estimated COW fields in the OTA manifest. 253 uint64 estimated_cow_size_bytes = 6; 254 255 // Time from boot to sys.boot_completed, in milliseconds. 256 uint32 boot_complete_time_ms = 7; 257 258 // Time from sys.boot_completed to merge start, in milliseconds. 259 uint32 boot_complete_to_merge_start_time_ms = 8; 260 261 // Merge failure code, filled if the merge failed at any time (regardless 262 // of whether it succeeded at a later time). 263 MergeFailureCode merge_failure_code = 9; 264 265 // The source fingerprint at the time the OTA was downloaded. 266 string source_build_fingerprint = 10; 267 268 // Whether this update attempt uses userspace snapshots. 269 bool userspace_snapshots_used = 11; 270 271 // Whether this update attempt uses XOR compression. 272 bool xor_compression_used = 12; 273 274 // Whether this update attempt used io_uring. 275 bool iouring_used = 13; 276 277 // Size of v3 operation buffer. Needs to be determined during writer initialization 278 uint64 estimated_op_count_max = 14; 279} 280