Commit graph

1651 commits

Author SHA1 Message Date
David Anderson
734047a231 libfiemap: Add a way to get the block device path of a mapped image.
This is needed for adb remount, to find the scratch device if it is
already mapped. Note that on devices without metadata encryption, this
cannot be done by querying device-mapper, since scratch will be a loop
device.

Bug: 134949511
Test: fiemap_image_test
Change-Id: Ia25d279c6f8a4838be32a8c01aefc67b5ec1e002
2019-12-20 16:41:35 -08:00
David Anderson
f41c7bbb96 libfiemap: Add helpers to remove images from recovery.
ImageManager can map images in recovery, but not delete them, because
/data is not mounted. libsnapshot handles this by storing extra state
files, but this is complex to manage and inconvenient for
fs_mgr_overlayfs.

Instead, this patch introduces two new calls:

 - DisableImage(), which indicates the image should not be used. This is
   implemented by adding a new DISABLED attribute to
   LpPartitionMetadata. CreateLogicalPartitions ignores this flag, and
   thus recovery/fastbootd can disable the scratch partition and
   communicate that it can be deleted. This cannot be called from binder
   since it is intended for recovery/first-stage init only.

 - RemoveDisabledImages(), which walks the images for a given folder on
   /metadata and deletes any that are disabled. This can be called from
   binder.

Note that there is no metadata version bump for this flag. It's
considered to be included in the flag list for minor version 1, and
currently is not used for the actual super partition.

Bug: 134949511
Test: adb remount, fastboot flash system
Test: fiemap_image_test
Change-Id: Iaeca2d1eddb5637dd9a20202cafd11ae60b4d0e3
2019-12-20 16:41:35 -08:00
David Anderson
43482de3f9 fs_mgr: Move libfiemap into libfs_mgr, and introduce libfs_mgr_binder.
This eliminates libfiemap as a standalone library and instead bundles it
into libfs_mgr. All consumers of libfiemap need libfs_mgr, and having
them tightly coupled reduces linkage complexity.

When to use libfs_mgr: In recovery, first-stage-init, or when libfiemap
or overlayfs is not used.

When to use libfs_mgr_binder: When not in recovery/first-stage init, and
overlayfs or libfiemap is needed. In this case, IImageManager will proxy
over binder to gsid.

Bug: 134949511
Test: builds, fiemap_writer/image_test passes.
Change-Id: I4c1a5698afdbf9b3bf87accec98254c1fb6f4e0e
2019-12-20 16:41:34 -08:00
Yifan Hong
18c6248ffe Merge changes from topic "wait_for_merge"
* changes:
  libsnapshot: add WaitForMerge
  libsnapshot: SnapshotUpdateTest::AddOperation
  libsnapshot: add GetCurrentSlot
2019-12-17 23:01:59 +00:00
David Anderson
1526a46e92 Merge "fs_mgr: Move libfiemap back to fs_mgr from system/gsid." 2019-12-17 17:32:09 +00:00
David Anderson
4fe398018b fs_mgr: Move libfiemap back to fs_mgr from system/gsid.
Bug: 134949511
Test: builds
Change-Id: I07943acce5d4671975afef6d8da1bdbeef43c39d
2019-12-16 20:10:26 -08:00
Nikita Ioffe
0dda423dd0 Unmount bind-mounts on top of /data before unmounting /data
Test: adb shell setprop sys.init.userdata_remount.force_umount_f2fs 1
Test: adb shell /system/bin/vdc checkpoint startCheckpoint 1
Test: adb reboot userspace
Bug: 135984674
Bug: 143970043
Change-Id: Icd7f3ad1c42d9b21bf4eacf1dec60355c9883254
2019-12-16 23:22:55 +00:00
David Anderson
18bb214b3f Merge "liblp: Expand the metadata header for future use." 2019-12-16 17:31:57 +00:00
Yifan Hong
1af515b57c libsnapshot: add WaitForMerge
Add an API that does not initiate the merge, but only waits for it to
finish. It is different from ProcessUpdateState API in that it also
blocks when state == UNVERIFIED and booting from the new slot.
(ProcessUpdateState immediately returns in this case).

This is useful for android.os.UpdateEngine.CleanupSuccessfulUpdate().
Bug: 138808328
Test: libsnapshot_test

