Avoid killing the FUSE daemon during unmount
The FUSE daemon is often holding fds on behalf of other apps and if a volume is ejected the daemon would often get killed first while vold is walking /proc/<pid>/fd to kill pids with open fds on the volume. This is required for the volume unmount successfully. To mitigate this, we avoid killing the FUSE daemon during the usual /proc walk. This ensures that we first send SIGINT, SIGTERM and SIGKILL to other apps first. There is an additional SIGKILL attempt and on that last attempt, we kill the FUSE daemon as a last resort Test: Manual Bug: 171673908 Change-Id: I100d2ce4cb4c145cbb49e0696842e97dfba2c1c9
This commit is contained in:
parent
2d0ea90538
commit
75273001a2
3 changed files with 13 additions and 7 deletions
|
@ -39,6 +39,7 @@
|
|||
#include <android-base/strings.h>
|
||||
|
||||
#include "Process.h"
|
||||
#include "Utils.h"
|
||||
|
||||
using android::base::StringPrintf;
|
||||
|
||||
|
@ -127,7 +128,7 @@ int KillProcessesWithMounts(const std::string& prefix, int signal) {
|
|||
return pids.size();
|
||||
}
|
||||
|
||||
int KillProcessesWithOpenFiles(const std::string& prefix, int signal) {
|
||||
int KillProcessesWithOpenFiles(const std::string& prefix, int signal, bool killFuseDaemon) {
|
||||
std::unordered_set<pid_t> pids;
|
||||
|
||||
auto proc_d = std::unique_ptr<DIR, int (*)(DIR*)>(opendir("/proc"), closedir);
|
||||
|
@ -164,7 +165,11 @@ int KillProcessesWithOpenFiles(const std::string& prefix, int signal) {
|
|||
}
|
||||
|
||||
if (found) {
|
||||
pids.insert(pid);
|
||||
if (!IsFuseDaemon(pid) || killFuseDaemon) {
|
||||
pids.insert(pid);
|
||||
} else {
|
||||
LOG(WARNING) << "Found FUSE daemon with open file. Skipping...";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (signal != 0) {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
namespace android {
|
||||
namespace vold {
|
||||
|
||||
int KillProcessesWithOpenFiles(const std::string& path, int signal);
|
||||
int KillProcessesWithOpenFiles(const std::string& path, int signal, bool killFuseDaemon = true);
|
||||
int KillProcessesWithMounts(const std::string& path, int signal);
|
||||
|
||||
} // namespace vold
|
||||
|
|
|
@ -525,24 +525,25 @@ status_t KillProcessesWithMountPrefix(const std::string& path) {
|
|||
}
|
||||
|
||||
status_t KillProcessesUsingPath(const std::string& path) {
|
||||
if (KillProcessesWithOpenFiles(path, SIGINT) == 0) {
|
||||
if (KillProcessesWithOpenFiles(path, SIGINT, false /* killFuseDaemon */) == 0) {
|
||||
return OK;
|
||||
}
|
||||
if (sSleepOnUnmount) sleep(5);
|
||||
|
||||
if (KillProcessesWithOpenFiles(path, SIGTERM) == 0) {
|
||||
if (KillProcessesWithOpenFiles(path, SIGTERM, false /* killFuseDaemon */) == 0) {
|
||||
return OK;
|
||||
}
|
||||
if (sSleepOnUnmount) sleep(5);
|
||||
|
||||
if (KillProcessesWithOpenFiles(path, SIGKILL) == 0) {
|
||||
if (KillProcessesWithOpenFiles(path, SIGKILL, false /* killFuseDaemon */) == 0) {
|
||||
return OK;
|
||||
}
|
||||
if (sSleepOnUnmount) sleep(5);
|
||||
|
||||
// Send SIGKILL a second time to determine if we've
|
||||
// actually killed everyone with open files
|
||||
if (KillProcessesWithOpenFiles(path, SIGKILL) == 0) {
|
||||
// This time, we also kill the FUSE daemon if found
|
||||
if (KillProcessesWithOpenFiles(path, SIGKILL, true /* killFuseDaemon */) == 0) {
|
||||
return OK;
|
||||
}
|
||||
PLOG(ERROR) << "Failed to kill processes using " << path;
|
||||
|
|
Loading…
Reference in a new issue