blob: cfb68bacb39d7e17c38b5ea24be08ca8502d9c27 [file] [log] [blame]
Jeff Sharkeydeb24052015-03-02 21:01:40 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jeff Sharkeydeb24052015-03-02 21:01:40 -080017#include "EmulatedVolume.h"
Zim3623a212019-07-19 16:46:53 +010018
19#include "AppFuseUtil.h"
Jeff Sharkeydeb24052015-03-02 21:01:40 -080020#include "Utils.h"
Sudheer Shanka40ab6742018-09-18 13:07:45 -070021#include "VolumeManager.h"
Jeff Sharkeydeb24052015-03-02 21:01:40 -080022
Elliott Hughes7e128fb2015-12-04 15:50:53 -080023#include <android-base/logging.h>
Zim3623a212019-07-19 16:46:53 +010024#include <android-base/properties.h>
Martijn Coenen449a7d82020-03-16 14:37:33 +010025#include <android-base/scopeguard.h>
Sudheer Shanka53947a32018-08-01 10:24:13 -070026#include <android-base/stringprintf.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080027#include <cutils/fs.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080028#include <private/android_filesystem_config.h>
Jeff Sharkey7bdf4d52017-09-18 14:47:10 -060029#include <utils/Timers.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080030
31#include <fcntl.h>
32#include <stdlib.h>
33#include <sys/mount.h>
34#include <sys/stat.h>
Elliott Hughes0e08e842017-05-18 09:08:24 -070035#include <sys/sysmacros.h>
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070036#include <sys/types.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080037#include <sys/wait.h>
38
Dan Albertae9e8902015-03-16 10:35:17 -070039using android::base::StringPrintf;
40
Jeff Sharkeydeb24052015-03-02 21:01:40 -080041namespace android {
42namespace vold {
43
Martijn Coenenadcc8452019-12-09 14:18:01 +010044static const char* kSdcardFsPath = "/system/bin/sdcard";
Jeff Sharkeydeb24052015-03-02 21:01:40 -080045
Zima438b242019-09-25 14:37:38 +010046EmulatedVolume::EmulatedVolume(const std::string& rawPath, int userId)
Martijn Coenenadcc8452019-12-09 14:18:01 +010047 : VolumeBase(Type::kEmulated) {
Zima438b242019-09-25 14:37:38 +010048 setId(StringPrintf("emulated;%u", userId));
Jeff Sharkeydeb24052015-03-02 21:01:40 -080049 mRawPath = rawPath;
Jeff Sharkey66270a22015-06-24 11:49:24 -070050 mLabel = "emulated";
Martijn Coenenfd7362d2019-12-11 14:57:59 +010051 mFuseMounted = false;
Daniel Rosenbergf36bddd2020-05-11 22:58:42 -070052 mUseSdcardFs = IsSdcardfsUsed();
Ricky Wai4ae2c652021-03-23 18:13:07 +000053 mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, true);
Jeff Sharkey3161fb32015-04-12 16:03:33 -070054}
55
Zima438b242019-09-25 14:37:38 +010056EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device, const std::string& fsUuid,
57 int userId)
Martijn Coenenadcc8452019-12-09 14:18:01 +010058 : VolumeBase(Type::kEmulated) {
Zima438b242019-09-25 14:37:38 +010059 setId(StringPrintf("emulated:%u,%u;%u", major(device), minor(device), userId));
Jeff Sharkey3161fb32015-04-12 16:03:33 -070060 mRawPath = rawPath;
Jeff Sharkey66270a22015-06-24 11:49:24 -070061 mLabel = fsUuid;
Greg Kaiser5298ccc2019-12-12 05:41:46 -080062 mFuseMounted = false;
Daniel Rosenbergf36bddd2020-05-11 22:58:42 -070063 mUseSdcardFs = IsSdcardfsUsed();
Ricky Wai4ae2c652021-03-23 18:13:07 +000064 mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, true);
Jeff Sharkeydeb24052015-03-02 21:01:40 -080065}
66
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070067EmulatedVolume::~EmulatedVolume() {}
Jeff Sharkeydeb24052015-03-02 21:01:40 -080068
Martijn Coenen6f5802e2019-11-28 11:53:53 +010069std::string EmulatedVolume::getLabel() {
Jeff Sharkey81f55c62015-07-07 14:37:03 -070070 // We could have migrated storage to an adopted private volume, so always
71 // call primary storage "emulated" to avoid media rescans.
Jeff Sharkey81f55c62015-07-07 14:37:03 -070072 if (getMountFlags() & MountFlags::kPrimary) {
Martijn Coenen6f5802e2019-11-28 11:53:53 +010073 return "emulated";
74 } else {
75 return mLabel;
Jeff Sharkey81f55c62015-07-07 14:37:03 -070076 }
Martijn Coenen6f5802e2019-11-28 11:53:53 +010077}
78
Martijn Coenen62a4b272020-01-31 15:23:09 +010079// Creates a bind mount from source to target
Martijn Coenen449a7d82020-03-16 14:37:33 +010080static status_t doFuseBindMount(const std::string& source, const std::string& target,
81 std::list<std::string>& pathsToUnmount) {
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +010082 LOG(INFO) << "Bind mounting " << source << " on " << target;
83 auto status = BindMount(source, target);
84 if (status != OK) {
85 return status;
86 }
87 LOG(INFO) << "Bind mounted " << source << " on " << target;
Martijn Coenen449a7d82020-03-16 14:37:33 +010088 pathsToUnmount.push_front(target);
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +010089 return OK;
90}
91
Martijn Coenen86f21a22020-01-06 09:48:14 +010092status_t EmulatedVolume::mountFuseBindMounts() {
93 std::string androidSource;
94 std::string label = getLabel();
95 int userId = getMountUserId();
Martijn Coenen449a7d82020-03-16 14:37:33 +010096 std::list<std::string> pathsToUnmount;
97
98 auto unmounter = [&]() {
99 LOG(INFO) << "mountFuseBindMounts() unmount scope_guard running";
100 for (const auto& path : pathsToUnmount) {
101 LOG(INFO) << "Unmounting " << path;
102 auto status = UnmountTree(path);
103 if (status != OK) {
104 LOG(INFO) << "Failed to unmount " << path;
105 } else {
106 LOG(INFO) << "Unmounted " << path;
107 }
108 }
109 };
110 auto unmount_guard = android::base::make_scope_guard(unmounter);
Martijn Coenen86f21a22020-01-06 09:48:14 +0100111
112 if (mUseSdcardFs) {
113 androidSource = StringPrintf("/mnt/runtime/default/%s/%d/Android", label.c_str(), userId);
114 } else {
115 androidSource = StringPrintf("/%s/%d/Android", mRawPath.c_str(), userId);
116 }
Martijn Coenen57002612019-11-28 11:56:13 +0100117
Ricky Wai07e64a42020-02-11 14:31:24 +0000118 status_t status = OK;
Ricky Wai259a49a2021-03-19 15:35:49 +0000119 // Zygote will unmount these dirs if app data isolation is enabled, so apps
120 // cannot access these dirs directly.
121 std::string androidDataSource = StringPrintf("%s/data", androidSource.c_str());
122 std::string androidDataTarget(
123 StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId));
124 status = doFuseBindMount(androidDataSource, androidDataTarget, pathsToUnmount);
125 if (status != OK) {
126 return status;
127 }
Ricky Wai07e64a42020-02-11 14:31:24 +0000128
Ricky Wai259a49a2021-03-19 15:35:49 +0000129 std::string androidObbSource = StringPrintf("%s/obb", androidSource.c_str());
130 std::string androidObbTarget(
131 StringPrintf("/mnt/user/%d/%s/%d/Android/obb", userId, label.c_str(), userId));
132 status = doFuseBindMount(androidObbSource, androidObbTarget, pathsToUnmount);
133 if (status != OK) {
134 return status;
Martijn Coenen57002612019-11-28 11:56:13 +0100135 }
Zimb6488f32020-03-17 15:15:42 +0000136
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +0100137 // Installers get the same view as all other apps, with the sole exception that the
138 // OBB dirs (Android/obb) are writable to them. On sdcardfs devices, this requires
139 // a special bind mount, since app-private and OBB dirs share the same GID, but we
140 // only want to give access to the latter.
Martijn Coenen449a7d82020-03-16 14:37:33 +0100141 if (mUseSdcardFs) {
Ricky Waief639212020-04-07 13:43:20 +0100142 std::string obbSource(StringPrintf("/mnt/runtime/write/%s/%d/Android/obb",
143 label.c_str(), userId));
144 std::string obbInstallerTarget(StringPrintf("/mnt/installer/%d/%s/%d/Android/obb",
145 userId, label.c_str(), userId));
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +0100146
Ricky Waief639212020-04-07 13:43:20 +0100147 status = doFuseBindMount(obbSource, obbInstallerTarget, pathsToUnmount);
148 if (status != OK) {
149 return status;
150 }
Ricky Waief639212020-04-07 13:43:20 +0100151 }
152
Martijn Coenen449a7d82020-03-16 14:37:33 +0100153 unmount_guard.Disable();
Martijn Coenen57002612019-11-28 11:56:13 +0100154 return OK;
155}
156
Martijn Coenen86f21a22020-01-06 09:48:14 +0100157status_t EmulatedVolume::unmountFuseBindMounts() {
158 std::string label = getLabel();
159 int userId = getMountUserId();
160
Ricky Waief639212020-04-07 13:43:20 +0100161 if (mUseSdcardFs || mAppDataIsolationEnabled) {
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +0100162 std::string installerTarget(
163 StringPrintf("/mnt/installer/%d/%s/%d/Android/obb", userId, label.c_str(), userId));
164 LOG(INFO) << "Unmounting " << installerTarget;
165 auto status = UnmountTree(installerTarget);
166 if (status != OK) {
167 LOG(ERROR) << "Failed to unmount " << installerTarget;
168 // Intentional continue to try to unmount the other bind mount
169 }
170 }
Ricky Waief639212020-04-07 13:43:20 +0100171 if (mAppDataIsolationEnabled) {
172 std::string obbTarget( StringPrintf("/mnt/androidwritable/%d/%s/%d/Android/obb",
173 userId, label.c_str(), userId));
174 LOG(INFO) << "Unmounting " << obbTarget;
175 auto status = UnmountTree(obbTarget);
176 if (status != OK) {
177 LOG(ERROR) << "Failed to unmount " << obbTarget;
178 // Intentional continue to try to unmount the other bind mount
179 }
180 std::string dataTarget(StringPrintf("/mnt/androidwritable/%d/%s/%d/Android/data",
181 userId, label.c_str(), userId));
182 LOG(INFO) << "Unmounting " << dataTarget;
183 status = UnmountTree(dataTarget);
184 if (status != OK) {
185 LOG(ERROR) << "Failed to unmount " << dataTarget;
186 // Intentional continue to try to unmount the other bind mount
187 }
188 }
189
Ricky Wai07e64a42020-02-11 14:31:24 +0000190 // When app data isolation is enabled, kill all apps that obb/ is mounted, otherwise we should
191 // umount the whole Android/ dir.
192 if (mAppDataIsolationEnabled) {
193 std::string appObbDir(StringPrintf("%s/%d/Android/obb", getPath().c_str(), userId));
Ricky Waia58b5352021-04-29 17:47:28 +0100194 // Here we assume obb/data dirs is mounted as tmpfs, then it must be caused by
195 // app data isolation.
196 KillProcessesWithTmpfsMountPrefix(appObbDir);
Ricky Wai07e64a42020-02-11 14:31:24 +0000197 } else {
Martijn Coenen449a7d82020-03-16 14:37:33 +0100198 std::string androidDataTarget(
199 StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId));
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +0100200
Martijn Coenen449a7d82020-03-16 14:37:33 +0100201 LOG(INFO) << "Unmounting " << androidDataTarget;
202 auto status = UnmountTree(androidDataTarget);
Ricky Wai07e64a42020-02-11 14:31:24 +0000203 if (status != OK) {
204 return status;
205 }
Martijn Coenen449a7d82020-03-16 14:37:33 +0100206 LOG(INFO) << "Unmounted " << androidDataTarget;
207
208 std::string androidObbTarget(
209 StringPrintf("/mnt/user/%d/%s/%d/Android/obb", userId, label.c_str(), userId));
210
211 LOG(INFO) << "Unmounting " << androidObbTarget;
212 status = UnmountTree(androidObbTarget);
213 if (status != OK) {
214 return status;
215 }
216 LOG(INFO) << "Unmounted " << androidObbTarget;
Martijn Coenen57002612019-11-28 11:56:13 +0100217 }
Martijn Coenen57002612019-11-28 11:56:13 +0100218 return OK;
219}
220
Martijn Coenen449a7d82020-03-16 14:37:33 +0100221status_t EmulatedVolume::unmountSdcardFs() {
222 if (!mUseSdcardFs || getMountUserId() != 0) {
223 // For sdcardfs, only unmount for user 0, since user 0 will always be running
224 // and the paths don't change for different users.
225 return OK;
226 }
227
228 ForceUnmount(mSdcardFsDefault);
229 ForceUnmount(mSdcardFsRead);
230 ForceUnmount(mSdcardFsWrite);
231 ForceUnmount(mSdcardFsFull);
232
233 rmdir(mSdcardFsDefault.c_str());
234 rmdir(mSdcardFsRead.c_str());
235 rmdir(mSdcardFsWrite.c_str());
236 rmdir(mSdcardFsFull.c_str());
237
238 mSdcardFsDefault.clear();
239 mSdcardFsRead.clear();
240 mSdcardFsWrite.clear();
241 mSdcardFsFull.clear();
242
243 return OK;
244}
245
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100246status_t EmulatedVolume::doMount() {
247 std::string label = getLabel();
248 bool isVisible = getMountFlags() & MountFlags::kVisible;
Jeff Sharkey81f55c62015-07-07 14:37:03 -0700249
Martijn Coenenadcc8452019-12-09 14:18:01 +0100250 mSdcardFsDefault = StringPrintf("/mnt/runtime/default/%s", label.c_str());
251 mSdcardFsRead = StringPrintf("/mnt/runtime/read/%s", label.c_str());
252 mSdcardFsWrite = StringPrintf("/mnt/runtime/write/%s", label.c_str());
253 mSdcardFsFull = StringPrintf("/mnt/runtime/full/%s", label.c_str());
Jeff Sharkey66270a22015-06-24 11:49:24 -0700254
255 setInternalPath(mRawPath);
Jeff Sharkey81f55c62015-07-07 14:37:03 -0700256 setPath(StringPrintf("/storage/%s", label.c_str()));
Jeff Sharkey66270a22015-06-24 11:49:24 -0700257
Martijn Coenenadcc8452019-12-09 14:18:01 +0100258 if (fs_prepare_dir(mSdcardFsDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
259 fs_prepare_dir(mSdcardFsRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
260 fs_prepare_dir(mSdcardFsWrite.c_str(), 0700, AID_ROOT, AID_ROOT) ||
261 fs_prepare_dir(mSdcardFsFull.c_str(), 0700, AID_ROOT, AID_ROOT)) {
Jeff Sharkey66270a22015-06-24 11:49:24 -0700262 PLOG(ERROR) << getId() << " failed to create mount points";
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800263 return -errno;
264 }
265
Martijn Coenenadcc8452019-12-09 14:18:01 +0100266 dev_t before = GetDevice(mSdcardFsFull);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700267
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100268 // Mount sdcardfs regardless of FUSE, since we need it to bind-mount on top of the
269 // FUSE volume for various reasons.
Martijn Coenen86f21a22020-01-06 09:48:14 +0100270 if (mUseSdcardFs && getMountUserId() == 0) {
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100271 LOG(INFO) << "Executing sdcardfs";
272 int sdcardFsPid;
273 if (!(sdcardFsPid = fork())) {
274 // clang-format off
275 if (execl(kSdcardFsPath, kSdcardFsPath,
276 "-u", "1023", // AID_MEDIA_RW
277 "-g", "1023", // AID_MEDIA_RW
278 "-m",
279 "-w",
280 "-G",
281 "-i",
282 "-o",
283 mRawPath.c_str(),
284 label.c_str(),
285 NULL)) {
286 // clang-format on
287 PLOG(ERROR) << "Failed to exec";
288 }
289
290 LOG(ERROR) << "sdcardfs exiting";
291 _exit(1);
292 }
293
294 if (sdcardFsPid == -1) {
295 PLOG(ERROR) << getId() << " failed to fork";
296 return -errno;
297 }
298
299 nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
300 while (before == GetDevice(mSdcardFsFull)) {
301 LOG(DEBUG) << "Waiting for sdcardfs to spin up...";
302 usleep(50000); // 50ms
303
304 nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
305 if (nanoseconds_to_milliseconds(now - start) > 5000) {
306 LOG(WARNING) << "Timed out while waiting for sdcardfs to spin up";
307 return -ETIMEDOUT;
308 }
309 }
310 /* sdcardfs will have exited already. The filesystem will still be running */
311 TEMP_FAILURE_RETRY(waitpid(sdcardFsPid, nullptr, 0));
312 sdcardFsPid = 0;
313 }
Martijn Coenen449a7d82020-03-16 14:37:33 +0100314
Ricky Waie78c78c2021-01-14 15:51:54 +0000315 if (isVisible) {
Martijn Coenen449a7d82020-03-16 14:37:33 +0100316 // Make sure we unmount sdcardfs if we bail out with an error below
317 auto sdcardfs_unmounter = [&]() {
318 LOG(INFO) << "sdcardfs_unmounter scope_guard running";
319 unmountSdcardFs();
320 };
321 auto sdcardfs_guard = android::base::make_scope_guard(sdcardfs_unmounter);
322
Zim3623a212019-07-19 16:46:53 +0100323 LOG(INFO) << "Mounting emulated fuse volume";
Nandana Dutta914cc72019-08-29 15:22:42 +0100324 android::base::unique_fd fd;
Zim981222f2019-09-09 10:24:44 +0100325 int user_id = getMountUserId();
Martijn Coenen62a4b272020-01-31 15:23:09 +0100326 auto volumeRoot = getRootPath();
Zim981222f2019-09-09 10:24:44 +0100327
Martijn Coenen62a4b272020-01-31 15:23:09 +0100328 // Make sure Android/ dirs exist for bind mounting
329 status_t res = PrepareAndroidDirs(volumeRoot);
330 if (res != OK) {
331 LOG(ERROR) << "Failed to prepare Android/ directories";
332 return res;
333 }
334
335 res = MountUserFuse(user_id, getInternalPath(), label, &fd);
336 if (res != 0) {
Zim3623a212019-07-19 16:46:53 +0100337 PLOG(ERROR) << "Failed to mount emulated fuse volume";
Martijn Coenen62a4b272020-01-31 15:23:09 +0100338 return res;
Zim3623a212019-07-19 16:46:53 +0100339 }
Zim5048b4b2019-11-19 09:16:03 +0000340
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100341 mFuseMounted = true;
Martijn Coenen449a7d82020-03-16 14:37:33 +0100342 auto fuse_unmounter = [&]() {
343 LOG(INFO) << "fuse_unmounter scope_guard running";
344 fd.reset();
345 if (UnmountUserFuse(user_id, getInternalPath(), label) != OK) {
346 PLOG(INFO) << "UnmountUserFuse failed on emulated fuse volume";
347 }
348 mFuseMounted = false;
349 };
350 auto fuse_guard = android::base::make_scope_guard(fuse_unmounter);
351
Zim5048b4b2019-11-19 09:16:03 +0000352 auto callback = getMountCallback();
353 if (callback) {
354 bool is_ready = false;
355 callback->onVolumeChecking(std::move(fd), getPath(), getInternalPath(), &is_ready);
356 if (!is_ready) {
357 return -EIO;
358 }
359 }
Martijn Coenen57002612019-11-28 11:56:13 +0100360
361 // Only do the bind-mounts when we know for sure the FUSE daemon can resolve the path.
Martijn Coenen62a4b272020-01-31 15:23:09 +0100362 res = mountFuseBindMounts();
Zimdf073f52020-01-15 15:00:07 +0000363 if (res != OK) {
Martijn Coenen449a7d82020-03-16 14:37:33 +0100364 return res;
Zimdf073f52020-01-15 15:00:07 +0000365 }
Martijn Coenen449a7d82020-03-16 14:37:33 +0100366
Nikita Ioffedcee5c12020-06-12 12:59:45 +0100367 ConfigureReadAheadForFuse(GetFuseMountPathForUser(user_id, label), 256u);
368
Martijn Coenena4850062020-06-29 11:53:34 +0200369 // By default, FUSE has a max_dirty ratio of 1%. This means that out of
370 // all dirty pages in the system, only 1% is allowed to belong to any
371 // FUSE filesystem. The reason this is in place is that FUSE
372 // filesystems shouldn't be trusted by default; a FUSE filesystem could
373 // take up say 100% of dirty pages, and subsequently refuse to write
374 // them back to storage. The kernel will then apply rate-limiting, and
375 // block other tasks from writing. For this particular FUSE filesystem
376 // however, we trust the implementation, because it is a part of the
377 // Android platform. So use the default ratio of 100%.
378 //
379 // The reason we're setting this is that there's a suspicion that the
380 // kernel starts rate-limiting the FUSE filesystem under extreme
381 // memory pressure scenarios. While the kernel will only rate limit if
382 // the writeback can't keep up with the write rate, under extreme
383 // memory pressure the write rate may dip as well, in which case FUSE
384 // writes to a 1% max_ratio filesystem are throttled to an extreme amount.
385 //
386 // To prevent this, just give FUSE 40% max_ratio, meaning it can take
387 // up to 40% of all dirty pages in the system.
388 ConfigureMaxDirtyRatioForFuse(GetFuseMountPathForUser(user_id, label), 40u);
389
Martijn Coenen449a7d82020-03-16 14:37:33 +0100390 // All mounts where successful, disable scope guards
391 sdcardfs_guard.Disable();
392 fuse_guard.Disable();
Zim3623a212019-07-19 16:46:53 +0100393 }
394
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800395 return OK;
396}
397
398status_t EmulatedVolume::doUnmount() {
Martijn Coenen8f1e7f22019-11-29 15:38:55 +0100399 int userId = getMountUserId();
400
401 // Kill all processes using the filesystem before we unmount it. If we
402 // unmount the filesystem first, most file system operations will return
Narayan Kamathea243a32016-01-21 12:26:05 +0000403 // ENOTCONN until the unmount completes. This is an exotic and unusual
404 // error code and might cause broken behaviour in applications.
Martijn Coenen8f1e7f22019-11-29 15:38:55 +0100405 if (mFuseMounted) {
406 // For FUSE specifically, we have an emulated volume per user, so only kill
407 // processes using files from this particular user.
408 std::string user_path(StringPrintf("%s/%d", getPath().c_str(), getMountUserId()));
409 LOG(INFO) << "Killing all processes referencing " << user_path;
410 KillProcessesUsingPath(user_path);
411 } else {
412 KillProcessesUsingPath(getPath());
413 }
Zim3623a212019-07-19 16:46:53 +0100414
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100415 if (mFuseMounted) {
416 std::string label = getLabel();
Ricky Wai07e64a42020-02-11 14:31:24 +0000417
Martijn Coenen57002612019-11-28 11:56:13 +0100418 // Ignoring unmount return status because we do want to try to unmount
419 // the rest cleanly.
Martijn Coenen449a7d82020-03-16 14:37:33 +0100420 unmountFuseBindMounts();
421
Martijn Coenen57002612019-11-28 11:56:13 +0100422 if (UnmountUserFuse(userId, getInternalPath(), label) != OK) {
Zima438b242019-09-25 14:37:38 +0100423 PLOG(INFO) << "UnmountUserFuse failed on emulated fuse volume";
424 return -errno;
Zim3623a212019-07-19 16:46:53 +0100425 }
426
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100427 mFuseMounted = false;
428 }
Zim3623a212019-07-19 16:46:53 +0100429
Martijn Coenen449a7d82020-03-16 14:37:33 +0100430 return unmountSdcardFs();
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800431}
432
Martijn Coenen62a4b272020-01-31 15:23:09 +0100433std::string EmulatedVolume::getRootPath() const {
434 int user_id = getMountUserId();
435 std::string volumeRoot = StringPrintf("%s/%d", getInternalPath().c_str(), user_id);
436
437 return volumeRoot;
438}
439
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800440} // namespace vold
441} // namespace android