From 4b733d5cd712c9156ba4448025847d4b30f043b8 Mon Sep 17 00:00:00 2001 From: Yusuke Sasaki Date: Fri, 12 Dec 2025 00:06:10 +0900 Subject: [PATCH] Stop abstraction via the trait `Notifier` --- examples/heartbeat.rs | 1 - examples/heartbeat_entry.rs | 1 - examples/poll.rs | 1 - src/lib.rs | 1 - src/notify.rs | 105 ------------------------------------ src/session.rs | 94 ++++++++++++++++++++++++++++++-- 6 files changed, 89 insertions(+), 114 deletions(-) delete mode 100644 src/notify.rs diff --git a/examples/heartbeat.rs b/examples/heartbeat.rs index 4d45b580..4411622e 100644 --- a/examples/heartbeat.rs +++ b/examples/heartbeat.rs @@ -10,7 +10,6 @@ use polyfuse::{ mount::MountOptions, - notify::Notifier as _, op::Operation, reply::{OpenOutFlags, ReplySender as _}, session::Session, diff --git a/examples/heartbeat_entry.rs b/examples/heartbeat_entry.rs index 6ff7e254..8f5951ab 100644 --- a/examples/heartbeat_entry.rs +++ b/examples/heartbeat_entry.rs @@ -10,7 +10,6 @@ use polyfuse::{ mount::MountOptions, - notify::Notifier as _, op::Operation, reply::{DirEntryBuf, ReplySender as _}, session::Session, diff --git a/examples/poll.rs b/examples/poll.rs index cfd644ef..8feae011 100644 --- a/examples/poll.rs +++ b/examples/poll.rs @@ -1,6 +1,5 @@ use polyfuse::{ mount::MountOptions, - notify::Notifier as _, op::{AccessMode, OpenFlags, Operation}, reply::{OpenOutFlags, ReplySender as _}, types::{ diff --git a/src/lib.rs b/src/lib.rs index f4d5cb02..d26ea60d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,6 @@ pub mod buf; pub mod bytes; pub mod io; pub mod mount; -pub mod notify; pub mod op; pub mod reply; pub mod session; diff --git a/src/notify.rs b/src/notify.rs deleted file mode 100644 index 4dfa9c47..00000000 --- a/src/notify.rs +++ /dev/null @@ -1,105 +0,0 @@ -use crate::{ - bytes::{Bytes, POD}, - types::{NodeID, NotifyID, PollWakeupID}, -}; -use polyfuse_kernel::{ - fuse_notify_code, fuse_notify_delete_out, fuse_notify_inval_entry_out, - fuse_notify_inval_inode_out, fuse_notify_poll_wakeup_out, fuse_notify_retrieve_out, - fuse_notify_store_out, -}; -use std::{ffi::OsStr, io, os::unix::prelude::*}; - -pub trait Notifier: Sized { - /// Send a notification message to the kernel. - fn send(self, code: fuse_notify_code, arg: B) -> io::Result<()> - where - B: Bytes; - - /// Generate a new NotifyID. - fn new_notify_unique(&self) -> NotifyID; - - fn inval_inode(self, ino: NodeID, off: i64, len: i64) -> io::Result<()> { - self.send( - fuse_notify_code::FUSE_NOTIFY_INVAL_INODE, - POD(fuse_notify_inval_inode_out { - ino: ino.into_raw(), - off, - len, - }), - ) - } - - fn inval_entry(self, parent: NodeID, name: impl AsRef) -> io::Result<()> { - let name = name.as_ref(); - self.send( - fuse_notify_code::FUSE_NOTIFY_INVAL_ENTRY, - ( - POD(fuse_notify_inval_entry_out { - parent: parent.into_raw(), - namelen: name.len() as u32, - flags: 0, - }), - name.as_bytes(), - "\0", - ), - ) - } - - fn delete(self, parent: NodeID, child: NodeID, name: impl AsRef) -> io::Result<()> { - let name = name.as_ref(); - self.send( - fuse_notify_code::FUSE_NOTIFY_DELETE, - ( - POD(fuse_notify_delete_out { - parent: parent.into_raw(), - child: child.into_raw(), - namelen: name.len() as u32, - padding: 0, - }), - name.as_bytes(), - b"\0", - ), - ) - } - - fn store(self, ino: NodeID, offset: u64, content: B) -> io::Result<()> - where - B: Bytes, - { - let size = content.size(); - self.send( - fuse_notify_code::FUSE_NOTIFY_STORE, - ( - POD(fuse_notify_store_out { - nodeid: ino.into_raw(), - offset, - size: size as u32, - padding: 0, - }), - content, - ), - ) - } - - fn retrieve(self, ino: NodeID, offset: u64, size: u32) -> io::Result { - let notify_unique = self.new_notify_unique(); - self.send( - fuse_notify_code::FUSE_NOTIFY_RETRIEVE, - POD(fuse_notify_retrieve_out { - notify_unique: notify_unique.into_raw(), - nodeid: ino.into_raw(), - offset, - size, - padding: 0, - }), - )?; - Ok(notify_unique) - } - - fn poll_wakeup(self, kh: PollWakeupID) -> io::Result<()> { - self.send( - fuse_notify_code::FUSE_NOTIFY_POLL, - POD(fuse_notify_poll_wakeup_out { kh: kh.into_raw() }), - ) - } -} diff --git a/src/session.rs b/src/session.rs index f321b826..0f086e6e 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,17 +1,19 @@ use crate::{ buf::{InHeader, RemainingData, RequestBuf}, - bytes::Bytes, + bytes::{Bytes, POD}, init::{KernelConfig, KernelFlags}, io::SpliceRead, msg::{send_msg, MessageKind}, op::{DecodeError, Operation}, reply::ReplySender, - types::NotifyID, + types::{NodeID, NotifyID, PollWakeupID}, }; use polyfuse_kernel::*; use rustix::io::Errno; use std::{ + ffi::OsStr, io, mem, + os::unix::prelude::*, sync::atomic::{AtomicBool, AtomicU64, Ordering}, }; @@ -203,7 +205,7 @@ pub struct Notifier<'sess, T> { conn: T, } -impl crate::notify::Notifier for Notifier<'_, T> +impl<'sess, T> Notifier<'sess, T> where T: io::Write, { @@ -215,7 +217,89 @@ where .or_else(|err| self.session.handle_reply_error(err)) } - fn new_notify_unique(&self) -> NotifyID { - NotifyID::from_raw(self.session.notify_unique.fetch_add(1, Ordering::AcqRel)) + pub fn inval_inode(self, ino: NodeID, off: i64, len: i64) -> io::Result<()> { + self.send( + fuse_notify_code::FUSE_NOTIFY_INVAL_INODE, + POD(fuse_notify_inval_inode_out { + ino: ino.into_raw(), + off, + len, + }), + ) + } + + pub fn inval_entry(self, parent: NodeID, name: impl AsRef) -> io::Result<()> { + let name = name.as_ref(); + self.send( + fuse_notify_code::FUSE_NOTIFY_INVAL_ENTRY, + ( + POD(fuse_notify_inval_entry_out { + parent: parent.into_raw(), + namelen: name.len() as u32, + flags: 0, + }), + name.as_bytes(), + "\0", + ), + ) + } + + pub fn delete(self, parent: NodeID, child: NodeID, name: impl AsRef) -> io::Result<()> { + let name = name.as_ref(); + self.send( + fuse_notify_code::FUSE_NOTIFY_DELETE, + ( + POD(fuse_notify_delete_out { + parent: parent.into_raw(), + child: child.into_raw(), + namelen: name.len() as u32, + padding: 0, + }), + name.as_bytes(), + b"\0", + ), + ) + } + + pub fn store(self, ino: NodeID, offset: u64, content: B) -> io::Result<()> + where + B: Bytes, + { + let size = content.size(); + self.send( + fuse_notify_code::FUSE_NOTIFY_STORE, + ( + POD(fuse_notify_store_out { + nodeid: ino.into_raw(), + offset, + size: size as u32, + padding: 0, + }), + content, + ), + ) + } + + pub fn retrieve(self, ino: NodeID, offset: u64, size: u32) -> io::Result { + let notify_unique = + NotifyID::from_raw(self.session.notify_unique.fetch_add(1, Ordering::AcqRel)); + self.send( + fuse_notify_code::FUSE_NOTIFY_RETRIEVE, + POD(fuse_notify_retrieve_out { + notify_unique: notify_unique.into_raw(), + nodeid: ino.into_raw(), + offset, + size, + padding: 0, + }), + )?; + Ok(notify_unique) + } + + pub fn poll_wakeup(self, kh: PollWakeupID) -> io::Result<()> { + self.send( + fuse_notify_code::FUSE_NOTIFY_POLL, + POD(fuse_notify_poll_wakeup_out { kh: kh.into_raw() }), + ) } }