From 81f55c6dc1a14ed68e404fa3a2c244dd343e4990 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 7 Jul 2015 14:37:03 -0700 Subject: [PATCH] Mount emulated volumes as consistent location. We really only support a single emulated volume on the device at a time, either on internal storage, or moved to a private volume. To avoid kicking off a giant rescan of all media when moved, keep all the paths the same when mounted as primary. Also ensure we have /data/media/0 ready on private volumes. Bug: 20275423 Change-Id: I0c102f430b865ca7536772b1fae56d8c9660a97a --- Benchmark.cpp | 4 ++++ EmulatedVolume.cpp | 17 ++++++++++++----- PrivateVolume.cpp | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Benchmark.cpp b/Benchmark.cpp index 7a3af65..810adf4 100644 --- a/Benchmark.cpp +++ b/Benchmark.cpp @@ -28,6 +28,8 @@ #include #include +#define ENABLE_DROP_CACHES 1 + using android::base::ReadFileToString; using android::base::WriteStringToFile; @@ -88,11 +90,13 @@ static nsecs_t benchmark(const std::string& path) { sync(); nsecs_t create = systemTime(SYSTEM_TIME_BOOTTIME); +#if ENABLE_DROP_CACHES LOG(VERBOSE) << "Before drop_caches"; if (!WriteStringToFile("3", "/proc/sys/vm/drop_caches")) { PLOG(ERROR) << "Failed to drop_caches"; } LOG(VERBOSE) << "After drop_caches"; +#endif nsecs_t drop = systemTime(SYSTEM_TIME_BOOTTIME); BenchmarkRun(); diff --git a/EmulatedVolume.cpp b/EmulatedVolume.cpp index d8d9198..f1ca97b 100644 --- a/EmulatedVolume.cpp +++ b/EmulatedVolume.cpp @@ -54,12 +54,19 @@ EmulatedVolume::~EmulatedVolume() { } status_t EmulatedVolume::doMount() { - mFuseDefault = StringPrintf("/mnt/runtime_default/%s", mLabel.c_str()); - mFuseRead = StringPrintf("/mnt/runtime_read/%s", mLabel.c_str()); - mFuseWrite = StringPrintf("/mnt/runtime_write/%s", mLabel.c_str()); + // We could have migrated storage to an adopted private volume, so always + // call primary storage "emulated" to avoid media rescans. + std::string label = mLabel; + if (getMountFlags() & MountFlags::kPrimary) { + label = "emulated"; + } + + mFuseDefault = StringPrintf("/mnt/runtime_default/%s", label.c_str()); + mFuseRead = StringPrintf("/mnt/runtime_read/%s", label.c_str()); + mFuseWrite = StringPrintf("/mnt/runtime_write/%s", label.c_str()); setInternalPath(mRawPath); - setPath(StringPrintf("/storage/%s", mLabel.c_str())); + setPath(StringPrintf("/storage/%s", label.c_str())); if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) || fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) || @@ -77,7 +84,7 @@ status_t EmulatedVolume::doMount() { "-m", "-w", mRawPath.c_str(), - mLabel.c_str(), + label.c_str(), NULL)) { PLOG(ERROR) << "Failed to exec"; } diff --git a/PrivateVolume.cpp b/PrivateVolume.cpp index 74b6b5b..6ddef3f 100644 --- a/PrivateVolume.cpp +++ b/PrivateVolume.cpp @@ -159,6 +159,7 @@ status_t PrivateVolume::doMount() { if (PrepareDir(mPath + "/app", 0771, AID_SYSTEM, AID_SYSTEM) || PrepareDir(mPath + "/user", 0711, AID_SYSTEM, AID_SYSTEM) || PrepareDir(mPath + "/media", 0770, AID_MEDIA_RW, AID_MEDIA_RW) || + PrepareDir(mPath + "/media/0", 0770, AID_MEDIA_RW, AID_MEDIA_RW) || PrepareDir(mPath + "/local", 0751, AID_ROOT, AID_ROOT) || PrepareDir(mPath + "/local/tmp", 0771, AID_SHELL, AID_SHELL)) { PLOG(ERROR) << getId() << " failed to prepare";