Progress towards dynamic storage support.

Wire up new Disk and VolumeBase objects and events to start replacing
older DirectVolume code.  Use filesystem UUID as visible PublicVolume
name to be more deterministic.

When starting, create DiskSource instances based on fstab, and watch
for kernel devices to appear.  Turn matching devices into Disk
objects, scan for partitions, and create any relevant VolumeBase
objects.  Broadcast all of these events towards userspace so the
framework can decide what to mount.

Keep track of the primary VolumeBase, and update the new per-user
/storage/self/primary symlink for all started users.

Provide a reset command that framework uses to start from a known
state when runtime is restarted.  When vold is unexpectedly killed,
try recovering by unmounting everything under /mnt and /storage
before moving forward.

Remove UMS sharing support for now, since no current devices support
it; MTP is the recommended solution going forward because it offers
better multi-user support.

Switch killProcessesWithOpenFiles() to directly take signal.  Fix
one SOCK_CLOEXEC bug, but SELinux says there are more lurking.

Bug: 19993667
Change-Id: I2dad1303aa4667ec14c52f774e2a28b3c1c1ff6d
diff --git a/Utils.cpp b/Utils.cpp
index 6ad5d16..b5d037a 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -14,14 +14,12 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "Vold"
-
 #include "sehandle.h"
 #include "Utils.h"
 #include "Process.h"
 
+#include <base/logging.h>
 #include <cutils/fs.h>
-#include <cutils/log.h>
 #include <private/android_filesystem_config.h>
 
 #include <fcntl.h>
@@ -53,8 +51,8 @@
     mode_t mode = 0660 | S_IFBLK;
     if (mknod(cpath, mode, dev) < 0) {
         if (errno != EEXIST) {
-            ALOGW("Failed to create device node for %ud:%ud at %s: %s",
-                    major(dev), minor(dev), cpath, strerror(errno));
+            PLOG(ERROR) << "Failed to create device node for " << major(dev)
+                    << ":" << minor(dev) << " at " << path;
             res = -errno;
         }
     }
@@ -81,23 +79,31 @@
     if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
         return OK;
     }
-    ALOGW("Failed to unmount %s (%s), sending SIGTERM", cpath, strerror(errno));
+    PLOG(WARNING) << "Failed to unmount " << path << "; sending SIGTERM";
     Process::killProcessesWithOpenFiles(cpath, SIGTERM);
     sleep(1);
 
     if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
         return OK;
     }
-    ALOGW("Failed to unmount %s (%s), sending SIGKILL", cpath, strerror(errno));
+    PLOG(WARNING) << "Failed to unmount " << path << "; sending SIGKILL";
     Process::killProcessesWithOpenFiles(cpath, SIGKILL);
     sleep(1);
 
     if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
         return OK;
     }
-    ALOGW("Failed to unmount %s (%s)", cpath, strerror(errno));
+    PLOG(ERROR) << "Failed to unmount " << path << "; giving up";
     return -errno;
 }
 
+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;
+        return -errno;
+    }
+    return OK;
+}
+
 }  // namespace vold
 }  // namespace android