Commit graph

2342 commits

Author SHA1 Message Date
David Anderson
75b982ad30 libsnapshot: Partially implement OpenSnapshotWriter.
Implement OpenSnapshotWriter for non-compressed Virtual A/B. This is
done by adding an OnlineKernelSnapshotWriter class, which forwards all
writes to a dm-snapshot block device.

This also introduces a new ISnapshotWriter class which extends
ICowWriter, and adds features specific to libsnapshot (versus ICowWriter
which is intended only for the new COW format). The OpenSnapshotReader
call has been moved here since the writer retains all the information
needed to create the reader.

To test the new call, vts_libsnapshot_test has been modified to use
OpenSnapshotWriter.

As part of this change, all consumers of libsnapshot must now link to
libsnapshot_cow.

Bug: 168554689
Test: vts_libsnapshot_test
Change-Id: Ieedfadc557833c1e0540922aabc6e95c80266a64
2020-09-28 11:24:37 -07:00
David Anderson
6560d23765 libsnapshot: Add a maximum block count to CowWriter.
Once COWs are allocated, their size is fixed, and we don't want to
write beyond the end. To make this validation less tedious, the virtual
methods of ICowWriter have been made internal. The user-facing API calls
do validation before calling the internal variants.

Bug: 168554689
Test: cow_writer_test
Change-Id: Ic9ebb5bc4b601180d35d915c47cd9c537bc423fa
2020-09-28 11:24:37 -07:00
David Anderson
f53794d1af libsnapshot: Make the new Open calls look more like MapUpdateSnapshot.
To make the transition to these new calls easier, give them a very
similar signature to MapUpdateSnapshot. Also, allow them to work in
non-compression mode.

Bug: 168554689
Test: builds
Change-Id: I2eb6b41ba8a294dbde1763aabd7701a80c0789f3
2020-09-21 12:06:49 -07:00
David Anderson
2f11ec6a13 libsnapshot: Prototype the new API for mapping writable snapshots.
Since we can't provide a single device or fd anymore, we need to expose
a CowWriter directly. Additionally, we expose an API for reading
snapshots through the FileDescriptor abstraction.

Bug: 168554689
Test: builds
Change-Id: If7e8adbfe69c2a84d34c63d4b0adff2b3365fd82
2020-09-18 14:24:40 -07:00
David Anderson
975ea3217e Merge changes from topic "vab-brotli"
* changes:
  libsnapshot: Add an append mode to CowWriter.
  libsnapshot: Add support for brotli compression.
2020-09-17 19:32:23 +00:00
Akilesh Kailash
516ded7320 Support of multiple device partitions by dm-user driver
Add basic support for daemon creation and handle signals

Test: Add test case to test system and product COW partitions
Bug: 162790322

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Icf8dbe49d2237cec6f7dbcdd84256eb6c5afa1cd
2020-09-16 00:35:42 +00:00
David Anderson
a889c87b0f libsnapshot: Add an append mode to CowWriter.
When in append mode, CowWriter will re-open the existing COW and resume
writing at the end of the old data position. All existing operations
will be reimported and buffered in memory.

The size calculation has been simplified to make this work. We now
advance ops_offset and no longer track the number of bytes written.

Additionally, a "header_size" field has been added to the header. This
was missing from the original format and is useful for introducing
forward compatibility later.

Finally, Finalize has been renamed to Flush. It's still mandatory, but
it can be called multiple times to continue appending data without
reopening.

Bug: 168554689
Test: cow_api_test gtest
Change-Id: I637e99ae08a4db5b273c06318e6db523ea8ec7c5
2020-09-15 16:15:41 -07:00
David Anderson
a652877bd6 libsnapshot: Add support for brotli compression.
Bug: 162274240
Test: cow_api_test
Change-Id: I0b0ceec3c3041a6aea4b1e6c4d01ed0a8860d7e8
2020-09-15 16:15:33 -07:00
Palmer Dabbelt
7dd8fe8e70 Add "dmctl uuid" command
This makes looking up device UUIDs a bit easier, as rather than depending on
the device mapper's sysfs layout we can depend on dmctl.  There's some
associated libdm plumbing, but the UUID was already pretty much availiable.

