Commit graph

147 commits

Author SHA1 Message Date
Mark Salyzyn
dffdb4374b fs_mgr: overlayfs: export fs_mgr_overlayfs_candidate_list
Refactor fs_mgr_candidate_list into fs_mgr_overlayfs_candidate_list
that reports all the possible candidates.  The caller is responsible
for filtering out any that have verity enabled.

Sundry improvements to the adb-remount-test.sh script to improve
stability and feedback.

Test: adb-remount-test.sh
Bug: 122602260
Change-Id: I2399f83d8ed77d8f3d2ad1405d0c187ccbace764
2019-02-13 10:49:18 -08:00
Tom Cherry
cf80b6d6e5 Refactor fs_mgr_update_verity_state()
fs_mgr_update_verity_state() has two callers with generally different
intentions.  One caller loops through all entries in the default fstab
to set partition.<mount_point>.verified properties.  The other caller
is only interested in whether or a specific mount point has verity
enabled.

Given this, we refactor fs_mgr_update_verity_state() to
fs_mgr_get_verity_mount_point() which takes a single FstabEntry and
returns the mount point used for the dm-verity device or an empty
option if verity is not enabled on that mount point.

Test: adb-remount-test.sh test on blueline
Change-Id: Ic7dd8390509e95b2931b21e544c919a544138864
2019-02-11 12:50:22 -08:00
Tom Cherry
685c2c7b1e Remove old C fs_mgr interface
Remove superfluous fs_mgr flags as well.

Bug: 62292478
Test: tree hugger, fs_mgr_unit_test
Change-Id: Ib307400941b46ca8bcb51d479668efd82fc3ed2d
2019-02-04 15:09:02 -08:00
Tom Cherry
a3530e6366 Add android::fs_mgr namespace for new Fstab code
Should have been done a while ago, but better late than never.

Test: treehugger
Change-Id: I0ea6e8d459cd3f3b3ce2d00a7a6a9786d52c52dd
2019-01-30 20:20:05 -08:00
Tom Cherry
2e545f8b2f fs_mgr: make changes needed to port vold to new Fstab interface
Particularly, capitulate that GetEntryForMountPoint() would be cleaner
than std::find_if() and update the rest of system/core to use it.

Test: build

Change-Id: I982b5a8552d44852d3ab22c20db83afcd4dd652b
2019-01-29 14:56:49 -08:00
Tom Cherry
b688d917cd Remove the rest of users of the old style fstab
And deprecate one more old style function that is not used after this
change.

Test: boot, disable and enable verity
Change-Id: Id509f479850120352b4ea4dc3b6c40f6e8e2e53e
2019-01-28 12:34:33 -08:00
David Anderson
908f07b0b8 fs_mgr: Add a helper for creating one-off dynamic partitions.
This will be used by gsid to invoke mkfs.ext4 on the userdata_gsi
partition. Since the extents are not located on the super partition, we
need a helper method that takes in an LpMetadata.

Bug: 121210348
Test: manual test
Change-Id: I00467ace8a745fb0c0d130babfda1a2d5d97c208
2019-01-07 18:31:54 -08:00
Yifan Hong
bf80e7dd91 Move parts of roots.cpp from librecovery
Move some mounting functionalities from librecovery so that
other modules can also mount logical partitions correctly.

- Also, refactor to use C++ Fstab struct.
- Also, fixed CreateLogicalPartitions() to take full path of
super device.

Test: run recovery tests
Test: vintf_object_recovery_test

Bug: 118634720
Bug: 113182233
Bug: 62292478
Change-Id: Ie02c3a941ed801fdae5818099faf5f3863444296
2018-12-19 10:23:50 -08:00
Yifan Hong
0cd2d5f048 fs_mgr_do_mount_one: allow overriding mount_point
Test: boots
Bug: 118634720
Change-Id: Ie2d05fdead27bfb1c922749272ff648bc7c418d1
2018-12-19 10:23:50 -08:00
Tom Cherry
23319ebebf Start using new C++ Fstab class widely
Bug: 62292478
Test: boot
Test: adb-remount-test.sh

