Commit graph

3463 commits

Author SHA1 Message Date
Dan Shi
69f57f98c5 Keep fs_mgr_vendor_overlay_test in internal cf.
Bug: 302382476
Change-Id: I369927033b407660d2c0e7bdb85494c826c0b406
Test: presubmit
2023-09-28 06:32:31 +00:00
Daniel Zheng
301acae35b Add copyright to libsnapshot/tools
Adding copyright to cow_benchmark + basic_v2_cow_writer

Test: th
Change-Id: Ic6c32b68bbeaa3c0c365f146ef4342356e13706a
2023-09-26 16:51:53 -07:00
Daniel Zheng
d7c5511095 Add binary to write basic COW
Adding small binary to write a simple COW for version 2. We will then
use updated reader to make sure we can read this version 2 cow. Think it
would be a good idea to keep the binary here to see how exactly we
generated the cow (useful for debugging and if we ever need to recreate
this cow)

Test: m basic_v2_cow_writer
Change-Id: I28435025b7a8280fc5c4574876cc9110b391cb0e
2023-09-26 16:51:48 -07:00
Akilesh Kailash
810274071d Create_cow: Hash of target blocks should not be stored.
Target block hash was in-correctly getting added to map thereby
overriding the source-hash.

Bug: 299011882
Test: Flash Pixel 6 Pro from A->B and from B->A
Change-Id: Ib3887c29cd6b8f2abd50e932273a5cfc2a096bd5
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-23 01:07:47 -07:00
Ryan Prichard
532a608f58 Merge changes I7790dde8,I065907a5,Id2e82024 into main
* changes:
  Add missing <assert.h> include
  Add missing <functional> and <vector> includes
  snapuserd_test: don't discard result of std::async
2023-09-22 19:42:45 +00:00
Ryan Prichard
93377e99e2 snapuserd_test: don't discard result of std::async
std::async returns a std::future whose destructor blocks until the
async function has completed, which defeats the purpose of using
std::async. The future needs to be kept alive to allow the function to
run concurrently.

Starting in C++20, std::async marked [[nodiscard]] to help catch this
misuse. Upgrading libc++ adds the [[nodiscard]] attribute to
std::async, so fixing this bug is necessary to keep the code compiling
after libc++ is updated.

Bug: 175635923
Test: treehugger
Test: m && m snapuserd_test
Change-Id: Id2e820248c2b6111aa843fb709e08a2c19677066
2023-09-21 17:52:18 -07:00
Daniel Zheng
1b52ac6efe Merge "Updating comments on cow layout" into main 2023-09-19 16:32:28 +00:00
Treehugger Robot
53a71f6b18 Merge "Add static_assert to check sizeof off_t" into main 2023-09-18 22:39:48 +00:00
Daniel Zheng
a10bfe1d13 Merge "Add CowOperationV2" into main 2023-09-18 21:30:29 +00:00
Akilesh Kailash
6ea36bd1e4 Add static_assert to check sizeof off_t
Add compile time flags which got dropped during refactoring.

Bug: 300178204
Test: Build on 32-bit userspace
Change-Id: I16be0973cb2cb2e174ff98c8b10fde27f997e4ab
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-18 14:09:27 -07:00
Daniel Zheng
cc44c37468 Updating comments on cow layout
Updating comments to match current format. Scratch space exists in
between header and operation

Test: th
Change-Id: I2f86e9dc4078f03370cdc38918136c894c6ca484
2023-09-18 14:02:17 -07:00
Daniel Zheng
d2ad53cf81 Add CowOperationV2
this is going to replace the current version of CowOperation and will
work with writer v2 and parser v2. This will be the on disk format of
the cow, while CowOperation will be updated to be the in memory format
of 15 bytes (implicitly will be the v3 version).

Test: m libsnapshot

Test: m libsnapshot
Change-Id: Ibd00ef014a9fc11cdf2bad97c52462db8eef9502
2023-09-18 12:47:59 -07:00
Akilesh Kailash
0a59994c5a Compile with -D_FILE_OFFSET_BITS to support 32-bit userspace
This is to support when partition sizes are greater than 2GB (2^31)
on 32-bit userspace.

Bug: 300178204
Test: OTA on device with 32-bit userspace + product partition > 2GB
Change-Id: I7074682352d8388ed410c684cb7cb0fa346ba24c
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-17 09:34:43 -07:00
Daniel Zheng
5528777496 Merge "Concatenate conditional" into main 2023-09-14 23:42:15 +00:00
Daniel Zheng
7f13bc4f47 Merge "Adding block sz to compressors" into main 2023-09-14 05:15:31 +00:00
Daniel Zheng
19a6aa6241 Concatenate conditional
Move two separate conditional checks to one in writer_v2

