From 4aebfdb9342dfd5e4cea1069f722e1cb4f17f0c2 Mon Sep 17 00:00:00 2001 From: owl Date: Mon, 23 Sep 2024 15:13:17 +0800 Subject: [PATCH] feat(ofs): introduce ofs macos stpport --- bin/ofs/Cargo.lock | 42 ++++----------------------- bin/ofs/Cargo.toml | 4 +-- bin/ofs/src/main.rs | 12 ++------ integrations/fuse3/Cargo.toml | 2 +- integrations/fuse3/src/file_system.rs | 23 +++++++++++++++ 5 files changed, 34 insertions(+), 49 deletions(-) diff --git a/bin/ofs/Cargo.lock b/bin/ofs/Cargo.lock index 7850162a8f4..7e825412715 100644 --- a/bin/ofs/Cargo.lock +++ b/bin/ofs/Cargo.lock @@ -213,12 +213,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "cfg_aliases" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" - [[package]] name = "cfg_aliases" version = "0.2.1" @@ -392,16 +386,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "cstr" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68523903c8ae5aacfa32a0d9ae60cadeb764e1da14ee0d26b1f3089f13a54636" -dependencies = [ - "proc-macro2", - "quote", -] - [[package]] name = "deranged" version = "0.3.11" @@ -517,18 +501,16 @@ dependencies = [ [[package]] name = "fuse3" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02ca1b211677ee014a10b94ab6aea31e622ad1ea35f48b1670ac492a4f88b1af" +version = "0.7.3" +source = "git+https://github.com/oowl/fuse3?branch=owl/macos-support-recreate#ad7fa7b05afc5159c618d0a4db14beb839c4b89d" dependencies = [ "async-notify", "bincode", "bytes", - "cstr", "futures-channel", "futures-util", "libc", - "nix 0.28.0", + "nix", "serde", "slab", "tokio", @@ -962,19 +944,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "nix" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" -dependencies = [ - "bitflags", - "cfg-if", - "cfg_aliases 0.1.1", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.29.0" @@ -983,8 +952,9 @@ checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ "bitflags", "cfg-if", - "cfg_aliases 0.2.1", + "cfg_aliases", "libc", + "memoffset", ] [[package]] @@ -1035,7 +1005,7 @@ dependencies = [ "futures-util", "libc", "log", - "nix 0.29.0", + "nix", "opendal", "sharded-slab", "tempfile", diff --git a/bin/ofs/Cargo.toml b/bin/ofs/Cargo.toml index 4383cdd5ce5..4430a261e2f 100644 --- a/bin/ofs/Cargo.toml +++ b/bin/ofs/Cargo.toml @@ -46,8 +46,8 @@ tokio = { version = "1.37.0", features = [ ] } url = "2.5.0" -[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies] -fuse3 = { "version" = "0.7.2", "features" = ["tokio-runtime", "unprivileged"] } +[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))'.dependencies] +fuse3 = { git = "https://github.com/oowl/fuse3", branch = "owl/macos-support-recreate", "features" = ["tokio-runtime", "unprivileged"] } fuse3_opendal = { version = "0.0.7", path = "../../integrations/fuse3" } libc = "0.2.154" nix = { version = "0.29.0", features = ["user"] } diff --git a/bin/ofs/src/main.rs b/bin/ofs/src/main.rs index a3e16afceaf..ce0b563fe00 100644 --- a/bin/ofs/src/main.rs +++ b/bin/ofs/src/main.rs @@ -42,7 +42,7 @@ async fn main() -> Result<()> { execute(cfg).await } -#[cfg(any(target_os = "linux", target_os = "freebsd"))] +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))] async fn execute(cfg: Config) -> Result<()> { use std::env; use std::str::FromStr; @@ -71,7 +71,7 @@ async fn execute(cfg: Config) -> Result<()> { let mut uid = nix::unistd::getuid().into(); mount_options.uid(uid); - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))] let mut mount_handle = if nix::unistd::getuid().is_root() { if let Some(sudo_gid) = env::var("SUDO_GID") .ok() @@ -100,9 +100,6 @@ async fn execute(cfg: Config) -> Result<()> { .await? }; - #[cfg(target_os = "freebsd")] - let mut mount_handle = Fuse::new().mount(cfg.mount_path, backend).await?; - let handle = &mut mount_handle; tokio::select! { res = handle => res?, @@ -190,8 +187,3 @@ async fn execute(cfg: Config) -> Result<()> { Ok(()) } - -#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "windows")))] -async fn execute(_cfg: Config) -> Result<()> { - Err(anyhow!("platform not supported")) -} diff --git a/integrations/fuse3/Cargo.toml b/integrations/fuse3/Cargo.toml index 04ddd15b664..233608d836f 100644 --- a/integrations/fuse3/Cargo.toml +++ b/integrations/fuse3/Cargo.toml @@ -29,7 +29,7 @@ version = "0.0.7" [dependencies] bytes = "1.6.0" -fuse3 = { version = "0.7.2", "features" = ["tokio-runtime", "unprivileged"] } +fuse3 = { git = "https://github.com/oowl/fuse3", branch = "owl/macos-support-recreate", "features" = ["tokio-runtime", "unprivileged"] } futures-util = "0.3.30" libc = "0.2.155" log = "0.4.21" diff --git a/integrations/fuse3/src/file_system.rs b/integrations/fuse3/src/file_system.rs index a3380d69ce4..18855787171 100644 --- a/integrations/fuse3/src/file_system.rs +++ b/integrations/fuse3/src/file_system.rs @@ -376,6 +376,11 @@ impl PathFilesystem for Filesystem { Err(libc::EOPNOTSUPP.into()) } + async fn opendir(&self, _req: Request, path: &OsStr, flags: u32) -> Result { + log::debug!("opendir(path={:?}, flags=0x{:x})", path, flags); + Ok(ReplyOpen { fh: 0, flags }) + } + async fn open(&self, _req: Request, path: &OsStr, flags: u32) -> Result { log::debug!("open(path={:?}, flags=0x{:x})", path, flags); @@ -821,6 +826,20 @@ impl PathFilesystem for Filesystem { copied: u64::from(written), }) } + + async fn statfs(&self, _req: Request, path: &OsStr) -> Result { + log::debug!("statfs(path={:?})", path); + Ok(ReplyStatFs { + blocks: 1, + bfree: 0, + bavail: 0, + files: 1, + ffree: 0, + bsize: 4096, + namelen: u32::MAX, + frsize: 0, + }) + } } const fn entry_mode2file_type(mode: EntryMode) -> FileType { @@ -855,6 +874,10 @@ const fn dummy_file_attr(kind: FileType, now: SystemTime, uid: u32, gid: u32) -> gid, rdev: 0, blksize: 4096, + #[cfg(target_os = "macos")] + crtime: now, + #[cfg(target_os = "macos")] + flags: 0, } }