Change-Id: I7cc59fcaf69616e7ec7ebe6101991b5106845b65
2019-12-13 19:52:31 -08:00
Yifan Hong
c810f1091a libsnapshot: SnapshotUpdateTest::AddOperation
Reusable test code.
Test: libsnapshot_test

Change-Id: I00a1a460d84c01b0dbd24b668293df87962e8b00
2019-12-13 19:52:31 -08:00
Yifan Hong
c64cefc027 libsnapshot: add GetCurrentSlot
Factor out obscure logic that reads boot indicator path.
GetCurrentSlot() returns three states:
- None (read failure)
- Old (before reboot)
- New (after reboot)
Use these "logical" slot values for simpler code.

Test: libsnapshot_test
Change-Id: I1fa2ce4916c5a1652d25682ec1f11e101c858822
2019-12-13 19:52:31 -08:00
Treehugger Robot
babc293140 Merge "libsnapshot: snaity check overflow bit at the end of update" 2019-12-14 03:05:19 +00:00
David Anderson
9f75098c60 liblp: Expand the metadata header for future use.
A few times we have wanted to stash small bits of information in the
super header, but we haven't had any bits to do so. This patch addresses
future needs in two ways:

  1. A "flags" field has been added for miscellanious bits that do not
     need a version bump.
  2. The header struct has been padded to 256 bytes to allow for future
     expansion without complicating the struct-parsing code.

This is the first time we've materially changed the format, so this
patch needs some extra explanation.

In all the places we rely on sizeof(LpMetadataHeader), we now need to
use the |header_size| field instead. To make newer versions of liblp
compatible with older headers, we read the minimum required header size
and fill in the extra bytes as needed. To make the validation and
reading logic more clear, it is now combined into a single function,
ReadMetdataHeader.

MetadataBuilder will still emit 1.0-compatible headers, to avoid
changing the on-disk format of existing devices. The new header will
only be emitted as-needed.

Bug: 134949511
Test: liblp_test gtest
      retrofit DAP device boots
      launch DAP device boots

Change-Id: I6221123768ff0057a73967ecb2ff9b006c17af88
2019-12-14 00:35:58 +00:00
David Anderson
2d79a4365e remount: Remove fs_mgr_overlayfs_scratch_device()
This is no longer needed now that GetScratchDevice exists. The cache can
go away too, since it only existed to avoid libdm spam. The spam is
avoided by checking GetState before calling GetDmDevicePathByName.

Bug: 134949511
Test: adb remount and adb_remount_test.sh
Change-Id: I9d94e2523af9de394a811d0b398fe20415708a6b
2019-12-12 14:13:40 -08:00
David Anderson
43d9f1833f remount: Refactor fs_mgr_overlayfs_teardown
This pulls code for mapping the scratch device into a separate function.
It also avoids implicitly failing by passing an empty device string.
Finally, it calls GetScratchDevice, to remove a caller of the deprecated
method fs_mgr_overlayfs_scratch_device().

Bug: 134949511
Test: adb remount and adb_remount_test.sh
Change-Id: If4a543d3fa26af3f8578ec8b236859c8e4d9bfd8
2019-12-12 14:13:40 -08:00
David Anderson
a3bf8478a3 remount: Do not run the create-scratch logic on older devices.
The prologue of fs_mgr_overlayfs_create_scratch() will implicitly
succeed on physical block devices, and implicitly fail if for some
reason they can't be accessed.

This patch makes the success and failure cases explicit. The logic
specific to DAP has been moved to CreateDynamicScratch.

fs_mgr_overlayfs_create_scratch now calls GetScratchStrategy, and only
calls CreateDynamicScratch for DAP-launch devices. In the case a
physical block device can be used, no action is taken.

Bug: 134949511
Test: adb remount and adb_remount_test.sh
Change-Id: I0af7cda9bc551416c9e2ffca5a36305f89d3bf46
2019-12-12 14:13:39 -08:00
David Anderson
864021fbf6 remount: Refactor fs_mgr_overlayfs_scratch_device().
This splits fs_mgr_overlayfs_scratch_device into two new methods. The
first, GetScratchStrategy, returns an enum detailing exactly how the
device will find space for scratch:
 - via system_<other>,
 - via super_<other>, or
 - via a dynamic partition.

The second method, GetScratchDevice, uses the strategy to either return
the underlying block device, or look up a dynamic partition.

fs_mgr_overlayfs_scratch_device will be removed completely in a separate
patch.

