Merge "fs_mgr: overlayfs: pre-emptive filesystem setup"

This commit is contained in:
Treehugger Robot 2019-06-03 14:18:45 +00:00 committed by Gerrit Code Review
commit 0c615194f4
3 changed files with 25 additions and 35 deletions

View file

@ -90,7 +90,7 @@ std::vector<std::string> fs_mgr_overlayfs_required_devices(Fstab*) {
return {};
}
bool fs_mgr_overlayfs_setup(const char*, const char*, bool* change) {
bool fs_mgr_overlayfs_setup(const char*, const char*, bool* change, bool) {
if (change) *change = false;
return false;
}
@ -903,7 +903,8 @@ std::vector<std::string> fs_mgr_overlayfs_required_devices(Fstab* fstab) {
// Returns false if setup not permitted, errno set to last error.
// If something is altered, set *change.
bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* change) {
bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* change,
bool force) {
if (change) *change = false;
auto ret = false;
if (fs_mgr_overlayfs_valid() == OverlayfsValidResult::kNotSupported) return ret;
@ -927,7 +928,7 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool*
continue;
}
save_errno = errno;
auto verity_enabled = fs_mgr_is_verity_enabled(*it);
auto verity_enabled = !force && fs_mgr_is_verity_enabled(*it);
if (errno == ENOENT || errno == ENXIO) errno = save_errno;
if (verity_enabled) {
it = candidates.erase(it);

View file

@ -250,53 +250,42 @@ int main(int argc, char* argv[]) {
// Check verity and optionally setup overlayfs backing.
auto reboot_later = false;
auto user_please_reboot_later = false;
auto uses_overlayfs = fs_mgr_overlayfs_valid() != OverlayfsValidResult::kNotSupported;
auto setup_overlayfs = false;
auto just_disabled_verity = false;
for (auto it = partitions.begin(); it != partitions.end();) {
auto& entry = *it;
auto& mount_point = entry.mount_point;
if (fs_mgr_is_verity_enabled(entry)) {
retval = VERITY_PARTITION;
auto ret = false;
if (android::base::GetProperty("ro.boot.vbmeta.device_state", "") != "locked") {
if (AvbOps* ops = avb_ops_user_new()) {
auto ret = avb_user_verity_set(
ret = avb_user_verity_set(
ops, android::base::GetProperty("ro.boot.slot_suffix", "").c_str(),
false);
avb_ops_user_free(ops);
if (ret) {
LOG(WARNING) << "Disabling verity for " << mount_point;
reboot_later = can_reboot;
if (reboot_later) {
// w/o overlayfs available, also check for dedupe
if (!uses_overlayfs) {
++it;
continue;
}
reboot();
}
user_please_reboot_later = true;
} else if (fs_mgr_set_blk_ro(entry.blk_device, false)) {
fec::io fh(entry.blk_device.c_str(), O_RDWR);
if (fh && fh.set_verity_status(false)) {
LOG(WARNING) << "Disabling verity for " << mount_point;
reboot_later = can_reboot;
if (reboot_later && !uses_overlayfs) {
++it;
continue;
}
user_please_reboot_later = true;
}
}
}
if (!ret && fs_mgr_set_blk_ro(entry.blk_device, false)) {
fec::io fh(entry.blk_device.c_str(), O_RDWR);
ret = fh && fh.set_verity_status(false);
}
if (ret) {
LOG(WARNING) << "Disabling verity for " << mount_point;
just_disabled_verity = true;
reboot_later = can_reboot;
user_please_reboot_later = true;
}
}
LOG(ERROR) << "Skipping " << mount_point << " for remount";
it = partitions.erase(it);
continue;
if (!ret) {
LOG(ERROR) << "Skipping " << mount_point << " for remount";
it = partitions.erase(it);
continue;
}
}
auto change = false;
errno = 0;
if (fs_mgr_overlayfs_setup(nullptr, mount_point.c_str(), &change)) {
if (fs_mgr_overlayfs_setup(nullptr, mount_point.c_str(), &change, just_disabled_verity)) {
if (change) {
LOG(INFO) << "Using overlayfs for " << mount_point;
reboot_later = can_reboot;
@ -312,7 +301,7 @@ int main(int argc, char* argv[]) {
++it;
}
if (partitions.empty()) {
if (partitions.empty() || just_disabled_verity) {
if (reboot_later) reboot(setup_overlayfs);
if (user_please_reboot_later) {
LOG(INFO) << "Now reboot your device for settings to take effect";

View file

@ -26,7 +26,7 @@ android::fs_mgr::Fstab fs_mgr_overlayfs_candidate_list(const android::fs_mgr::Fs
bool fs_mgr_overlayfs_mount_all(android::fs_mgr::Fstab* fstab);
std::vector<std::string> fs_mgr_overlayfs_required_devices(android::fs_mgr::Fstab* fstab);
bool fs_mgr_overlayfs_setup(const char* backing = nullptr, const char* mount_point = nullptr,
bool* change = nullptr);
bool* change = nullptr, bool force = true);
bool fs_mgr_overlayfs_teardown(const char* mount_point = nullptr, bool* change = nullptr);
bool fs_mgr_overlayfs_is_setup();
bool fs_mgr_has_shared_blocks(const std::string& mount_point, const std::string& dev);