Commit Graph

910 Commits

Author SHA1 Message Date
Eric Biggers 82c6ba74e2 Merge "init: use libfscrypt for file-based encryption setup" 2018-10-29 17:19:39 +00:00
Mark Salyzyn 044f04baed fastboot: wipe overlayfs for partition
Arrange to delete the overlayfs backing when a specified partition
has been flashed.

Test: manual
Bug: 109821005
Bug: 117605276
Change-Id: I1c6a0341c6cd2ecfbb7c71bec5679a74d579aadd
2018-10-26 20:57:14 +00:00
Eric Biggers f05da4a4be init: use libfscrypt for file-based encryption setup
The file-based encryption setup code is being refactored into its own
library because it applies to both ext4 and f2fs, not just ext4.  Update
init to use the new location.   For fs_mgr, just remove the include of
ext4_crypt_init_extensions.h since it was unneeded.

Test: built, booted device with f2fs encryption
Change-Id: I392a763e3349f001bdbc09eb9ca975aa3451fd68
2018-10-25 17:10:15 -07:00
Treehugger Robot 89eb017780 Merge "liblp: Add an abstraction layer for opening partitions." 2018-10-25 18:55:47 +00:00
David Anderson 13e160e09f Merge "liblp: Store device information in a new block device table." 2018-10-25 18:54:55 +00:00
Mark Salyzyn cf81db320e Merge "fs_mgr: fs_mgr_overlayfs_teardown access to dynamic partition data" 2018-10-25 15:08:28 +00:00
David Anderson 7a6c511a6d liblp: Add an abstraction layer for opening partitions.
This change introduces an IPartitionOpener abstraction. Methods that
interact with live metadata, such as ReadMetadata, UpdatePartitionTable,
and FlashPartitionTable, now require an IPartitionOpener object. Its
purpose is dependency injection: it will make these methods much easier
to test when the super partition spans multiple block devices.

All non-test consumers should be using PartitionOpener, and as such,
some helper methods have been added that automatically create one.

Bug: 116802789
Test: liblp_test gtest
      device with super partition boots
Change-Id: I76725a5830ef643c5007c152c00ccaad8085151f
2018-10-24 14:18:38 -07:00
David Anderson 9a5324178e liblp: Store device information in a new block device table.
This patch removes the alignment, block device size, and starting sector
fields from LpGeometry into a new LpMetadataBlockDevice struct. The
metadata now contains a table of these structs, and the table will have
exactly one entry representing the super partition.

This refactoring will make it easier to have logical partitions span
multiple physical partitions. When that happens, the table will be
allowed to have more than one entry, and the first entry of the table
will be considered the "root" of the super partition.

Bug: 116802789
Test: liblp_test gtest
      device with logical partitions flashes and boots
Change-Id: I97f23beac0363182cb6ae78ba2595860950afcf0
2018-10-24 14:18:35 -07:00
David Anderson 3e77d7a960 Merge "liblp: Add MetadataBuilder helpers for pruning unused groups." 2018-10-23 01:50:39 +00:00
Treehugger Robot fa677f573a Merge "liblp: Move free-region calculation into a separate function." 2018-10-22 23:41:27 +00:00
Mark Salyzyn 7f47e4bac3 fs_mgr: fs_mgr_overlayfs_teardown access to dynamic partition data
If fs_mgr_overlayfs_teardown is called with a specific mount_point
reference (eg: /vendor, /product, /system) when /mnt/scratch is not
mounted (eg: in recovery or fastboot mode), then mount it to perform
the directory teardown.

Test: manual on future changes: fastboot flash vendor -> fastbootd
Bug: 109821105
Bug: 117605276
Change-Id: I5735008e33b57d35345a799dc68bb43c9189135a
2018-10-22 12:38:17 -07:00
Mark Salyzyn 0b23968e25 fs_mgr: overlayfs unit test
Provide a means to test out overlayfs work

Test: adb-remount-test.sh
Bug: 109821105
Bug: 117605276
Change-Id: Ia6114c8f4d0c3424cb869d002cc61cfc6863151c
2018-10-22 12:36:10 -07:00
David Anderson 5cb50a24bc liblp: Add MetadataBuilder helpers for pruning unused groups.
These will help update_engine clear the target slot before applying an OTA.

