blob: 270d0974d69576597bf11b380a9f5a8170408557 [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;
Alessio Balsini583ae3e2022-03-23 18:27:59 +000052 mFuseBpfEnabled = IsFuseBpfEnabled();
Daniel Rosenbergf36bddd2020-05-11 22:58:42 -070053 mUseSdcardFs = IsSdcardfsUsed();
Ricky Wai07e64a42020-02-11 14:31:24 +000054 mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
Jeff Sharkey3161fb32015-04-12 16:03:33 -070055}
56
Zima438b242019-09-25 14:37:38 +010057EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device, const std::string& fsUuid,
58 int userId)
Martijn Coenenadcc8452019-12-09 14:18:01 +010059 : VolumeBase(Type::kEmulated) {
Zima438b242019-09-25 14:37:38 +010060 setId(StringPrintf("emulated:%u,%u;%u", major(device), minor(device), userId));
Jeff Sharkey3161fb32015-04-12 16:03:33 -070061 mRawPath = rawPath;
Jeff Sharkey66270a22015-06-24 11:49:24 -070062 mLabel = fsUuid;
Greg Kaiser5298ccc2019-12-12 05:41:46 -080063 mFuseMounted = false;
Alessio Balsini583ae3e2022-03-23 18:27:59 +000064 mFuseBpfEnabled = IsFuseBpfEnabled();
Daniel Rosenbergf36bddd2020-05-11 22:58:42 -070065 mUseSdcardFs = IsSdcardfsUsed();
Ricky Wai07e64a42020-02-11 14:31:24 +000066 mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
Jeff Sharkeydeb24052015-03-02 21:01:40 -080067}
68
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070069EmulatedVolume::~EmulatedVolume() {}
Jeff Sharkeydeb24052015-03-02 21:01:40 -080070
Martijn Coenen6f5802e2019-11-28 11:53:53 +010071std::string EmulatedVolume::getLabel() {
Jeff Sharkey81f55c62015-07-07 14:37:03 -070072 // We could have migrated storage to an adopted private volume, so always
73 // call primary storage "emulated" to avoid media rescans.
Jeff Sharkey81f55c62015-07-07 14:37:03 -070074 if (getMountFlags() & MountFlags::kPrimary) {
Martijn Coenen6f5802e2019-11-28 11:53:53 +010075 return "emulated";
76 } else {
77 return mLabel;
Jeff Sharkey81f55c62015-07-07 14:37:03 -070078 }
Martijn Coenen6f5802e2019-11-28 11:53:53 +010079}
80
Martijn Coenen62a4b272020-01-31 15:23:09 +010081// Creates a bind mount from source to target
Martijn Coenen449a7d82020-03-16 14:37:33 +010082static status_t doFuseBindMount(const std::string& source, const std::string& target,
83 std::list<std::string>& pathsToUnmount) {
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +010084 LOG(INFO) << "Bind mounting " << source << " on " << target;
85 auto status = BindMount(source, target);
86 if (status != OK) {
87 return status;
88 }
89 LOG(INFO) << "Bind mounted " << source << " on " << target;
Martijn Coenen449a7d82020-03-16 14:37:33 +010090 pathsToUnmount.push_front(target);
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +010091 return OK;
92}
93
Martijn Coenen86f21a22020-01-06 09:48:14 +010094status_t EmulatedVolume::mountFuseBindMounts() {
95 std::string androidSource;
96 std::string label = getLabel();
97 int userId = getMountUserId();
Martijn Coenen449a7d82020-03-16 14:37:33 +010098 std::list<std::string> pathsToUnmount;
99
100 auto unmounter = [&]() {
101 LOG(INFO) << "mountFuseBindMounts() unmount scope_guard running";
102 for (const auto& path : pathsToUnmount) {
103 LOG(INFO) << "Unmounting " << path;
104 auto status = UnmountTree(path);
105 if (status != OK) {
106 LOG(INFO) << "Failed to unmount " << path;
107 } else {
108 LOG(INFO) << "Unmounted " << path;
109 }
110 }
111 };
112 auto unmount_guard = android::base::make_scope_guard(unmounter);
Martijn Coenen86f21a22020-01-06 09:48:14 +0100113
114 if (mUseSdcardFs) {
115 androidSource = StringPrintf("/mnt/runtime/default/%s/%d/Android", label.c_str(), userId);
116 } else {
117 androidSource = StringPrintf("/%s/%d/Android", mRawPath.c_str(), userId);
118 }
Martijn Coenen57002612019-11-28 11:56:13 +0100119
Ricky Wai07e64a42020-02-11 14:31:24 +0000120 status_t status = OK;
Ricky Wai259a49a2021-03-19 15:35:49 +0000121 // Zygote will unmount these dirs if app data isolation is enabled, so apps
122 // cannot access these dirs directly.
123 std::string androidDataSource = StringPrintf("%s/data", androidSource.c_str());
124 std::string androidDataTarget(
125 StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId));
126 status = doFuseBindMount(androidDataSource, androidDataTarget, pathsToUnmount);
127 if (status != OK) {
128 return status;
129 }
Ricky Wai07e64a42020-02-11 14:31:24 +0000130
Ricky Wai259a49a2021-03-19 15:35:49 +0000131 std::string androidObbSource = StringPrintf("%s/obb", androidSource.c_str());
132 std::string androidObbTarget(
133 StringPrintf("/mnt/user/%d/%s/%d/Android/obb", userId, label.c_str(), userId));
134 status = doFuseBindMount(androidObbSource, androidObbTarget, pathsToUnmount);
135 if (status != OK) {
136 return status;
Martijn Coenen57002612019-11-28 11:56:13 +0100137 }
Zimb6488f32020-03-17 15:15:42 +0000138
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +0100139 // Installers get the same view as all other apps, with the sole exception that the
140 // OBB dirs (Android/obb) are writable to them. On sdcardfs devices, this requires
141 // a special bind mount, since app-private and OBB dirs share the same GID, but we
142 // only want to give access to the latter.
Martijn Coenen449a7d82020-03-16 14:37:33 +0100143 if (mUseSdcardFs) {
Ricky Waief639212020-04-07 13:43:20 +0100144 std::string obbSource(StringPrintf("/mnt/runtime/write/%s/%d/Android/obb",
145 label.c_str(), userId));
146 std::string obbInstallerTarget(StringPrintf("/mnt/installer/%d/%s/%d/Android/obb",
147 userId, label.c_str(), userId));
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +0100148
Ricky Waief639212020-04-07 13:43:20 +0100149 status = doFuseBindMount(obbSource, obbInstallerTarget, pathsToUnmount);
150 if (status != OK) {
151 return status;
152 }
Ricky Waief639212020-04-07 13:43:20 +0100153 }
154
Martijn Coenen449a7d82020-03-16 14:37:33 +0100155 unmount_guard.Disable();
Martijn Coenen57002612019-11-28 11:56:13 +0100156 return OK;
157}
158
Martijn Coenen86f21a22020-01-06 09:48:14 +0100159status_t EmulatedVolume::unmountFuseBindMounts() {
160 std::string label = getLabel();
161 int userId = getMountUserId();
162
Ricky Waief639212020-04-07 13:43:20 +0100163 if (mUseSdcardFs || mAppDataIsolationEnabled) {
Martijn Coenen3a2dbfe2020-01-11 19:38:37 +0100164 std::string installerTarget(
165 StringPrintf("/mnt/installer/%d/%s/%d/Android/obb", userId, label.c_str(), userId));
166 LOG(INFO) << "Unmounting " << installerTarget;
167 auto status = UnmountTree(installerTarget);
168 if (status != OK) {
169 LOG(ERROR) << "Failed to unmount " << installerTarget;
170 // Intentional continue to try to unmount the other bind mount
171 }
172 }
Ricky Waief639212020-04-07 13:43:20 +0100173 if (mAppDataIsolationEnabled) {
174 std::string obbTarget( StringPrintf("/mnt/androidwritable/%d/%s/%d/Android/obb",
175 userId, label.c_str(), userId));
176 LOG(INFO) << "Unmounting " << obbTarget;
177 auto status = UnmountTree(obbTarget);
178 if (status != OK) {
179 LOG(ERROR) << "Failed to unmount " << obbTarget;
180 // Intentional continue to try to unmount the other bind mount
181 }
182 std::string dataTarget(StringPrintf("/mnt/androidwritable/%d/%s/%d/Android/data",
183 userId, label.c_str(), userId));
184 LOG(INFO) << "Unmounting " << dataTarget;
185 status = UnmountTree(dataTarget);
186 if (status != OK) {
187 LOG(ERROR) << "Failed to unmount " << dataTarget;
188 // Intentional continue to try to unmount the other bind mount
189 }
190 }
191
Ricky Wai07e64a42020-02-11 14:31:24 +0000192 // When app data isolation is enabled, kill all apps that obb/ is mounted, otherwise we should
193 // umount the whole Android/ dir.
194 if (mAppDataIsolationEnabled) {
195 std::string appObbDir(StringPrintf("%s/%d/Android/obb", getPath().c_str(), userId));
Ricky Wai23356372021-04-30 09:53:07 +0100196 // Here we assume obb/data dirs is mounted as tmpfs, then it must be caused by
197 // app data isolation.
198 KillProcessesWithTmpfsMountPrefix(appObbDir);
Martijn Coenen57002612019-11-28 11:56:13 +0100199 }
Ricky Wai5f2a9fe2021-05-05 14:43:45 +0000200
201 // Always unmount data and obb dirs as they are mounted to lowerfs for speeding up access.
202 std::string androidDataTarget(
203 StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId));
204
205 LOG(INFO) << "Unmounting " << androidDataTarget;
206 auto status = UnmountTree(androidDataTarget);
207 if (status != OK) {
208 return status;
209 }
210 LOG(INFO) << "Unmounted " << androidDataTarget;
211
212 std::string androidObbTarget(
213 StringPrintf("/mnt/user/%d/%s/%d/Android/obb", userId, label.c_str(), userId));
214
215 LOG(INFO) << "Unmounting " << androidObbTarget;
216 status = UnmountTree(androidObbTarget);
217 if (status != OK) {
218 return status;
219 }
220 LOG(INFO) << "Unmounted " << androidObbTarget;
Martijn Coenen57002612019-11-28 11:56:13 +0100221 return OK;
222}
223
Martijn Coenen449a7d82020-03-16 14:37:33 +0100224status_t EmulatedVolume::unmountSdcardFs() {
225 if (!mUseSdcardFs || getMountUserId() != 0) {
226 // For sdcardfs, only unmount for user 0, since user 0 will always be running
227 // and the paths don't change for different users.
228 return OK;
229 }
230
231 ForceUnmount(mSdcardFsDefault);
232 ForceUnmount(mSdcardFsRead);
233 ForceUnmount(mSdcardFsWrite);
234 ForceUnmount(mSdcardFsFull);
235
236 rmdir(mSdcardFsDefault.c_str());
237 rmdir(mSdcardFsRead.c_str());
238 rmdir(mSdcardFsWrite.c_str());
239 rmdir(mSdcardFsFull.c_str());
240
241 mSdcardFsDefault.clear();
242 mSdcardFsRead.clear();
243 mSdcardFsWrite.clear();
244 mSdcardFsFull.clear();
245
246 return OK;
247}
248
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100249status_t EmulatedVolume::doMount() {
250 std::string label = getLabel();
Youkichi Hosoi2991cbe2021-11-11 11:23:01 +0900251 bool isVisible = isVisibleForWrite();
Jeff Sharkey81f55c62015-07-07 14:37:03 -0700252
Martijn Coenenadcc8452019-12-09 14:18:01 +0100253 mSdcardFsDefault = StringPrintf("/mnt/runtime/default/%s", label.c_str());
254 mSdcardFsRead = StringPrintf("/mnt/runtime/read/%s", label.c_str());
255 mSdcardFsWrite = StringPrintf("/mnt/runtime/write/%s", label.c_str());
256 mSdcardFsFull = StringPrintf("/mnt/runtime/full/%s", label.c_str());
Jeff Sharkey66270a22015-06-24 11:49:24 -0700257
258 setInternalPath(mRawPath);
Jeff Sharkey81f55c62015-07-07 14:37:03 -0700259 setPath(StringPrintf("/storage/%s", label.c_str()));
Jeff Sharkey66270a22015-06-24 11:49:24 -0700260
Martijn Coenenadcc8452019-12-09 14:18:01 +0100261 if (fs_prepare_dir(mSdcardFsDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
262 fs_prepare_dir(mSdcardFsRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
263 fs_prepare_dir(mSdcardFsWrite.c_str(), 0700, AID_ROOT, AID_ROOT) ||
264 fs_prepare_dir(mSdcardFsFull.c_str(), 0700, AID_ROOT, AID_ROOT)) {
Jeff Sharkey66270a22015-06-24 11:49:24 -0700265 PLOG(ERROR) << getId() << " failed to create mount points";
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800266 return -errno;
267 }
268
Martijn Coenenadcc8452019-12-09 14:18:01 +0100269 dev_t before = GetDevice(mSdcardFsFull);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700270
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100271 // Mount sdcardfs regardless of FUSE, since we need it to bind-mount on top of the
272 // FUSE volume for various reasons.
Martijn Coenen86f21a22020-01-06 09:48:14 +0100273 if (mUseSdcardFs && getMountUserId() == 0) {
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100274 LOG(INFO) << "Executing sdcardfs";
275 int sdcardFsPid;
276 if (!(sdcardFsPid = fork())) {
277 // clang-format off
278 if (execl(kSdcardFsPath, kSdcardFsPath,
279 "-u", "1023", // AID_MEDIA_RW
280 "-g", "1023", // AID_MEDIA_RW
281 "-m",
282 "-w",
283 "-G",
284 "-i",
285 "-o",
286 mRawPath.c_str(),
287 label.c_str(),
288 NULL)) {
289 // clang-format on
290 PLOG(ERROR) << "Failed to exec";
291 }
292
293 LOG(ERROR) << "sdcardfs exiting";
294 _exit(1);
295 }
296
297 if (sdcardFsPid == -1) {
298 PLOG(ERROR) << getId() << " failed to fork";
299 return -errno;
300 }
301
302 nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
303 while (before == GetDevice(mSdcardFsFull)) {
304 LOG(DEBUG) << "Waiting for sdcardfs to spin up...";
305 usleep(50000); // 50ms
306
307 nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
308 if (nanoseconds_to_milliseconds(now - start) > 5000) {
309 LOG(WARNING) << "Timed out while waiting for sdcardfs to spin up";
310 return -ETIMEDOUT;
311 }
312 }
313 /* sdcardfs will have exited already. The filesystem will still be running */
314 TEMP_FAILURE_RETRY(waitpid(sdcardFsPid, nullptr, 0));
315 sdcardFsPid = 0;
316 }
Martijn Coenen449a7d82020-03-16 14:37:33 +0100317
Ricky Waie78c78c2021-01-14 15:51:54 +0000318 if (isVisible) {
Martijn Coenen449a7d82020-03-16 14:37:33 +0100319 // Make sure we unmount sdcardfs if we bail out with an error below
320 auto sdcardfs_unmounter = [&]() {
321 LOG(INFO) << "sdcardfs_unmounter scope_guard running";
322 unmountSdcardFs();
323 };
324 auto sdcardfs_guard = android::base::make_scope_guard(sdcardfs_unmounter);
325
Zim3623a212019-07-19 16:46:53 +0100326 LOG(INFO) << "Mounting emulated fuse volume";
Nandana Dutta914cc72019-08-29 15:22:42 +0100327 android::base::unique_fd fd;
Zim981222f2019-09-09 10:24:44 +0100328 int user_id = getMountUserId();
Martijn Coenen62a4b272020-01-31 15:23:09 +0100329 auto volumeRoot = getRootPath();
Zim981222f2019-09-09 10:24:44 +0100330
Martijn Coenen62a4b272020-01-31 15:23:09 +0100331 // Make sure Android/ dirs exist for bind mounting
332 status_t res = PrepareAndroidDirs(volumeRoot);
333 if (res != OK) {
334 LOG(ERROR) << "Failed to prepare Android/ directories";
335 return res;
336 }
337
338 res = MountUserFuse(user_id, getInternalPath(), label, &fd);
339 if (res != 0) {
Zim3623a212019-07-19 16:46:53 +0100340 PLOG(ERROR) << "Failed to mount emulated fuse volume";
Martijn Coenen62a4b272020-01-31 15:23:09 +0100341 return res;
Zim3623a212019-07-19 16:46:53 +0100342 }
Zim5048b4b2019-11-19 09:16:03 +0000343
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100344 mFuseMounted = true;
Martijn Coenen449a7d82020-03-16 14:37:33 +0100345 auto fuse_unmounter = [&]() {
346 LOG(INFO) << "fuse_unmounter scope_guard running";
347 fd.reset();
348 if (UnmountUserFuse(user_id, getInternalPath(), label) != OK) {
349 PLOG(INFO) << "UnmountUserFuse failed on emulated fuse volume";
350 }
351 mFuseMounted = false;
352 };
353 auto fuse_guard = android::base::make_scope_guard(fuse_unmounter);
354
Zim5048b4b2019-11-19 09:16:03 +0000355 auto callback = getMountCallback();
356 if (callback) {
357 bool is_ready = false;
358 callback->onVolumeChecking(std::move(fd), getPath(), getInternalPath(), &is_ready);
359 if (!is_ready) {
360 return -EIO;
361 }
362 }
Martijn Coenen57002612019-11-28 11:56:13 +0100363
Alessio Balsinidd1e91f2021-10-13 12:03:18 +0100364 if (!mFuseBpfEnabled) {
365 // Only do the bind-mounts when we know for sure the FUSE daemon can resolve the path.
366 res = mountFuseBindMounts();
367 if (res != OK) {
368 return res;
369 }
Zimdf073f52020-01-15 15:00:07 +0000370 }
Martijn Coenen449a7d82020-03-16 14:37:33 +0100371
Nikita Ioffedcee5c12020-06-12 12:59:45 +0100372 ConfigureReadAheadForFuse(GetFuseMountPathForUser(user_id, label), 256u);
373
Martijn Coenena4850062020-06-29 11:53:34 +0200374 // By default, FUSE has a max_dirty ratio of 1%. This means that out of
375 // all dirty pages in the system, only 1% is allowed to belong to any
376 // FUSE filesystem. The reason this is in place is that FUSE
377 // filesystems shouldn't be trusted by default; a FUSE filesystem could
378 // take up say 100% of dirty pages, and subsequently refuse to write
379 // them back to storage. The kernel will then apply rate-limiting, and
380 // block other tasks from writing. For this particular FUSE filesystem
381 // however, we trust the implementation, because it is a part of the
382 // Android platform. So use the default ratio of 100%.
383 //
384 // The reason we're setting this is that there's a suspicion that the
385 // kernel starts rate-limiting the FUSE filesystem under extreme
386 // memory pressure scenarios. While the kernel will only rate limit if
387 // the writeback can't keep up with the write rate, under extreme
388 // memory pressure the write rate may dip as well, in which case FUSE
389 // writes to a 1% max_ratio filesystem are throttled to an extreme amount.
390 //
391 // To prevent this, just give FUSE 40% max_ratio, meaning it can take
392 // up to 40% of all dirty pages in the system.
393 ConfigureMaxDirtyRatioForFuse(GetFuseMountPathForUser(user_id, label), 40u);
394
Martijn Coenen449a7d82020-03-16 14:37:33 +0100395 // All mounts where successful, disable scope guards
396 sdcardfs_guard.Disable();
397 fuse_guard.Disable();
Zim3623a212019-07-19 16:46:53 +0100398 }
399
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800400 return OK;
401}
402
403status_t EmulatedVolume::doUnmount() {
Martijn Coenen8f1e7f22019-11-29 15:38:55 +0100404 int userId = getMountUserId();
405
406 // Kill all processes using the filesystem before we unmount it. If we
407 // unmount the filesystem first, most file system operations will return
Narayan Kamathea243a32016-01-21 12:26:05 +0000408 // ENOTCONN until the unmount completes. This is an exotic and unusual
409 // error code and might cause broken behaviour in applications.
Martijn Coenen8f1e7f22019-11-29 15:38:55 +0100410 if (mFuseMounted) {
411 // For FUSE specifically, we have an emulated volume per user, so only kill
412 // processes using files from this particular user.
413 std::string user_path(StringPrintf("%s/%d", getPath().c_str(), getMountUserId()));
414 LOG(INFO) << "Killing all processes referencing " << user_path;
415 KillProcessesUsingPath(user_path);
416 } else {
417 KillProcessesUsingPath(getPath());
418 }
Zim3623a212019-07-19 16:46:53 +0100419
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100420 if (mFuseMounted) {
421 std::string label = getLabel();
Ricky Wai07e64a42020-02-11 14:31:24 +0000422
Alessio Balsinidd1e91f2021-10-13 12:03:18 +0100423 if (!mFuseBpfEnabled) {
424 // Ignoring unmount return status because we do want to try to
425 // unmount the rest cleanly.
426 unmountFuseBindMounts();
427 }
Martijn Coenen449a7d82020-03-16 14:37:33 +0100428
Martijn Coenen57002612019-11-28 11:56:13 +0100429 if (UnmountUserFuse(userId, getInternalPath(), label) != OK) {
Zima438b242019-09-25 14:37:38 +0100430 PLOG(INFO) << "UnmountUserFuse failed on emulated fuse volume";
431 return -errno;
Zim3623a212019-07-19 16:46:53 +0100432 }
433
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100434 mFuseMounted = false;
435 }
Zim3623a212019-07-19 16:46:53 +0100436
Martijn Coenen449a7d82020-03-16 14:37:33 +0100437 return unmountSdcardFs();
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800438}
439
Martijn Coenen62a4b272020-01-31 15:23:09 +0100440std::string EmulatedVolume::getRootPath() const {
441 int user_id = getMountUserId();
442 std::string volumeRoot = StringPrintf("%s/%d", getInternalPath().c_str(), user_id);
443
444 return volumeRoot;
445}
446
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800447} // namespace vold
448} // namespace android