Commit graph

1440 commits

Author SHA1 Message Date
David Anderson
1145c01e8e libsnapshot: Improve how devices are collapsed after merging.
Currently, we replace snapshot-merge with a linear device wrapping the
base device. This is not efficient. This patch reads LpMetadata for the
underlying partition, and duplicates its table into the snapshot-merge
device. This removes a layer of stacking and also allows removing the
base device.

Note that snapshot_test is growing a bit unwiedly, because it's starting
to implement pieces of libsnapshot that will be filled in later for
update_engine. (MapUpdatePartitions is a good example of this.) When
those pieces land in libsnapshot, snapshot_test will be cleaned up to
remove much of this manual fiddling.

Bug: 139090440
Test: libsnapshot_test gtest
Change-Id: I3872dc51d9e5980803303806f42a5c7e74b0b78a
2019-08-27 15:09:56 -07:00
David Anderson
ad970fc055 fastbootd: Cancel snapshots when modifying partitions.
When flashing or resizing partitions, remove the
LP_PARTITION_ATTR_UPDATED flag. This will cause first-stage init to skip
any snapshots for that partition, and the backing storage (if any)
will later be reclaimed.

Bug: 139155473
Test: manual test
Change-Id: I3b185f68dfecb5a93636af0b5ae289ead1363fd0
2019-08-27 14:03:44 -07:00
David Anderson
a6e288a178 Clean up update state when snapshots are interrupted or cancelled.
This patch addresses two edge cases with interrupted updates:
 (1) If the device reverts to the old slot *before* merging, snapshots
     must be removed.
 (2) If during a merge, a snapshot is detected to be invalid (due to
     flashing), the snapshot must be removed.

To encapsulate this logic, WaitForMerge has been renamed to
ProcessUpdateState. It is still intended to be called after /data is
mounted, or after a merge is initiated.

Bug: 139154795
Test: libsnapshot_test gtest
Change-Id: I37a25ca722f30ae9548894dcfbd70cb64330e416
2019-08-27 13:43:18 -07:00
David Anderson
c058df7b12 libsnapshot: Do not map snapshots for partitions that were reflashed.
Bug: 139154795
Test: libsnapshot_test gtests
Change-Id: Ic4bb663d4286040adec4c0141373c66a487c91ff
2019-08-27 13:43:18 -07:00
Treehugger Robot
f8d80b7d56 Merge "libsnapshot: use DeleteDeviceIfExists() when required" 2019-08-27 19:59:13 +00:00
Paul Lawrence
8c8ce02e2e Merge "Fix ext4/metadata/udc issue" 2019-08-27 15:21:58 +00:00
Yifan Hong
ee9b49d729 Merge "libsnapshot: Add helper for first-stage init mounting" 2019-08-27 01:56:41 +00:00
David Anderson
e0b2b759fa Merge "liblp: Expose MockPropertyFetcher for liblp-dependent tests." 2019-08-26 19:13:49 +00:00
David Anderson
9966699af7 liblp: Expose MockPropertyFetcher for liblp-dependent tests.
Bug: 139154795
Test: liblp_test_static builds
Change-Id: I22b15523a32272ed67a8fe16e386f41b3fcf0bb0
2019-08-23 14:44:51 -07:00
David Anderson
9267c3f5c4 libsnapshot: Add helper for first-stage init mounting
With this patch, init can mount snapshots in the first stage by
performing the following operations:
 1. First, check if SnapshotManager::kBootIndicatorPath exists.
 2. If so, call SnapshotManager::NewForFirstStageMount.
 3. If NeedSnapshotsInFirstStageMount returns true,
 4. Call CreateLogicalAndSnapshotPartitions().

When called, this replaces any calls to CreateLogicalPartitions().

Rather than split this into multiple functions (to generate uevents as
needed), we instead use major:minor strings for device-mapper tables.
This means we don't have to wait for paths to resolve.

Bug: 139204329
Test: libsnapshot_test gtest
Change-Id: Ia7ec196a62e51748d6f01a66fe4e9eef25f2898f
2019-08-23 14:42:05 -07:00
Yifan Hong
3a136e58e3 rename liblp_test_static to vts_kernel_liblp_test.
Test: builds
Change-Id: I708ecef257b806c29a7f1e6108d91f52b2ed4241
2019-08-23 13:58:47 -07:00
Yifan Hong
fd659bdfed Add liblp_test to presubmit.
Create a new test binary, liblp_test, that can run on presubmit.

