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
This commit is contained in:
Jeff Sharkey 2015-07-07 14:37:03 -07:00
parent c86ab6f538
commit 81f55c6dc1
3 changed files with 17 additions and 5 deletions

View file

@ -28,6 +28,8 @@
#include <sys/resource.h> #include <sys/resource.h>
#include <unistd.h> #include <unistd.h>
#define ENABLE_DROP_CACHES 1
using android::base::ReadFileToString; using android::base::ReadFileToString;
using android::base::WriteStringToFile; using android::base::WriteStringToFile;
@ -88,11 +90,13 @@ static nsecs_t benchmark(const std::string& path) {
sync(); sync();
nsecs_t create = systemTime(SYSTEM_TIME_BOOTTIME); nsecs_t create = systemTime(SYSTEM_TIME_BOOTTIME);
#if ENABLE_DROP_CACHES
LOG(VERBOSE) << "Before drop_caches"; LOG(VERBOSE) << "Before drop_caches";
if (!WriteStringToFile("3", "/proc/sys/vm/drop_caches")) { if (!WriteStringToFile("3", "/proc/sys/vm/drop_caches")) {
PLOG(ERROR) << "Failed to drop_caches"; PLOG(ERROR) << "Failed to drop_caches";
} }
LOG(VERBOSE) << "After drop_caches"; LOG(VERBOSE) << "After drop_caches";
#endif
nsecs_t drop = systemTime(SYSTEM_TIME_BOOTTIME); nsecs_t drop = systemTime(SYSTEM_TIME_BOOTTIME);
BenchmarkRun(); BenchmarkRun();

View file

@ -54,12 +54,19 @@ EmulatedVolume::~EmulatedVolume() {
} }
status_t EmulatedVolume::doMount() { status_t EmulatedVolume::doMount() {
mFuseDefault = StringPrintf("/mnt/runtime_default/%s", mLabel.c_str()); // We could have migrated storage to an adopted private volume, so always
mFuseRead = StringPrintf("/mnt/runtime_read/%s", mLabel.c_str()); // call primary storage "emulated" to avoid media rescans.
mFuseWrite = StringPrintf("/mnt/runtime_write/%s", mLabel.c_str()); 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); 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) || if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
fs_prepare_dir(mFuseRead.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", "-m",
"-w", "-w",
mRawPath.c_str(), mRawPath.c_str(),
mLabel.c_str(), label.c_str(),
NULL)) { NULL)) {
PLOG(ERROR) << "Failed to exec"; PLOG(ERROR) << "Failed to exec";
} }

View file

@ -159,6 +159,7 @@ status_t PrivateVolume::doMount() {
if (PrepareDir(mPath + "/app", 0771, AID_SYSTEM, AID_SYSTEM) || if (PrepareDir(mPath + "/app", 0771, AID_SYSTEM, AID_SYSTEM) ||
PrepareDir(mPath + "/user", 0711, 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", 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", 0751, AID_ROOT, AID_ROOT) ||
PrepareDir(mPath + "/local/tmp", 0771, AID_SHELL, AID_SHELL)) { PrepareDir(mPath + "/local/tmp", 0771, AID_SHELL, AID_SHELL)) {
PLOG(ERROR) << getId() << " failed to prepare"; PLOG(ERROR) << getId() << " failed to prepare";