Bug: 117182932
Test: liblp_test gtest
Change-Id: I6ad370e617f22f2098245a0028a93488f9ac8674
2018-10-22 12:00:23 -07:00
David Anderson 11440493a7 liblp: Move free-region calculation into a separate function.
In preparation for supporting multiple block devices, this factors out
the free-list calculation for resizing partitions.

Additionally, it fixes a bug where space in between the first usable
sector and the first extent wasn't added to the free list.

Bug: 116802789
Test: liblp_test gtest
Change-Id: I965760eef0176020e9a5691ce1be2c8b5e0c8bc8
2018-10-22 12:00:13 -07:00
Mark Salyzyn 9b44e80948 fs_mgr: fs_mgr_overlayfs_teardown_one use .<hidden>
Switch to using a leading . to reference a teardown directory, and
if the top directory (/mnt/scratch/overlay) report ENOTEMPTY then
check if there is any non-hidden content, and if not then consider
removing the scratch partition.

Although not currently a problem, use basename of mount point in
fs_mgr_overlayfs_teardown_one when referencing the overlay directory
tree to match the setup behavior.  Would have become a problem if
we started dealing with sub-mount points (eg: /vendor/firmware_mnt).

Test: manual
Bug: 109821105
Change-Id: I05dafe29c9e376e8423aedc8783fe674a657b3ee
2018-10-19 16:49:16 +00:00
Treehugger Robot 1230ddc94b Merge "liblp: Always align the first usable sector." 2018-10-19 05:29:17 +00:00
David Anderson 6f4722e98e Merge "liblp: Reserve the first logical block of the super partition." 2018-10-19 02:04:08 +00:00
Treehugger Robot 30fa1b7864 Merge "fs_mgr: fs_mgr_overlayfs_teardown_one failure to teardown scratch" 2018-10-18 21:23:43 +00:00
Treehugger Robot 224263da96 Merge "fs_mgr: fs_mgr_overlayfs_mount_scratch try alternate" 2018-10-18 19:21:41 +00:00
Treehugger Robot d2dfb33942 Merge "fs_mgr: fs_mgr_rm_all error propagation inconsequential EPERM" 2018-10-18 14:28:46 +00:00
Treehugger Robot 0a6c743179 Merge "fs_mgr: string literal cleanup" 2018-10-18 14:28:43 +00:00
David Anderson 87391664e3 liblp: Always align the first usable sector.
Align the first usable sector to the logical block size, if no other
alignment was specified. This fixes a bunch of warnings during certain
gtests (ones with unaligned metadata sizes). The warnings were coming
from MetadataBuilder::GrowPartition() which expects the first sector
to always be block-aligned.

Bug: 116802789
Test: liblp_test gtest
Change-Id: I8dcf502aa4c2ba0674c5b4dcb77a274f300ff0a3
2018-10-17 23:17:24 +00:00
David Anderson 692049259c liblp: Reserve the first logical block of the super partition.
Traditionally the first 512 bytes of a partition can be interpreted as
an MBR. To prevent any compatibility issues, we explicitly zero the
first 4096 bytes of the super partition (one logical block, on most
systems).

Bug: 116802789
Test: liblp_test gtest
      device with super partition flashes and boots

Change-Id: I29688ca75dbb52442f1464e8ab35893678a4f79e
2018-10-17 16:15:41 -07:00
Treehugger Robot 4bc53d20af Merge "liblp: Add partitions to the correct group when writing LpMetadata." 2018-10-17 01:54:09 +00:00
Treehugger Robot 30793ac5fa Merge "liblp: Remove last_logical_sector from LpMetadataGeometry." 2018-10-16 23:41:42 +00:00
David Anderson 875434618f liblp: Add partitions to the correct group when writing LpMetadata.
The group_indices variable was intended to facilitate this, but I forgot
to actually use it.

Bug: 116817738
Test: lpmake, lpdump super_empty.img
Change-Id: Ia0da50b56b6c09e277324ec9d7aea6ce48fdc10a
2018-10-16 15:30:05 -07:00
Mark Salyzyn e97469bd14 fs_mgr: fs_mgr_overlayfs_teardown_one failure to teardown scratch
If fs_mgr_overlayfs_teardown_one can not access the top directory,
then we should teardown the scratch volume.

