Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool DartComponentController::CreateAndBindNamespace() {
}

if (ns_entry.path() == kTmpPath) {
// /tmp is covered by the local memfs.
// /tmp is covered by a locally served virtual filesystem.
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool DartTestComponentController::CreateAndBindNamespace() {
}

if (ns_entry.path() == kTmpPath) {
// /tmp is covered by the local memfs.
// /tmp is covered by a locally served virtual filesystem.
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions shell/platform/fuchsia/flutter/component_v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ ComponentV2::ComponentV2(
return;
}

// Setup /tmp to be mapped to the process-local memfs.
// Setup /tmp to be mapped to a process-local virtual filesystem.
dart_utils::RunnerTemp::SetupComponent(fdio_ns_.get());

// ComponentStartInfo::ns (optional)
if (start_info.has_ns()) {
for (auto& entry : *start_info.mutable_ns()) {
// /tmp/ is mapped separately to the process-level memfs, so we ignore it
// here.
// /tmp/ is mapped separately to to a process-local virtual filesystem,
// so we ignore it here.
const auto& path = entry.path();
if (path == kTmpPath) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char const* argv[]) {
&already_started);
}

// Set up the process-wide /tmp memfs.
// Set up the process-wide /tmp virtual filesystem.
dart_utils::RunnerTemp runner_temp;

fml::MessageLoop& loop = fml::MessageLoop::GetCurrent();
Expand Down
1 change: 0 additions & 1 deletion shell/platform/fuchsia/runtime/dart/utils/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ template("make_utils") {
"$fuchsia_sdk_root/pkg:async-loop-cpp",
"$fuchsia_sdk_root/pkg:async-loop-default",
"$fuchsia_sdk_root/pkg:fdio",
"$fuchsia_sdk_root/pkg:memfs",
"$fuchsia_sdk_root/pkg:sys_cpp",
"$fuchsia_sdk_root/pkg:sys_inspect_cpp",
"$fuchsia_sdk_root/pkg:syslog",
Expand Down
53 changes: 33 additions & 20 deletions shell/platform/fuchsia/runtime/dart/utils/tempfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <lib/async-loop/default.h>
#include <lib/async/cpp/task.h>
#include <lib/fdio/namespace.h>
#include <lib/memfs/memfs.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>
Expand All @@ -23,7 +23,6 @@
namespace {

constexpr char kTmpPath[] = "/tmp";
[[maybe_unused]] constexpr size_t kMaxTmpPages = 1024;

} // namespace

Expand All @@ -38,31 +37,45 @@ RunnerTemp::RunnerTemp()

RunnerTemp::~RunnerTemp() = default;

static vfs::PseudoDir tmp_dir;

void RunnerTemp::Start() {
std::promise<void> finished;
std::promise<zx_status_t> finished;
async::PostTask(loop_->dispatcher(), [this, &finished]() {
#if defined(DART_PRODUCT)
zx_status_t status = memfs_install_at_with_page_limit(
loop_->dispatcher(), kMaxTmpPages, kTmpPath);
#else
memfs_filesystem_t* fs;
// Hot reload uses /tmp to hold the updated dills and assets so do not
// impose any size limitation in non product runners.
zx_status_t status = memfs_install_at(loop_->dispatcher(), kTmpPath, &fs);
#endif
finished.set_value();
if (status != ZX_OK) {
FX_LOGF(ERROR, LOG_TAG, "Failed to install a /tmp memfs: %s",
zx_status_get_string(status));
return;
}
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;
}());
});
finished.get_future().wait();
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) {
// TODO(zra): Should isolates share a /tmp file system within a process, or
// should isolates each get their own private memfs for /tmp? For now,
// 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;
Expand Down
8 changes: 4 additions & 4 deletions shell/platform/fuchsia/runtime/dart/utils/tempfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace dart_utils {
// Sets up /tmp for the dart_runner and flutter_runner.
class RunnerTemp {
public:
// Sets up a memfs bound to /tmp in the process-wide namespace that has the
// lifetime of this instance.
// Sets up a virtual filesystem bound to /tmp in the process-wide namespace
// that has the lifetime of this instance.
RunnerTemp();
~RunnerTemp();

// Take the memfs mapped into the process-wide namespace for /tmp, and map it
// to /tmp in the given namespace.
// 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:
Expand Down
4 changes: 0 additions & 4 deletions tools/fuchsia/fuchsia_libs.gni
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ common_libs = [
name = "libfdio.so"
path = rebase_path("$fuchsia_sdk_dist")
},
{
name = "libmemfs.so"
path = rebase_path("$fuchsia_sdk_dist")
},
{
name = "libsyslog.so"
path = rebase_path("$fuchsia_sdk_dist")
Expand Down