Bug: 134949511
Test: adb remount and adb_remount_test.sh
Change-Id: Ic7e3815ada4adaf5fd7c19b84dc22249f3dcc881
2019-12-12 03:06:21 +00:00
Treehugger Robot
1ef36b7491 Merge "Using a dir /avb for DSU avb keys" 2019-12-11 23:56:09 +00:00
David Anderson
ce8ab2b546 Merge "remount: Factor some code out of fs_mgr_overlayfs_mount_all()." 2019-12-11 22:27:38 +00:00
David Anderson
cd720dc313 remount: Factor some code out of fs_mgr_overlayfs_mount_all().
To ease on the indentation, this factors the innermost code of
overlayfs_mountall() into a new TryMountScratch() function.

Bug: 134949511
Test: adb remount
Change-Id: I894cbcd17bb6bd64751f235a074fa5ba7ce5157c
2019-12-11 14:26:06 -08:00
Nikita Ioffe
da776c394d Merge "userdata_checkpoint_remount: delete all devices in dm-stack under /data" 2019-12-11 18:40:21 +00:00
Bowgo Tsai
a2ac846ff3 Using a dir /avb for DSU avb keys
Previously the AVB public keys for DSU is hard coded for each key path.
This adds the burden for maintaining the codebase, e.g., need to change
avb_keys each time when any new key is added or some old key is deleted.

With commit Ie74845d8c8e4aa45e8a9e3b862424cec641f8090, it's possible to
load avb keys from a directory. Let's use "/avb" for DSU AVB keys.

Also removing fstab entries that specifying vbmeta_partition. The AVB
keys used in DSU flow should be a separate set from the original
vbmeta.img (or vbmeta_system.img).

The following link has more info about DSU:
  https://developer.android.com/topic/dsu

Bug: 141284191
Bug: 144399552
Test: boot a GSI via DSU

Change-Id: I6bc1e068368e64cb0bbf6ef63805444b35a1fdfb
2019-12-11 09:00:46 +00:00
Treehugger Robot
9af7878ec5 Merge "Allowing the fs_mgr flag of avb_keys to be a dir" 2019-12-11 04:26:57 +00:00
Nikita Ioffe
d572c80ace userdata_checkpoint_remount: delete all devices in dm-stack under /data
This enables unmounting + remounting of metadata encrypted ext4
userdata. Also added a sysprop to force unmount+remount logic even for
f2fs userdata which comes handy for testing, since we don't have
metadata encrypted ext4 devices to test on.

Test: adb shell setprop sys.init.userdata_remount.force_umount_f2fs 1
Test: adb shell /system/bin/vdc checkpoint startCheckpoint 1
Test: adb reboot userspace
Test: adb shell dumpsys activity
Bug: 135984674
Bug: 143970043
Change-Id: Icc30f5c99f4d9ee374352610ae17b5d9814f815b
2019-12-10 16:03:45 +00:00
Yifan Hong
a16f2c81a8 libsnapshot: snaity check overflow bit at the end of update
Make sure CoW device doesn't overflow. Otherwise, data previously
written to snapshot device may be overwritten.

This check acts as a safety guard to bug like b/145180464, where
the computed CoW device size is less than required, but cannot be
caught by FilesystemVerifierAction in update_engine.

Note that this is a sanity check. It doesn't prevent the following:
(1) write a snapshot until it overflows
(2) unmap and re-map the snapshot
(3) Call FinishedSnapshotWrites()

When a snapshot is re-mapped, DeviceMapper::GetTableStatus() won't
return "Overflow".

However, update_engine always writes the full hashtree / FEC / etc.
data (outside of |PartitionUpdate.operations|), calls
FinishedSnapshotWrites(), and then writes the checkpoint. If the process
is interrupted, update_engine does the full FilesystemVerifierAction
from the beginning. Snapshots aren't remapped during the process. Hence,
the hypothetical case above won't happen in reality (at time of writing)
until FilesystemVerifierAction is broken down into steps with
checkpoints.

Still, given the above hypothetical case, this function is only served
as a sanity check.

FinishedSnapshotWrites() now requires all snapshots to be mapped before
calling. Hence, tests needs to be fixed:
- For SnapshotTest (that tests SnapshotManager private APIs), map
  snapshot before calling FinishedSnapshotWrites().
- Factor out common code in SnapshotTest (PrepareOneSnapshot and
  SimulateReboot)
- For SnapshotUpdateTest and children, add MapUpdateSnapshots() helper
  and map all snapshots before calling FinishedSnapshotWrites().

