From 70f44d96729d5ee38448365c8b7968c56d1ffd5c Mon Sep 17 00:00:00 2001 From: Victor Hsieh Date: Wed, 9 Mar 2022 19:44:58 +0000 Subject: [PATCH] fuse: Add FuseConfig builder API fuse::worker::start_message_loop is not a scalable API, so deprecate it. This paves the way to support multiple threads. BUG=b:220386264 TEST=Modify a client in Android to use the API Change-Id: I41e8d5267384311a7b03beb67f7774332863fbf7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3514617 Reviewed-by: Daniel Verkamp Tested-by: kokoro Commit-Queue: Victor Hsieh --- fuse/src/lib.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++ fuse/src/worker.rs | 2 ++ 2 files changed, 49 insertions(+) diff --git a/fuse/src/lib.rs b/fuse/src/lib.rs index 5346d8b0f4..379e06bc44 100644 --- a/fuse/src/lib.rs +++ b/fuse/src/lib.rs @@ -3,6 +3,7 @@ // found in the LICENSE file. use std::ffi::FromBytesWithNulError; +use std::fs::File; use std::io; use remain::sorted; @@ -20,6 +21,8 @@ pub mod worker; pub use mount::mount; pub use server::{Mapper, Reader, Server, Writer}; +use filesystem::FileSystem; + /// Errors that may occur during the creation or operation of an Fs device. #[sorted] #[derive(ThisError, Debug)] @@ -62,3 +65,47 @@ pub enum Error { } pub type Result = ::std::result::Result; + +#[derive(Default)] +pub struct FuseConfig { + dev_fuse_file: Option, + max_write_bytes: Option, + max_read_bytes: Option, +} + +impl FuseConfig { + pub fn new() -> Self { + FuseConfig { + ..Default::default() + } + } + + pub fn dev_fuse(&mut self, file: File) -> &mut Self { + self.dev_fuse_file = Some(file); + self + } + + pub fn max_read(&mut self, bytes: u32) -> &mut Self { + self.max_read_bytes = Some(bytes); + self + } + + pub fn max_write(&mut self, bytes: u32) -> &mut Self { + self.max_write_bytes = Some(bytes); + self + } + + pub fn enter_message_loop(self, fs: F) -> Result<()> { + let FuseConfig { + dev_fuse_file, + max_write_bytes, + max_read_bytes, + } = self; + worker::start_message_loop( + dev_fuse_file.ok_or(Error::MissingParameter)?, + max_write_bytes.ok_or(Error::MissingParameter)?, + max_read_bytes.ok_or(Error::MissingParameter)?, + fs, + ) + } +} diff --git a/fuse/src/worker.rs b/fuse/src/worker.rs index 27dcbee944..b733e3fde3 100644 --- a/fuse/src/worker.rs +++ b/fuse/src/worker.rs @@ -144,6 +144,8 @@ impl Mapper for DevFuseMapper { } /// Start the FUSE message handling loop. Returns when an error happens. +/// +/// [deprecated(note="Please migrate to the `FuseConfig` builder API"] pub fn start_message_loop( dev_fuse: File, max_write: u32,