Test: I just ran this by hand.
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Change-Id: I7028eec6ab04601308047b67057e51a0ff44c0a7
2020-09-15 18:39:39 +00:00
David Anderson
1f8c18ee55 Merge "libsnapshot: Refactor cow_reader decompression." 2020-09-10 23:05:08 +00:00
David Anderson
511c4bc601 libsnapshot: Refactor cow_reader decompression.
Bug: 162274240
Test: cow_api_test
Change-Id: I12c177f3ebb7bb0550669bd5edbdbbde6f572cfd
2020-09-09 21:54:48 -07:00
Xin Li
e1ebeab9c5 Merge Android R
Bug: 168057903
Merged-In: I88f6774ca9985fb50f015756b8f8508d4691dc62
Change-Id: Iefe2872d29836b77344479ad2552a9c03d81bdcb
2020-09-09 20:21:27 -07:00
Akilesh Kailash
c7c7252289 Merge "libsnapshot:Snapuserd: IO path support with dm-snapshot target" 2020-09-10 01:59:38 +00:00
Akilesh Kailash
2c6c0bff7d libsnapshot:Snapuserd: IO path support with dm-snapshot target
Integrate Snapuserd daemon with libsnapshot library and handle
IO requests from dm-snap and dm-snap-persistent.

Tested all the 3 COW operations on a compressed
cow-device file generated through vab_converter_payload.

BUG: 163046732
Test: Added test case to independently test snapuserd IO path.
      Manual test on compressed cow file generated and verifying
      md5sum.

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I9d017ac671733a93c3bc21344228260224640c78
[Palmer: clean up some build issues]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-09-10 00:27:50 +00:00
Nikita Ioffe
4e311d69b5 Merge "Only store result of mount_all that mounted userdata" am: edc501d674
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1420053

Change-Id: I444f74692633b2bc4f5bcf03cd036b5c52b120aa
2020-09-08 23:10:11 +00:00
Nikita Ioffe
9ede7ec273 Only store result of mount_all that mounted userdata
During boot sequence there can be multiple calls to mount_all. For the
userspace reboot to correctly remount userdata, we need to store the
return code of the one that was responsible in mounting userdata.

Test: adb root
Test: adb shell setprop init.userspace_reboot.is_supported 1
Test: adb reboot userspace
Test: checked dmsg
Bug: 166353152
Change-Id: Id0ae15f3bcf65fa54e4e72b76f64716c053af7fb
2020-09-08 21:58:43 +01:00
David Anderson
9bd7d9bd18 Merge "libsnapshot: Add a tool for estimating non-A/B OTA sizes with the new COW format." am: f9a436a052
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1411189

Change-Id: Iecd270c757577315cd485aad52e268ca601fb5fe
2020-09-04 19:29:15 +00:00
David Anderson
f4ebaca8a7 libsnapshot: Add a tool for estimating non-A/B OTA sizes with the new COW format.
This tool allows users to estimate the COW size for a non-A/B update.
It works by scanning the partitions of two target-files packages, and
identifying moved or copied blocks, and simulating the impact in the new
COW format.

It has two modes:

    estimate_cow_from_non_ab_ota -ota_tf <path>

Will estimate the COW size for a full OTA. For an incremental OTA, you
need two target files packages:

    estimate_cow_from_non_ab_ota -source_tf <path> -ota_tf <path>

There is an optional -compression argument which accepts either "none"
or "gz".

Bug: 161497962
Test: manual test
Change-Id: I335059cd870a464f34c5d644eefefdc76775386e
2020-09-03 19:04:34 -07:00
Treehugger Robot
9bfc688fe9 Merge "Return bytes written in CowWriter" am: b745a960f8
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1419388