Test: libsnapshot_test
Bug: 145180464

Change-Id: I3558dd1615059ba27f369c27af22e3c686e392f7
2019-12-09 16:06:03 -08:00
Bowgo Tsai
acaa95dc44 Allowing the fs_mgr flag of avb_keys to be a dir
Hard coding multiple keys in the avb_keys flag isn't flexible and
causes some pains when upgrading an Android codebase.
e.g., from Android 10 to Android 11.

This CL supports specifying a directory for the avb_keys
for fs_mgr to list then use the avb keys under the directory.

Bug: 144399552
Test: config a fstab using avb_keys as a dir to boot
Test: atest libfs_avb_test
Test: atest libfs_avb_internal_test
Change-Id: Ie74845d8c8e4aa45e8a9e3b862424cec641f8090
2019-12-09 14:29:52 +08:00
Yifan Hong
0daaa72b0f libsnapshot: add library for test helpers
Add libsnapshot_test_helpers for update engine tests
to properly set up depended modules.

Test: update_engine_unittests
Test: libsnapshot_test
Change-Id: Idd90a74cd6fb489f6ae14f44493b2288205c4a94
2019-12-06 17:42:40 -08:00
Nikita Ioffe
9fb63038f7 libdm: add an api to unwind dm stack
This API is an attempt to consolidate dm-stack unwinding logic
re-implemented in several different places (libfsmgr, libfstab,
libfiemap, etc.).

Test: libdm_test
Bug: 135984674
Change-Id: I9672d4c1e882824ef980667818d4c3aabcb82e1f
2019-12-06 22:10:45 +00:00
Nikita Ioffe
dde59c32ac Merge "libdm: add an overload of DeleteDevice accepting a timeout_ms" 2019-12-06 02:35:23 +00:00
Yifan Hong
ab0b17c081 Merge changes from topic "libsnapshot_write_atomic"
* changes:
  libsnapshot: write files atomically
  libsnapshot: lock on /metadata/ota
2019-12-05 20:13:21 +00:00
Nikita Ioffe
2c28919d48 libdm: add an overload of DeleteDevice accepting a timeout_ms
In some scenarios (e.g. apexd or userspace reboot), dm-devices are
getting deleted and re-created. Since this operation can be racy (newly
created device can get the same path as the previously deleted one,
resulting in the unexpected ENOENT errors on a system call to the path),
it will be nice to have an API that blocks until ueventd processes
corresponding udev events.

Test: libdm_test
Bug: 143970043
Bug: 122059364
Change-Id: I31a19afd9e245bf5e3554011bdde1c3cc4878f1c
2019-12-05 10:37:47 +00:00
Yifan Hong
55974f1425 libsnapshot: write files atomically
... by writing to a temporary file then rename()'ing it
back.

Test: libsnapshot_test
Bug: 144549076
Change-Id: Ide400aff8d67d56d422d0adea3a4f1673ebc9994
2019-12-04 14:49:47 -08:00
Yifan Hong
b6663cfb5a libsnapshot: lock on /metadata/ota
We used to flock() on /metadata/ota/state to ensure
atomic access. However, writing the file itself is
not necessary atomic and may lead to inconsistent
states.

This change redirects flock() to the outer directory, /metadata/ota,
which is very likely to exist (see exception below).
flock() is called on this directory instead of /state. This allows
a follow-up change to turn all writes to the /metadata partition
atomic.

Note: /metadata/ota may not exist during first boot after a flash
with wipe. However, first_stage_init always checks existence of
boot indicator before even trying to flock() (via
IsSnapshotManagerNeeded() and NeedSnapshotsInFirstStageMount()). If
the boot indicator exists, /metadata/ota must exist as well.

Also add tests to ensure LockExclusive() and LockShared() works as
expected.

Test: libsnapshot_test
Test: apply OTA from older build to this, then reboot

Bug: 144549076

Change-Id: Ib4dd9e9be1a43013c328e181b9398ac0b514dbce
2019-12-04 14:49:47 -08:00
Nikita Ioffe
9f71d6193a Merge "Add basic support for remounting ext4 userdata into checkpoint" 2019-12-04 19:22:50 +00:00
Treehugger Robot
fea51309dc Merge "libsnapshot: Call EnsureImageManager before RemoveAllImages" 2019-12-04 13:53:36 +00:00
Yifan Hong
e62591ec3b libsnapshot: Call EnsureImageManager before RemoveAllImages
Calls to RemoveAllImages may be on uninitialized
image manager.

