mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 10:10:41 +00:00
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 <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
This commit is contained in:
parent
ee60fe491f
commit
70f44d9672
2 changed files with 49 additions and 0 deletions
|
@ -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<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FuseConfig {
|
||||
dev_fuse_file: Option<File>,
|
||||
max_write_bytes: Option<u32>,
|
||||
max_read_bytes: Option<u32>,
|
||||
}
|
||||
|
||||
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<F: FileSystem + Sync + Send>(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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<F: FileSystem + Sync>(
|
||||
dev_fuse: File,
|
||||
max_write: u32,
|
||||
|
|
Loading…
Reference in a new issue