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, gz, or brotli). 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 119// Next: 8 120enum UpdateState { 121 // No update or merge is in progress. 122 None = 0; 123 124 // An update is applying; snapshots may already exist. 125 Initiated = 1; 126 127 // An update is pending, but has not been successfully booted yet. 128 Unverified = 2; 129 130 // The kernel is merging in the background. 131 Merging = 3; 132 133 // Post-merge cleanup steps could not be completed due to a transient 134 // error, but the next reboot will finish any pending operations. 135 MergeNeedsReboot = 4; 136 137 // Merging is complete, and needs to be acknowledged. 138 MergeCompleted = 5; 139 140 // Merging failed due to an unrecoverable error. 141 MergeFailed = 6; 142 143 // The update was implicitly cancelled, either by a rollback or a flash 144 // operation via fastboot. This state can only be returned by WaitForMerge. 145 Cancelled = 7; 146}; 147 148// Next 14: 149// 150// To understand the source of each failure, read snapshot.cpp. To handle new 151// sources of failure, avoid reusing an existing code; add a new code instead. 152enum MergeFailureCode { 153 Ok = 0; 154 ReadStatus = 1; 155 GetTableInfo = 2; 156 UnknownTable = 3; 157 GetTableParams = 4; 158 ActivateNewTable = 5; 159 AcquireLock = 6; 160 ListSnapshots = 7; 161 WriteStatus = 8; 162 UnknownTargetType = 9; 163 QuerySnapshotStatus = 10; 164 ExpectedMergeTarget = 11; 165 UnmergedSectorsAfterCompletion = 12; 166 UnexpectedMergeState = 13; 167 GetCowPathConsistencyCheck = 14; 168 OpenCowConsistencyCheck = 15; 169 ParseCowConsistencyCheck = 16; 170 OpenCowDirectConsistencyCheck = 17; 171 MemAlignConsistencyCheck = 18; 172 DirectReadConsistencyCheck = 19; 173 WrongMergeCountConsistencyCheck = 20; 174}; 175 176// Next: 8 177message SnapshotUpdateStatus { 178 UpdateState state = 1; 179 180 // Total number of sectors allocated in the COW files before performing the 181 // merge operation. This field is used to keep track of the total number 182 // of sectors modified to monitor and show the progress of the merge during 183 // an update. 184 uint64 sectors_allocated = 2; 185 186 // Total number of sectors of all the snapshot devices. 187 uint64 total_sectors = 3; 188 189 // Sectors allocated for metadata in all the snapshot devices. 190 uint64 metadata_sectors = 4; 191 192 // Whether compression/dm-user was used for any snapshots. 193 bool using_snapuserd = 5; 194 195 // Merge phase (if state == MERGING). 196 MergePhase merge_phase = 6; 197 198 // Merge failure code, filled if state == MergeFailed. 199 MergeFailureCode merge_failure_code = 7; 200 201 // Source build fingerprint. 202 string source_build_fingerprint = 8; 203 204 // user-space snapshots 205 bool userspace_snapshots = 9; 206 207 // io_uring support 208 bool io_uring_enabled = 10; 209} 210 211// Next: 10 212message SnapshotMergeReport { 213 // Status of the update after the merge attempts. 214 UpdateState state = 1; 215 216 // Number of reboots that occurred after issuing and before completeing the 217 // merge of all the snapshot devices. 218 int32 resume_count = 2; 219 220 // Total size of all the COW images before the update. 221 uint64 cow_file_size = 3; 222 223 // Whether compression/dm-user was used for any snapshots. 224 bool compression_enabled = 4; 225 226 // Total size used by COWs, including /data and the super partition. 227 uint64 total_cow_size_bytes = 5; 228 229 // Sum of the estimated COW fields in the OTA manifest. 230 uint64 estimated_cow_size_bytes = 6; 231 232 // Time from boot to sys.boot_completed, in milliseconds. 233 uint32 boot_complete_time_ms = 7; 234 235 // Time from sys.boot_completed to merge start, in milliseconds. 236 uint32 boot_complete_to_merge_start_time_ms = 8; 237 238 // Merge failure code, filled if the merge failed at any time (regardless 239 // of whether it succeeded at a later time). 240 MergeFailureCode merge_failure_code = 9; 241 242 // The source fingerprint at the time the OTA was downloaded. 243 string source_build_fingerprint = 10; 244 245 // Whether this update attempt uses userspace snapshots. 246 bool userspace_snapshots_used = 11; 247 248 // Whether this update attempt uses XOR compression. 249 bool xor_compression_used = 12; 250 251 // Whether this update attempt used io_uring. 252 bool iouring_used = 13; 253} 254