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

Allow users to create Notifier objects when handling requests #303

Merged
merged 2 commits into from
Oct 19, 2024
Merged
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: 3 additions & 3 deletions examples/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use libc::{EACCES, EBADF, EBUSY, EINVAL, ENOENT, ENOTDIR};

use fuser::{
consts::{FOPEN_DIRECT_IO, FOPEN_NONSEEKABLE, FUSE_POLL_SCHEDULE_NOTIFY},
FileAttr, FileType, MountOption, Request, FUSE_ROOT_ID,
FileAttr, FileType, MountOption, PollHandle, Request, FUSE_ROOT_ID,
};

const NUMFILES: u8 = 16;
Expand Down Expand Up @@ -251,7 +251,7 @@ impl fuser::Filesystem for FSelFS {
_req: &Request,
_ino: u64,
fh: u64,
kh: u64,
ph: PollHandle,
_events: u32,
flags: u32,
reply: fuser::ReplyPoll,
Expand All @@ -271,7 +271,7 @@ impl fuser::Filesystem for FSelFS {

if flags & FUSE_POLL_SCHEDULE_NOTIFY != 0 {
d.notify_mask |= 1 << idx;
d.poll_handles[idx as usize] = kh;
d.poll_handles[idx as usize] = ph.into();
}

let nbytes = d.bytecnt[idx as usize];
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::session::MAX_WRITE_SIZE;
pub use ll::fuse_abi::fuse_forget_one;
pub use mnt::mount_options::MountOption;
#[cfg(feature = "abi-7-11")]
pub use notify::Notifier;
pub use notify::{Notifier, PollHandle};
#[cfg(feature = "abi-7-11")]
pub use reply::ReplyPoll;
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -884,14 +884,14 @@ pub trait Filesystem {
_req: &Request<'_>,
ino: u64,
fh: u64,
kh: u64,
ph: PollHandle,
events: u32,
flags: u32,
reply: ReplyPoll,
) {
debug!(
"[Not Implemented] poll(ino: {:#x?}, fh: {}, kh: {}, events: {}, flags: {})",
ino, fh, kh, events, flags
"[Not Implemented] poll(ino: {:#x?}, fh: {}, ph: {:?}, events: {}, flags: {})",
ino, fh, ph, events, flags
);
reply.error(ENOSYS);
}
Expand Down
36 changes: 35 additions & 1 deletion src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,42 @@ use crate::{
reply::ReplySender,
};

/// A handle to a pending poll() request. Can be saved and used to notify the
/// kernel when a poll is ready.
#[derive(Clone)]
pub struct PollHandle {
handle: u64,
notifier: Notifier,
}

impl PollHandle {
pub(crate) fn new(cs: ChannelSender, kh: u64) -> Self {
Self {
handle: kh,
notifier: Notifier::new(cs),
}
}

/// Notify the kernel that the associated file handle is ready to be polled.
pub fn notify(self) -> io::Result<()> {
self.notifier.poll(self.handle)
}
}

impl From<PollHandle> for u64 {
fn from(value: PollHandle) -> Self {
value.handle
}
}

impl std::fmt::Debug for PollHandle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("PollHandle").field(&self.handle).finish()
}
}

/// A handle by which the application can send notifications to the server
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Notifier(ChannelSender);

impl Notifier {
Expand Down
6 changes: 5 additions & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::reply::ReplyDirectoryPlus;
use crate::reply::{Reply, ReplyDirectory, ReplySender};
use crate::session::{Session, SessionACL};
use crate::Filesystem;
#[cfg(feature = "abi-7-11")]
use crate::PollHandle;
use crate::{ll, KernelConfig};

/// Request data structure
Expand Down Expand Up @@ -522,11 +524,13 @@ impl<'a> Request<'a> {
}
#[cfg(feature = "abi-7-11")]
ll::Operation::Poll(x) => {
let ph = PollHandle::new(se.ch.sender(), x.kernel_handle());

se.filesystem.poll(
self,
self.request.nodeid().into(),
x.file_handle().into(),
x.kernel_handle(),
ph,
x.events(),
x.flags(),
self.reply(),
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Session<FS: Filesystem> {
/// Filesystem operation implementations
pub(crate) filesystem: FS,
/// Communication channel to the kernel driver
ch: Channel,
pub(crate) ch: Channel,
/// Handle to the mount. Dropping this unmounts.
mount: Arc<Mutex<Option<Mount>>>,
/// Mount point
Expand Down
Loading