|
|
|
@ -123,35 +123,57 @@ status_t ForceUnmount(const std::string& path) {
|
|
|
|
|
if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
PLOG(WARNING) << "Failed to unmount " << path;
|
|
|
|
|
|
|
|
|
|
// Apps might still be handling eject request, so wait before
|
|
|
|
|
// we start sending signals
|
|
|
|
|
sleep(5);
|
|
|
|
|
Process::killProcessesWithOpenFiles(cpath, SIGINT);
|
|
|
|
|
|
|
|
|
|
Process::killProcessesWithOpenFiles(cpath, SIGINT);
|
|
|
|
|
sleep(5);
|
|
|
|
|
if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
PLOG(WARNING) << "Failed to unmount " << path;
|
|
|
|
|
|
|
|
|
|
sleep(5);
|
|
|
|
|
Process::killProcessesWithOpenFiles(cpath, SIGTERM);
|
|
|
|
|
|
|
|
|
|
sleep(5);
|
|
|
|
|
if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
PLOG(WARNING) << "Failed to unmount " << path;
|
|
|
|
|
|
|
|
|
|
sleep(5);
|
|
|
|
|
Process::killProcessesWithOpenFiles(cpath, SIGKILL);
|
|
|
|
|
|
|
|
|
|
sleep(5);
|
|
|
|
|
if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
PLOG(ERROR) << "Failed to unmount " << path;
|
|
|
|
|
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t KillProcessesUsingPath(const std::string& path) {
|
|
|
|
|
const char* cpath = path.c_str();
|
|
|
|
|
if (Process::killProcessesWithOpenFiles(cpath, SIGINT) == 0) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
sleep(5);
|
|
|
|
|
|
|
|
|
|
if (Process::killProcessesWithOpenFiles(cpath, SIGTERM) == 0) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
sleep(5);
|
|
|
|
|
|
|
|
|
|
if (Process::killProcessesWithOpenFiles(cpath, SIGKILL) == 0) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
sleep(5);
|
|
|
|
|
|
|
|
|
|
// Send SIGKILL a second time to determine if we've
|
|
|
|
|
// actually killed everyone with open files
|
|
|
|
|
if (Process::killProcessesWithOpenFiles(cpath, SIGKILL) == 0) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
PLOG(ERROR) << "Failed to kill processes using " << path;
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t BindMount(const std::string& source, const std::string& target) {
|
|
|
|
|
if (::mount(source.c_str(), target.c_str(), "", MS_BIND, NULL)) {
|
|
|
|
|
PLOG(ERROR) << "Failed to bind mount " << source << " to " << target;
|
|
|
|
|