Commit graph

1552 commits

Author SHA1 Message Date
Alessio Balsini
d0de1114a9 Fix fuzzer name and sizeof(array)
The fuzzer name "dm_table_fuzzer" was too generic. Looking forward to an
extension to host tests where each fuzzer name should be considered a
unique identifier, change the fuzzer name to, "dm_linear_table_fuzzer".

Fix also the syntax of sizeof(array) declaration.

Bug: none
Test: dm_linear_table_fuzzer
Change-Id: Iaa0ee9a0eb1352f0c5269b07198d0a34d8fb3254
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-10-21 11:44:08 +00:00
David Anderson
c243e19936 Merge "Integrate libsnapshot with the boot control HAL." 2019-10-17 19:57:04 +00:00
Treehugger Robot
356951f2be Merge "fs_mgr: vts_core_liblp_test requires root" 2019-10-17 19:55:23 +00:00
Treehugger Robot
d8a72367e5 Merge "Utility class for COW size calculation" 2019-10-17 13:55:44 +00:00
Yifan Hong
4fc16610df fs_mgr: vts_core_liblp_test requires root
Test: atest vts_core_liblp_test

Fixes: 141940321
Change-Id: I2d6e06f4e596cdb985ea67e383e38545d666833b
2019-10-16 18:26:40 -07:00
Yifan Hong
b4383e144e Merge "liblp: MetadataBuilder::NewForUpdate takes always_keep_source_slot arg" 2019-10-17 00:10:32 +00:00
David Anderson
dfe6d07a4b Integrate libsnapshot with the boot control HAL.
This patch translates UpdateState states into a MergeStatus from
IBootControl 1.1, and asks the HAL to store it. Unfortunately this patch
has to work around a few issues.

The first issue is that Soong doesn't allow including only the headers
from a HAL. The second issue is that entraining the headers requires
linking to libraries that would otherwise not be needed in init.

To address this, we now have three ways of linking to libsnapshot:
  1. libsnapshot - Has access to gsid and HALs.
  2. libsnapshot_nobinder - Has access to HALs, but not binder (for
                            recovery).
  3. libsnapshot_init - Does not use binder or HALs.

The HAL code is #ifdef'd behind LIBSNAPSHOT_USE_HAL and we make use of
forward declarations and dependency injection to minimize its spread.

Bug: 139154945
Test: libsnapshot_test gtest
Change-Id: I21ffd8a79a43d0589f2f71f346ac1b019584a183
2019-10-16 16:09:38 -07:00
Alessio Balsini
0355d22d64 Use ReadFileToString() in GetHash()
On some devices the previous implementation of GetHash() was failing at
reading files, returning "Bad file descriptor" error.
Using ReadFileToString() that seems to have fixed the issue.

Test: libsnapshot_test
Change-Id: Ie3598d8bad5b3db1cf816c120e6922a066aa2743
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-10-15 18:55:10 +01:00
Alessio Balsini
a6e3d497ae Utility class for COW size calculation
The Linux kernel's dm-snapshot relies on a COW device to keep trace of
all the modified sectors.
The COW device has a precise structure, which allows to compute its
space requirement in advance, as a function of:
- sector size;
- chunk size;
- list of modifications applied to the snapshot device.

Create a class that implements the COW device space occupancy given this
information.

Bug: 140835698
Test: libsnapshot_test
Change-Id: I50e3815741ee689d14fc3611532ff9d3b3e0e879
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-10-15 13:06:48 +01:00
Yifan Hong
6bc5b47ac6 liblp: MetadataBuilder::NewForUpdate takes always_keep_source_slot arg
When applying a downgrade package on a Virtual A/B device
(to a non-Virtual A/B build), source slot partitions must
be kept in the metadata.

Test: liblp_test
Bug: 138258570
Change-Id: I87afe68bcfa768bdc015f5966b593758b856c741
2019-10-14 19:32:17 -07:00
Alessio Balsini
9e95202e4d Publish chunk size in utility.h
The chunk size of the snapshot should be kept consistent among different
files.
Move it to libsnapshot/utility.h to improve its visibility.

