Commit graph

34 commits

Author SHA1 Message Date
Tom Cherry
54ea49ba05 Merge "Add android::fs_mgr namespace for new Fstab code" 2019-01-31 19:35:54 +00: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
Jiyong Park
7c7189c469 Handle adb sync with Bionic under /bionic
Background:
We now have two sets of Bionic: the bootstrap Bionic which is at
/system/{lib|bin}/bootstrap for early processes and the default Bionic
which is from the runtime APEX for all the others. In order to give the
same path for Bionic to both categories of processes, the init prepares
two mount namespaces and bind-mount appropriate Bionic files onto the
common mount points under /bionic. For example,
/system/bin/bootstrap/linker is bind-mounted to /bionic/bin/linker for
the early processes. Likewise, /apex/com.android.runtime/bin/linker is
bind-mounted to the same path for rest of the processes.

In addition, in order not to propagate mount events in one mount
namespace to the other namespace, /bionic itself is created as a mount
namespace (via self bind-mount) and its propagation type is set to
private.

Changes required:
This however requires some adjustments to adb sync and remount
mechanism.

For remounting, /bionic path should also be re-mounted for RW, because
it is a RO mount in the beginning. This remounting is done only for the
system-as-root devices where entire / can be re-mounted as RW.

For synching, the sync thread creates a temporary mount namespace where
there is no bind-mount. This ensures that a path that the thread handles
is pointing to the correct file that is expected from the client side.

In addition, push operation to /bionic path is done without unlinking.
This is required because the mount points under /bionic are gone in the
current mount namespace but are still active in other mount namespaces.
If unlinked, the existing mounts on the path are all silently removed.
In order to prevent the unwanted situation, the moint points are not
unlinked but truncated to 0. This however is not a significant problem
because the files that serve as mount points do not carry any
useful information (i.e. the content is meaningless).

Bug: 879416
Test: adb sync
adb push <random_file> /bionic/bin/linker64
adb push <random_file> /system/bin/bootstrap/bin/linker64
system/core/fs_mgr/tests/adb-remount-test.sh
Change-Id: Id87dc9ee7ec5c43d06b54969b55e2cb394329317
2019-01-30 19:18:22 +09:00
Tom Cherry
eb6da459a0 fs_mgr: test parsing all mount and fs mgr options
Test: these new unit tests
Change-Id: Ibdecf0c97b313dc157b982340ca022b617757383
2019-01-25 16:03:52 -08:00
Tom Cherry
7e34f75075 fs_mgr: store file_contents_mode and file_names_mode directly
It doesn't really make sense to have extra logic to convert these
strings to enums then back again to strings for usage, especially
since with the C++ fstab, these strings are small enough to fall into
the small string optimization of std::string.

This will help make future changes cleaner as well.
Test: boot, fs_mgr_test

Change-Id: I5669ed10f2fc3eafdb137747446a2e93c24d55c4
2019-01-25 11:14:29 -08:00
Tom Cherry
afa0d88eea Merge "Update fs_mgr tests for new fstab format and add to TEST_MAPPING" 2019-01-25 17:25:58 +00:00
Mark Salyzyn
91ed3340d5 fs_mgr: overlayfs: test: test mount -o rw,remount command
WAI: Using mount -o rw,remount command can only work after the
overlays are setup.  After the second 'adb disable-verity' or
'adb remount -R' has been issued; the first only disables
verity and does not setup the backing storage.  If mount remount
command is issued after the first on an overlayfs system, it will
report a r/o filesystem.

Add a test that confirms that at least this supported behavior is
working, we do not test the corner case.

In the case of overlayfs, we have declared we will not support the
mount remount operation until then; we would need to modify toybox
to add logic that resides inside adb remount service.  toybox is
allowed to be adjusted to compile under Android and bionic, but it
is not supposed to have code that is specific to Android.

Fix last test to before this one to move us back into this state.
Fix the adb_sh command parser to handle properly quoting arguments
as it passes them to adb, since we will need it working for this
added test.

Report the product serial number of build description to aid triage.