Bug: 138328907
Test: TH
Test: atest liblp_test

Change-Id: I968ff84078524e5733da9b009d9a7222aad299bd
2019-08-23 13:58:47 -07:00
Treehugger Robot
f2c7dd666e Merge "liblp_test_static: fix test" 2019-08-23 02:51:58 +00:00
Yifan Hong
607e4dfa1c liblp_test_static: fix test
- Fix test so that it skips compliance test on non-DAP devices
  and retrofit devices as well. Move these device-dependent tests
  into the DeviceTest test suite and skip them on non-DAP devices.
- Also add "ResetPropertyFetcher" in some tests in io_test.cpp.
- Also change some ASSERT to EXPECT.

Note that VtsKernelLiblpTest runs this test. VtsKernelDynamicPartitionsTest
enforces ro.boot.dynamic_partitions to be set.

Bug: 138328907
Test: run it

Change-Id: Ic5cd3921033142f38aae071585f6c0fa563ae362
2019-08-22 14:59:10 -07:00
David Anderson
9612e2767e Merge "libsnapshot: Use a real fake super partition for tests." 2019-08-22 20:39:59 +00:00
David Anderson
7e5bae88b8 libsnapshot: Use a real fake super partition for tests.
We are currently creating test partitions via ImageManager, which
unfortunately leads to a lot of hacks in my local tree to test
first-stage init. ImageManager devices look nothing like real partitions
in super, and it's a lot of work to massage it to act the same.

Instead, let's create an actual super partition. We can do this via
ImageManager, and give it its very own partition table. To make this
work, we need a special IPartitionOpener that will redirect requests for
"super" to our temporary device. A new .cpp file has been added to house
this. A few other tidbits have moved there as well.

This makes setup code a bit more complicated, but now our tests will
behave much closer to a real device.

Bug: 139204329
Test: libsnapshot_test gtest
Change-Id: I2f40109cd3c1d6343d6f52979789e25f9afd533a
2019-08-22 13:28:29 -07:00
Alessio Balsini
727c7f3bb2 libsnapshot: use DeleteDeviceIfExists() when required
Use the DeleteDeviceIfExists() helper function, instead of duplicating
its code..

Test: manual
Change-Id: I2cba65f1f69c3dc56fe277bfb0a3411ea2a9ec2b
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-08-22 19:05:38 +01:00
David Anderson
251ec05f01 liblp: Support sdcards in PartitionOpener.
Before ImageManager was introduced, gsid avoided using PartitionOpener
when writing to external media. PartitionOpener couldn't interact with
non-boot devices, because it prepends /dev/block/by-name. We hacked
around this in both gsid and in first-stage init, which manually detects
the problem and prepends /dev/block instead.

After the ImageManager refactoring, sdcard support broke in gsid,
because it started relying on PartitionOpener. Let's fix this by allowing
/dev/block for mmcblk* names in PartitionOpener.

Bug: 139204329
Test: fiemap_image_test gtest
Change-Id: Ic1cbdbe0a18fc09522ee38cc62b35fd8193ce250
2019-08-21 12:27:56 -07:00
David Anderson
370226e662 libdm: Add a helper function for GetState+DeleteDevice checks.
Bug: N/A
Test: manual test
Change-Id: Ie97b63b53f548af1e82b73893fa491fac42b32ea
2019-08-21 12:27:56 -07:00
David Anderson
63fe0e9a36 Merge "fs_mgr: Allow using major:minor device strings in CreateLogicalPartition." 2019-08-20 20:42:24 +00:00
Yifan Hong
70a368119d Merge "liblp: UpdateMetadataForInPlaceSnapshot" 2019-08-17 00:18:54 +00:00
Mark Salyzyn
e5aa946b63 Merge "fs_mgr: overlayfs: empty system partitions excluded." 2019-08-16 17:41:32 +00:00
Yifan Hong
1d6d4507a4 Merge "liblp: CreateLogicalPartition with a given mapped name" 2019-08-16 17:41:22 +00:00
David Anderson
c1c6008b78 Merge "libsnapshot: Improve test reliability." 2019-08-16 14:54:22 +00:00
David Anderson
f79af03011 Merge "libsnapshot: Don't compare strings for snapshot state." 2019-08-16 14:53:14 +00:00
David Anderson
3b5d5b5b8a libsnapshot: Improve test reliability.
The test suite is still quite buggy if interrupted. This fixes a number
of issues (such as bad ordering of setup calls), and refactors things to
add more ASSERTs.

