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