Change-Id: Id707e37c7cb64d05922c7db9db0d0b26685136c4
2020-09-03 22:31:45 +00:00
Kelvin Zhang
8e75a38edd Return bytes written in CowWriter
delta_generator in update_engine needs to know number of bytes written
to estimate cow image sizes. This change modifies CowWriter::Finalize to
return relevant information.

Test: unnitest
Change-Id: I7cf6b9124b90f089a7c5f3850c38200f82da18e6
2020-09-03 15:59:17 -04:00
Kelvin Zhang
756e361551 Merge "Enable libsnapshot_cow in recovery builds" am: 0b26cbb6b1
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1416091

Change-Id: Ia4e0b0c1447336ac2d149ef6273decd9d6d0e790
2020-09-03 00:45:20 +00:00
Kelvin Zhang
f6219e2d56 Enable libsnapshot_cow in recovery builds
update_engine is enabled in recovery mode, needs to link with
libsnapshot_cow

Test: mm -j
Change-Id: Ia4823c866b16f47cd03dda1779701e957a77aed6
2020-09-02 20:08:46 -04:00
David Anderson
4852a2654a Merge "liblp: fix host lpdump cannot work issue" am: 29e7b2af30
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1320937

Change-Id: Ifc77676b6f750c98557f42707f4ca9a96f05cad7
2020-09-02 17:57:42 +00:00
David Anderson
29e7b2af30 Merge "liblp: fix host lpdump cannot work issue" 2020-09-02 17:36:00 +00:00
Xin Li
0a112d52f8 Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507
Merged-In: Id18cb0e2d2f3e776a42b566c4a1af2e250890896
Change-Id: Iba7cab32ab3aa6f47952c840ff6dc8492e8d0704
2020-08-29 01:42:13 -07:00
Greg Kaiser
8ad3957d76 libsnapshot: Fix uninitialized variables
We fix two separate instances of classes not initializing members
in their constructors.

Test: TreeHugger
Change-Id: If1b7a7625572c9b005f9b8331b282ed11ceb6e97
2020-08-27 08:09:14 -07:00
David Anderson
ad35dcc5b8 libsnapshot: Off-line tool for converting OTA payloads to COWs.
The A/B version of this tool takes in a payload.bin file (from an OTA
package), and converts it into COWs in the new format. It uses the
CowWriter API to do this. This tool can be used to precisely see the
size of a COW relative to an OTA. Since there is one COW per partition,
it also takes an output folder:

    make_cow_from_ab_ota payload.bin ./ota-cows/

If the payload is incremental, a source target-files package is needed.
It must be the exact package used to build the OTA, otherwise, the
conversion is likely to fail. Example:

    make_cow_from_ab_ota -source_tf target-files-XYZ.zip \
                         payload.bin ./ota-cows/

Bug: 162274240
Test: manual tests
Change-Id: I8cb1554e71384625c8073f1c351a976b5ae00a36
2020-08-26 11:39:01 -07:00
Ankit Goyal
77ea69e9a7 Merge "Revert "libsnapshot: Off-line tool for converting OTA payloads t..."" 2020-08-26 07:24:08 +00:00
Ankit Goyal
4dd34114de Revert "libsnapshot: Off-line tool for converting OTA payloads t..."
Revert submission 1405248-vab-offline-cow

Reason for revert: Reason for revert: Droidcop-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?branch=git_master-without-vendor&target=sdk_mac&lkgb=6790614&lkbb=6791107&fkbb=6791107, bug 166383275
Reverted Changes:
If8a1bbf99:Expose extent_ranges for libsnapshot to use in res...
I22c86546f:libsnapshot: Off-line tool for converting OTA payl...