Bug: 139204329
Test: libsnapshot_test gtest
Change-Id: I224608715c29f343b34512a9ac1143f0dde932e9
2019-08-15 17:42:51 -07:00
David Anderson
f27c063ba9 libsnapshot: Don't compare strings for snapshot state.
Convert the string field to an enum. We still write a string back to the
state file.

Bug: N/A
Test: libsnapshot_test gtest
Change-Id: I7cc1cb597dacd7d6faaaba05fb01c0a86bd54c8f
2019-08-15 17:42:47 -07:00
David Anderson
4929df0c44 fs_mgr: Allow using major:minor device strings in CreateLogicalPartition.
IPartitionOpener is useful for writing gtests, however, it can't easily
be used with CreateLogicalPartition. fs_mgr assumes the super partition
name will map to /dev/block/by-name/super whereas in tests we want to
redirect it to a different block device.

This CL makes two changes. First, it adds a new method to IPartitionOpener
to return a "device string" for a device name. The string must either be
an absolute path (for example /dev/block/by-name/super) or a major:minor
sequence, since device-mapper will accept either.

Second, CreateLogicalPartition now accepts an optional IPartitionOpener.
When converting block devices to paths, it uses the opener instead of
automatically prepending /dev/block/by-name.

Bug: 139204329
Test: liblp_test gtest
      libsnapshot_test gtest

Change-Id: Id6b3120cc2ef5c0dd941b29ff96215ad3c8ec848
2019-08-15 16:39:48 -07:00
Mark Salyzyn
18085418ee fs_mgr: overlayfs: empty system partitions excluded.
Beside using the 1% threshold for determining that a filesystem
should be an overlayfs candidate, do so also if the free space
is below 8MB.  This will cover nearly empty filesystems that can
not be right-sized below the smallest ext4 filesystem size.

Adjust the test to cover the new cases.

Should test all system partitions, including new /system_ext and
any others that get added in the future.

Fix instance of dir that were supposed to be die.  Using || die
does not work as expected within a function, so use if ! <cond>.

Test: adb-remount-test.sh
Bug: 139471424
Change-Id: If3e4cac5dce7bee998727052130eaf362e9e2fb5
2019-08-15 11:37:18 -07:00
Yifan Hong
293cd027f7 liblp: UpdateMetadataForInPlaceSnapshot
For Virtual A/B devices, rename partitions / groups ending in
source slot to target slot, so that the metadata can later
be written to target metadata slot.

Test: liblp_test_static
Bug: 135752105
Change-Id: I6a7b25e8da2808b1831f317760f4345df6b22689
2019-08-14 14:27:03 -07:00
Yifan Hong
5217c1cf0e Rename libfiemap libraries.
Update Android.bp for libfiemap library renames.

Test: builds

Change-Id: I318c5f64452726579cebb41792b95f6b9e47fbb8
2019-08-14 14:17:22 -07:00
Yifan Hong
fadce1ee1f liblp: Don't halve super partition for virtual a/b devices
For Virtual A/B devices, we snapshot the partitions. Hence
there is no need to prioritize using the second half of super
partition for _b partitions.

Test: liblp_test_static
Bug: 135752105

Change-Id: I8bd669e6ffa0a4d114a1b386133179bd2819099b
2019-08-14 14:17:22 -07:00
Yifan Hong
8367b9f73a liblp: MetadataBuilder::GetBlockDevicePartitionName
Allow to retrieve name of a block device partition at
a certain index. If the index is out of range, return
empty string.