Test: manual
Bug: 109821105
Change-Id: Ic86e10f1af1be354242fc004a95cac92d77619a6
2018-10-16 11:14:36 -07:00
Mark Salyzyn 6b313de3e3 fs_mgr: fs_mgr_overlayfs_mount_scratch try alternate
Harden fs_mgr_overlayfs_mount_scratch to try alternate filesystem
mount type just in case (f2fs <-> ext4).

Cleanup remove any unnecessary string literals.

Test: manual
Bug: 109821105
Change-Id: I36ea974ffeeae392553fff779939dc76a12ab96e
2018-10-16 11:14:24 -07:00
Mark Salyzyn 3a445df4fc fs_mgr: fs_mgr_rm_all error propagation inconsequential EPERM
If in fs_mgr_rm_all opendir on a subdirectory fails because of EPERM,
but a subsequent rmdir succeeds then there was no reason to report
the EPERM as an overall failure error code.

Test: manual
Bug: 117605276
Change-Id: I79fbf8567af1667094595e59ca2b536450f34b94
2018-10-16 11:14:15 -07:00
Mark Salyzyn 9b9bd39b7a fs_mgr: string literal cleanup
Cleanup remove any unnecessary string literals.

Test: compile
Bug: 109821105
Change-Id: Id22629201b8d874afb6b8f9157fa474fdfcf3f43
2018-10-16 11:14:06 -07:00
Treehugger Robot 0730260a6a Merge changes Ib244a98f,Ib173f251
* changes:
  liblp: Don't store BlockDeviceInfo separately in MetadataBuilder.
  liblp: Move backup sectors to the start of the partition.
2018-10-12 20:28:37 +00:00
David Anderson db29503b4d liblp: Remove last_logical_sector from LpMetadataGeometry.
Now that backup metadata is stored at the start of the super partition,
this field is no longer needed. In actuality, it was not needed even
before then: both it and first_logical_sector exist for convenience,
since they can be re-derived at any time given an LpMetadataGeometry.

Bug: 116802789
Test: liblp_test gtest
      device with dynamic partitions flashes and boots

Change-Id: I259a443097e689a0a9db7f822bbf1a52d40076dc
2018-10-12 13:05:12 -07:00
David Anderson a520c5e28b liblp: Don't store BlockDeviceInfo separately in MetadataBuilder.
There's no reason to do this, since the fields are already in
LpMetadataGeometry. Removing this also simplifies multiple-block-device
support.

Bug: 116802789
Test: liblp_test gtest
Change-Id: Ib244a98fdd9d36c94a2dffd81bef68a1d5644ab9
2018-10-12 13:05:12 -07:00
David Anderson 06f7a967be liblp: Move backup sectors to the start of the partition.
Previously, metadata backups were stored at the end of the partition to
make them easy to locate. On older devices where the super partition
could span system/vendor partitions, we may want to leave the end of
each partition free to store an AVB footer. To allow this, we now store
geometry and metadata backups near the start of the partition instead.
They are still positioned at a fixed offset.

Bug: 116802789
Test: device boots after flashing new metadata
Change-Id: Ib173f251a4a13e290adcc4ac5cfbeb030eacda30
2018-10-12 13:05:11 -07:00
Treehugger Robot 5c61dbd12c Merge "fs_mgr: overlay drop redundant check" 2018-10-12 19:51:11 +00:00
Treehugger Robot c53a0e9158 Merge "liblp: Add a gtest for sparse image creation." 2018-10-12 15:18:47 +00:00
David Anderson f89838887f liblp: Add a gtest for sparse image creation.
Note that this moves SparseBuilder into images.h, and splits
ReadLogicalPartitionGeometry into componenet methods for better
testability.

Bug: 116802789
Test: liblp_test gtest
Change-Id: Ib41a46b633c71623c136a10fcc8017e4de20884c
2018-10-11 17:49:50 -07:00
Mark Salyzyn 21afa1693f fs_mgr: overlay drop redundant check
fs_mgr_update_verity_state() provides the needed result, we do not
need to check verity state manually.

Caveat:

The open-coded verity check is not 100% redundant, as it ensures
that if /vendor is not mounted, where the device mount table resides
to aid in a correct enumeration of all verity-enabled mount points,
that /system is not accidentally overlay mounted on a verity checked
volume.  This is a unlikely corner condition.  A fix for this
condition in the future is to instead migrate this redundant
checking into fs_mgr_update_verity_state() since system is
considered ever present and can be blindly performed without the
required /system or / mount point entries in fstab.  Note that
the overlay logic is #ifdef'd out on user builds, so it is not
really a security or reliability issue on a release build.

