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