Test: apply OTA to self

Change-Id: Id57c01ddfdb6985fb2c3c142ee19fd65eef6c131
2019-12-04 00:24:55 -08:00
Yifan Hong
51fb2a0855 Merge "libsnapshot: start in background" 2019-12-04 00:04:54 +00:00
Wei Wang
6db520807d libsnapshot: start in background
so that it won't block init starting other services on boot_completed.

Test: build
Bug: 145612906
Change-Id: I1ca325b9ef191c4689e925da2e797271ec9c7979
2019-12-03 13:27:05 -08:00
Yifan Hong
3a8001476d Merge changes I8c5ab552,If8546dea
* changes:
  libsnapshot: tests uses common MapUpdateSnapshot/WriteSnapshotAndHash
  libsnapshot: Add test for accounting for hash tree
2019-12-03 19:44:51 +00:00
Yifan Hong
8b8ffbb2df Merge "SOURCE_COPY operation: implement src == dst" 2019-12-03 19:44:35 +00:00
David Anderson
710d6cc419 Merge "libsnapshot: Remove all image data and metadata when cancelling an update." 2019-12-03 00:36:56 +00:00
Alessio Balsini
ef2c39bd6b SOURCE_COPY operation: implement src == dst
Helper function to compare the source and destination extents of a
SOURCE_COPY InstallOperation.
The function returns true iff source and destination are identical with
the use of std::equal().

Bug: 141207436
Test: build
Change-Id: I146aeba1c8ede35f21cfef8e21d4af62274bda84
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-12-02 14:58:17 -08:00
Yifan Hong
18a78959ab libsnapshot: tests uses common MapUpdateSnapshot/WriteSnapshotAndHash
Factor out duplicated code.
Test: run it

Change-Id: I8c5ab552b97837b0e37cada6263eeda23f7f71b4
2019-12-02 13:59:48 -08:00
Yifan Hong
defcbb4b7f libsnapshot: Add test for accounting for hash tree
Test: libsnapshot_Test
Bug: 145180464
Change-Id: If8546dea89fdd7ec7499522a232a777699c52d82
2019-12-02 13:59:48 -08:00
Alessio Balsini
33836a6061 PartitionCowCreator accounts for extra extents
dm-verity and error correction use part of the partitions using these
features to store their data.  Their data may be modified during an
update, so the COW device for the dm-snapshot must reserve some extra
space for them.
This patch extends the PartitionCowCreator data structure with the
extra_extents field that will store the (optional) additional extents,
e.g., the hash table extent for dm-verity or the error correction
extent.

Test: incremental OTA apply
Test: libsnapshot_test
Bug: 145180464
Change-Id: I387a6cc8438507ad41a85cc3400241ecaf627b8f
Signed-off-by: Alessio Balsini <balsini@google.com>
2019-12-02 12:49:38 -08:00
Nikita Ioffe
bee7b8c811 Add basic support for remounting ext4 userdata into checkpoint
Metadata encrypted ext4 userdata and v2 encryption keys will be
supported in follow up CLs.

Test: adb shell /system/bin/vdc checkpoint startCheckpoint 1
Test: adb reboot userspace
Bug: 135984674
Bug: 143970043
Change-Id: I8dbf3bddd811cf54d3f2b2ee2c1ea64159d8c6e0
2019-12-02 11:59:51 +00:00
Bowgo Tsai
110988d57a Adding require_root for libfs_avb_device_test
The test requires to load and verify vbmeta struct from partitions,
and thus needs adb root.

Bug: None
Test: atest libfs_avb_device_test
Change-Id: I4924d6e41edc78898d9ef9c3d7f52c9066f750b1
2019-12-02 15:07:58 +08:00
Yifan Hong
834e4751e6 Merge "libsnapshot: Fix test UpdateBootControlHal" 2019-11-27 21:04:39 +00:00
Yifan Hong
217e10e3d4 Merge changes Ifc76203e,I194d15cf
* changes:
  libsnapshot: Fix DataWipeRollbackInRecovery test
  libsnapshot: Fix test MergeInRecovery
2019-11-27 18:43:16 +00:00
Yifan Hong
4711b3238e Merge "libsnapshot: Check for snapshot status none" 2019-11-27 18:42:58 +00:00