fs_mgr: Add fs_mgr_flag overlayfs_remove_missing_lowerdir

If this flag is given, then fs_mgr_mount_overlayfs_fstab_entry() shall
filter out missing directories in the lowerdir= list.

For example,

  test /mnt/vendor/overlay_test overlay \
    ro,lowerdir=/dir1:/dir2:/missing_dir3 \
    first_stage_mount,overlayfs_remove_missing_lowerdir

should mount the overlayfs device with "lowerdir=/dir1:/dir2".

Bug: 186342252
Test: Manual boot test with modified fstab on CF
Change-Id: Id06b37d0c236528cef981e495280b4f4e9c2b4bb
This commit is contained in:
Yi-Yo Chiang 2021-08-03 01:02:31 +08:00
parent d6ddc20d83
commit e7783a98af
3 changed files with 20 additions and 1 deletions

View file

@ -2322,7 +2322,24 @@ bool fs_mgr_mount_overlayfs_fstab_entry(const FstabEntry& entry) {
return false;
}
auto options = "lowerdir=" + entry.lowerdir;
auto lowerdir = entry.lowerdir;
if (entry.fs_mgr_flags.overlayfs_remove_missing_lowerdir) {
bool removed_any = false;
std::vector<std::string> lowerdirs;
for (const auto& dir : android::base::Split(entry.lowerdir, ":")) {
if (access(dir.c_str(), F_OK)) {
PWARNING << __FUNCTION__ << "(): remove missing lowerdir '" << dir << "'";
removed_any = true;
} else {
lowerdirs.push_back(dir);
}
}
if (removed_any) {
lowerdir = android::base::Join(lowerdirs, ":");
}
}
auto options = "lowerdir=" + lowerdir;
if (overlayfs_valid_result == OverlayfsValidResult::kOverrideCredsRequired) {
options += ",override_creds=off";
}

View file

@ -181,6 +181,7 @@ void ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) {
CheckFlag("fsverity", fs_verity);
CheckFlag("metadata_csum", ext_meta_csum);
CheckFlag("fscompress", fs_compress);
CheckFlag("overlayfs_remove_missing_lowerdir", overlayfs_remove_missing_lowerdir);
#undef CheckFlag

View file

@ -86,6 +86,7 @@ struct FstabEntry {
bool fs_verity : 1;
bool ext_meta_csum : 1;
bool fs_compress : 1;
bool overlayfs_remove_missing_lowerdir : 1;
} fs_mgr_flags = {};
bool is_encryptable() const {