Test: adb-remount-test.sh
Bug: 109821005
Bug: 122602260
Bug: 123079041
Change-Id: Ida051dbe2a918182db97f0f22f64b299e3c0a068
2019-01-23 14:41:49 -08:00
Tom Cherry
4e904768f7 Update fs_mgr tests for new fstab format and add to TEST_MAPPING
And fix a bug in the meantime, where mounts with no filesystem
specific mount options were incorrectly having an empty string in
their set of mount options.

Test: this test
Change-Id: I9b1f14d00a90f8b95a13fcecb3cfa7fe10a2f96a
2019-01-23 11:28:00 -08:00
Mark Salyzyn
52490faabe fs_mgr: overlayfs: test: check for existence of userspace fastboot
If there is no userspace fastboot, then overlayfs has a corner case
bug where overlay content is not wiped when the partition is flashed.
We will report a warning instead.

This is done to reduce the flakiness of the test results as we do not
intend to fix this specific corner case in the short term.  We would
require to record a sha representing the flash image, and the risks
were evaluated as too high of an impact on libavb to add interfaces
to expose the signatures, especially at first stage mount time.  All
new devices must support Dynamic Android Partitions (DAP), which
means they all have support for userspace fastboot, it will be
considered a misconfiguration and thus the position is we will not
fix this issue and only use this test adjustment to deal with legacy
products.  If a legacy non-DAP product wishes to close the issue
today, they must supply a user space fastboot.

Test: adb-remount-test.sh
Bug: 109821005
Bug: 123079041
Change-Id: I420cb87c19e3e184a974dfc373fb17c097d4858f
2019-01-22 15:28:38 -08:00
Mark Salyzyn
3fe0a8164d fs_mgr: overlayfs: test: check for ext4 dedupe needing overlay
Check if any system partition looks like it has ext dedupe or
rather shared_blocks feature enabled, if so then we expect
overlayfs to kick in.  We do this to deal with any flakiness
in the test when right-sizing is not applied to the platform.

Minor: older devices mounted persist to /persist.

Test: adb-remount-test.sh
Bug: 109821005
Bug: 123079041
Change-Id: Iab7c6cf7f24f2c446aeb149e3f65d6793a42c6ea
2019-01-22 15:28:23 -08:00
Mark Salyzyn
546e76f1c7 adb_remount_test allow to run on eng builds.
Test: adb_remount_test.sh
Change-Id: I06e7a5e217e2769fc9eb95f6e9a6dcdfd56a8ad2
2019-01-17 13:42:25 -08:00
Mark Salyzyn
7d6431d852 fs_mgr: overlayfs: test fix problems with runtime apex bind mounts
bind mounts create administrivia in /proc/mounts that can not be
easily discerned to confirm expectations.  We squash the stutter,
and filter out overlay backing references for /system/<path>/<file>.

Test: adb-remount-test.sh
Bug: 122737045
Change-Id: I61342f5f76f54a1a8201a52efb8054acde100a6f
2019-01-15 11:42:03 -08:00
Justin Yun
d3e2a78a99 Exclude mount entries for vendor overlay
When testing adb-remount with overlayfs, vendor overlay may fail the
test because there are unexpected overlayfs uses by vendor overlay.
By excluding mount entries for vendor overlay, the test runs
regardless of vendor overlay mount.

Bug: 122231184
Test: run adb-remount-test.sh with vendor overlay mount
Change-Id: I795774b27d5e5f973792337813b67487a5d72e29
2019-01-10 00:40:33 +00:00
Bowgo Tsai
fa416f9bec Support host build for libdm and libfstab
The host builds for both libs are needed for libfs_avb host unit test.
Also replaces strlcat()/strlcpy() with snprintf() because the former
doesn't have a glibc version. Or switch char* to std::string*.

Bug: 112103720
Bug: 117960205
Test: m libdm ARCH=x86_64
Test: m libfstab ARCH=x86_64
Test: atest libdm_test
Test: atest fs_mgr_unit_test
Test: boot a device

Change-Id: Id9b92b5286b8ed9ab0d80f18ab5802dcfeb83dfa
2019-01-08 17:56:56 +08:00
Mark Salyzyn
b3c0074917 fs_mgr: overlayfs test fix adb_sh
Some commands like 'adb_sh grep " rw," /proc/mounts' do not preserve
the embedded spaces when transferred to the device and thus do not
entirely behave as expected.  There are several commands issued this
way throughout the test that are similarly broken.  To add
consistency, pass any arguments that are not explicitly (double)
quoted and contain embedded spaces as quoted to preserve.