Change-Id: Id4715af4c1f03e2cfc67de92d3ea58e933685e51
2018-12-12 17:08:09 +00:00
Tom Cherry
02eff5cccd Update fs_mgr_update_verity_state() for new C++ Fstab
Bug: 62292478
Test: boot and check verity state
Change-Id: I4912a16ada9a6d72480d7ac905654b764c5d18b6
2018-12-07 14:14:54 -08:00
Treehugger Robot
323ca1ea6b Merge "fs_mgr: Add fs_mgr_overlayfs_is_setup()" 2018-12-06 01:01:06 +00:00
Tom Cherry
e1e71b9b98 Merge "init: allow first stage mount to read an fstab" 2018-12-05 20:32:08 +00:00
Alistair Strachan
5d55580fe1 Merge "Handle renamed "super" device correctly" 2018-12-05 00:06:41 +00:00
Alistair Strachan
1906d5f357 Handle renamed "super" device correctly
In the non-retrofit case, the metadata source partition will be
hardcoded as "super", but such a partition may not exist or may have
been overridden by super_partition=<something>. Make this work reliably
by plumbing the resolved metadata block device through, and using it any
time a partition called "super" is requested.

This also fixes a case in the first_stage_mount code that assumed that
detected a non-A/B, non-retrofit case by assuming the metadata source
partition would be called "super".

Bug: 113175337
Test: boot test on cuttlefish
Change-Id: I8ce1defb902e257eeb7170d697b378eba31faee3
2018-12-04 11:21:34 -08:00
Mark Salyzyn
dd748aa41c fs_mgr: Add fs_mgr_overlayfs_is_setup()
Provide a means to determine if overlayfs is currently active with
fs_mgr_overlayfs_is_setup().  Search for current clues in the system
that the overrides are in play.  If /mnt/scratch/ is mounted, that
may be enough of a smoking gun because the resource itself may
interfere with operations.

Related to update_engine calling this function to reject performing
an OTA as its operations are incompatible with the overrides.

Test: adb-remount-test.sh
Bug: 120034852
Change-Id: I641163b1559c1a83fe7d0c336d04c10e9956ad3a
2018-12-04 11:06:47 -08:00
Tom Cherry
e68bf85fd6 init: allow first stage mount to read an fstab
Now that we have a first stage ramdisk (or use recovery in its place),
it's possible to place a vendor specific fstab along with first stage
init, removing the need for device tree modifications to have an
fstab.

Bug: 117933812
Test: hikey boots with only an fstab in first stage ramdisk
Test: blueline mainline boots with a disabled DT fstab and an fstab in recovery
Change-Id: I4460b88851557a75ba06ff795cd842e7dfb6da46
2018-12-04 11:06:30 -08:00
Tom Cherry
3055457a96 Convert fs_mgr_swapon_all() to use the new Fstab struct
Bug: 62292478
Test: build
Change-Id: Ifbde514bf73d3ce2f321326291daa025b6afac46
2018-12-03 09:41:01 -08:00
Bowgo Tsai
c1bc2813c9 fs_mgr: move AVB related source into libfs_avb
This CL also adds namespace android::fs_mgr and remove FsManager* prefix
for class names. Note that android::fs_mgr::FsManagerAvbOps will be removed
in later CLs when fs_mgr doesn't rely on libavb->avb_slot_verify() to
parse vbmeta structs.

Some lingering sources for by_name_symlink_map_ are also removed.

Bug: 112103720
Test: boot crosshatch_mainline-userdebug
Change-Id: I2d1a5cc39bcd5a699da8d5539f191d8c7737c4af
2018-11-29 22:21:33 +08:00
Tom Cherry
9856460763 fs_mgr: remove by_name_symlinks_map_ from AvpOps
With the addition of the /dev/block/by-name/ symlinks created for the
boot_device, we no longer need to use a map to track the symlinks for
the partitions AVB needs to access.

This will help us in removing the requirement to specify which
partitions contain AVB metadata.