This is needed for an hypothetical edge case when an
intersection of two LinearExtent needs to be computed,
and the two metadata have a different list of block
device names. In reality, Virtual A/B devices are always
launched with dynamic partitions, so it will always return
"super" for index 0 and "" otherwise.

Test: liblp_test_static
Bug: 135752105

Change-Id: I9ea59edefdc41d0e69e3644aa2452676372938b4
2019-08-14 14:17:22 -07:00
Yifan Hong
4644f84208 liblp_test_static: GetMockedInstance->GetMockedPropertyFetcher
Rename it to be a better name.
Test: run it

Change-Id: Idcf271e84f8758737a98a4f6c18ea6744b91f79b
2019-08-14 13:33:59 -07:00
Yifan Hong
94da8944f5 libsnapshot: UnmapSnapshot: don't delete device that doesn't exist.
Otherwise, DeleteDevice will just return false and it will
be stuck here.

Test: apply OTA after first boot, update_engine can unmap system_b
Bug: 135752105

Change-Id: If2b00336f4b948ba5f57a5e129fc070a739848fa
2019-08-14 13:33:59 -07:00
Yifan Hong
b278e013b9 liblp: change some functions to use string_view
Converting all of them to string_view requires some
non-trivial amount of refactoring (because there is not
an implicit conversion from string_view to string), and
hence may be done later if necessary.

Test: builds
Bug: 135752105
Change-Id: I936ae7117500fadc7b34a5b91b279bc863d9919d
2019-08-14 13:33:59 -07:00
Paul Lawrence
f3405ad73e Fix ext4/metadata/udc issue
Test: Cannot currently test since no device supports this combo
Bug: 137924328
Change-Id: I6474211e7229323da831f99d9572283e0c2d49df
2019-08-14 10:10:31 -07:00
Josh Gao
edf8040152 Merge "adb: use shell for remount to forward return codes." 2019-08-14 00:26:04 +00:00
David Anderson
15aa9540df liblp: CreateLogicalPartition with a given mapped name
Introduce a parameter struct to eliminate parameter explosion, and refactor
existing callers to use the new helper.

Test: manual test
Bug: 135752105
Change-Id: I0c5ebe4e084ad7503c2ac6c65886a71505d50d00
2019-08-13 13:41:36 -07:00
David Anderson
6ecedd2040 Merge "libsnapshot: Track the source slot across reboots." 2019-08-13 20:39:23 +00:00
Josh Gao
8c2198c809 adb: use shell for remount to forward return codes.
Bug: http://b/25842395
Test: manual
Change-Id: I719c86bdf573db14ca2a0bdf608065ad63f573c1
2019-08-12 18:31:45 -07:00
Treehugger Robot
cbd1af9db0 Merge "fs_mgr: adb-remount-test: non-verity recovery" 2019-08-13 00:40:17 +00:00
David Anderson
3c0fea923b libsnapshot: Track the source slot across reboots.
The purpose of this is twofold. First, we need a way to detect whether
the device has booted into the new slot after an update. Second, we need
a quick-and-dirty test for first-stage init so it can avoid searching
for snapshots if it doesn't need to.

We can solve both of these problems by storing the source slot in
/metadata/ota/snapshot-boot. The existence of the file implies a more
complex check is needed, and the file stores the source slot.

Test: libsnapshot_test gtest
Bug: 139204329
Bug: 139089801
Change-Id: I919dd1c27a65734c61f3a9bdffefb32bdebd723b
2019-08-12 17:10:21 -07:00
Anatol Pomazau
6b2ea1ca70 Add header that declares memcpy()
It helps to fix a compilation issue with host libc:

core/fs_mgr/liblp/reader.cpp:252:9: error: use of undeclared identifier 'memcpy'; did you mean 'wmemcpy'?
        memcpy(&partition, cursor, sizeof(partition));
        ^~~~~~
        wmemcpy

Change-Id: I68f9c5b815b09f846aeba67bce0290f6829c80cf
2019-08-12 18:34:49 +00:00
Mark Salyzyn
ae8b8a4e00 fs_mgr: adb-remount-test: non-verity recovery
For devices that do not have verity, or start the test with
verity disabled, but are using overlayfs, use a 'secret' surgical
technique to revert the device back to original state.

