From 4df104f335db57c0ee82d310689e6faf9cf7c2d0 Mon Sep 17 00:00:00 2001 From: "LongPing.WEI" Date: Wed, 28 Nov 2018 11:13:23 +0800 Subject: [PATCH] Do lazy-unmount to /storage directly From man 2 umount: MNT_DETACH (since Linux 2.4.11) Perform a lazy unmount: make the mount point unavailable for new accesses, immediately disconnect the filesystem and all filesystems mounted below it from each other and from the mount table, and actually perform the unmount when the mount point ceases to be busy. So we don't need to unmount the filesystems under it one by one. Bug: 113796163 Test: atest android.appsecurity.cts.PermissionsHostTest#testInteractiveGrant23 Change-Id: I6a0422466a9865ff6d17122505ca73d041de9d54 --- Utils.cpp | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/Utils.cpp b/Utils.cpp index c0b7f01..0bc0103 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -755,29 +755,10 @@ bool IsRunningInEmulator() { } status_t UnmountTree(const std::string& prefix) { - FILE* fp = setmntent("/proc/mounts", "re"); - if (fp == NULL) { - PLOG(ERROR) << "Failed to open /proc/mounts"; + if (umount2(prefix.c_str(), MNT_DETACH)) { + PLOG(ERROR) << "Failed to unmount " << prefix; return -errno; } - - // Some volumes can be stacked on each other, so force unmount in - // reverse order to give us the best chance of success. - std::list toUnmount; - mntent* mentry; - while ((mentry = getmntent(fp)) != NULL) { - auto test = std::string(mentry->mnt_dir) + "/"; - if (android::base::StartsWith(test, prefix)) { - toUnmount.push_front(test); - } - } - endmntent(fp); - - for (const auto& path : toUnmount) { - if (umount2(path.c_str(), MNT_DETACH)) { - PLOG(ERROR) << "Failed to unmount " << path; - } - } return OK; }