Don't use heuristics to pick volumes to overlay
Instead simply overlay all on dynamic partition
Bug: 401140635
Flag: overlay_dynamic_partitions_only
Test: system/core/fs_mgr/tests/adb-remount-test.sh
Change-Id: Ib554f5aa245047847bbf1ab1e8b53dccd44ac622
diff --git a/fs_mgr/README.overlayfs.md b/fs_mgr/README.overlayfs.md
index 94b2f8c..df5d775 100644
--- a/fs_mgr/README.overlayfs.md
+++ b/fs_mgr/README.overlayfs.md
@@ -79,16 +79,15 @@
done file by file. Be mindful of wasted space. For example, defining
**BOARD_IMAGE_PARTITION_RESERVED_SIZE** has a negative impact on the
right-sizing of images and requires more free dynamic partition space.
-- The kernel requires **CONFIG_OVERLAY_FS=y**. If the kernel version is higher
- than 4.4, it requires source to be in line with android-common kernels.
- The patch series is available on the upstream mailing list and the latest as
- of Sep 5 2019 is https://www.spinics.net/lists/linux-mtd/msg08331.html
- This patch adds an override_creds _mount_ option to OverlayFS that
- permits legacy behavior for systems that do not have overlapping
- sepolicy rules, principals of least privilege, which is how Android behaves.
- For 4.19 and higher a rework of the xattr handling to deal with recursion
- is required. https://patchwork.kernel.org/patch/11117145/ is a start of that
- adjustment.
+- The kernel requires **CONFIG_OVERLAY_FS=y**. overlayfs is used 'as is' as of
+ android 16, no modifications are required.
+- In order for overlayfs to work, overlays are mounted in the overlay_remounter
+ domain, defined here: system/sepolicy/private/overlay_remounter.te. This domain
+ must have full access to the files on the underlying volumes, add any other file
+ and directory types here
+- For devices with dynamic partitions, we use a simpler logic to decide which
+ partitions to remount, being all logical ones. In case this isn't correct,
+ we added the overlay=on and overlay=off mount flags to allow detailed control.
- _adb enable-verity_ frees up OverlayFS and reverts the device to the state
prior to content updates. The update engine performs a full OTA.
- _adb remount_ overrides are incompatible with OTA resources, so the update
diff --git a/fs_mgr/fs_mgr_overlayfs_mount.cpp b/fs_mgr/fs_mgr_overlayfs_mount.cpp
index 69d3161..bd914f2 100644
--- a/fs_mgr/fs_mgr_overlayfs_mount.cpp
+++ b/fs_mgr/fs_mgr_overlayfs_mount.cpp
@@ -49,6 +49,10 @@
#include "fs_mgr_overlayfs_mount.h"
#include "fs_mgr_priv.h"
+// Flag to simplify algorithm for choosing which partitions to overlay to simply overlay
+// all dynamic partitions
+constexpr bool overlay_dynamic_partitions_only = false;
+
using namespace std::literals;
using namespace android::fs_mgr;
using namespace android::storage_literals;
@@ -669,6 +673,19 @@
Fstab candidates;
for (const auto& entry : fstab) {
+ // fstab overlay flag overrides all other behavior
+ if (entry.fs_mgr_flags.overlay_off) continue;
+ if (entry.fs_mgr_flags.overlay_on) {
+ candidates.push_back(entry);
+ continue;
+ }
+
+ // overlay_dynamic_partitions_only simplifies logic to overlay exactly dynamic partitions
+ if (overlay_dynamic_partitions_only) {
+ if (entry.fs_mgr_flags.logical) candidates.push_back(entry);
+ continue;
+ }
+
// Filter out partitions whose type doesn't match what's mounted.
// This avoids spammy behavior on devices which can mount different
// filesystems for each partition.
diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp
index 010fbc8..ec23ce5 100644
--- a/fs_mgr/libfstab/fstab.cpp
+++ b/fs_mgr/libfstab/fstab.cpp
@@ -209,6 +209,8 @@
CheckFlag("metadata_csum", ext_meta_csum);
CheckFlag("fscompress", fs_compress);
CheckFlag("overlayfs_remove_missing_lowerdir", overlayfs_remove_missing_lowerdir);
+ CheckFlag("overlay=on", overlay_on);
+ CheckFlag("overlay=off", overlay_off);
#undef CheckFlag
diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h
index 0ff3188..4924ae3 100644
--- a/fs_mgr/libfstab/include/fstab/fstab.h
+++ b/fs_mgr/libfstab/include/fstab/fstab.h
@@ -87,6 +87,8 @@
bool fs_compress : 1;
bool overlayfs_remove_missing_lowerdir : 1;
bool is_zoned : 1;
+ bool overlay_on : 1;
+ bool overlay_off : 1;
} fs_mgr_flags = {};
bool is_encryptable() const { return fs_mgr_flags.crypt; }