Change-Id: I7f85fb24a350c610d0837886716c22c2742ab144
2020-08-26 07:01:26 +00:00
David Anderson
5b940dc7f9 Merge "libsnapshot: Off-line tool for converting OTA payloads to COWs." 2020-08-21 23:05:36 +00:00
Yo Chiang
5ca85a05e3 Merge "Improve ImageManager error message" 2020-08-21 08:01:21 +00:00
Yo Chiang
36a21704e0 Merge "TranformFstabForDsu adds missing partition entries to fstab" 2020-08-20 06:38:44 +00:00
David Anderson
a258293a97 libsnapshot: Off-line tool for converting OTA payloads to COWs.
The A/B version of this tool takes in a payload.bin file (from an OTA
package), and converts it into COWs in the new format. It uses the
CowWriter API to do this. This tool can be used to precisely see the
size of a COW relative to an OTA. Since there is one COW per partition,
it also takes an output folder:

    make_cow_from_ab_ota payload.bin ./ota-cows/

If the payload is incremental, a source target-files package is needed.
It must be the exact package used to build the OTA, otherwise, the
conversion is likely to fail. Example:

    make_cow_from_ab_ota -source_tf target-files-XYZ.zip \
                         payload.bin ./ota-cows/

Bug: 162274240
Test: manual tests
Change-Id: I22c86546f4166ee9df99165399646b7daa3519d5
2020-08-19 13:58:09 -07:00
David Anderson
0324725548 Initial prototype of COW format and API.
This is an initial prototype of the new COW format. It does not have
support for merge sequencing or merge state tracking.

The reader and writer APIs have pure virtual interfaces to support
mocking. The writer implementation performs compression, but the reader
interface does not (yet), it only supports iterating over metadata and
performing basic validation.

Bug: 162274240
Test: manual tests
      cow_api_test gtest
Change-Id: Ib9fddc1f210700688e6786917b023dfabd5fb3d9
2020-08-19 13:56:57 -07:00
Yo Chiang
93c78c243d Improve ImageManager error message
Print more helpful error messages to logcat.

Bug: 165471299
Test: Observe logcat
Change-Id: I3dca834a7cd3f653b038fc3a4020e96f500e1d1f
2020-08-19 19:31:15 +08:00
Yo Chiang
e48dbc2004 TranformFstabForDsu adds missing partition entries to fstab
Fix odd bug that TranformFstabForDsu doesn't emplace entry to fstab.

.avb_keys should be set to "/avb", the directory that stores all DSU
avbpubkeys, instead of appending.

Bug: 165471299
Test: Boot a multipartition DSU package
Change-Id: I62ee2f8bf7113f6d2af8cc34ef19c9743029ea0a
2020-08-19 14:17:37 +08:00
Paul Crowley
5350746a2b Merge "Set ro.crypto.type even on failure" 2020-08-17 20:14:25 +00:00
Jaegeuk Kim
5ba5b90cd6 fs_mgr: try tune2fs for casefolding on /data only
Bug: 163420666
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: Id646bd25d6fed0f547fb0647150acdc4845a5eec
2020-08-14 12:57:25 -07:00
Paul Crowley
9acab5a4d6 Set ro.crypto.type even on failure
Move responsibility for setting ro.crypto.type into fs_mgr_mount_all,
so that even if setting up the filesystem fails, the type is set
correctly and so errors are appropriately handled.

