fs_mgr: overlay: umount scratch more aggressively

For specific teardown operations, if we mount scratch with the
intention of it being temporary to strike out content for a specific
partition, umount it.  Otherwise it could interfer with fastboot.

Test: adb-remount-test.sh
Bug: 120034852
Change-Id: Ieff3f6ea0bcda5eb540e9acf6cab8a56d1453b3e
This commit is contained in:
Mark Salyzyn 2018-11-26 09:57:17 -08:00
parent 67fe6f09d5
commit c0966c9a1b
1 changed files with 19 additions and 10 deletions

View File

@ -395,6 +395,18 @@ bool fs_mgr_overlayfs_has_logical(const fstab* fstab) {
return false;
}
void fs_mgr_overlayfs_umount_scratch() {
// Lazy umount will allow us to move on and possibly later
// establish a new fresh mount without requiring a reboot should
// the developer wish to restart. Old references should melt
// away or have no data. Main goal is to shut the door on the
// current overrides with an expectation of a subsequent reboot,
// thus any errors here are ignored.
umount2(kScratchMountPoint.c_str(), MNT_DETACH);
LINFO << "umount(" << kScratchMountPoint << ")";
rmdir(kScratchMountPoint.c_str());
}
// reduce 'DM_DEV_STATUS failed for scratch: No such device or address' noise
std::string scratch_device_cache;
@ -408,13 +420,7 @@ bool fs_mgr_overlayfs_teardown_scratch(const std::string& overlay, bool* change)
auto save_errno = errno;
if (fs_mgr_overlayfs_already_mounted(kScratchMountPoint, false)) {
// Lazy umount will allow us to move on and possibly later
// establish a new fresh mount without requiring a reboot should
// the developer wish to restart. Old references should melt
// away or have no data. Main goal is to shut the door on the
// current overrides with an expectation of a subsequent reboot,
// thus any errors here are ignored.
umount2(kScratchMountPoint.c_str(), MNT_DETACH);
fs_mgr_overlayfs_umount_scratch();
}
auto builder = MetadataBuilder::New(super_device, slot_number);
if (!builder) {
@ -773,8 +779,7 @@ bool fs_mgr_overlayfs_mount_all(fstab* fstab) {
fs_mgr_overlayfs_mount_scratch(scratch_device,
fs_mgr_overlayfs_scratch_mount_type()) &&
!fs_mgr_access(kScratchMountPoint + kOverlayTopDir)) {
umount2(kScratchMountPoint.c_str(), MNT_DETACH);
rmdir(kScratchMountPoint.c_str());
fs_mgr_overlayfs_umount_scratch();
}
}
if (fs_mgr_overlayfs_mount(mount_point)) ret = true;
@ -867,6 +872,7 @@ bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
auto ret = true;
// If scratch exists, but is not mounted, lets gain access to clean
// specific override entries.
auto mount_scratch = false;
if ((mount_point != nullptr) && !fs_mgr_overlayfs_already_mounted(kScratchMountPoint, false)) {
auto scratch_device = fs_mgr_overlayfs_scratch_device();
if (scratch_device.empty()) {
@ -876,7 +882,8 @@ bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
CreateLogicalPartition(super_device, slot_number, partition_name, true, 0s,
&scratch_device);
}
fs_mgr_overlayfs_mount_scratch(scratch_device, fs_mgr_overlayfs_scratch_mount_type());
mount_scratch = fs_mgr_overlayfs_mount_scratch(scratch_device,
fs_mgr_overlayfs_scratch_mount_type());
}
for (const auto& overlay_mount_point : kOverlayMountPoints) {
ret &= fs_mgr_overlayfs_teardown_one(overlay_mount_point, mount_point ?: "", change);
@ -894,6 +901,8 @@ bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
PERROR << "teardown";
ret = false;
}
if (mount_scratch) fs_mgr_overlayfs_umount_scratch();
return ret;
}