diff options
author | 2024-06-14 11:11:43 +0100 | |
---|---|---|
committer | 2024-06-14 12:36:33 +0000 | |
commit | d8a9faa0d63083174e96bf09f9e255e5049a9f67 (patch) | |
tree | 4242f0aae5eed9f9c5c62fac062ee4e0dd106428 /dexopt_chroot_setup | |
parent | 2b4eb676348f122ab0a21e19d7a3c57bd9898c6c (diff) |
Retry unmount with MNT_DETACH.
This makes the teardown succeed when the normal umount call fails. For
exampel, when stack sampling is on, `/mnt/pre_reboot_dexopt/chroot/proc`
cannot be unmounted with a normal umount call.
Bug: 346869873
Test: -
1. Turn on stack sampling (Settings -> System -> Developer options -> System Tracing -> Record CPU profile).
2. adb shell pm art pr-dexopt-job --run
Test: -
1. Turn on stack sampling (Settings -> System -> Developer options -> System Tracing -> Record CPU profile).
2. system/update_engine/scripts/update_device.py <ota-package-zip>
Change-Id: I6972aebf25a4b71407133785f0807ed76368c8b1
Diffstat (limited to 'dexopt_chroot_setup')
-rw-r--r-- | dexopt_chroot_setup/dexopt_chroot_setup.cc | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/dexopt_chroot_setup/dexopt_chroot_setup.cc b/dexopt_chroot_setup/dexopt_chroot_setup.cc index 937cd3028b..3d9c6e3b9c 100644 --- a/dexopt_chroot_setup/dexopt_chroot_setup.cc +++ b/dexopt_chroot_setup/dexopt_chroot_setup.cc @@ -122,6 +122,18 @@ Result<void> CreateDir(const std::string& path) { return {}; } +Result<void> Unmount(const std::string& target) { + if (umount2(target.c_str(), UMOUNT_NOFOLLOW) == 0) { + return {}; + } + LOG(WARNING) << ART_FORMAT( + "Failed to umount2 '{}': {}. Retrying with MNT_DETACH", target, strerror(errno)); + if (umount2(target.c_str(), UMOUNT_NOFOLLOW | MNT_DETACH) == 0) { + return {}; + } + return ErrnoErrorf("Failed to umount2 '{}'", target); +} + Result<void> BindMount(const std::string& source, const std::string& target) { // Don't bind-mount repeatedly. CHECK(!PathStartsWith(source, DexoptChrootSetup::CHROOT_DIR)); @@ -201,9 +213,7 @@ Result<void> BindMount(const std::string& source, const std::string& target) { /*data=*/nullptr) != 0) { return ErrnoErrorf("Failed to bind-mount '{}' at '{}'", *kBindMountTmpDir, target); } - if (umount2(kBindMountTmpDir->c_str(), UMOUNT_NOFOLLOW) != 0) { - return ErrnoErrorf("Failed to umount2 '{}'", *kBindMountTmpDir); - } + OR_RETURN(Unmount(*kBindMountTmpDir)); LOG(INFO) << ART_FORMAT("Bind-mounted '{}' at '{}'", source, target); return {}; } @@ -518,9 +528,7 @@ Result<void> DexoptChrootSetup::TearDownChroot() const { // The list is in mount order. std::vector<FstabEntry> entries = OR_RETURN(GetProcMountsDescendantsOfPath(CHROOT_DIR)); for (auto it = entries.rbegin(); it != entries.rend(); it++) { - if (umount2(it->mount_point.c_str(), UMOUNT_NOFOLLOW) != 0) { - return ErrnoErrorf("Failed to umount2 '{}'", it->mount_point); - } + OR_RETURN(Unmount(it->mount_point)); LOG(INFO) << ART_FORMAT("Unmounted '{}'", it->mount_point); } @@ -533,9 +541,8 @@ Result<void> DexoptChrootSetup::TearDownChroot() const { LOG(INFO) << ART_FORMAT("Removed '{}'", CHROOT_DIR); } - if (!OR_RETURN(GetProcMountsDescendantsOfPath(*kBindMountTmpDir)).empty() && - umount2(kBindMountTmpDir->c_str(), UMOUNT_NOFOLLOW) != 0) { - return ErrnoErrorf("Failed to umount2 '{}'", *kBindMountTmpDir); + if (!OR_RETURN(GetProcMountsDescendantsOfPath(*kBindMountTmpDir)).empty()) { + OR_RETURN(Unmount(*kBindMountTmpDir)); } std::filesystem::remove_all(*kBindMountTmpDir, ec); |