Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Session to allow users to mount it themselves #301

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ readme = "README.md"
authors = ["Christopher Berner <[email protected]>"]
keywords = ["fuse", "filesystem", "system", "bindings"]
categories = ["external-ffi-bindings", "api-bindings", "filesystem", "os::unix-apis"]
build = "build.rs"

[dependencies]
libc = "0.2.51"
Expand All @@ -31,12 +30,7 @@ serde = { version = "1.0.102", features = ["std", "derive"] }
tempfile = "3.10.1"
nix = { version = "0.28.0", features = ["poll", "fs", "ioctl"] }

[build-dependencies]
pkg-config = { version = "0.3.14", optional = true }

[features]
default = ["libfuse"]
libfuse = ["pkg-config"]
serializable = ["serde"]
abi-7-9 = []
abi-7-10 = ["abi-7-9"]
Expand Down
46 changes: 0 additions & 46 deletions build.rs

This file was deleted.

7 changes: 6 additions & 1 deletion examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,10 @@ fn main() {
if matches.get_flag("allow-root") {
options.push(MountOption::AllowRoot);
}
fuser::mount2(HelloFS, mountpoint, &options).unwrap();

if options.contains(&MountOption::AutoUnmount) {
fuser::fusermount(HelloFS, mountpoint, &options).unwrap();
} else {
fuser::mount2(HelloFS, mountpoint, &options).unwrap();
}
}
3 changes: 1 addition & 2 deletions examples/notify_inval_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ fn main() {
timeout: Duration::from_secs_f32(opts.timeout),
};

let session = fuser::Session::new(fs, opts.mount_point, &options).unwrap();
let session = fuser::spawn_mount2(fs, opts.mount_point, &options).expect("failed to mount");
let notifier = session.notifier();
let _bg = session.spawn().unwrap();

loop {
let mut fname = fname.lock().unwrap();
Expand Down
3 changes: 1 addition & 2 deletions examples/notify_inval_inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ fn main() {
lookup_cnt,
};

let session = fuser::Session::new(fs, opts.mount_point, &options).unwrap();
let session = fuser::spawn_mount2(fs, opts.mount_point, &options).expect("failed to mount");
let notifier = session.notifier();
let _bg = session.spawn().unwrap();

loop {
let mut s = fdata.lock().unwrap();
Expand Down
6 changes: 2 additions & 4 deletions examples/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ fn main() {
let fs = FSelFS { data: data.clone() };

let mntpt = std::env::args().nth(1).unwrap();
let session = fuser::Session::new(fs, mntpt, &options).unwrap();
let bg = session.spawn().unwrap();

producer(&data, &bg.notifier());
let session = fuser::spawn_mount2(fs, mntpt, &options).expect("failed to mount");
producer(&data, &session.notifier());
}
23 changes: 14 additions & 9 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2039,21 +2039,26 @@ fn main() {
.unwrap()
.to_string();

let result = fuser::mount2(
SimpleFS::new(
data_dir,
matches.get_flag("direct-io"),
matches.get_flag("suid"),
),
mountpoint,
&options,
let fs = SimpleFS::new(
data_dir,
matches.get_flag("direct-io"),
matches.get_flag("suid"),
);
let result = if options.contains(&MountOption::AutoUnmount) {
fuser::fusermount(fs, mountpoint, &options)
} else {
fuser::mount2(fs, mountpoint, &options)
};

if let Err(e) = result {
error!("{}", e.to_string());

// Return a special error code for permission denied, which usually indicates that
// "user_allow_other" is missing from /etc/fuse.conf
if e.kind() == ErrorKind::PermissionDenied {
error!("{}", e.to_string());
std::process::exit(2);
} else {
std::process::exit(1);
}
}
}
22 changes: 3 additions & 19 deletions mount_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function run_allow_root_test {
useradd fusertest1
useradd fusertest2
DIR=$(su fusertest1 -c "mktemp --directory")
cargo build --example hello --features libfuse,abi-7-30 > /dev/null 2>&1
su fusertest1 -c "target/debug/examples/hello $DIR --allow-root" &
cargo build --example hello --features abi-7-30 > /dev/null 2>&1
su fusertest1 -c "target/debug/examples/hello $DIR --allow-root --auto_unmount" &
FUSE_PID=$!
sleep 2

Expand Down Expand Up @@ -62,7 +62,7 @@ function test_no_user_allow_other {
DIR=$(su fusertestnoallow -c "mktemp --directory")
DATA_DIR=$(su fusertestnoallow -c "mktemp --directory")
cargo build --example simple $1 > /dev/null 2>&1
su fusertestnoallow -c "target/debug/examples/simple -vvv --data-dir $DATA_DIR --mount-point $DIR"
su fusertestnoallow -c "target/debug/examples/simple -vvv --data-dir $DATA_DIR --mount-point $DIR --auto_unmount"
exitCode=$?
if [[ $exitCode -eq 2 ]]; then
echo -e "$GREEN OK Detected lack of user_allow_other: $2 $NC"
Expand Down Expand Up @@ -139,22 +139,6 @@ run_test --no-default-features 'without libfuse, with fusermount3'
run_test --no-default-features 'without libfuse, with fusermount3' --auto_unmount
test_no_user_allow_other --no-default-features 'without libfuse, with fusermount3'

apt remove --purge -y fuse3
apt autoremove -y
apt install -y libfuse-dev pkg-config fuse
echo 'user_allow_other' >> /etc/fuse.conf

run_test --features=libfuse 'with libfuse'
run_test --features=libfuse 'with libfuse' --auto_unmount

apt remove --purge -y libfuse-dev fuse
apt autoremove -y
apt install -y libfuse3-dev fuse3
echo 'user_allow_other' >> /etc/fuse.conf

run_test --features=libfuse,abi-7-30 'with libfuse3'
run_test --features=libfuse,abi-7-30 'with libfuse3' --auto_unmount

run_allow_root_test

export TEST_EXIT_STATUS=0
21 changes: 17 additions & 4 deletions src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
use std::{fs::File, io, os::unix::prelude::AsRawFd, sync::Arc};
use std::{
io,
os::{
fd::{AsFd, BorrowedFd, OwnedFd},
unix::prelude::AsRawFd,
},
sync::Arc,
};

use libc::{c_int, c_void, size_t};

use crate::reply::ReplySender;

/// A raw communication channel to the FUSE kernel driver
#[derive(Debug)]
pub struct Channel(Arc<File>);
pub struct Channel(Arc<OwnedFd>);

impl Channel {
/// Create a new communication channel to the kernel driver by mounting the
/// given path. The kernel driver will delegate filesystem operations of
/// the given path to the channel.
pub(crate) fn new(device: Arc<File>) -> Self {
pub(crate) fn new(device: Arc<OwnedFd>) -> Self {
Self(device)
}

Expand Down Expand Up @@ -42,8 +49,14 @@ impl Channel {
}
}

impl AsFd for Channel {
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_fd()
}
}

#[derive(Clone, Debug)]
pub struct ChannelSender(Arc<File>);
pub struct ChannelSender(Arc<OwnedFd>);

impl ReplySender for ChannelSender {
fn send(&self, bufs: &[io::IoSlice<'_>]) -> io::Result<()> {
Expand Down
Loading
Loading