Bug: 117933812
Test: boot blueline_mainline with AVB
Change-Id: I1d46dba5b2fc16b2a14f861b34225ac0f2995b60
2018-11-13 11:37:36 -08:00
Mark Salyzyn
6a11694c1b fs_mgr: overlayfs earlier kernels do not need override_creds=off
Kernels at or older than 4.6, the overlayfs drivers do not need,
or support, override_creds=off.  Drop using the mount option.

Commit 3fe6e52f062643676eb4518d68cee3bc1272091b introduced the
need for override_creds=off, and none of the kernels that contain
this patch without the patch that introduces override_creds can
be used with Android.

Test: compile
Bug: 118882257
Bug: 109821005
Change-Id: I832c8ca3fce0269bdef4ce988541adb7ba9662ed
2018-11-07 11:05:18 -08:00
David Anderson
f89b1df1a5 init: Regenerate uevents for dependent super partition devices.
This patch adds another uevent-regeneration pass to the first stage
mount. When the super partition spans multiple block devices, we need
/dev/block/by-name symlinks to have been created before we begin mapping
dynamic partitions.

Bug: 116802789
Test: retrofit device boots
Change-Id: I00bb277e1d81385a457c5b4205a95d8fbe365bb2
2018-11-05 17:53:49 -08:00
Justin Yun
6bab0a9c23 Mount vendor overlay from the system partition
Using overlayfs, the system partition may provide files for older
version of vendor partitions by overlaying on the vendor partition.
Directories in /system/vendor_overlay will be overlaid on the
directories in /vendor to override existing files or provide new
files.

This feature works only if the kernel support overlayfs and has a
patch for override_creds. Otherwise, no-op.

Bug: 114679254
Test: Build and boot: nothing affected without overlayfs, or
                      vendor file is overrided with overlayfs

Change-Id: Iff3a308945299034123ba7bcb40dc787e102730e
2018-11-01 10:26:12 +09:00
Mark Salyzyn
a762e007c5 fs_mgr: overlayfs takes const std::vector<const fstab_rec*>&
fs_mgr_overlayfs_mount_all() and fs_mgr_overlayfs_required_devices()
to also take const std::vector<const fstab_rec*>& argument.

Bug: 117933812
Test: manual adb-remount-test.sh
Change-Id: Ic72fcca1fe32c311ff3f903c7275e6f7dfba46a7
2018-10-31 14:42:44 +00:00
Mark Salyzyn
1b066c313b fs_mgr: fs_mgr_has_shared_blocks() needs logical blk_device
For logical partitions, the fstab supplied during
fs_mgr_overlayfs_setup() does not have the correct blk_device and
thus check in fs_mgr_has_shared_blocks() inside
fs_mgr_overlayfs_enabled() will fail to provide the correct status.

Call fs_mgr_update_logical_partition() to fix this up.  Side effect
is an API change where fstab can no longer be considered const when
passed into fs_mgr_overlayfs_mount_all() and
fs_mgr_overlayfs_required_devices().

Some additional minor cleanup as well.  Move fs_mgr_rm_all() higher
up as-is in the file as it has no dependencies, which will complicate
future changes.  Add --help to adb-remount-test.sh unit test script,
improve error handling and checking.

Test: adb-remount-test.sh
Bug: 109821005
Bug: 117605276
Change-Id: I548d3797d49661529490d1a0bf96b63e57491704
2018-10-26 22:54:46 +00: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
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
David Anderson
5cbd2e43ee Don't hardcode the super partition name.
If a device has logical partitions but does not use a partition called
"super", we will need this to be configurable. Note that the "slot"
argument is currently unused, but will be necessary for update_engine if
there are A and B super partitions.

Bug: 116608795
Test: super partition works
Change-Id: Ieb548a158faeb423f3561230f26d582325efbc6b
2018-10-01 14:13:22 -07:00
Mark Salyzyn
f35db9b11b fs_mgr: init: adb: add fstab argument to fs_mgr_overlayfs_mount_all
Add an fstab argument for fs_mgr_overlayfs_mount_all so that it can
leverage the locally and timely acquired fstab entries.  Affects all
callers, adb and init.

Test: manual
Bug: 109821005
Bug: 115751838
Change-Id: I96e2045d88525a6ce39bef63327a0fcf0704e9bc
2018-09-25 07:30:55 -07:00
Daniel Rosenberg
4c93b256f6 fs_mgr: Support checkpoints
Adds support for partitions with checkpointing enabled. If the
checkpoint= fs_mgr flag is set, and the system has checkpointing on,
the partition will be mounted in checkpointing mode.

Test: Use vdc checkpoint commands, the checkpoint=fs fs_mgr flag
      in the fstab, and a kernel containing the f2fs checkpoint
      changes. https://lkml.org/lkml/2018/8/21/22
Change-Id: I3ea8da932de06fcfd2eed06b8640a8b1df837f1f
2018-09-20 17:28:23 -07:00
David Anderson
c8ac4e7644 fastbootd: Wait for /dev/block paths when opening logical partitions.
Note that in addition to waiting for the path to appear, we must also
wait for it to be unlinked. Otherwise, we could accidentally access an
older device when opening and closing the same partition twice in a row.

Bug: 114198005
Test: fastboot flashall works
Change-Id: Iddffc34e1ac8aa066c28e7b1a92b09b6dfd7945c
2018-09-06 17:38:06 -07:00
Mark Salyzyn
3ff87d89ef fs_mgr: add fs_mgr_has_shared_blocks and make default if overlayfs
Add fs_mgr_has_shared_blocks in fs_mgr.  Use it as a default decision
to utilize overlayfs if not overridden by the platform.

Test: compile
Bug: 109821005
Change-Id: Ifab22a4c9898966515e268349c24bb4c28a39368
2018-08-15 10:07:27 -07:00
Mark Salyzyn
b28389f5ee fs_mgr: add overlayfs handling for squashfs system filesystems
Logistics for adb remount on developer builds for readonly system
partitions using overlayfs to deal with not being able to remount
with read-write.

Conditions are that filesystem is squashfs, read-only, debug build,
kernel supports overlayfs.  The default is a valid /cache/overlay/
directory, with .../<mount_point>/upper and .../<mount_point>/work,
associated with each system partition <mount_point>.

Will take the sepolicy of context of lowerdir as rootcontext= option.

Add fs_mgr_overlayfs_mount_all() to recurse through
fs_mgr_read_fstab_default(), and checking against /proc/mounts to
add any acceptable overlayfs mounts.  The checking with /proc/mounts
makes sure we do not overlayfs overtop an overlayfs.

Add fs_mgr_overlayfs_setup(const char*, const char* bool*) and
fs_mgr_overlayfs_teardown(const char*, bool*) to respectively setup
or teardown the overlayfs support directories.  Return value
includes success and optional supplied change booleans.

Test: compile
Bug: 109821005
Bug: 110985612
Change-Id: Ie9b4e9ca0f2bdd9275ac2e2e905431636948e131
2018-08-08 15:38:53 -07:00
David Anderson
4d71d85805 liblp: Allow flashing to readonly logical partitions.
By default, logical partitions with the readonly flag are created with a
readonly device. This change allows callers of CreateLogicalPartition
to create writable devices so they can still be flashed.

Bug: 78793464
Test: fastboot flash product_services works with fastbootd
Change-Id: Ia8d2761a3067e3b62815acbf0b6fb7f033072ba2
2018-08-06 15:47:26 -07:00
David Anderson
23de22d54b fs_mgr: Add a method for creating one-off partition instances.
fastbootd needs to temporarily map and unmap logical partitions in order
to flash them. To make this easier, this change introduces fs_mgr
methods to create and destroy a single logical partition by name.

Bug: 79173901
Test: N/A
Change-Id: Ic085f2175c26a5edf5f18544012dcfe6d8088f09
2018-07-23 11:43:27 -07:00
David Anderson
e0384bbc69 fs_mgr: Remove early prototype code.
This early code is no longer needed now that logical partitions can be
created and flashed normally.