adb enable-verity will carry risk in that if the device did not
arrive with verity enabled, we can not guarantee it will boot
if we turn on verity.

Test: atest adb-remount-sh
Bug: 138649540
Change-Id: If6d55c57fb9daca9305c42a4df2c18c7f8c5eefa
2019-08-12 10:14:18 -07:00
David Anderson
5b9832748f Merge changes I5e93fcbf,I9d4c8bcf,Icd580aae,I7b2399a4
* changes:
  libsnapshot: Implement merge flow.
  libsnapshot: Unmap COW devices when deleting snapshots.
  libsnapshot: Eliminate per-snapshot flocks.
  libsnapshot: Improve first test-run and test cleanup.
2019-08-09 19:34:52 +00:00
Mark Salyzyn
31c14e15b9 fs_mgr: overlayfs: dig harder for /dev/root equivalent
Check for A/B /dev/block/by-name/system<slot> and also non-A/B
/dev/block/by-name/system to discover what /dev/root can be when
evaluating candidates for using overlayfs.

This is to handle a misconfigured (or legacy) system-as-root device.
It is recommended that the default fstab specifically mentions the
root mount's device node to prevent going down this path.

Test: adb-remount-test.sh
Bug: 138407617
Change-Id: I3853d203b9376d0f848cb490150ff00cc4ed3d5f
2019-08-08 11:50:36 -07:00
David Anderson
5312c466b9 libsnapshot: Implement merge flow.
This implements InitiateMerge() and WaitForMerge(). InitiateMerge() is
meant to be called after an update has been marked successful.
WaitForMerge() is designed to be called either: immediately after
InitiateMerge, or during each subsequent boot where merging has not
completed.

InitiateMerge converts each snapshot device to a snapshot-merge device.

WaitForMerge polls each snapshot-merge device until no device reports a
"merging" state. One of the following states can result from this:
 - MergeFailed. This will happen if any device failed to merge, or we
   were unable to poll, or any other system-level failure occurred.
 - MergeNeedsReboot. This will happen if a snapshot-merge device has
   completed merging, but we were unable to clean it up due to something
   holding a resource open.
 - MergeCompleted. This indicates that all snapshots completed merging
   and were cleaned up.

If WaitForMerge() returns MergeCompleted, then all snapshots have been
removed and a new update can begin. GetUpdateState() will return None.

MergeFailed and MergeNeedsReboot, on the other hand, are "sticky". They
indicate a merge is still pending. When called again, WaitForMerge()
will poll again to attempt to make more progress in the merge. For
NeedsReboot, a single reboot will ensure all resources are released and
the next WaitForMerge() will successfully finish cleanup. In the failure
case, it is unlikely the next WaitForMerge will succeed, but we always
retry anyway (there is no harm in doing so, and if we get lucky, the
device can take more OTAs).

Bug: 136678799
Test: libsnapshot_test gtests
Change-Id: I5e93fcbffee1973da5ff76363df12d6317a7a7c7
2019-08-07 18:42:23 -07:00
David Anderson
986095036c libsnapshot: Unmap COW devices when deleting snapshots.
When we stopped unmapping snapshots in DeleteSnapshot, this also stopped
unmapping the COW device. Of course, the caller has no way to unmap this
since it's an implementation detail. Therefore unmap it in
DeleteSnapshot.

This scenario can arise after rewriting or removing a snapshot-merge
device.

Bug: 136678799
Test: manual test
Change-Id: I9d4c8bcfbb95b4454edd1cf0853d51b441e895fa
2019-08-07 18:42:22 -07:00
David Anderson
d986fefa3b libsnapshot: Eliminate per-snapshot flocks.
Per-snapshot locks don't solve any problems and add a great deal of
complexity. Instead, refactor the Read/WriteSnapshotStatus methods so
the caller just needs the snapshot name, and is not responsible for
opening a file.

As part of this change, callers of WriteSnapshotStatus must always take
an exclusive flock on the update state file. This is enforced by adding
a helper method to LockedFile to check the lock mode.

Bug: 136678799
Test: libsnapshot_test gtest
Change-Id: Icd580aaec7dfc916b3eed174d86b26688cd2291b
2019-08-07 18:42:22 -07:00