OSDN Git Service

do not sleep if it is shutting down
authorKeun-young Park <keunyoung@google.com>
Thu, 3 Aug 2017 00:45:48 +0000 (17:45 -0700)
committerKeun-young Park <keunyoung@google.com>
Thu, 3 Aug 2017 00:45:48 +0000 (17:45 -0700)
- Various sleep(5) for vold shutdown can increase shutdown time a lot.
- If it is shutting down, do not sleep at all. init will take care of
  active partitions if not unmounted.

bug: 64143519
Test: reboot and check logs from vold, check if "ShutdownThread: Shutdown wait timed out" happens.
Change-Id: I7cb91427ad2205fe23a054d255caf7ffdfd9f6c3

Utils.cpp
VolumeManager.cpp
VolumeManager.h

index 15b3c0b..2b8d0a5 100644 (file)
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -17,6 +17,7 @@
 #include "sehandle.h"
 #include "Utils.h"
 #include "Process.h"
+#include "VolumeManager.h"
 
 #include <android-base/file.h>
 #include <android-base/logging.h>
@@ -126,22 +127,22 @@ status_t ForceUnmount(const std::string& path) {
     }
     // Apps might still be handling eject request, so wait before
     // we start sending signals
-    sleep(5);
+    if (!VolumeManager::shutting_down) sleep(5);
 
     Process::killProcessesWithOpenFiles(cpath, SIGINT);
-    sleep(5);
+    if (!VolumeManager::shutting_down) sleep(5);
     if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
         return OK;
     }
 
     Process::killProcessesWithOpenFiles(cpath, SIGTERM);
-    sleep(5);
+    if (!VolumeManager::shutting_down) sleep(5);
     if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
         return OK;
     }
 
     Process::killProcessesWithOpenFiles(cpath, SIGKILL);
-    sleep(5);
+    if (!VolumeManager::shutting_down) sleep(5);
     if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
         return OK;
     }
@@ -154,17 +155,17 @@ status_t KillProcessesUsingPath(const std::string& path) {
     if (Process::killProcessesWithOpenFiles(cpath, SIGINT) == 0) {
         return OK;
     }
-    sleep(5);
+    if (!VolumeManager::shutting_down) sleep(5);
 
     if (Process::killProcessesWithOpenFiles(cpath, SIGTERM) == 0) {
         return OK;
     }
-    sleep(5);
+    if (!VolumeManager::shutting_down) sleep(5);
 
     if (Process::killProcessesWithOpenFiles(cpath, SIGKILL) == 0) {
         return OK;
     }
-    sleep(5);
+    if (!VolumeManager::shutting_down) sleep(5);
 
     // Send SIGKILL a second time to determine if we've
     // actually killed everyone with open files
index 4ba0c36..8398498 100644 (file)
@@ -89,6 +89,8 @@ const char *VolumeManager::ASECDIR           = "/mnt/asec";
  */
 const char *VolumeManager::LOOPDIR           = "/mnt/obb";
 
+bool VolumeManager::shutting_down = false;
+
 static const char* kPathUserMount = "/mnt/user";
 static const char* kPathVirtualDisk = "/data/misc/vold/virtual_disk";
 
@@ -704,12 +706,14 @@ int VolumeManager::shutdown() {
     if (mInternalEmulated == nullptr) {
         return 0; // already shutdown
     }
+    shutting_down = true;
     mInternalEmulated->destroy();
     mInternalEmulated = nullptr;
     for (const auto& disk : mDisks) {
         disk->destroy();
     }
     mDisks.clear();
+    shutting_down = false;
     return 0;
 }
 
index 796a91d..537aebe 100644 (file)
@@ -70,6 +70,9 @@ public:
     static const char *ASECDIR;
     static const char *LOOPDIR;
 
+    //TODO remove this with better solution, b/64143519
+    static bool shutting_down;
+
 private:
     static VolumeManager *sInstance;