Change-Id: I1cae6530a07c88f3a0091ca7d8bb2eb590a6710f
Bug: 140835698
Test: m
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-10-14 21:07:07 +01:00
Alessio Balsini
3f6334e623 Remove magic numbers from test and use storage literals
Use constant expressions and storage literals to simplify readability.

Change-Id: I7ffaa260a2cd77dc0e24980f115f9e8df72708e6
Bug: 140835698
Test: libsnapshot_test
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-10-14 21:07:02 +01:00
Treehugger Robot
0e9a0f9831 Merge changes I8804f7dd,I3cbca589
* changes:
  [fs_mgr] fix -Wreorder-init-list
  [debuggerd] fix -Wreorder-init-list
2019-10-11 19:52:37 +00:00
Nick Desaulniers
8e048440e5 [fs_mgr] fix -Wreorder-init-list
C++20 will require members in a designated initializer to be in order
unlike C99.

Bug: 139945549
Test: mm
Change-Id: I8804f7dd5cba1035ac7a2979a47b661d722f664a
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
2019-10-11 10:54:53 -07:00
Alessio Balsini
08916b9ea2 Fuzzer for libdm's dm-linear devices creation
Create a fuzzer that fuzzes the parameters used for the creation
of dm-linear tables through libdm.
This fuzzer is based on libdm::DmLinear.

Bug: none
Test: dm_linear_fuzzer
Change-Id: I052144c6eb0db4fa6a37b5e54fbcb8193e5dc88f
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-10-10 20:59:33 +01:00
Alessio Balsini
5e6dc03fd5 Move TempDevice to test_util.h
TempDevice is useful class for tests, move it to test_util.h to improve
its visibility and make it usable by other tests.

Bug: none
Test: none
Change-Id: Idad5667844b10559b24f8f5e657e47d99e14209e
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-10-10 20:59:33 +01:00
Eric Biggers
736557c510 Merge changes from topic "fscrypt-key-mgmt-improvements"
* changes:
  init/fscrypt_init_extensions: support setting v2 encryption policies
  fs_mgr_fstab: support specifying encryption policy version in fstab
2019-10-07 19:09:43 +00:00
Treehugger Robot
db11fdcca3 Merge "fs_mgr: overlayfs: fsck scratch filesystem" 2019-10-04 16:13:06 +00:00
Yifan Hong
5fcc2b5d71 Convert SnapshotStatus to proto
Also, add a "name" field to SnapshotStatus, and delete
the "name" arg from CreateSnapshot / WriteSnapshotStatus.
ReadSnapshotStatus will warn if the name mismatches from
the file name, and auto-correct it.

Test: libsnapshot_test

Change-Id: I725cf39c07684b100b140a8a21ea9d23ab9d2241
2019-10-03 14:26:01 -07:00
Yifan Hong
58ae8d4780 Merge changes I7bb0b559,If147df2d,I25d7d590
* changes:
  libsnapshot: Skip initializing snapshot if not created.
  libdm: Fix DmTable::num_sectors
  Fix fds libdm_test
2019-10-03 18:58:38 +00:00
Mark Salyzyn
63f97b6f49 fs_mgr: overlayfs: fsck scratch filesystem
Enable fsck phase for scratch filesystem.  Solved a resulting
problem where the end of the fsck executable would result in a
SIGHUP to the caller.

Add some debugging details from adb-remount-test.sh script

Test: adb-remount-test.sh
Bug: 138577868
Bug: 139283818
Bug: 139226412
Change-Id: I129d86b7cf4e938001ba6db8d03247bc9903988d
2019-10-02 13:30:07 -07:00
Yifan Hong
9ae5a6ccaa Merge "libsnapshot: Return path if snapshot is already merged" 2019-10-02 18:11:33 +00:00
Yifan Hong
1d99674e5d libsnapshot: Skip initializing snapshot if not created.
If no opeartions is to be executed on a partition, it is
possible that no snapshot is created for it. In that case,
don't crash when initalizing snapshots.