Bug: 162289984
Test: simulate a failure and check that it's set.
Change-Id: Ib061a454e7e21d7206c3c1fa8e88e16618099581
2020-08-14 11:36:39 -07:00
Eric Biggers
75ebdd9c7c fs_mgr: use __ANDROID_API_Q__ instead of pre_gki_level
The name "pre_gki_level" is causing some confusion because not all
devices launching with Android R are subject to the GKI requirement.
(See b/161563110#comment11.)  E.g., devices that use a 4.14-based kernel
are exempt from GKI.  However, the encryption requirements still apply.

Just use __ANDROID_API_Q__ directly instead.

No change in behavior.

Change-Id: I4242745ccc9f88e084a1adfab5796daa9bc59b6e
2020-08-10 11:43:52 -07:00
Yifan Hong
0198ce0ca7 Merge "Fix allowlist for unreliable pinning." 2020-08-07 17:57:13 +00:00
Yifan Hong
75d5e98401 Merge "libsnapshot_test: skip global setup on non-VAB devices." 2020-08-07 17:57:00 +00:00
Yifan Hong
f0cb5a04f3 Delete fiemap_image_test_presubmit
No tests are skipped in presubmit now.

Test: presubmit
Fixes: 148874852

Change-Id: Ic0ce7489ff4a92ab90986dd76f836c262f5aa3fc
2020-08-06 17:38:02 -07:00
Yifan Hong
a7c00a0943 libsnapshot_test: skip global setup on non-VAB devices.
On non-VAB devices, fake super image creation may fail because it
may not support f2fs file pinning.

Also changes global setup to a testing::Environment object because it is
the recommended way in gtest's guide. SnapshotTestEnvironement::TearDown
is automatically executed before RUN_ALL_TEST returns.

Test: vts_libsnapshot_test
Test: make IsVirtualAbEnabled() return false, then all tests are
skipped.

Bug: 162557082
Change-Id: I1382f9a4ddec146fa2d8cfb21ac66ca22a2e110f
2020-08-06 17:21:50 -07:00
Yifan Hong
900fdf47ce Fix allowlist for unreliable pinning.
When checking IsUnreliablePinningAllowed, the existing code calls
IsTestDir on a value starts with "/data", but IsTestDir expects
metadata_dir_. Fix it.

Also, make subdir checks more robust and add test cases for IsSubdir.

Fixes: 162557082
Test: vts_libsnapshot_test
Test: fiemap_image_test

Change-Id: I495cfae3da11d1e0800b8abf520df10dd9a29dce
2020-08-06 15:02:56 -07:00
Eric Biggers
dc3e897a88 fs_mgr: Revert "Try to recover corrupted ext4 /data with backup superblock"
This reverts commit 72abd7b246
(change Ia39af3340c0e241f62557b7c2cc8b800443342f9).

When vold enables either FDE or metadata encryption, it encrypts the
filesystem in-place.  Unfortunately, due to a bug, for ext4 filesystems
it hasn't been encrypting the backup superblocks.

Also, in read_ext4_superblock(), the check for
StartsWith(blk_device, "/dev/block/dm-") can return true even if the
encryption mapping hasn't been added yet, since when a GSI image is
booted the userdata block device is a logical volume using dm-linear.

The result is that read_ext4_superblock() can recognize a backup
superblock when the encryption mapping hasn't been added yet, causing
e2fsck to run without the encryption mapping and corrupt the filesystem.

https://android-review.googlesource.com/c/platform/system/vold/+/1385029
will fix this for new or factory-reset devices.  However, there probably
are many existing devices that already have their backup superblocks
unencrypted.  Therefore, the EncryptInPlace fix isn't enough and we have
to revert the change that started using the backup superblocks too.

Bug: 161871210
Bug: 162479411
Change-Id: I279f84c072bc6c8d3e251a5e95c78f8d6c0d50ba
2020-08-04 11:34:30 -07:00
Treehugger Robot
86313d6fdb Merge "libsnapshot: Properly set partial_update_" 2020-07-31 23:02:05 +00:00
Yifan Hong
0403d8d2d5 libsnapshot: Properly set partial_update_
On GKI updates, has_dynamic_partition_metadata() may be false. Even if
it is the case, partial_update_ should be set properly.

Test: apply GKI update
Bug: 162616968

Change-Id: Icf055d8eb3060e36b3e977541a24f62f9fe11a6f
2020-07-31 14:42:14 -07:00
Tom Cherry
2d451663be Cleanup for #inclusivefixit.
Test: build
Change-Id: If11a32c130367560394eccf442de95d941918073
2020-07-27 11:37:19 -07:00
David Anderson
67665a4571 Merge changes I49495684,I0db2e0f4,I07bb811b
* changes:
  init: Initiate other misc devices from BlockDevInitializer.
  Allow snapuserd to be included in the initial ramdisk.
  Add experimental daemon for handling dm-user requests.
2020-07-24 19:18:45 +00:00