Also devices that report the kernel internal device /dev/root in
/proc/mounts should be suppressed when investigating whether
overlayfs is needed.  If /dev/root is reported, then we should assume
that the mount point / represents it for the following df command
when trying to determine if the partition is right-sized.

When there is only one device attached, and a serial number is not
specified, correctly determine this condition to progress to
the testing.

Test: adb_remount_test.sh
Bug: 122231184
Change-Id: I913e297dd272d6691110bb5d7a7c7f54321b6833
2019-01-07 21:39:56 +00:00
Mark Salyzyn
38a17f0d76 fs_mgr: overlayfs: test issues with single super device
Cleanup test issues with single super device.  Indicate mount point
instead of partitions as that can lead to confusion when referencing
the partition when there is none.  For example root (/) partition
uses overlay on /system.  Resolve a script syntax error when there
are no devices.  Fix script logic surrounding detection of overlayfs
takeover and handling of reboot device request from
adb disable-verity.

In README.overlayfs.md discuss
BOARD_<partitiion>IMAGE_PARTITION_RESERVED_SIZE and its negative
impact on right sizing.

Soften README.overlayfs.md wording with respect to update_engine
to match changes in handling.

Test: adb-remount-test.sh
Bug: 120536582
Bug: 109821005
Change-Id: Iad7e19a436322ff9c3bdc597f4545028be112ff5
2018-12-17 11:26:03 -08:00
Mark Salyzyn
436464ab71 fs_mgr: overlayfs: test w/o sepolicy in enforced mode
Skip sepolicy test if device is not in enforcing mode.

Test: adb-remount-test.sh
Change-Id: I1558674819bda0c9f575d5202f693fec55c9d84f
2018-12-13 16:48:41 -08:00
Mark Salyzyn
f7572ec8ff fs_mgr: overlayfs: test inAdb and inFastboot
If no serial number is supplied, then check if there is 0 devices

Test: adb-remount-test.sh
Change-Id: Ie78c379078d3d99d67594a5be1a22795bfcc6d36
2018-12-13 16:19:35 -08:00
Mark Salyzyn
da27fa0b53 fs_mgr: adb-remount-test in non overlayfs world
Extend test script to check non overlayfs case too.  Establish
whether overlayfs is supported, or needed, and adjust expectations.
For the flash vendor code, make sure it is the _right_ vendor,
skip instead of fail.

Improve quality of the testing and handle more cases.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: Ic9957cb378d8e7737ffc4ba04078c1cb6bbd1bbd
2018-12-12 14:21:42 -08:00
Mark Salyzyn
f269312466 fs_mgr: overlay: use alternate for backing storage
When we have multiple physical super partitions, it is prudent to
take the alternate super physical partition in its raw entirety
rather than to construct a logical partition out of the current
super partition's limited remaining space.

SideEffect: alternate boot partitions destroyed for the sake of debug
Test: adb-remount-test.sh (including manually disabled to check
      both code paths).
Bug: 119885423
Change-Id: I368d3a5619f69de3b0d1fcad73c4b42d25d0d969
2018-12-05 14:01:59 -08:00
Mark Salyzyn
03d6f9a176 fs_mgr: overlay: test assumption wrong if verity is enabled
Test script assumes overlayfs takeup after disable-verity, although
that can happen if verity is already disabled, it is not the case
for devices that just had it disabled.  Move takeup and first stage
init tests downwards to where the condition is guaranteed.

Differentiate the test for devices that support or have verity, and
those that do not.

