From f088a43a8b75b6bb7e5bdf767c5d4bbcd9ac40fd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 12 Jun 2023 15:21:22 +0000 Subject: [PATCH 1/2] Remove reference to memfs_install_at_with_page_limit This was removed in https://fxrev.dev/363037 over 3 years ago. --- shell/platform/fuchsia/runtime/dart/utils/tempfs.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc b/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc index becfffddf0874..f226976e1433f 100644 --- a/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc +++ b/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc @@ -23,7 +23,6 @@ namespace { constexpr char kTmpPath[] = "/tmp"; -[[maybe_unused]] constexpr size_t kMaxTmpPages = 1024; } // namespace @@ -41,15 +40,8 @@ RunnerTemp::~RunnerTemp() = default; void RunnerTemp::Start() { std::promise 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", From a5e03db6614458dff1c1eaca5c43003c2b1e34e6 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 12 Jun 2023 15:39:15 +0000 Subject: [PATCH 2/2] Remove dependency on memfs memfs was removed from the fuchsia SDK in https://fxrev.dev/c/867584. Replace its usage with vfs::PseudoDir. Fixes https://github.com/flutter/flutter/issues/128703. --- .../dart_runner/dart_component_controller.cc | 2 +- .../dart_test_component_controller.cc | 2 +- .../platform/fuchsia/flutter/component_v2.cc | 6 +-- shell/platform/fuchsia/flutter/main.cc | 2 +- .../fuchsia/runtime/dart/utils/BUILD.gn | 1 - .../fuchsia/runtime/dart/utils/tempfs.cc | 45 ++++++++++++++----- .../fuchsia/runtime/dart/utils/tempfs.h | 8 ++-- tools/fuchsia/fuchsia_libs.gni | 4 -- 8 files changed, 43 insertions(+), 27 deletions(-) diff --git a/shell/platform/fuchsia/dart_runner/dart_component_controller.cc b/shell/platform/fuchsia/dart_runner/dart_component_controller.cc index c0803410c7b29..52c0fd7227d50 100644 --- a/shell/platform/fuchsia/dart_runner/dart_component_controller.cc +++ b/shell/platform/fuchsia/dart_runner/dart_component_controller.cc @@ -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; } diff --git a/shell/platform/fuchsia/dart_runner/dart_test_component_controller.cc b/shell/platform/fuchsia/dart_runner/dart_test_component_controller.cc index a1786e26497c5..ca69e2c07924d 100644 --- a/shell/platform/fuchsia/dart_runner/dart_test_component_controller.cc +++ b/shell/platform/fuchsia/dart_runner/dart_test_component_controller.cc @@ -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; } diff --git a/shell/platform/fuchsia/flutter/component_v2.cc b/shell/platform/fuchsia/flutter/component_v2.cc index 3ad4169869ad4..7139e8971b308 100644 --- a/shell/platform/fuchsia/flutter/component_v2.cc +++ b/shell/platform/fuchsia/flutter/component_v2.cc @@ -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; diff --git a/shell/platform/fuchsia/flutter/main.cc b/shell/platform/fuchsia/flutter/main.cc index cb41db4576cc6..05f09a8305471 100644 --- a/shell/platform/fuchsia/flutter/main.cc +++ b/shell/platform/fuchsia/flutter/main.cc @@ -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(); diff --git a/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn b/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn index fc1e9cc5c9d5c..a2924cf0c3273 100644 --- a/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn +++ b/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn @@ -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", diff --git a/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc b/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc index f226976e1433f..151183c348085 100644 --- a/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc +++ b/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc @@ -12,8 +12,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -37,24 +37,45 @@ RunnerTemp::RunnerTemp() RunnerTemp::~RunnerTemp() = default; +static vfs::PseudoDir tmp_dir; + void RunnerTemp::Start() { - std::promise finished; + std::promise finished; async::PostTask(loop_->dispatcher(), [this, &finished]() { - memfs_filesystem_t* fs; - zx_status_t status = memfs_install_at(loop_->dispatcher(), kTmpPath, &fs); - 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; diff --git a/shell/platform/fuchsia/runtime/dart/utils/tempfs.h b/shell/platform/fuchsia/runtime/dart/utils/tempfs.h index 1861ee1e6d0c0..bce1ef71b8597 100644 --- a/shell/platform/fuchsia/runtime/dart/utils/tempfs.h +++ b/shell/platform/fuchsia/runtime/dart/utils/tempfs.h @@ -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: diff --git a/tools/fuchsia/fuchsia_libs.gni b/tools/fuchsia/fuchsia_libs.gni index 2458e4e617d29..c5608ed20a077 100644 --- a/tools/fuchsia/fuchsia_libs.gni +++ b/tools/fuchsia/fuchsia_libs.gni @@ -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")