Merge "Configure read ahead for fuse mounts" into rvc-dev am: bcd7d5e7ce am: 7e29904e8c am: ee31d7a050

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

Change-Id: I529a5b90aee69c5b11bf4e2b8e5d9385bcb76d4d
This commit is contained in:
Nikita Ioffe 2020-06-17 17:26:30 +00:00 committed by Automerger Merge Worker
commit f325f2ba7c
4 changed files with 40 additions and 0 deletions

View file

@ -63,6 +63,7 @@ using android::base::EndsWith;
using android::base::ReadFileToString;
using android::base::StartsWith;
using android::base::StringPrintf;
using android::base::unique_fd;
namespace android {
namespace vold {
@ -92,6 +93,10 @@ static const char* kMediaProviderAppCtx = "u:r:mediaprovider_app:";
// other between multiple threads.
static std::mutex kSecurityLock;
std::string GetFuseMountPathForUser(userid_t user_id, const std::string& relative_upper_path) {
return StringPrintf("/mnt/user/%d/%s", user_id, relative_upper_path.c_str());
}
status_t CreateDeviceNode(const std::string& path, dev_t dev) {
std::lock_guard<std::mutex> lock(kSecurityLock);
const char* cpath = path.c_str();
@ -1381,6 +1386,33 @@ status_t EnsureDirExists(const std::string& path, mode_t mode, uid_t uid, gid_t
return OK;
}
// Configures read ahead property of the fuse filesystem with the mount point |fuse_mount| by
// writing |read_ahead_kb| to the /sys/class/bdi/MAJOR:MINOR/read_ahead_kb.
void ConfigureReadAheadForFuse(const std::string& fuse_mount, size_t read_ahead_kb) {
LOG(INFO) << "Configuring read_ahead of " << fuse_mount << " fuse filesystem to "
<< read_ahead_kb << "kb";
// First figure out MAJOR:MINOR of fuse_mount. Simplest way is to stat the path.
struct stat info;
if (stat(fuse_mount.c_str(), &info) != 0) {
PLOG(ERROR) << "Failed to stat " << fuse_mount;
return;
}
unsigned int maj = major(info.st_dev);
unsigned int min = minor(info.st_dev);
LOG(INFO) << fuse_mount << " has major:minor " << maj << ":" << min;
// We found major:minor of our filesystem, time to configure read ahead!
std::string read_ahead_file = StringPrintf("/sys/class/bdi/%u:%u/read_ahead_kb", maj, min);
unique_fd fd(TEMP_FAILURE_RETRY(open(read_ahead_file.c_str(), O_WRONLY | O_CLOEXEC)));
if (fd.get() == -1) {
PLOG(ERROR) << "Failed to open " << read_ahead_file;
return;
}
LOG(INFO) << "Writing " << read_ahead_kb << " to " << read_ahead_file;
if (!WriteStringToFd(std::to_string(read_ahead_kb), fd)) {
PLOG(ERROR) << "Failed to write to " << read_ahead_file;
}
}
status_t MountUserFuse(userid_t user_id, const std::string& absolute_lower_path,
const std::string& relative_upper_path, android::base::unique_fd* fuse_fd) {
std::string pre_fuse_path(StringPrintf("/mnt/user/%d", user_id));

View file

@ -47,6 +47,8 @@ extern security_context_t sFsckUntrustedContext;
// TODO remove this with better solution, b/64143519
extern bool sSleepOnUnmount;
std::string GetFuseMountPathForUser(userid_t user_id, const std::string& relative_upper_path);
status_t CreateDeviceNode(const std::string& path, dev_t dev);
status_t DestroyDeviceNode(const std::string& path);
@ -174,6 +176,8 @@ bool FsyncDirectory(const std::string& dirname);
bool writeStringToFile(const std::string& payload, const std::string& filename);
void ConfigureReadAheadForFuse(const std::string& fuse_mount, size_t read_ahead_kb);
status_t MountUserFuse(userid_t user_id, const std::string& absolute_lower_path,
const std::string& relative_upper_path, android::base::unique_fd* fuse_fd);

View file

@ -402,6 +402,8 @@ status_t EmulatedVolume::doMount() {
return res;
}
ConfigureReadAheadForFuse(GetFuseMountPathForUser(user_id, label), 256u);
// All mounts where successful, disable scope guards
sdcardfs_guard.Disable();
fuse_guard.Disable();

View file

@ -250,6 +250,8 @@ status_t PublicVolume::doMount() {
return -EIO;
}
}
ConfigureReadAheadForFuse(GetFuseMountPathForUser(user_id, stableName), 256u);
}
return OK;