Test: manual
Bug: 109821005
Change-Id: Ib4a7f9438b2a3cb008e263605a7a7647737c40f2
2018-10-11 13:45:51 -07:00
Mark Salyzyn d556c41a48 fs_mgr: deprecate check for ro.build.system_root_image
If there is a "/" in the fstab, can only be there on system as root.

This drops the troubling and annoying log message:

    [libfs_mgr]Could not find verity device for mount point: /: No such device or address

Test: manual
Bug: 109821005
Change-Id: I6bbfc0af63e1526e52a1c6365241dbc1d5ee7c6a
2018-10-10 14:42:29 -07:00
Mark Salyzyn 69ebd440fe fs_mgr: overlayfs create scratch using a Dynamic Logical Partition
The default is a valid /mnt/scratch/overlay/ or /cache/overlay/
directory, with .../<mount_point>/upper and .../<mount_point>/work,
associated with each system partition <mount_point>.  Add support
for Dynamically Resized Partitions to create /mnt/scratch.

Test: manual
Bug: 109821005
Change-Id: I5e3f66778ea9e937c839e25541fedb6fbf34ab50
2018-10-10 12:26:51 -07:00
Mark Salyzyn b5ca72811c fs_mgr.h cleanup
Drop struct from specifications, fix style.

Test: compile
Change-Id: I94665a41d514501d2f4cd6888361316e08813431
2018-10-10 12:26:49 -07:00
Mark Salyzyn 54e47908c3 fs_mgr: overlayfs deal with verity detection issues
Stop checking verity on each entry in the fstab, collect the verity
list whole and use in the loop.  Open code verity detection for
"system" for cases where device table is incompletely specified, does
not specify a "/" or a "/system" entry.

Test: manual, /system on system-as-root overlays correctly.
Bug: 109821005
Change-Id: I7bc5fbef6577bb0823cb5deb26c370219e4e597b
2018-10-10 07:26:50 -07:00
Treehugger Robot a1bb191541 Merge "Handle retry count correctly" 2018-10-10 00:44:49 +00:00
Paul Lawrence b920cb44aa Handle retry count correctly
Test: vdc startCheckpoint 2 then reboot 3 times checking state

Change-Id: I4eeda7f73d82a7c8b2469571fa558df2fac47354
2018-10-08 14:06:06 -07:00
Mark Salyzyn be29673f30 fs_mgr: fs_mgr_update_verity_state cleanup
Test: compile
Bug: 109821005
Change-Id: Ia2e7074dd4cfb86619da65a4acb1d06b47154070
2018-10-08 11:38:21 -07:00
Mark Salyzyn aace48642f fs_mgr: add fs_mgr_access() as no-errno access(,F_OK) wrapper
Simplification of code paths.

Test: compile
Bug: 74595769
Bug: 63736262
Change-Id: Ie03f3895bc4b520fc23854ab662d99497c31bc66
2018-10-05 15:23:53 -07:00
Mark Salyzyn ea928bbc1f fs_mgr: candidate list check mount_point
if we specify mount_point /vendor, candidate list should not add
/system as a candidate.  eg: adb disable-verity /vendor.

Test: manual
Bug: 109821005
Change-Id: Id4d9ee617262cf1b68a790c9c43476d0f907353a
2018-10-05 15:23:53 -07:00
Chih-Hung Hsieh 747eb149d0 Add noexcept to move constructors and assignment operators.
Bug: 116614593
Test: build with WITH_TIDY=1
Change-Id: I5a7461386946ca623ab509609092aa0ac8418b80
2018-10-05 16:43:47 +00:00
Mark Salyzyn 780db02f7d fs_mgr: split out fs_mgr_overlayfs_setup_dir()
In preparation for adding a list of possible backing storage.

Test: compile
Bug: 109821005
Change-Id: If3664d44c232db32f79b1355799ec239cfe7633a
2018-10-04 15:15:11 -07:00
Mark Salyzyn e511e3a3b1 fs_mgr: Add fs_mgr_overlayfs_required_devices()
Added fs_mgr_overlayfs_required_devices() as hint to init to make sure
the device gets created before fs_mgr_overlayfs_mount_all().

Test: manual
Bug: 109821005
Change-Id: Iab038f3e0252a357b082bb08db3679512b9badec
2018-10-04 15:15:02 -07:00