Test: m libsnapshot
Change-Id: Id70db313754b770e3fa091e9c127839b9f2a5138
2023-09-13 22:14:19 -07:00
Daniel Zheng
b309292859 Adding block sz to compressors
Adding block sz to compressor classes to prepare for variable block size
compression

Test: m libsnapshot
Change-Id: I84db20c80c0f95188f79ccc73b5c30678bd75e78
2023-09-13 22:14:19 -07:00
Yi-Yo Chiang
37467f3665 fs_mgr: Refactor fs_mgr_overlayfs_already_mounted() to be more readable
Bug: 293695109
Test: adb_remount test
Change-Id: Idadd5b99e48fa601b1046aef533027ea6ba5c2f6
2023-09-12 16:08:30 +08:00
Yi-Yo Chiang
244e581a31 fs_mgr: Use /proc/mounts to check if /cache is mounted
The fstab provided by the user/caller might not be the default fstab,
which might not include the /cache mount entry. We should just use the
procfs mount info to determine if /cache is currently mounted.

Bug: 300036012
Test: adb_remount test
Change-Id: I4643d0a21ae21f3513f715de424f0be1fe64ff9e
2023-09-12 16:08:30 +08:00
Akilesh Kailash
bcae6b5e60 libsnapshot_cow: Prepare device to boot from pre-created snapshots
Two new API's have been added:

1: BootFromSnapshotsWithoutSlotSwitch: This will create a new marker
which indicates first-stage init to mount the partitions off snapshots.

We need this marker as during boot, there are couple of places during
mounting snapshots wherein the marker is used. However, there is no
change in the existing I/O path related to OTA.

2: PrepareDeviceToBootWithoutSnapshot: This will delete the marker so
that subsequent reboot will not have the partitions mounted without the
snapshots.

VTS tests covers both these API's. Additionally, when these
markers are present, new OTA's cannot be installed. All these
are covered in VTS tests.

===========================================================

snapshotctl: General flow to apply and revert pre-created snapshots

1: To install the pre-created snapshots:

$snapshotctl map-snapshots <directory path containing snapshots patches>

Now the device is ready to boot from snapshots.

2: After device reboots, partitions are mounted off the snapshots. There
   is no snapshot-merge.

3: In order to go back to previous build:

$snapshotctl revert-snapshots

Now the device is ready to boot from base build.

4: After device reboots back to previous build, all the snapshot states
   and COW images are removed.

============================================

Additional commands:

To delete the pre-created snapshots:

$snapshotctl delete-snapshots

======================================

Tested it on Pixel 6 Pro between two builds which are ~24 hours apart.

1: Creating snapshots on a linux-host - ~4-6 seconds
2: Applying pre-created snapshots - ~10-15 seconds (includes intermediate
   transfer of patches to the device). This depends on the size of snapshot patches.
3: Device reboot - ~12-14 seconds.

Bug: 299011882
Test: 1: Apply pre-created snapshots
2: Reboot device: Verify new build
3: Apply OTA when partitions are mounted of snapshots and verify OTA
   fails.
3: Revert-snapshot and reboot.
4: Verify device goes back to base build.

Full OTA on Pixel. vts_libsnapshot_test

Change-Id: I36a72d973d8f70ae49773ebd45dd996fac22a4e3
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-08 23:09:45 -07:00
Julien Desprez
670f983f45 Reland exporting create_snapshot
Previous attempt: aosp/2743815
Disabled on windows & mac.

