Skip to content

Commit 84d20a1

Browse files
Vociferixcberner
authored andcommitted
implemented direct mounting without libfuse or fusermount
1 parent 04dbde1 commit 84d20a1

8 files changed

Lines changed: 682 additions & 9 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ libfuse2 = ["libfuse"]
5959
libfuse3 = ["libfuse"]
6060
serializable = ["serde"]
6161
macfuse-4-compat = []
62+
direct-mount = ["nix/resource", "nix/signal"]
6263
# abi-7-xx feature flags are deprecated and don't do anything.
6364
abi-7-20 = []
6465
abi-7-21 = []

build.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
// Register rustc cfg for switching between mount implementations.
33
println!(
4-
"cargo::rustc-check-cfg=cfg(fuser_mount_impl, values(\"pure-rust\", \"libfuse2\", \"libfuse3\", \"macos-no-mount\"))"
4+
"cargo::rustc-check-cfg=cfg(fuser_mount_impl, values(\"direct-mount\", \"pure-rust\", \"libfuse2\", \"libfuse3\", \"macos-no-mount\"))"
55
);
66

77
let target_os =
@@ -12,7 +12,11 @@ fn main() {
1212
"linux" | "freebsd" | "dragonfly" | "openbsd" | "netbsd"
1313
) && cfg!(not(feature = "libfuse"))
1414
{
15-
println!("cargo::rustc-cfg=fuser_mount_impl=\"pure-rust\"");
15+
if cfg!(feature = "direct-mount") {
16+
println!("cargo::rustc-cfg=fuser_mount_impl=\"direct-mount\"");
17+
} else {
18+
println!("cargo::rustc-cfg=fuser_mount_impl=\"pure-rust\"");
19+
}
1620
} else if target_os == "macos" {
1721
if cfg!(feature = "macos-no-mount") {
1822
println!("cargo::rustc-cfg=fuser_mount_impl=\"macos-no-mount\"");

fuser-tests/src/commands/bsd_mount.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ use crate::ansi::green;
88
use crate::canonical_temp_dir::CanonicalTempDir;
99
use crate::cargo::cargo_build_example;
1010
use crate::command_utils::command_success;
11+
use crate::features::Feature;
1112
use crate::mount_util::wait_for_fuse_mount;
1213

1314
pub(crate) async fn run_bsd_mount_tests() -> anyhow::Result<()> {
15+
// Run tests using pure-rust (fusermount) implementation
16+
run_bsd_mount_tests_with_features(&[]).await?;
17+
18+
// Run tests using direct-mount (direct mount syscall) implementation
19+
run_bsd_mount_tests_with_features(&[Feature::DirectMount]).await?;
20+
21+
Ok(())
22+
}
23+
24+
async fn run_bsd_mount_tests_with_features(features: &[Feature]) -> anyhow::Result<()> {
1425
let mount_dir = CanonicalTempDir::new()?;
1526
let mount_path = mount_dir.path();
1627

17-
let hello_exe = cargo_build_example("hello", &[]).await?;
28+
let hello_exe = cargo_build_example("hello", features).await?;
1829

1930
eprintln!("Starting hello filesystem...");
2031
let mut fuse_process = Command::new(&hello_exe)

fuser-tests/src/commands/mount.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ async fn run_mount_tests_inner(libfuse: Libfuse) -> anyhow::Result<()> {
4444
run_test(&[], Unmount::Auto, libfuse.fusermount(), 1, false).await?;
4545
test_no_user_allow_other(&[], &libfuse).await?;
4646

47+
// Tests without libfuse feature (direct mount syscall implementation)
48+
run_test(
49+
&[Feature::DirectMount],
50+
Unmount::Manual,
51+
Fusermount::False,
52+
1,
53+
false,
54+
)
55+
.await?;
56+
run_test(
57+
&[Feature::DirectMount],
58+
Unmount::Auto,
59+
Fusermount::False,
60+
1,
61+
false,
62+
)
63+
.await?;
64+
test_no_user_allow_other(&[Feature::DirectMount], &libfuse).await?;
65+
4766
// Tests with libfuse
4867
run_test(
4968
&[libfuse.feature()],
@@ -65,6 +84,22 @@ async fn run_mount_tests_inner(libfuse: Libfuse) -> anyhow::Result<()> {
6584
// Multi-threaded tests
6685
run_test(&[], Unmount::Auto, libfuse.fusermount(), 2, false).await?;
6786
run_test(&[], Unmount::Auto, libfuse.fusermount(), 2, true).await?;
87+
run_test(
88+
&[Feature::DirectMount],
89+
Unmount::Auto,
90+
Fusermount::False,
91+
2,
92+
false,
93+
)
94+
.await?;
95+
run_test(
96+
&[Feature::DirectMount],
97+
Unmount::Auto,
98+
Fusermount::False,
99+
2,
100+
true,
101+
)
102+
.await?;
68103

69104
if let Libfuse::Libfuse3 = libfuse {
70105
run_allow_root_test()

fuser-tests/src/features.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub(crate) enum Feature {
1111
Libfuse2,
1212
/// Use libfuse3 for mounting.
1313
Libfuse3,
14+
/// Use mount syscall directly for mounting.
15+
DirectMount,
1416
}
1517

1618
impl Feature {
@@ -20,6 +22,7 @@ impl Feature {
2022
Feature::Experimental => "experimental",
2123
Feature::Libfuse2 => "libfuse2",
2224
Feature::Libfuse3 => "libfuse3",
25+
Feature::DirectMount => "direct-mount",
2326
}
2427
}
2528
}

0 commit comments

Comments
 (0)