If rollback is detected in ProcessUpdateState, call
RemoveUpdateState and return UpdateState::Cancelled. Now that
update_engine is reponsible for initiating the merge, it can react to
this state and clean up markers appropriately.
Test: libsnapshot_test
Test: apply OTA, manually rollback (by setting the active slot), then
inspect /metadata/ota as well as /data/misc/update_engine/prefs.
Bug: 147696014
Change-Id: Ibfee11fb50e4f4fb7c6cf02b4921b35e77b8f5a5
Init skips first stage mount entirely in recovery, so
the check is useless. Also, __ANDROID_RECOVERY__ is always
set for first stage init.
Also add logs if rollback indicator is set.
Fixes: 149956852
Test: apply OTA, manually rollback, reboot, see rollback indicator
Change-Id: Iac967baf4b51ea5ce9f6eb962a33cb7ee5819c1d
Change callback type of ProcessUpdateState to bool() so that, when callback
returns false, immediately returns Merging.
Test: libsnapshot_test
Bug: 147696014
Change-Id: I9dcb8e1658b95216c0f1991e2e4c1ea2e7e7b2e5
These functions are used directly in update_engine now that
it is responsible for initiating the merge. update_engine has
its own message loop, so WaitForMerge / InitiateMergeAndWait
becomes useless and are deprecated.
Bug: 147696014
Test: compiles
Change-Id: Id8cb14f5f18b4893e2fc3d0d2b374a867a220e6f
Add an optional prolog arg (function<bool()>) that is invoked
before snapshots are deleted and update state set to none.
This allows update_engine to delete markers before deleting snapshots
to avoid depending on the erroneous markers. Otherwise, if update_engine
delete markers after libsnapshot deletes update states, the device could
technically get into a state where update_engine thinks the update has
been applied, but snapshots are gone.
Bug: 147696014
Test: libsnapshot_test
Change-Id: I71bfc04a81ea4f94b3072558be50d2f80565113e
update_engine is now responsible for initiating the merge. snapshotctl
becomes a debugging tool for libsnapshot now.
Bug: 147696014
Test: libsnapshot_test
Change-Id: Ia2527a35e0c0f0789dbe5c477e174663ef406903
Enable the --report flag in init rc script to collect and send snapshot
merge statistics after OTA.
Bug: 138817833
Test: statsd_testdrive
Change-Id: Ie32a2c6d7d1671ca2b1846c6a8d33cea2ab22a4c
Signed-off-by: Alessio Balsini <balsini@google.com>
Add the --report flag to spshotctl to submit Android metrics on the final state
of the snapshot merge operation, the duration if the merge is completed in a
single session, or the number of reboots that happened before completing the
merge.
Bug: 138817833
Bug: 148138124
Test: m + OTA + statsd_testdrive
Change-Id: Id657f33963bb9926553fa6eeb1721a5229f11e87
Signed-off-by: Alessio Balsini <balsini@google.com>
Merged-In: Id657f33963bb9926553fa6eeb1721a5229f11e87
Some tests were temporarily disabled due to errors in Cuttlefish.
Now that the issues were fixed, the tests can be put back in presubmit.
Bug: 148889015
Test: vts_libsnapshot_test (Cuttlefish + Pixel 4)
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: Idcb2b7831b2183b2d734bdf8821fd34746f2beee
The Resume() operation is supposed to increment the resume counter, but
the updated counter value was not written to the device.
Fix by adding the write operation and refactoring the code.
Bug: none
Test: m
Change-Id: I3fffd61cc779c59e2780900809f0ce0b84258e78
Signed-off-by: Alessio Balsini <balsini@google.com>
This test was causing the failure of vts_libsnapshot_test.
Disable until a fix is found and tests are stable again.
Bug: 149738928
Test: atests vts_libsnapshot_test
Change-Id: Ibbe5cd72aad93d9ade4ac1542f08dec9cd926a3b
Signed-off-by: Alessio Balsini <balsini@google.com>
The SnapshotMergeStats class is issued by SnapshotManager to track the
merge duration and possible reboots during the merge process.
Bug: 138817833
Test: m
Change-Id: I04e53bb8f6aa9e740c0dcc77c3a9566383954fba
Signed-off-by: Alessio Balsini <balsini@google.com>
With the Virtual A/B feature, when the device successfully boots after an OTA
update, a dm-snapshot merge operation is performed, which consolidates the
updated images to the base devices. This merge operation depends on the OTA
size and may affect the device performance until completed.
Create the SnapshotMergeStats class that takes care of measuring the duration
of a merge operation and manages the merge state file to continue tracking the
merge in the case of an interruption due to a reboot.
Bug: 138817833
Test: m
Change-Id: I9dcf1423716c89d8f9b4a0feb4e75bb7b9d18935
Signed-off-by: Alessio Balsini <balsini@google.com>
/metadata/ota/snapshot_state is a temporary file that keeps track of
snapshot merge operations across reboots.
Bug: 138817833
Test: m
Change-Id: I9785db3f73e1575b8ac8a522d938d09f8948e1b0
Signed-off-by: Alessio Balsini <balsini@google.com>
Set callstack logs as 0644 so that they are readable
by dumpstate.
Test: take OTA, cancel, delete /data/misc/update_engine/prefs/*
manually, retrigger OTA (so that callstack is logged), then re-take bug report
Bug: 148818798
Change-Id: I598e484b57dcd3ce6ed7bb483aee57ce2ba881e7
Set persistent logs for snapshotctl to 0644
so that they are readable by dumpstate.
Not using mode field in open() because it is masked
by umask. Directly use fchmod instead.
Test: reboot and take bugreport
Bug: 148818798
Change-Id: I515f8fd1345fcfb82aa2a1ec0c95da4b6921c039
This library is empty, and its functionality has moved
into libbinder/libhwbinder.
Bug: 148692216
Test: N/A
Change-Id: I306a2c18ec7770cfb6c3939b5e3d42a55c3165fb
Add libsnapshot test to the TEST_MAPPING's presubmit of fs_mgr to run
the test on TH whenever changes are applied to the fs_mgr contents.
Some of the tests are temporarily disabled due to a WIP bug.
Test: TH
Bug: 142513589
Change-Id: I2a283645b433ed1fd2b08d1c4919cac26d19cf16
Signed-off-by: Alessio Balsini <balsini@google.com>
Do not delete snapshots for any reason other than merge-complete or a
cancel request from update_engine. Additionally, create a rollback
indicator file if booting into the source slot, so update_engine can
attempt to cancel the update.
Bug: 147819418
Bug: 147347110
Test: libsnapshot_test gtest
Change-Id: Id357a91cec467a60246c7c3d133f6c54ccb3fc93
Bug: 148818798
Test: apply OTA but cancel it in the middle, then
delete /data/misc/update_engine/prefs/*, then
reapply it again (to trigger CancelUpdate()).
Stack is dumped.
Change-Id: I2dfb6b7f15b9d5854d0b81ed8ad260538d21c922
snapshotctl merge --logcat --log-to-file
- If --logcat, log to logcat
- If --log-to-file, log to /data/misc/snapshotctl_log/
- If both, log to both
- If none, log to stdout
Test: manually test these 4 cases
Bug: 148818798
Change-Id: I44b52936c0d095867acc6ee781c6bec04f6ebd6b
In tests CreateLogicalAndSnapshotPartitions may give flaky results
because not synchronous.
Add a bounded delay that prevents this behavior defined by a single
constexpr.
Bug: none
Test: libsnapshot_test
Change-Id: Iad3c24b1d3e82e3bd695d6dbbc8af8eab75bee32
Signed-off-by: Alessio Balsini <balsini@google.com>
In a device with malformed metadata, the MetadataBuilder returns a
nullptr that may cause segmentation faults when using the builder.
Fix by handling the nullptr exception in CreateUpdateSnapshot and
propagating the error to its caller.
Bug: n/a
Test: libsnapshot_test
Change-Id: Ie9148a552cf4bb223ab8d54b1d30d2b13d92bb22
Signed-off-by: Alessio Balsini <balsini@google.com>
The libsnapshot features are currently not used anywhere else than the
update system with Virtual A/B.
Ignore libsnapshot tests for devices that are not implementing this
feature.
Test: m, snapshot_test, OTA
Bug: 142513589
Change-Id: I4580bae5ed315f21501556eea062e6af1f982ab3
Signed-off-by: Alessio Balsini <balsini@google.com>
CreateLogicalAndSnapshotPartition is used in first-stage init and by
default never blocks (thanks to a timeout set to 0). This causes some
libsnapshot tests to fail, because snapshot devices may be accessed
before there actual creation is complete.
Fix by introducing a timeout_ms argument, set to 0 if unspecified.
Test: libsnapshot_test
Bug: 142513589
Change-Id: I5e23adaaf6df8603df501b9a25fdd1e9d8c15252
Signed-off-by: Alessio Balsini <balsini@google.com>
Reorder, remove and fix some of the dependencies in the Android.bp for
snapshot.
Test: m, snapshot_test, OTA
Bug: 142513589
Change-Id: Id214a8d6453a5675e60cda4352094dc3987292ec
Signed-off-by: Alessio Balsini <balsini@google.com>
Add flag in Android.bp to force the execution of libsnapshot_test as
root.
Test: m
Bug: 142513589
Change-Id: I9d047a9e1f9ea6d6e5540fa66fb42603ea136641
Signed-off-by: Alessio Balsini <balsini@google.com>
It now returns Ok() if successful, NeedsReboot() if merge
it should be checked again after reboot, and Error() for
other errors.
This wraps UpdateState to help clients interpret the UpdateState value.
Also separate SnapshotManager::Return from FiemapStatus since they are
for different libraries and have (potentially) different set of error codes.
Test: libsnapshot_test
Bug: 138808328
Change-Id: I8c95417c2b0b7b2a362beb12585f861453a79278
Now that the class becomes more complicated, move it out
of SnapshotManager.
Also, make it independent of FiemapStatus. libsnapshot and
libfiemap has different return classes.
Test: libsnapshot_test
Change-Id: If340959ba60bcd51c36e2b48f4d11c149ead907a
Instead of just mentioning that something wrong has been found when
parsing UpdateState, also log the value of the erroneous status.
Bug: none
Test: m
Change-Id: I487a115a9347199059a684ef682bec79fa5f26a9
Signed-off-by: Alessio Balsini <balsini@google.com>
Compute and print the progress percentage of the dm-snapshot devices
merging after an update is marked as successful.
All the snapshot devices are queried for their update states and all
their allocated, metadata and total sectors are summed as if the system
consists of a single big snapshot device, as well as the initial
allocated sectors to keep trace of the absolute progress. Then the merge
percentage is computed on the numbers for this fake snapshot device.
Bug: 139088917
Test: manual OTA
Change-Id: Ia9a51742105c90b7fd043f3cbf4249877def7f08
Signed-off-by: Alessio Balsini <balsini@google.com>
Convert UpdateState and introduce SnapshotUpdateStatus to protobuf to
simplify its access.
In addition, SnapshotUpdateStatus also stores the sum of all the
snapshot sector information. This additional data is used to improve the
merge progress progress.
Bug: 139088917
Test: manual OTA
Change-Id: Ic777d50244c1afa1cdd75fe9b2ffc6dd9ba19ade
Signed-off-by: Alessio Balsini <balsini@google.com>
When there is not enough space on /userdata, CreateUpdateSnapshot
returns SnapshotManager::Return with ErrorCode::NO_SPACE.
Test: libsnapshot_test
Bug: 138808058
Change-Id: If2effe63f6a4324eff8d05d4db4ce98be8190262
IImageManager::CreateBackingImage and ZeroFillNewImage now returns
FiemapStatus, which is an error code and provides more information
about the reason of error.
In particular, the error code is NO_SPACE if disk space is full during
allocation / writing.
Bug: 138808058
Test: libsnapshot_test
Change-Id: I500a3d9f55a2d7e60438b5b4ae70f8b5fed162fa