Bug: 79173901
Test: N/A
Change-Id: I393ef23b3d3ce1cd9c80833358051838d0e9f333
2018-07-19 14:38:33 -07:00
Mark Salyzyn
b5065fcb28 fs_mgr: fs_mgr_update_verity_state take std::function
By changing to a std:function from a plain function pointer as an
argument to fs_mgr_update_verity_state(), a lambda with captured
objects can be executed providing thread safety.

Test: compile and boot
Bug: 109821005
Change-Id: I2699a08cc2c5216625dcbf84eeac0c460f4ae36a
2018-06-28 08:43:35 -07:00
David Anderson
4b52440812 fs_mgr: Use libdm for dm-linear devices.
This removes the custom ioctl code in fs_mgr_dm_linear.cpp in favor of
using libdm.

Bug: 110035986
Test: logical partitions are still created in first-stage init
Change-Id: I941a27ce865aa1bc712b91d8d4c874462e0d11df
2018-06-25 12:56:15 -07:00
David Anderson
6590df2763 init: Create logical partitions via liblp.
Currently, init can create logical partitions by hardcoding them in
fs_mgr or by specifying them in device-tree. This change allows init to
also create logical partitions by using liblp, which stores partition
tables in a physical partition. The current name for this partition is
"android".

Two aspects of this code will change long-term. One, the prototype code
using device-tree will be deleted once fastboot supports logical
partitions. Two, libdm will obsolete most of the code in
fs_mgr_dm_linear.cpp. For now however we preserve how the prototype code
functions and we layer liblp on top of the existing dm_linear logic.

Bug: 79173901
Test: N/A
Change-Id: If014a109da78fa12269bf0df0dda39028ac2d1aa
2018-06-19 14:03:58 -07:00
Tom Cherry
e6eabf42f2 fs_mgr: remove some unused functions
Test: build
Change-Id: I8a44f2f777fff369df06c73f06d53e448826f7b5
2018-06-07 16:49:01 -07:00
David Anderson
62e5b20b50 init/fs_mgr: prototype first-stage dm-linear support
This adds an API to fs_mgr for reading dm-linear tables out of device trees
and issuing device-mapper ioctls. The device tree code will be
implemented separately. The dm-linear structures in fs_mgr are organized
assuming we may want to pull them from sources other than DT (for
example, text files, binary blobs, or something hardcoded for testing).

File systems which are mounted from these logical partitions have
specific fstab requirements. The block device must be a partition name,
and if Verified Boot is used, that name must match the vbmeta partition name.
Second, the entry must have the "logical" fs_mgr flag. Example fstab
entry:

    vendor  /vendor  ext4  ro  wait,logical

Example fstab entry in device tree:

    vendor {
        compatible = "android,fstab";
        dev = "vendor";
        type = "ext4";
        mnt_flags = "ro";
        fs_mgr_flags = "wait,slotselect,avb,logical";
    };

Bug: 78914864
Test: N/A
Change-Id: I4d8878ea8858f26310119616cadc3ee0dd08566c
2018-05-14 12:43:42 -07:00
Bowgo Tsai
a4b15d7e2c Merge "fs_mgr: removing __BEGIN_DECLS and __END_DECLS"
am: 85b80dc18d

Change-Id: I6c86972b32534f7962656531de072a2ccc654ed8
2017-10-11 01:53:35 +00:00
Bowgo Tsai
d837f837ad fs_mgr: removing __BEGIN_DECLS and __END_DECLS
fs_mgr isn't usable by C now as we've migrated all fs_mgr clients in AOSP
to CPP. Removing the support for C clients.

Bug: 67024518
Bug: 67444051
Test: boot sailfish

Change-Id: Iac57f51eb6a524c6dcdc625c83af75602b4f9b3b
2017-10-10 18:17:29 +08:00
Jiyong Park
28bd98999b resolve merge conflicts of 645026c74 to oc-dr1-dev-plus-aosp
Test: I solemnly swear I tested this conflict resolution.
Merged-In: If8fc73e4ae4c2f8281c41a12f1c18079aab8baa2
Change-Id: Iadfcd7e75044d62f2015dc62c69ee68869b40cd7
2017-06-28 22:52:25 +09:00
Jiyong Park
e7df1f7623 fs_mgr: add libfstab for vendor
libfstab is a subset of libfs_mgr, intended for vendors to use. It
exposes APIs for reading fstab. Note this 'visible to vendor' does not
mean that the API should be stable forever. The API can be changed in
later releases of Android, ,but the newer Android must not cause
run-time error when there is an older version of this static library
being used somewhere.

