Remove process-local tempfs (flutter/engine#43056)
This was incorrectly made read-only in 0984c52a8f; instead of implementing it locally, ask the component manager for the directory.
This commit is contained in:
@@ -182,7 +182,7 @@ bool DartComponentController::CreateAndBindNamespace() {
|
||||
zx_status_get_string(ns_create_status));
|
||||
}
|
||||
|
||||
dart_utils::RunnerTemp::SetupComponent(namespace_);
|
||||
dart_utils::BindTemp(namespace_);
|
||||
|
||||
// Bind each directory in start_info's namespace to the controller's namespace
|
||||
// instance.
|
||||
|
||||
@@ -195,7 +195,7 @@ bool DartTestComponentController::CreateAndBindNamespace() {
|
||||
zx_status_get_string(ns_create_status));
|
||||
}
|
||||
|
||||
dart_utils::RunnerTemp::SetupComponent(namespace_);
|
||||
dart_utils::BindTemp(namespace_);
|
||||
|
||||
// Bind each directory in start_info's namespace to the controller's namespace
|
||||
// instance.
|
||||
|
||||
@@ -62,7 +62,6 @@ int main(int argc, const char** argv) {
|
||||
#endif // defined(AOT_RUNTIME)
|
||||
#endif // !defined(DART_PRODUCT)
|
||||
|
||||
dart_utils::RunnerTemp runner_temp;
|
||||
dart_runner::DartRunner runner(context.get());
|
||||
|
||||
// Wait to serve until we have finished all of our setup.
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
},
|
||||
],
|
||||
use: [
|
||||
// This is used by the Dart VM to communicate from Dart code to C++ code.
|
||||
{
|
||||
storage: "tmp",
|
||||
path: "/tmp",
|
||||
},
|
||||
// This is used by the Dart VM to load i18n data.
|
||||
{
|
||||
directory: "config-data",
|
||||
|
||||
@@ -182,8 +182,7 @@ ComponentV2::ComponentV2(
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup /tmp to be mapped to a process-local virtual filesystem.
|
||||
dart_utils::RunnerTemp::SetupComponent(fdio_ns_.get());
|
||||
dart_utils::BindTemp(fdio_ns_.get());
|
||||
|
||||
// ComponentStartInfo::ns (optional)
|
||||
if (start_info.has_ns()) {
|
||||
|
||||
@@ -40,9 +40,6 @@ int main(int argc, char const* argv[]) {
|
||||
&already_started);
|
||||
}
|
||||
|
||||
// Set up the process-wide /tmp virtual filesystem.
|
||||
dart_utils::RunnerTemp runner_temp;
|
||||
|
||||
fml::MessageLoop& loop = fml::MessageLoop::GetCurrent();
|
||||
flutter_runner::Runner runner(loop.GetTaskRunner(), context.get());
|
||||
|
||||
|
||||
@@ -4,16 +4,9 @@
|
||||
|
||||
#include "tempfs.h"
|
||||
|
||||
#include <future>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <string_view>
|
||||
|
||||
#include <lib/async-loop/cpp/loop.h>
|
||||
#include <lib/async-loop/default.h>
|
||||
#include <lib/async/cpp/task.h>
|
||||
#include <lib/fdio/namespace.h>
|
||||
#include <lib/syslog/global.h>
|
||||
#include <lib/vfs/cpp/pseudo_dir.h>
|
||||
#include <zircon/errors.h>
|
||||
#include <zircon/status.h>
|
||||
#include <zircon/syscalls.h>
|
||||
@@ -28,60 +21,13 @@ constexpr char kTmpPath[] = "/tmp";
|
||||
|
||||
namespace dart_utils {
|
||||
|
||||
RunnerTemp::RunnerTemp()
|
||||
: loop_(std::make_unique<async::Loop>(
|
||||
&kAsyncLoopConfigNoAttachToCurrentThread)) {
|
||||
loop_->StartThread("RunnerTemp");
|
||||
Start();
|
||||
}
|
||||
|
||||
RunnerTemp::~RunnerTemp() = default;
|
||||
|
||||
static vfs::PseudoDir tmp_dir;
|
||||
|
||||
void RunnerTemp::Start() {
|
||||
std::promise<zx_status_t> finished;
|
||||
async::PostTask(loop_->dispatcher(), [this, &finished]() {
|
||||
finished.set_value([this]() {
|
||||
zx::channel client, server;
|
||||
if (zx_status_t status = zx::channel::create(0, &client, &server);
|
||||
status != ZX_OK) {
|
||||
return status;
|
||||
}
|
||||
if (zx_status_t status =
|
||||
tmp_dir.Serve(fuchsia::io::OpenFlags::RIGHT_READABLE |
|
||||
fuchsia::io::OpenFlags::RIGHT_WRITABLE |
|
||||
fuchsia::io::OpenFlags::DIRECTORY,
|
||||
std::move(server), loop_->dispatcher());
|
||||
status != ZX_OK) {
|
||||
return status;
|
||||
}
|
||||
fdio_ns_t* ns;
|
||||
if (zx_status_t status = fdio_ns_get_installed(&ns); status != ZX_OK) {
|
||||
return status;
|
||||
}
|
||||
if (zx_status_t status = fdio_ns_bind(ns, kTmpPath, client.release());
|
||||
status != ZX_OK) {
|
||||
return status;
|
||||
}
|
||||
return ZX_OK;
|
||||
}());
|
||||
});
|
||||
if (zx_status_t status = finished.get_future().get(); status != ZX_OK) {
|
||||
FX_LOGF(ERROR, LOG_TAG, "Failed to install a /tmp virtual filesystem: %s",
|
||||
zx_status_get_string(status));
|
||||
}
|
||||
}
|
||||
|
||||
void RunnerTemp::SetupComponent(fdio_ns_t* ns) {
|
||||
void BindTemp(fdio_ns_t* ns) {
|
||||
// TODO(zra): Should isolates share a /tmp file system within a process, or
|
||||
// should isolates each get their own private file system for /tmp? For now,
|
||||
// sharing the process-wide /tmp simplifies hot reload since the hot reload
|
||||
// devfs requires sharing between the service isolate and the app isolates.
|
||||
zx_status_t status;
|
||||
fdio_flat_namespace_t* rootns;
|
||||
status = fdio_ns_export_root(&rootns);
|
||||
if (status != ZX_OK) {
|
||||
if (zx_status_t status = fdio_ns_export_root(&rootns); status != ZX_OK) {
|
||||
FX_LOGF(ERROR, LOG_TAG, "Failed to export root ns: %s",
|
||||
zx_status_get_string(status));
|
||||
return;
|
||||
@@ -89,18 +35,14 @@ void RunnerTemp::SetupComponent(fdio_ns_t* ns) {
|
||||
|
||||
zx_handle_t tmp_dir_handle;
|
||||
for (size_t i = 0; i < rootns->count; i++) {
|
||||
if (strcmp(rootns->path[i], kTmpPath) == 0) {
|
||||
tmp_dir_handle = rootns->handle[i];
|
||||
} else {
|
||||
zx_handle_close(rootns->handle[i]);
|
||||
rootns->handle[i] = ZX_HANDLE_INVALID;
|
||||
if (std::string_view{rootns->path[i]} == kTmpPath) {
|
||||
tmp_dir_handle = std::exchange(rootns->handle[i], ZX_HANDLE_INVALID);
|
||||
}
|
||||
}
|
||||
free(rootns);
|
||||
rootns = nullptr;
|
||||
fdio_ns_free_flat_ns(rootns);
|
||||
|
||||
status = fdio_ns_bind(ns, kTmpPath, tmp_dir_handle);
|
||||
if (status != ZX_OK) {
|
||||
if (zx_status_t status = fdio_ns_bind(ns, kTmpPath, tmp_dir_handle);
|
||||
status != ZX_OK) {
|
||||
zx_handle_close(tmp_dir_handle);
|
||||
FX_LOGF(ERROR, LOG_TAG,
|
||||
"Failed to bind /tmp directory into isolate namespace: %s",
|
||||
|
||||
@@ -5,34 +5,13 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_TEMPFS_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_TEMPFS_H_
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <lib/async-loop/cpp/loop.h>
|
||||
#include <lib/fdio/namespace.h>
|
||||
|
||||
namespace dart_utils {
|
||||
|
||||
// Sets up /tmp for the dart_runner and flutter_runner.
|
||||
class RunnerTemp {
|
||||
public:
|
||||
// Sets up a virtual filesystem bound to /tmp in the process-wide namespace
|
||||
// that has the lifetime of this instance.
|
||||
RunnerTemp();
|
||||
~RunnerTemp();
|
||||
|
||||
// Take the virtual filesystem mapped into the process-wide namespace for
|
||||
// /tmp, and map it to /tmp in the given namespace.
|
||||
static void SetupComponent(fdio_ns_t* ns);
|
||||
|
||||
private:
|
||||
void Start();
|
||||
|
||||
std::unique_ptr<async::Loop> loop_;
|
||||
|
||||
// Disallow copy and assignment.
|
||||
RunnerTemp(const RunnerTemp&) = delete;
|
||||
RunnerTemp& operator=(const RunnerTemp&) = delete;
|
||||
};
|
||||
// Take the virtual filesystem mapped into the process-wide namespace for /tmp,
|
||||
// and map it to /tmp in the given namespace.
|
||||
void BindTemp(fdio_ns_t* ns);
|
||||
|
||||
} // namespace dart_utils
|
||||
|
||||
|
||||
Reference in New Issue
Block a user