From 7fcebd5d4047688ea06a5b34e5c5ee518d818290 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Sun, 4 Feb 2024 18:05:55 +0800 Subject: [PATCH 1/7] refactor: replace async-trait crate with AFIT feature --- Cargo.toml | 18 +++++++++--------- examples/Cargo.toml | 1 - examples/src/helloworld/main.rs | 2 -- examples/src/memfs/main.rs | 2 -- examples/src/path_memfs/main.rs | 2 -- examples/src/poll/main.rs | 2 -- src/helper.rs | 2 +- src/lib.rs | 2 -- src/mount_options.rs | 2 +- src/path/inode_path_bridge.rs | 2 -- src/path/path_filesystem.rs | 5 ++--- src/raw/filesystem.rs | 5 ++--- src/raw/session.rs | 7 +++---- 13 files changed, 18 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6208e7b..a200aac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ categories = ["api-bindings", "filesystem"] license = "MIT" repository = "https://github.com/Sherlock-Holo/fuse3" description = "FUSE user-space library async version implementation." -rust-version = "1.63" +rust-version = "1.75" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -24,19 +24,19 @@ unprivileged = ["nix/socket", "which"] doc = ["file-lock", "unprivileged", "tokio-runtime"] [dependencies] -futures-util = { version = "0.3", features = ["sink"] } -futures-channel = { version = "0.3", features = ["sink"] } -async-trait = "0.1.2" +async-io = { version = "1.4", optional = true } +bincode = "1.3.1" +bytes = "1" cstr = "0.2" +futures-channel = { version = "0.3", features = ["sink"] } +futures-util = { version = "0.3", features = ["sink"] } libc = "0.2.147" -bincode = "1.3.1" -serde = { version = "1.0.103", features = ["derive"] } nix = { version = "0.27", default-features = false, features = ["fs", "mount"] } -which = { version = "4", optional = true } -async-io = { version = "1.4", optional = true } -bytes = "1" +serde = { version = "1.0.103", features = ["derive"] } slab = "0.4.2" tracing = "0.1.21" +trait-variant = { version = "0.1", git = "https://github.com/Sherlock-Holo/impl-trait-utils", branch = "support-default-method" } +which = { version = "4", optional = true } [target.'cfg(target_os = "linux")'.dependencies] nix = { version = "0.27", default-features = false, features = ["user"] } diff --git a/examples/Cargo.toml b/examples/Cargo.toml index ebbcbb1..b631fd7 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -25,7 +25,6 @@ path = "src/path_memfs/main.rs" [dependencies] fuse3 = { path = "../", features = ["tokio-runtime", "unprivileged"] } -async-trait = "0.1.2" libc = "0.2.147" tokio = { version = "1", features = ["macros", "rt", "time"] } futures-util = "0.3" diff --git a/examples/src/helloworld/main.rs b/examples/src/helloworld/main.rs index b18fab6..2eab2d8 100644 --- a/examples/src/helloworld/main.rs +++ b/examples/src/helloworld/main.rs @@ -4,7 +4,6 @@ use std::iter::Skip; use std::time::{Duration, SystemTime}; use std::vec::IntoIter; -use async_trait::async_trait; use bytes::Bytes; use fuse3::raw::prelude::*; use fuse3::{MountOptions, Result}; @@ -33,7 +32,6 @@ const STATFS: ReplyStatFs = ReplyStatFs { struct HelloWorld; -#[async_trait] impl Filesystem for HelloWorld { type DirEntryStream = Iter>>>; type DirEntryPlusStream = Iter>>>; diff --git a/examples/src/memfs/main.rs b/examples/src/memfs/main.rs index 5057ae8..6db9e06 100644 --- a/examples/src/memfs/main.rs +++ b/examples/src/memfs/main.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use std::time::{Duration, SystemTime}; use std::vec::IntoIter; -use async_trait::async_trait; use bytes::{Buf, BytesMut}; use fuse3::raw::prelude::*; use fuse3::{Errno, Inode, MountOptions, Result}; @@ -188,7 +187,6 @@ impl Default for Fs { } } -#[async_trait] impl Filesystem for Fs { type DirEntryStream = Empty>; type DirEntryPlusStream = Iter>>; diff --git a/examples/src/path_memfs/main.rs b/examples/src/path_memfs/main.rs index d5c7953..e05d414 100644 --- a/examples/src/path_memfs/main.rs +++ b/examples/src/path_memfs/main.rs @@ -5,7 +5,6 @@ use std::io::{Cursor, Read, Write}; use std::time::{Duration, SystemTime}; use std::vec::IntoIter; -use async_trait::async_trait; use bytes::{Buf, BufMut, BytesMut}; use fuse3::path::prelude::*; use fuse3::{Errno, MountOptions, Result}; @@ -138,7 +137,6 @@ impl Default for Fs { } } -#[async_trait] impl PathFilesystem for Fs { type DirEntryStream = Empty>; type DirEntryPlusStream = Iter>>; diff --git a/examples/src/poll/main.rs b/examples/src/poll/main.rs index 82171a1..31317c2 100644 --- a/examples/src/poll/main.rs +++ b/examples/src/poll/main.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use std::time::{Duration, SystemTime}; use std::vec::IntoIter; -use async_trait::async_trait; use bytes::Bytes; use fuse3::raw::prelude::*; use fuse3::{MountOptions, Result}; @@ -32,7 +31,6 @@ struct Poll { ready: Arc, } -#[async_trait] impl Filesystem for Poll { type DirEntryStream = Iter>>>; type DirEntryPlusStream = Iter>>>; diff --git a/src/helper.rs b/src/helper.rs index 3b3f827..b604ff5 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -41,7 +41,7 @@ pub fn mode_from_kind_and_perm(kind: FileType, perm: u16) -> u32 { } /// returns the permission for a given file kind and mode -#[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms. +#[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms. pub fn perm_from_mode_and_kind(kind: FileType, mode: mode_t) -> u16 { (mode ^ mode_t::from(kind)) as u16 } diff --git a/src/lib.rs b/src/lib.rs index 61e54ff..6878f07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,8 +22,6 @@ use std::{ time::{Duration, SystemTime, UNIX_EPOCH}, }; -/// re-export [`async_trait`][async_trait::async_trait]. -pub use async_trait::async_trait; pub use errno::Errno; pub use helper::{mode_from_kind_and_perm, perm_from_mode_and_kind}; pub use mount_options::MountOptions; diff --git a/src/mount_options.rs b/src/mount_options.rs index c9adc02..0d45955 100644 --- a/src/mount_options.rs +++ b/src/mount_options.rs @@ -272,7 +272,7 @@ impl MountOptions { opts.push("allow_other".to_string()); } - if matches!(self.read_only, true) { + if self.read_only { opts.push("ro".to_string()); } diff --git a/src/path/inode_path_bridge.rs b/src/path/inode_path_bridge.rs index 8c403c2..99b8e52 100644 --- a/src/path/inode_path_bridge.rs +++ b/src/path/inode_path_bridge.rs @@ -7,7 +7,6 @@ use std::vec::IntoIter; #[cfg(all(not(feature = "tokio-runtime"), feature = "async-std-runtime"))] use async_std::sync::RwLock; -use async_trait::async_trait; use bytes::Bytes; use futures_util::stream::{self, Iter, Stream, StreamExt}; use slab::Slab; @@ -144,7 +143,6 @@ impl Debug for InodePathBridge { } } -#[async_trait] impl Filesystem for InodePathBridge where FS: PathFilesystem + Send + Sync, diff --git a/src/path/path_filesystem.rs b/src/path/path_filesystem.rs index 768703b..08c7dc4 100644 --- a/src/path/path_filesystem.rs +++ b/src/path/path_filesystem.rs @@ -1,6 +1,5 @@ use std::ffi::OsStr; -use async_trait::async_trait; use bytes::Bytes; use futures_util::stream::Stream; @@ -16,14 +15,14 @@ use crate::notify::Notify; use crate::{Result, SetAttr}; #[allow(unused_variables)] -#[async_trait] +#[trait_variant::make(PathFilesystem: Send)] /// Path based filesystem trait. /// /// # Notes: /// /// this trait is defined with async_trait, you can use /// [`async_trait`](https://docs.rs/async-trait) to implement it, or just implement it directly. -pub trait PathFilesystem { +pub trait LocalPathFilesystem { /// dir entry stream given by [`readdir`][PathFilesystem::readdir]. type DirEntryStream: Stream> + Send; diff --git a/src/raw/filesystem.rs b/src/raw/filesystem.rs index d961ea7..cacfe19 100644 --- a/src/raw/filesystem.rs +++ b/src/raw/filesystem.rs @@ -1,6 +1,5 @@ use std::ffi::OsStr; -use async_trait::async_trait; use bytes::Bytes; use futures_util::stream::Stream; @@ -10,14 +9,14 @@ use crate::raw::request::Request; use crate::{Inode, Result, SetAttr}; #[allow(unused_variables)] -#[async_trait] +#[trait_variant::make(Filesystem: Send)] /// Inode based filesystem trait. /// /// # Notes: /// /// this trait is defined with async_trait, you can use /// [`async_trait`](https://docs.rs/async-trait) to implement it, or just implement it directly. -pub trait Filesystem { +pub trait LocalFilesystem { /// dir entry stream given by [`readdir`][Filesystem::readdir]. type DirEntryStream: Stream> + Send; diff --git a/src/raw/session.rs b/src/raw/session.rs index 9179ae7..a282a34 100644 --- a/src/raw/session.rs +++ b/src/raw/session.rs @@ -245,10 +245,9 @@ impl Session { task::spawn(async move { Self::reply_fuse(fuse_write_connection, receiver).await }) .fuse(); #[cfg(all(not(feature = "async-std-runtime"), feature = "tokio-runtime"))] - let reply_task = - task::spawn(Self::reply_fuse(fuse_write_connection, receiver)) - .fuse() - .map(Result::unwrap); + let reply_task = task::spawn(Self::reply_fuse(fuse_write_connection, receiver)) + .fuse() + .map(Result::unwrap); pin_mut!(reply_task); From c2891830ae0974600b45860b763543295c3003c4 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Sat, 17 Feb 2024 12:19:29 +0800 Subject: [PATCH 2/7] refactor: replace trait-variant with trait-make --- Cargo.toml | 6 +++--- src/lib.rs | 2 ++ src/path/path_filesystem.rs | 4 ++-- src/raw/filesystem.rs | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a200aac..92525fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ tokio-runtime = ["tokio"] async-std-runtime = ["async-std", "async-io"] file-lock = [] unprivileged = ["nix/socket", "which"] -doc = ["file-lock", "unprivileged", "tokio-runtime"] [dependencies] async-io = { version = "1.4", optional = true } @@ -35,7 +34,7 @@ nix = { version = "0.27", default-features = false, features = ["fs", "mount"] } serde = { version = "1.0.103", features = ["derive"] } slab = "0.4.2" tracing = "0.1.21" -trait-variant = { version = "0.1", git = "https://github.com/Sherlock-Holo/impl-trait-utils", branch = "support-default-method" } +trait-make = "0.1" which = { version = "4", optional = true } [target.'cfg(target_os = "linux")'.dependencies] @@ -52,7 +51,8 @@ features = ["fs", "rt", "sync", "net", "macros"] optional = true [package.metadata.docs.rs] -features = [ "doc" ] +rustdoc-args = ["--cfg", "docsrs"] +features = ["file-lock", "unprivileged", "tokio-runtime"] targets = [ "i686-unknown-freebsd", "i686-unknown-linux-gnu", diff --git a/src/lib.rs b/src/lib.rs index 6878f07..73591f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,8 @@ //! //! You must enable `async-std-runtime` or `tokio-runtime` feature. +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + use std::{ convert::TryInto, time::{Duration, SystemTime, UNIX_EPOCH}, diff --git a/src/path/path_filesystem.rs b/src/path/path_filesystem.rs index 08c7dc4..ef31336 100644 --- a/src/path/path_filesystem.rs +++ b/src/path/path_filesystem.rs @@ -15,14 +15,14 @@ use crate::notify::Notify; use crate::{Result, SetAttr}; #[allow(unused_variables)] -#[trait_variant::make(PathFilesystem: Send)] +#[trait_make::make(Send)] /// Path based filesystem trait. /// /// # Notes: /// /// this trait is defined with async_trait, you can use /// [`async_trait`](https://docs.rs/async-trait) to implement it, or just implement it directly. -pub trait LocalPathFilesystem { +pub trait PathFilesystem { /// dir entry stream given by [`readdir`][PathFilesystem::readdir]. type DirEntryStream: Stream> + Send; diff --git a/src/raw/filesystem.rs b/src/raw/filesystem.rs index cacfe19..c33bf14 100644 --- a/src/raw/filesystem.rs +++ b/src/raw/filesystem.rs @@ -9,14 +9,14 @@ use crate::raw::request::Request; use crate::{Inode, Result, SetAttr}; #[allow(unused_variables)] -#[trait_variant::make(Filesystem: Send)] +#[trait_make::make(Send)] /// Inode based filesystem trait. /// /// # Notes: /// /// this trait is defined with async_trait, you can use /// [`async_trait`](https://docs.rs/async-trait) to implement it, or just implement it directly. -pub trait LocalFilesystem { +pub trait Filesystem { /// dir entry stream given by [`readdir`][Filesystem::readdir]. type DirEntryStream: Stream> + Send; From eddcad2590a0b42f93f98a856422ff280696e317 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Sat, 17 Feb 2024 17:41:53 +0800 Subject: [PATCH 3/7] ci: update ci config --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index dda92c8..6b36698 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -7,7 +7,7 @@ build: &BUILD - rustup component add clippy - cargo check --all-targets --features=tokio-runtime,file-lock,unprivileged - cargo check --all-targets --features=async-std-runtime,file-lock,unprivileged - - cargo doc --no-deps --features=doc + - RUSTDOCFLAGS="--cfg docsrs" cargo doc --features=file-lock,unprivileged,tokio-runtime - cargo clippy --all-targets --features=tokio-runtime,file-lock,unprivileged - cargo clippy --all-targets --features=async-std-runtime,file-lock,unprivileged before_cache_script: rm -rf $HOME/.cargo/registry/index From 8fe45d3ca725d71c630d7dc42643883fcc358131 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Sat, 17 Feb 2024 17:42:10 +0800 Subject: [PATCH 4/7] refactor: update deps --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 92525fa..ebcde16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ serde = { version = "1.0.103", features = ["derive"] } slab = "0.4.2" tracing = "0.1.21" trait-make = "0.1" -which = { version = "4", optional = true } +which = { version = "6", optional = true } [target.'cfg(target_os = "linux")'.dependencies] nix = { version = "0.27", default-features = false, features = ["user"] } From e620f3b78ab431d2d6f894e993ac917f5b7ad738 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Sat, 17 Feb 2024 17:43:26 +0800 Subject: [PATCH 5/7] feat: implement Hash, Ord, PartialOrd for Request --- src/raw/request.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raw/request.rs b/src/raw/request.rs index ef75375..52ed783 100644 --- a/src/raw/request.rs +++ b/src/raw/request.rs @@ -1,6 +1,6 @@ use crate::raw::abi::fuse_in_header; -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] /// Request data pub struct Request { /// the unique identifier of this request. From b7027901b3cd342dde51bc2ff63a632d41d30716 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Sat, 17 Feb 2024 17:48:35 +0800 Subject: [PATCH 6/7] ci: fix ci --- .cirrus.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index 6b36698..b026970 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -7,7 +7,8 @@ build: &BUILD - rustup component add clippy - cargo check --all-targets --features=tokio-runtime,file-lock,unprivileged - cargo check --all-targets --features=async-std-runtime,file-lock,unprivileged - - RUSTDOCFLAGS="--cfg docsrs" cargo doc --features=file-lock,unprivileged,tokio-runtime + # - RUSTDOCFLAGS="--cfg docsrs" cargo doc --features=file-lock,unprivileged,tokio-runtime # disable until doc_cfg and doc_auto_cfg are stable + - cargo doc --features=file-lock,unprivileged,tokio-runtime - cargo clippy --all-targets --features=tokio-runtime,file-lock,unprivileged - cargo clippy --all-targets --features=async-std-runtime,file-lock,unprivileged before_cache_script: rm -rf $HOME/.cargo/registry/index From a86b2aad876c002aceddeab24e9bc8b9108a5c33 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Sat, 17 Feb 2024 17:59:33 +0800 Subject: [PATCH 7/7] ci: fix ci minver error --- Cargo.toml | 10 +++++----- examples/Cargo.toml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ebcde16..5c8fc2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,16 +24,16 @@ unprivileged = ["nix/socket", "which"] [dependencies] async-io = { version = "1.4", optional = true } -bincode = "1.3.1" +bincode = "1.3.3" bytes = "1" cstr = "0.2" futures-channel = { version = "0.3", features = ["sink"] } futures-util = { version = "0.3", features = ["sink"] } -libc = "0.2.147" +libc = "0.2.153" nix = { version = "0.27", default-features = false, features = ["fs", "mount"] } -serde = { version = "1.0.103", features = ["derive"] } -slab = "0.4.2" -tracing = "0.1.21" +serde = { version = "1.0.196", features = ["derive"] } +slab = "0.4.9" +tracing = "0.1.40" trait-make = "0.1" which = { version = "6", optional = true } diff --git a/examples/Cargo.toml b/examples/Cargo.toml index b631fd7..ea29472 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -25,11 +25,11 @@ path = "src/path_memfs/main.rs" [dependencies] fuse3 = { path = "../", features = ["tokio-runtime", "unprivileged"] } -libc = "0.2.147" +libc = "0.2.153" tokio = { version = "1", features = ["macros", "rt", "time"] } futures-util = "0.3" mio = { version = "0.8", features = ["os-poll"] } tempfile = "3" bytes = "1" -tracing = "0.1.21" +tracing = "0.1.40" tracing-subscriber = "0.3"