Fortify test to also use /data mount to check init first stage limit.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: I5241d6c97bf374614e50aa0aa18a1b9d118be093
2018-11-30 07:49:32 -08:00
Mark Salyzyn
a30b6964d6 fastboot: propagate error for format command
If fastboot format command fails, return error.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: Ic4e1a1dea8861028f19ac7f9c834d26e8adba56c
2018-11-27 13:51:42 -08:00
Mark Salyzyn
cb2f6b6776 fs_mgr: overlayfs: resize scratch should it be too small
If scratch gets made too small (eg: fastboot flash scratch small-file)
it can not recover without a workaround.  The workaround is not
intuitive, (adb enable-verity then adb disable-verity to erase and
re-establish the proper sized scratch.  This needs to be automatic.
If we detect it is too small to support a filesystem, resize it to an
more appropriate size if it exists.

Alter unit test to check for fastboot characteristics and assumptions
associated with the scratch partition, and a test case to flash the
partition.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: Icfceaa461c2bf13ca5a7dd4e34675dde8a4d251f
2018-11-27 13:46:55 -08:00
Mark Salyzyn
271485feba fs_mgr: overlayfs: test: adding diagnostic value
Add a test report df before overlay applied to make it clearer what
the device looked like before applying for remount.  Check error
code from adb disable-verity and use that to terminate test if bad.
Collect a sliced logcat for failures to help diagnose problems.
If the device does not come back after flashing, timeout and fail
when waiting.  Fix some issues that result when running script under
set -x when diagnosing the tests logistics.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: Iffbd6261703393417cb6ec3a12042d59523c348d
2018-11-15 23:02:29 +00:00
Mark Salyzyn
0733a86990 fs_mgr: overlayfs: test: skip apex mounts
Strip out /dev/block/loop* devices to filter out apex mounts.  Deal
with scale of skip_administrative_mounts function to make for easier
maintenance.

Test: adb-remount-test.sh
Bug: 109821005
Bug: 112455435
Change-Id: Ic7382a613db8f3ac7cdc10721194042378d136b9
2018-11-15 23:01:27 +00:00
Mark Salyzyn
beb4cb8e43 adb: overlayfs failed to remount /system
Regression introduced commit bb1efbd1c6

By not first checking if overlayfs mount on /system is in /proc/mounts
remount fails to discover the override and take the selected action.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: I1f0bae22caae1bca84fc1e33b508b54d98f4ed5c
2018-11-06 09:49:10 -08:00
Mark Salyzyn
2fde1ec836 fs_mgr: overlay backing, force filesystem for f2fs
Under the condition of an existing, but broken, filesystem on the
scratch device, force recreation. Add the -f flag for f2fs,
already present for ext4.

Test is enhanced.  The test needs to check, and if necessary wipe
out any existing overrides and reboot before running the remainder
of test.  Report which overrides are being used, and how they are
setup.  Fail if they are not as expected.  Improve efficiency of
checks by reducing the duplication of commands issued to the device.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: I9ac4fac952e334c00b089fec0b73b2cd2cc0af5c
2018-11-02 13:41:07 -07:00
Treehugger Robot
b7d9b6a995 Merge "fs_mgr: fs_mgr_has_shared_blocks() needs logical blk_device" 2018-10-29 22:18:37 +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
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
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
Tom Cherry
f274e78eeb fs_mgr/init: use unique_ptr + CLO_EXEC for setmntent()/fopen()
We ran into an issue with an fd leaking due to missing both CLO_EXEC
and fclose() in related code, so let's make sure we're safe here too.

Test: boot
Change-Id: Ief893c936859815c78fa6d7e06cb88ad34aadbac
2018-10-03 13:19:04 -07:00
Mark Salyzyn
eba4706a2e fs_mgr: Add support in fs_mgr_read_fstab_file for /proc/mounts
Generate fstab from /proc/mounts.  Basically like any regular fstab
minus the requirement for the Android fs_mgr_flags.  Added a unit
test to confirm that fs_mgr_read_fstab("/proc/mounts") matches the
setmntent("/proc/mounts")+getmntent() content.

As a result, discovered a bug in parse_flags that would report "ro"
if the "rootcontext=..." flag was referenced.

Test: fs_mgr_unit_test
Bug: 109821005
Change-Id: I635ee979e11ee089b09adbedb5f42b6ba78026de
2018-06-27 14:49:06 -07:00
Mark Salyzyn
596fac3c6d fs_mgr: fs_mgr_get_boot_config_from_kernel_cmdline deal with quote
Spans quoted with " are dealt with atomically, and are stripped from
the key/value results when parsing the kernel cmdline.

Test: compile, device boot, fs_mgr_unit_test
Bug: 109821005
Change-Id: I45f3d7395f34295edefdeaafa4c15c6ee25cc4da
2018-06-08 16:04:17 -07:00