Test: libsnapshot_test
Change-Id: I7bb0b5596aa6e4eca319e9c88f6552d1907a6944
2019-10-01 19:43:33 -07:00
Yifan Hong
55fb297a0c libdm: Fix DmTable::num_sectors
Test: libdm_test
Change-Id: If147df2d5c4f3b3df7ca57200f16a9ad59ae8327
2019-10-01 19:43:33 -07:00
Yifan Hong
9c7903124c Fix fds libdm_test
Failed because of double free of fds.
Test: run it

Change-Id: I25d7d590ca52d57fb14a5483ff8751127f6a48a6
2019-10-01 19:43:33 -07:00
Yifan Hong
20ec0cd6ce Merge "libsnapshot: Remove GetSnapshotSize" 2019-10-01 18:37:48 +00:00
Yifan Hong
0a14d17665 libsnapshot: Remove GetSnapshotSize
A single number is not enough to represent the ranges
that needs to be snapshotted in the target partition. For
prototyping now, just use device_size instead.

Add test in PartitionCowCreatorTest to ensure that this
doesn't regress. Also fix some trivial tests.

In follow-up CLs, snapshot ranges should be represented
with a more complicated structure. See b/141889746.

Bug: 141889746
Test: libsnapshot_test

Change-Id: I1a508c2464abce216ad4049cc2533ffdaa8cd14f
2019-09-30 18:11:23 -07:00
Eric Biggers
d964376a92 fs_mgr_fstab: support specifying encryption policy version in fstab
Allow the encryption policy version to be specified as a third field in
the "fileencryption=" fstab option, and expose it through the fstab
record so that vold can use it.

Bug: 140500999
Test: tested as series; see If64028d8580584b2c33c614cabd5d6b93657f608.
      Also updated and ran the fs_mgr unit tests.
Change-Id: If5d56f4c84c4cd51e3f14c0a861c3e3ab6ff903f
2019-09-30 10:27:38 -07:00
Treehugger Robot
a18907da54 Merge "[vts-core] Remove extra folder for vts_core_liblp_test and vts_libdm_test" 2019-09-30 05:34:15 +00:00
Yifan Hong
a171ef38aa libsnapshot: Return path if snapshot is already merged
If snapshot is already merged, MapUpdateSnapshot
will only map the base device, but it doesn't return
the path. Now, it returns the path of the base device as well.

Test: libsnapshot_test

Change-Id: Ic56bc1a624651f24185c52401a3a01e8942d5d57
2019-09-27 16:11:39 -07:00
Tom Cherry
aef269f11b Merge changes from topic "logwrapper-api-update"
* changes:
  Update init/fs_mgr for new logwrapper function
  logwrap: convert to C++, rename function logwrap_fork_execvp().
2019-09-27 15:31:04 +00:00
nelsonli
3beec54bf1 [vts-core] Remove extra folder for vts_core_liblp_test and vts_libdm_test
Remove the extra folder of vts_core for vts_core_liblp_test and
vts_libdm_test since we have a better auto-gen option of auto_gen_config.

Bug: 141684102
Test: 1. m -j vts_core_liblp_test
      2. m -j vts_libdm_test
      3. check out/.../vts_core_liblp_test.config
         and
         out/.../vts_libdm_test.config

Change-Id: Ibcdf96104205b50b3da522364199330ad0190c70
2019-09-27 15:00:12 +08:00
Yifan Hong
3edff134ef Merge "libsnapshot: refactor CreateUpdateSnapshots" 2019-09-27 01:11:22 +00:00
Tom Cherry
3a803eb2d4 Update init/fs_mgr for new logwrapper function
Test: cuttlefish boots, fsck logs seen
Change-Id: Icbc01161b44e097be813f4af648fa671739078b9
2019-09-26 10:29:57 -07:00
Colin Cross
2a62d42704 Merge "Use libcrypto_static instead of libcrypto" 2019-09-26 14:32:33 +00:00
Yifan Hong
98aa26fe69 libsnapshot: refactor CreateUpdateSnapshots
This function is too big. Refactor it a bit.

- Reorder checks / variable initializations a bit.
  They are independent of each other, so they can be
  safely reordered.
- Put snapshot creation and initialization to their own
  functions so that CreateUpdateSnapshots looks shorter.