Bug: 62990533
Test: BOARD_VNDK_VERSION=current m -j libfstab.vendor
Change-Id: I371174fa1f6b4de6d6dd437b84ce4ed1e8740672
Merged-In: If8fc73e4ae4c2f8281c41a12f1c18079aab8baa2
2017-06-28 11:24:25 +09:00
Bowgo Tsai
61cdb66230 Merge "AVB: allow no metadata in the generic system.img for project Treble" am: c70bf5836c am: caa5b4417f
am: 2410d0c792

Change-Id: I5b03a7ac1cdb883df27aca8122c4a1383d805126
2017-06-24 01:51:47 +00:00
Bowgo Tsai
2410d0c792 Merge "AVB: allow no metadata in the generic system.img for project Treble" am: c70bf5836c
am: caa5b4417f

Change-Id: I4859e15d3bf05c22a708761e91b2e52fbb28ca1f
2017-06-24 01:40:33 +00:00
Bowgo Tsai
60f19a0792 AVB: allow no metadata in the generic system.img for project Treble
The generic system.img released from project Treble can't contain any verity
metadata (e.g., vboot 1.0, AVB, or any other implementation) because it's
*generic*. To make any device can boot with it, `avbctl disable-verification`
is introduced to set a new flag AVB_VBMETA_IMAGE_FLAGS_VERIFICATION_DISABLED
in the top-level vbmeta to disable the entire AVB verification process. This
should be done prior to flash the generic system.img. See the following link
for details:

    https://android-review.googlesource.com/#/c/418399/

This CL checks whether AVB_VBMETA_IMAGE_FLAGS_VERIFICATION_DISABLED is
set in the top-level vbmeta. When set, skip verifying the vbmeta structs
against androidboot.vbmeta.{hash_alg, size, digest} because it will be
absent in kernel cmdline. Also, only top-level vbmeta struct is read then
returned by libavb in this case.

Note that another flag AVB_VBMETA_IMAGE_FLAGS_HASHTREE_DISABLED, usually
set by `adb disable-verity`, is used to signal fs_mgr to skip setting up
dm-verity, but libavb still verifies all vbmeta structs. fs_mgr will
also verify all vbmeta structs against androidboot.vbmeta.{hash_alg,
size, digest} from kernel cmdline as well.

Also rename SetUpAvb() to SetUpAvbHashtree() to better fit its usage.
This function will return kDisabled when any of the above two flags is set.

Finally, regardless of which flag is set or not set, we still only allow two
return values from avb_slot_verify():

   - AVB_SLOT_VERIFY_RESULT_OK: it's still possible to get this value
     when any of these flags are set in build time. e.g.,
     BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS=--flags 2

   - AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION: in most cases we should
     get this value, because the flags are likely set at run time.

Bug: 62523303
Test: boot device with 'avbctl disable-verification'.
Test: boot device with 'avbctl enable-verification'.
Test: boot device with 'adb disable-verity'.
Test: boot device with 'adb enable-verity'.

Test: build image with BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS=--flags 2, then boot device.
      repeat the above steps to boot device again.

Change-Id: Ie8436f3e0e82c78490208f3b85eac5238a9fdfdb
2017-06-24 09:20:15 +08:00
Sandeep Patil
2980f49447 Merge changes from topic 'eng_first_stage_mount' am: b7e2f272ee am: e5341cf56a
am: 91b5f4b172

Change-Id: Iea367c4aa1a9fe381c4b5b4b23f6365035b4939d
2017-06-22 00:15:48 +00:00
Sandeep Patil
91b5f4b172 Merge changes from topic 'eng_first_stage_mount' am: b7e2f272ee
am: e5341cf56a

Change-Id: I285217db1c18adfcc10d31280c1ec55d80052e43
2017-06-22 00:08:17 +00:00