Skip to content

Commit

Permalink
refactor(bin/ofs): make ofs API public (#4387)
Browse files Browse the repository at this point in the history
refactor: make ofs API public
  • Loading branch information
ho-229 authored Mar 24, 2024
1 parent bff9a55 commit 873c14b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/ofs/src/bin/ofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ async fn main() -> Result<()> {
let cfg = ofs::Config::parse();

env_logger::init();
ofs::new_app(cfg).await
ofs::execute(cfg).await
}
5 changes: 3 additions & 2 deletions bin/ofs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ use url::Url;
#[command(version, about)]
pub struct Config {
/// fuse mount path
#[cfg(target_os = "linux")]
#[arg(env = "OFS_MOUNT_PATH", index = 1)]
pub(crate) mount_path: String,
pub mount_path: String,

/// location of opendal service
/// format: <scheme>://?<key>=<value>&<key>=<value>
/// example: fs://?root=/tmp
#[arg(env = "OFS_BACKEND", index = 2)]
pub(crate) backend: Url,
pub backend: Url,
}
6 changes: 3 additions & 3 deletions bin/ofs/src/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ impl FileKey {
}
}

pub(super) struct Ofs {
pub(super) struct Fuse {
op: Operator,
gid: u32,
uid: u32,
opened_files: Slab<OpenedFile>,
}

impl Ofs {
impl Fuse {
pub fn new(op: Operator, uid: u32, gid: u32) -> Self {
Self {
op,
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Ofs {
}

#[async_trait]
impl PathFilesystem for Ofs {
impl PathFilesystem for Fuse {
type DirEntryStream = BoxStream<'static, Result<DirectoryEntry>>;
type DirEntryPlusStream = BoxStream<'static, Result<DirectoryEntryPlus>>;

Expand Down
12 changes: 6 additions & 6 deletions bin/ofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use config::Config;
#[cfg(target_os = "linux")]
mod fuse;

pub async fn new_app(cfg: Config) -> Result<()> {
pub async fn execute(cfg: Config) -> Result<()> {
if cfg.backend.has_host() {
log::warn!("backend host will be ignored");
}
Expand All @@ -52,7 +52,7 @@ pub async fn new_app(cfg: Config) -> Result<()> {
mount_path: cfg.mount_path,
backend,
};
execute(args).await
execute_inner(args).await
}

#[derive(Debug)]
Expand All @@ -63,13 +63,13 @@ struct Args {
}

#[cfg(not(target_os = "linux"))]
async fn execute(args: Args) -> Result<()> {
async fn execute_inner(args: Args) -> Result<()> {
_ = args.backend;
Err(anyhow::anyhow!("platform not supported"))
}

#[cfg(target_os = "linux")]
async fn execute(args: Args) -> Result<()> {
async fn execute_inner(args: Args) -> Result<()> {
use fuse3::path::Session;
use fuse3::MountOptions;

Expand All @@ -81,10 +81,10 @@ async fn execute(args: Args) -> Result<()> {
mount_option.gid(gid.into());
mount_option.no_open_dir_support(true);

let ofs = fuse::Ofs::new(args.backend, uid.into(), gid.into());
let adapter = fuse::Fuse::new(args.backend, uid.into(), gid.into());

let mount_handle = Session::new(mount_option)
.mount_with_unprivileged(ofs, args.mount_path)
.mount_with_unprivileged(adapter, args.mount_path)
.await?;

mount_handle.await?;
Expand Down

0 comments on commit 873c14b

Please sign in to comment.