Merge "Log error message if setting project quota ID fails" am: 7505efbd5d am: 44df16de69 am: 1768a47b25

Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1694189

Change-Id: If76a5f6341b8f21ed49e079e14bd67362fb35f7a
diff --git a/Process.cpp b/Process.cpp
index 62d51a2..79fe15d 100644
--- a/Process.cpp
+++ b/Process.cpp
@@ -84,7 +84,7 @@
 }
 
 // TODO: Refactor the code with KillProcessesWithOpenFiles().
-int KillProcessesWithMounts(const std::string& prefix, int signal) {
+int KillProcessesWithTmpfsMounts(const std::string& prefix, int signal) {
     std::unordered_set<pid_t> pids;
 
     auto proc_d = std::unique_ptr<DIR, int (*)(DIR*)>(opendir("/proc"), closedir);
@@ -112,7 +112,8 @@
         // Check if obb directory is mounted, and get all packages of mounted app data directory.
         mntent* mentry;
         while ((mentry = getmntent(fp.get())) != nullptr) {
-            if (android::base::StartsWith(mentry->mnt_dir, prefix)) {
+            if (mentry->mnt_fsname != nullptr && strncmp(mentry->mnt_fsname, "tmpfs", 5) == 0
+                    && android::base::StartsWith(mentry->mnt_dir, prefix)) {
                 pids.insert(pid);
                 break;
             }
diff --git a/Process.h b/Process.h
index a56b9ce..f3728b5 100644
--- a/Process.h
+++ b/Process.h
@@ -21,7 +21,7 @@
 namespace vold {
 
 int KillProcessesWithOpenFiles(const std::string& path, int signal, bool killFuseDaemon = true);
-int KillProcessesWithMounts(const std::string& path, int signal);
+int KillProcessesWithTmpfsMounts(const std::string& path, int signal);
 
 }  // namespace vold
 }  // namespace android
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 4f62642..49b2d60 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1,9 +1,15 @@
 {
   "presubmit": [
     {
+      "name": "CtsScopedStorageCoreHostTest"
+    },
+    {
       "name": "CtsScopedStorageHostTest"
     },
     {
+      "name": "CtsScopedStorageDeviceOnlyTest"
+    },
+    {
       "name": "AdoptableHostTest"
     }
   ]
diff --git a/Utils.cpp b/Utils.cpp
index 9b31f72..4635975 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -504,25 +504,25 @@
     return -errno;
 }
 
-status_t KillProcessesWithMountPrefix(const std::string& path) {
-    if (KillProcessesWithMounts(path, SIGINT) == 0) {
+status_t KillProcessesWithTmpfsMountPrefix(const std::string& path) {
+    if (KillProcessesWithTmpfsMounts(path, SIGINT) == 0) {
         return OK;
     }
     if (sSleepOnUnmount) sleep(5);
 
-    if (KillProcessesWithMounts(path, SIGTERM) == 0) {
+    if (KillProcessesWithTmpfsMounts(path, SIGTERM) == 0) {
         return OK;
     }
     if (sSleepOnUnmount) sleep(5);
 
-    if (KillProcessesWithMounts(path, SIGKILL) == 0) {
+    if (KillProcessesWithTmpfsMounts(path, SIGKILL) == 0) {
         return OK;
     }
     if (sSleepOnUnmount) sleep(5);
 
     // Send SIGKILL a second time to determine if we've
     // actually killed everyone mount
-    if (KillProcessesWithMounts(path, SIGKILL) == 0) {
+    if (KillProcessesWithTmpfsMounts(path, SIGKILL) == 0) {
         return OK;
     }
     PLOG(ERROR) << "Failed to kill processes using " << path;
diff --git a/Utils.h b/Utils.h
index 4771593..a3316c3 100644
--- a/Utils.h
+++ b/Utils.h
@@ -78,8 +78,8 @@
 /* Kills any processes using given path */
 status_t KillProcessesUsingPath(const std::string& path);
 
-/* Kills any processes using given mount prifix */
-status_t KillProcessesWithMountPrefix(const std::string& path);
+/* Kills any processes using given tmpfs mount prifix */
+status_t KillProcessesWithTmpfsMountPrefix(const std::string& path);
 
 /* Creates bind mount from source to target */
 status_t BindMount(const std::string& source, const std::string& target);
diff --git a/VoldNativeService.cpp b/VoldNativeService.cpp
index 5ea72bb..8d63a83 100644
--- a/VoldNativeService.cpp
+++ b/VoldNativeService.cpp
@@ -54,6 +54,7 @@
 namespace {
 
 constexpr const char* kDump = "android.permission.DUMP";
+constexpr auto kIncFsReadNoTimeoutMs = 100;
 
 static binder::Status error(const std::string& msg) {
     PLOG(ERROR) << msg;
@@ -956,6 +957,7 @@
 
 binder::Status VoldNativeService::mountIncFs(
         const std::string& backingPath, const std::string& targetDir, int32_t flags,
+        const std::string& sysfsName,
         ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
     ENFORCE_SYSTEM_OR_ROOT;
     CHECK_ARGUMENT_PATH(backingPath);
@@ -963,9 +965,11 @@
 
     auto control = incfs::mount(backingPath, targetDir,
                                 {.flags = IncFsMountFlags(flags),
+                                 // Mount with read timeouts.
                                  .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
                                  // Mount with read logs disabled.
-                                 .readLogBufferPages = 0});
+                                 .readLogBufferPages = 0,
+                                 .sysfsName = sysfsName.c_str()});
     if (!control) {
         return translate(-errno);
     }
@@ -974,6 +978,9 @@
     _aidl_return->cmd.reset(unique_fd(fds[CMD].release()));
     _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release()));
     _aidl_return->log.reset(unique_fd(fds[LOGS].release()));
+    if (fds[BLOCKS_WRITTEN].ok()) {
+        _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release()));
+    }
     return Ok();
 }
 
@@ -986,11 +993,12 @@
 
 binder::Status VoldNativeService::setIncFsMountOptions(
         const ::android::os::incremental::IncrementalFileSystemControlParcel& control,
-        bool enableReadLogs) {
+        bool enableReadLogs, bool enableReadTimeouts) {
     ENFORCE_SYSTEM_OR_ROOT;
 
     auto incfsControl =
-            incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get());
+            incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(),
+                                 control.blocksWritten ? control.blocksWritten->get() : -1);
     auto cleanupFunc = [](auto incfsControl) {
         for (auto& fd : incfsControl->releaseFds()) {
             (void)fd.release();
@@ -1000,7 +1008,8 @@
             std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc);
     if (auto error = incfs::setOptions(
                 incfsControl,
-                {.defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
+                {.defaultReadTimeoutMs =
+                         enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs,
                  .readLogBufferPages = enableReadLogs ? INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES : 0});
         error < 0) {
         return binder::Status::fromServiceSpecificError(error);
diff --git a/VoldNativeService.h b/VoldNativeService.h
index 33d0f3a..1414c38 100644
--- a/VoldNativeService.h
+++ b/VoldNativeService.h
@@ -162,11 +162,12 @@
     binder::Status incFsEnabled(bool* _aidl_return) override;
     binder::Status mountIncFs(
             const std::string& backingPath, const std::string& targetDir, int32_t flags,
+            const std::string& sysfsName,
             ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) override;
     binder::Status unmountIncFs(const std::string& dir) override;
     binder::Status setIncFsMountOptions(
             const ::android::os::incremental::IncrementalFileSystemControlParcel& control,
-            bool enableReadLogs) override;
+            bool enableReadLogs, bool enableReadTimeouts) override;
     binder::Status bindMount(const std::string& sourceDir, const std::string& targetDir) override;
 
     binder::Status destroyDsuMetadataKey(const std::string& dsuSlot) override;
diff --git a/binder/android/os/IVold.aidl b/binder/android/os/IVold.aidl
index 62685e5..f20faca 100644
--- a/binder/android/os/IVold.aidl
+++ b/binder/android/os/IVold.aidl
@@ -140,9 +140,9 @@
     FileDescriptor openAppFuseFile(int uid, int mountId, int fileId, int flags);
 
     boolean incFsEnabled();
-    IncrementalFileSystemControlParcel mountIncFs(@utf8InCpp String backingPath, @utf8InCpp String targetDir, int flags);
+    IncrementalFileSystemControlParcel mountIncFs(@utf8InCpp String backingPath, @utf8InCpp String targetDir, int flags, @utf8InCpp String sysfsName);
     void unmountIncFs(@utf8InCpp String dir);
-    void setIncFsMountOptions(in IncrementalFileSystemControlParcel control, boolean enableReadLogs);
+    void setIncFsMountOptions(in IncrementalFileSystemControlParcel control, boolean enableReadLogs, boolean enableReadTimeouts);
     void bindMount(@utf8InCpp String sourceDir, @utf8InCpp String targetDir);
 
     void destroyDsuMetadataKey(@utf8InCpp String dsuSlot);
diff --git a/model/EmulatedVolume.cpp b/model/EmulatedVolume.cpp
index 9431f95..cfb68ba 100644
--- a/model/EmulatedVolume.cpp
+++ b/model/EmulatedVolume.cpp
@@ -50,7 +50,7 @@
     mLabel = "emulated";
     mFuseMounted = false;
     mUseSdcardFs = IsSdcardfsUsed();
-    mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
+    mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, true);
 }
 
 EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device, const std::string& fsUuid,
@@ -61,7 +61,7 @@
     mLabel = fsUuid;
     mFuseMounted = false;
     mUseSdcardFs = IsSdcardfsUsed();
-    mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
+    mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, true);
 }
 
 EmulatedVolume::~EmulatedVolume() {}
@@ -191,7 +191,9 @@
     // umount the whole Android/ dir.
     if (mAppDataIsolationEnabled) {
         std::string appObbDir(StringPrintf("%s/%d/Android/obb", getPath().c_str(), userId));
-        KillProcessesWithMountPrefix(appObbDir);
+        // Here we assume obb/data dirs is mounted as tmpfs, then it must be caused by
+        // app data isolation.
+        KillProcessesWithTmpfsMountPrefix(appObbDir);
     } else {
         std::string androidDataTarget(
                 StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId));