[incfs] Use new IncFs_ReleaseControlFds() instead of duping

Vold needs to pass / accept IncFs control via Binder, so it
neeeds to get and put its internal FDs in and out. Using the new
release() function it works without extra fd duping

Bug: 153704006
Test: builds & boots
Change-Id: I64bc5b1ca9f2c69e34c3a860ed3edbe58bd9ea29
gugelfrei
Yurii Zubrytskyi 4 years ago
parent 4e1e7ef09a
commit fc7b6697b4

@ -41,7 +41,7 @@
#include "VoldUtil.h" #include "VoldUtil.h"
#include "VolumeManager.h" #include "VolumeManager.h"
#include "cryptfs.h" #include "cryptfs.h"
#include "incfs_ndk.h" #include "incfs.h"
using android::base::StringPrintf; using android::base::StringPrintf;
using std::endl; using std::endl;
@ -879,7 +879,7 @@ binder::Status VoldNativeService::resetCheckpoint() {
binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) { binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) {
ENFORCE_SYSTEM_OR_ROOT; ENFORCE_SYSTEM_OR_ROOT;
*_aidl_return = IncFs_IsEnabled(); *_aidl_return = incfs::enabled();
return Ok(); return Ok();
} }
@ -890,22 +890,19 @@ binder::Status VoldNativeService::mountIncFs(
CHECK_ARGUMENT_PATH(backingPath); CHECK_ARGUMENT_PATH(backingPath);
CHECK_ARGUMENT_PATH(targetDir); CHECK_ARGUMENT_PATH(targetDir);
auto control = IncFs_Mount(backingPath.c_str(), targetDir.c_str(), auto control = incfs::mount(backingPath, targetDir,
{.flags = IncFsMountFlags(flags), {.flags = IncFsMountFlags(flags),
.defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
// Mount with read logs disabled. // Mount with read logs disabled.
.readLogBufferPages = 0}); .readLogBufferPages = 0});
if (control == nullptr) { if (!control) {
return translate(-1); return translate(-errno);
} }
using unique_fd = ::android::base::unique_fd; auto fds = control.releaseFds();
_aidl_return->cmd.reset(unique_fd(dup(IncFs_GetControlFd(control, CMD)))); using android::base::unique_fd;
_aidl_return->pendingReads.reset(unique_fd(dup(IncFs_GetControlFd(control, PENDING_READS)))); _aidl_return->cmd.reset(unique_fd(fds[CMD].release()));
auto logsFd = IncFs_GetControlFd(control, LOGS); _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release()));
if (logsFd >= 0) { _aidl_return->log.reset(unique_fd(fds[LOGS].release()));
_aidl_return->log.reset(unique_fd(dup(logsFd)));
}
IncFs_DeleteControl(control);
return Ok(); return Ok();
} }
@ -913,7 +910,7 @@ binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
ENFORCE_SYSTEM_OR_ROOT; ENFORCE_SYSTEM_OR_ROOT;
CHECK_ARGUMENT_PATH(dir); CHECK_ARGUMENT_PATH(dir);
return translate(IncFs_Unmount(dir.c_str())); return translate(incfs::unmount(dir));
} }
binder::Status VoldNativeService::setIncFsMountOptions( binder::Status VoldNativeService::setIncFsMountOptions(
@ -921,19 +918,24 @@ binder::Status VoldNativeService::setIncFsMountOptions(
bool enableReadLogs) { bool enableReadLogs) {
ENFORCE_SYSTEM_OR_ROOT; ENFORCE_SYSTEM_OR_ROOT;
auto status = Ok(); auto incfsControl =
auto incfsControl = IncFs_CreateControl(dup(control.cmd.get()), dup(control.pendingReads.get()), incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get());
dup(control.log.get())); auto cleanupFunc = [](auto incfsControl) {
if (auto error = IncFs_SetOptions( for (auto& fd : incfsControl->releaseFds()) {
(void)fd.release();
}
};
auto cleanup =
std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc);
if (auto error = incfs::setOptions(
incfsControl, incfsControl,
{.defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, {.defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
.readLogBufferPages = enableReadLogs ? INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES : 0}); .readLogBufferPages = enableReadLogs ? INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES : 0});
error < 0) { error < 0) {
status = binder::Status::fromServiceSpecificError(error); return binder::Status::fromServiceSpecificError(error);
} }
IncFs_DeleteControl(incfsControl);
return status; return Ok();
} }
binder::Status VoldNativeService::bindMount(const std::string& sourceDir, binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
@ -942,7 +944,7 @@ binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
CHECK_ARGUMENT_PATH(sourceDir); CHECK_ARGUMENT_PATH(sourceDir);
CHECK_ARGUMENT_PATH(targetDir); CHECK_ARGUMENT_PATH(targetDir);
return translate(IncFs_BindMount(sourceDir.c_str(), targetDir.c_str())); return translate(incfs::bindMount(sourceDir, targetDir));
} }
} // namespace vold } // namespace vold

Loading…
Cancel
Save