Test: presubmit, (previously failed build: https://android-build.googleplex.com/builds/abtd/run/L06100000962955289?referrer=email now passing)
Bug: 290951369
Change-Id: I3d8084c13d843ea5919e3b50a0513faf386ccfed
2023-09-07 17:05:50 +00:00
Marvin Ramin
a4d34c5715 Revert "Export create_snapshot to sdk targets"
This reverts commit bf72b25a07.

Reason for revert: DroidMonitor: Culprit for b/299411079

Change-Id: I9d46abcbcc81d43fde23d4431b6757d3520d4b2c
2023-09-07 09:03:25 +00:00
Julien Desprez
bf72b25a07 Export create_snapshot to sdk targets
Similar to fastboot binaries. This will ease the
automation to use this tool

Test: presubmit
Bug: 290951369
Change-Id: I5c879acc7cdecbafebfa074ef76034403cb0cd72
2023-09-06 11:10:03 -07:00
Akilesh Kailash
9ccb84a8ba snapshotctl: Create and write pre-created snapshots
Extend snapshotctl binary on the device
to create and apply pre-created snapshots.

snapshotctl map-snapshots <directory-where snapshot patches are present>

1: snapshotctl creates the block device based on the size of the
       snapshot patches.

2: snapshotctl will copy the data to the block device.

unmap and delete snapshots will cleanup.

No change in libsnapshot library except with minor refactoring.

This patch doesn't yet prepare the device to reboot from these
snapshots.

On Pixel 6 Pro, applying pre-created snapshots for all partitions
takes ~3 seconds wherein the delta between two builds are 24 hours apart.

Bug: 299011882

Test: snapshotctl map-snapshots /data/test-snapshots/
snapshotctl unmap-snapshots
snapshotctl delete-snapshots

Change-Id: I98a0fbd9cf7234c2188bad85cdd092ded8997710
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-06 06:02:51 +00:00
Akilesh Kailash
214d62e3f7 create_snapshot: Create snapshot patch comparing two partition images
This is a host based tool wherein it compares two Android images and generates snapshot patches which are similar to Android OTA format.

There are few advantages:

1: All the computation of snapshot logic is pushed onto the host.
2: Each partition can have different compression algorithm.
3: All the libsnapshot_cow changes can be tested very quickly.

Here is the test run. This compares two builds which are 24 hours apart.

```

create_snapshot --source=$ANDROID_PRODUCT_OUT/system.img --target=./images/system.img --compression="zstd" &
create_snapshot --source=$ANDROID_PRODUCT_OUT/product.img --target=./images/product.img --compression="lz4" &
create_snapshot --source=$ANDROID_PRODUCT_OUT/vendor.img --target=./images/vendor.img &
create_snapshot --source=$ANDROID_PRODUCT_OUT/system_ext.img --target=./images/system_ext.img --compression="gz" &
create_snapshot --source=$ANDROID_PRODUCT_OUT/vendor_dlkm.img --target=./images/vendor_dlkm.img &

echo "Waiting for snapshot patch creation"
wait $(jobs -p)
echo "Snapshot patch creation completed"
```

========================================
Waiting for snapshot patch creation
Snapshot patch: vendor_dlkm.patch created successfully
Snapshot patch: vendor.patch created successfully
Snapshot patch: system_ext.patch created successfully
Snapshot patch: product.patch created successfully
Snapshot patch: system.patch created successfully
Snapshot patch creation completed

real	0m3.848s
user	0m14.239s
sys	0m8.045s
========================================

It takes ~4 seconds to generate the snapshot patches on the host. Snapshot patches are named as <partition-name>.patch.

Bug: 299011882
Test: create_snapshot between two builds as mentioned above.
Change-Id: Ic87dd3349a866b5626fa03f1f879f417a8116cc2
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-09-05 15:42:11 -07:00
David Anderson
5b91ae9f4e Merge "snapuserd: Add snapuserd_test to presubmit and VTS." into main 2023-08-29 22:10:27 +00:00
David Anderson
c718295a58 Merge "snapuserd: Fix race condition in MergeWorker::WaitForMergeBegin." into main 2023-08-25 16:09:35 +00:00
Treehugger Robot
c728c39121 Merge "Update bug component from Android Systems to OTA client" into main 2023-08-24 11:13:12 +00:00
Daniel Zheng
f278b54731 Merge "Add unit test for cow compressor performance" into main 2023-08-23 19:45:55 +00:00
Daniel Zheng
eb70926ad6 Add unit test for cow compressor performance
Adding test to measure performance differences between cow compression
algorithms + levels. This gives us an easy way to test performance
between the tunables without having to run an OTA every time. Ultimately we want this to be separate from
cow_api_test so it would be nice to have this be it's own binary. Can
add some tests for decompression + compressing from a part of an actual
img file too.

Test: m cow_benchmark
Change-Id: Iba92ae3c0b2ad4ff6f842556b701b223d7d37823
2023-08-23 10:20:15 -07:00
Daniel Zheng
b497e6f317 Fix one liner
Ensuring that the expression is evaluated before being outputed. In
response to comment from aosp/2708333

Test: th
Change-Id: I073c143f1c4e32af11e235ce782947b250117dc5
2023-08-22 14:45:15 -07:00
Alessio Balsini
d35715c021 Update bug component from Android Systems to OTA client
It's been a while since the Android Systems bug component does not
access the creation of new bugs for triage, instead, new bugs must
be created in the subcomponents of the team.
This change updates the bug component originally associated to this
subsystem from the Android Systems' 30545 to OTA client's 1014951.

Test: none
Bug: 270571229
Change-Id: I5455086bf777dd20abb2e2f0360f76a003120126
Signed-off-by: Alessio Balsini <balsini@google.com>
2023-08-22 10:18:47 +01:00
Treehugger Robot
30b1c4dd3b Merge "libfs_avb: Allow overriding the slot suffix." into main 2023-08-21 19:12:16 +00:00
Daniel Zheng
4215f1a9fc Merge changes I5032300e,Idec3e051,I09be447b into main
* changes:
  ZSTD read from wrong buf
  Fix warning
  Fix zstd optimization api usage
2023-08-17 22:32:35 +00:00
Daniel Zheng
36882e98b4 ZSTD read from wrong buf
Fix zstd to read from ignore_buf rather than buf since that is where we
are first copying the date

Test: zstd ota
Change-Id: I5032300e4628ecd7e49f1fa9f76dc9a828fb58e6
2023-08-17 14:18:56 -07:00
Daniel Zheng
21aab6cb83 Fix warning
remove some unused headers and fix warning: Moving a temporary object prevents copy elision

Test: m libsnapshot
Change-Id: Idec3e051837dab5f1b95e677d1cdb09e9a57e73e
2023-08-17 14:18:56 -07:00
Daniel Zheng
96b78feec1 Fix zstd optimization api usage
ZSTD_c_windowLog should be set as log base 2 of max block size. Changing
hardcoded value to be determined by this variable.

Test: m libsnapshot
Change-Id: I09be447b7f1e95cb72a6a42eddb4035f61a43aad
2023-08-17 14:18:55 -07:00
Daniel Zheng
7bb24d3274 Merge "Removing extra string creation for log" into main 2023-08-17 18:19:10 +00:00
David Anderson
ed7716f2c4 snapuserd: Add snapuserd_test to presubmit and VTS.
Bug: 269361087
Test: presubmit
Change-Id: Ic80025b1e75f049abdc7fdbcfdd5a142f56d702e
2023-08-15 15:14:01 -07:00
David Anderson
fb7e268552 snapuserd: Fix race condition in MergeWorker::WaitForMergeBegin.
The pre-conditions and post-conditions to cv.wait() in this function are
different, which leads to a race. If the merge is never initiated, but
I/O is terminated, the wait() will hang.

This is easy to hit in tests where I/O terminates quickly, but should
not affect actual OTA flow in practice.

Bug: 269361087
Test: snapuserd_test
Change-Id: I85ed9c357031ec6fd74d6a3f49d85e6cbb037eee
2023-08-15 15:14:01 -07:00
David Anderson
8d9940bdaf Update OWNERS.
Change-Id: Ib069b181fd48d73e5320f44c435b8814f269d291
2023-08-15 15:14:01 -07:00
Daniel Zheng
03acfdbeb6 Optimize zstd compression
reuse the same context for zstd compression. One context should be used
per compression thread for optimal performance. Discussion and
reccomendations can be found at go/android-hw-compression-vendor

Results (level 3 compression)
full ota on raven with optimizations:  1191.304 seconds
without optimizations:  1461.854 seconds

compression ratio remains unchanged and merge time difference are
negligible ~1% delta (probably just noise)

Test: ota_from_target_files, update_device.py
Change-Id: I3feede9f1f119874e369c54b29c594475fbf7376
2023-08-14 16:07:33 -07:00
Daniel Zheng
de6e446efa Adding compressor class
Adding in compressor class to clean up code for cow_compress.cpp.
Since we are making some api changes (to zstd) that are unique to each
compression methods, these should be implementation details should be
hidden to the parent class

Test: m libsnapshot

Change-Id: I9194e2c615aefed078458f525382253228bc1b69
2023-08-14 16:07:26 -07:00
Daniel Zheng
90d4f89e8b Removing extra string creation for log
Removin unneccessary string from being created in logging

Test: m libsnapshot
Change-Id: I123b6a10f349dfb0c275e630b5f02d1cec8c2687
2023-08-14 15:16:36 -07:00
Tomasz Wasilczyk
6bfa6a0231 Merge "Migrate String8/16 from .string() to c_str()" into main 2023-08-11 22:56:43 +00:00
Tomasz Wasilczyk
18b746188c Migrate String8/16 from .string() to c_str()
This will align usage with std::string.

Bug: 295394788
Test: make checkbuild
Change-Id: Ic5c215b011197950dcbcb0339f44cc68fefc65a1
2023-08-11 19:53:20 +00:00
Treehugger Robot
acdc4848e0 Merge "libsnapshot: Check for valid snapshots based on current slot" into main 2023-08-10 17:29:46 +00:00
Akilesh Kailash
3983f9aa6e libsnapshot: Check for valid snapshots based on current slot
We may have snapshot files in /metadata/ota/snapshot/ which ends with
.tmp such as system_a.tmp - This happens if the device
reboots just before `rename` in `WriteStringToFileAtomic`. This
can lead to spurious merge failures.

Log the error and skip these snapshot files. It is ok to skip
as we will still have original snapshot status files since
we are already in the merge path. Additionally, try to remove
these files when snapshot is deleted.

Bug: 292198189
Test: OTA
Change-Id: I5db3dbd5a919b263ae577185de3e7f79a5e9b89a
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-08-10 09:36:35 -07:00
Daniel Zheng
86f037c245 Merge "decompressor maintenence" into main 2023-08-09 20:04:07 +00:00
Daniel Zheng
dc3c5292c7 Merge "Moving includes" into main 2023-08-09 20:04:00 +00:00