Test: libsnapshot_test
Change-Id: I135b415d8e046dd91d31326fe7962ae44be4ccf8
2019-09-25 15:20:50 -07:00
Yifan Hong
ab09a1764b Merge changes Iab867ded,Id37e34b4
* changes:
  libsnapshot: CreateUpdateSnapshots reuse COW space
  libsnapshot: fix tests
2019-09-25 22:19:50 +00:00
Yifan Hong
bc71949dd7 Merge "libsnapshot: Fix mocked property fetcher" 2019-09-25 22:19:35 +00:00
Treehugger Robot
9e8f01101f Merge "liblp: convert more functions to use string_view (#5)" 2019-09-25 20:49:36 +00:00
Yifan Hong
30bdee9910 libsnapshot: CreateUpdateSnapshots reuse COW space
At the second update for Virtual A/B device,
PartitionCowCreator thinks the COW partitions in
the existing super metadata as occupied. In fact, these
partitions aren't used after the merge.

Now, unmap these partitions from the device mapper. If
something bad happens and the previous update has not been
merged yet, the unmap will fail. Then, delete these old
COW partitions from the device.

Test: Virtual A/B update twice
Bug: 135752105
Change-Id: Iab867ded19755089e6e0800e553a10fbcddbb931
2019-09-25 12:13:17 -07:00
Yifan Hong
3396e9327a libsnapshot: fix tests
- Add TestDeviceInfo(string, string) to avoid holding
the 'rebooted' TestDeviceInfo variable after ownership is
transferred

- OTA client calls BeginUpdate after unmapping partitions.

Test: run libsnapshot_test
Change-Id: Id37e34b421d728eb320c0e0906abef3b61897e7c
2019-09-25 12:13:17 -07:00
Yifan Hong
30adb65103 libsnapshot: Fix mocked property fetcher
Add a new SnapshotTestPropertyFetcher that sets up
good defaults for all test cases in libsnapshot_test.

Test: run libsnapshot_test
Change-Id: I6e0b31872d604bbd5f15b64ab7a8ea56d7c67405
2019-09-25 12:05:53 -07:00
Treehugger Robot
b4a65cf1ec Merge "[vts-core] Add vts_core_liblp_test to vts-core" 2019-09-25 05:54:31 +00:00
Treehugger Robot
5781a185e1 Merge "[vts-core] Add libdm_test in vts-core" 2019-09-25 03:00:50 +00:00
Yifan Hong
a1c1eb604d liblp: convert more functions to use string_view (#5)
Test: builds

Change-Id: I59ef370489b36410e3eaf90dc2623efaeefd613b
2019-09-24 19:34:54 -07:00
Treehugger Robot
8c055fbe3e Merge "snapshotctl: merge when boot" 2019-09-24 20:13:52 +00:00
Yifan Hong
71667636fb Merge "libsnapshot: add snapshotctl" 2019-09-24 18:06:53 +00:00
nelsonli
5642e23949 [vts-core] Add libdm_test in vts-core
Add libdm_test to vts-core suite and skip the test if the
first-api-level < 29.

Bug: 132702215
Test: atest vts_libdm_test
Change-Id: Ic805a4c08e5bf9f6c69019d4ea01825ae888e1fe
2019-09-24 11:34:59 +08:00
Yifan Hong
8a679e673f snapshotctl: merge when boot
Test: reboot after OTA on virtual A/B device, see merge
Bug: 135752105

Change-Id: I92eb8d0961635008366c336ead40e3038173257f
2019-09-23 18:50:12 -07:00
Yifan Hong
2feb47a29b libsnapshot: add snapshotctl
... which handles merge when boot completed. It also
dumps debug information when requested.

Bug: 135752105
Test: adb shell su 0 snapshotctl dump
Test: call snapshotctl merge at different stage of OTA:
  - before OTA (exit normally)
  - during OTA is applied (exit with error)
  - after OTA is applied but before reboot (exit with error)
  - after reboot (finish merge and exit normally)
  - Manually stop its execution during merge and run again
      (finish merge and exit normally)

Change-Id: Idcc6aea8d7bbeb9a1a288c966b8f5e14b3f6a3e7
2019-09-23 18:50:12 -07:00