Skip to content
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
5 changes: 0 additions & 5 deletions src/ll/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,11 +1317,6 @@ mod op {
#[expect(dead_code)]
header: &'a fuse_in_header,
}
impl<'a> Destroy<'a> {
pub(crate) fn reply(&self) -> Response<'a> {
Response::new_empty()
}
}

/// Control device
#[derive(Debug)]
Expand Down
16 changes: 7 additions & 9 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) struct RequestWithSender<'a> {
/// Channel sender for sending the reply
ch: ChannelSender,
/// Parsed request
request: ll::AnyRequest<'a>,
pub(crate) request: ll::AnyRequest<'a>,
}

impl<'a> RequestWithSender<'a> {
Expand All @@ -55,7 +55,7 @@ impl<'a> RequestWithSender<'a> {
/// Dispatch request to the given filesystem.
/// This calls the appropriate filesystem operation method for the
/// request and sends back the returned reply to the kernel
pub(crate) fn dispatch<FS: Filesystem>(&self, se: &mut Session<FS>) {
pub(crate) fn dispatch<FS: Filesystem>(&self, se: &Session<FS>) {
debug!("{}", self.request);
let res = match self.dispatch_req(se) {
Ok(Some(resp)) => resp,
Expand All @@ -67,7 +67,7 @@ impl<'a> RequestWithSender<'a> {

fn dispatch_req<FS: Filesystem>(
&self,
se: &mut Session<FS>,
se: &Session<FS>,
) -> Result<Option<Response<'_>>, Errno> {
let op = self.request.operation().map_err(|_| Errno::ENOSYS)?;
// Implement allow_root & access check for auto_unmount
Expand Down Expand Up @@ -103,11 +103,9 @@ impl<'a> RequestWithSender<'a> {
error!("Unexpected FUSE_INIT after handshake completed");
return Err(Errno::EIO);
}
// Filesystem destroyed
ll::Operation::Destroy(x) => {
se.filesystem.destroy();
se.destroyed = true;
return Ok(Some(x.reply()));
ll::Operation::Destroy(_x) => {
// This is handled before dispatch call.
return Err(Errno::EIO);
}
// Any operation is invalid after destroy
_ if se.destroyed => {
Expand Down Expand Up @@ -557,7 +555,7 @@ impl<'a> RequestWithSender<'a> {

/// Create a reply object for this request that can be passed to the filesystem
/// implementation and makes sure that a request is replied exactly once
fn reply<T: Reply>(&self) -> T {
pub(crate) fn reply<T: Reply>(&self) -> T {
Reply::new(self.request.unique(), ReplySender::Channel(self.ch.clone()))
}

Expand Down
37 changes: 33 additions & 4 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ use crate::Errno;
use crate::Filesystem;
use crate::KernelConfig;
use crate::MountOption;
use crate::ReplyEmpty;
use crate::Request;
use crate::channel::Channel;
use crate::channel::ChannelSender;
use crate::dev_fuse::DevFuse;
use crate::ll;
use crate::ll::Operation;
use crate::ll::Response;
use crate::ll::Version;
use crate::ll::flags::init_flags::InitFlags;
Expand Down Expand Up @@ -169,29 +171,56 @@ impl<FS: Filesystem> Session<FS> {

self.handshake(buf)?;

let ret = self.event_loop(buf);

self.filesystem.destroy();
self.destroyed = true;

match ret {
Err(e) => Err(e),
Ok(None) => Ok(()),
Ok(Some(destroy_reply)) => {
destroy_reply.ok();
Ok(())
}
}
}

/// Return `Some` if reply to `FUSE_DESTROY` needs to be sent.
fn event_loop(&self, buf: &mut [u8]) -> io::Result<Option<ReplyEmpty>> {
loop {
// Read the next request from the given channel to kernel driver
// The kernel driver makes sure that we get exactly one request per read
match self.ch.receive(buf) {
Ok(size) => match RequestWithSender::new(self.ch.sender(), &buf[..size]) {
// Dispatch request
Some(req) => req.dispatch(&mut self),
Some(req) => {
if let Ok(Operation::Destroy(_)) = req.request.operation() {
return Ok(Some(req.reply()));
} else {
req.dispatch(self)
}
}
// Quit loop on illegal request
None => break,
None => {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Invalid request",
));
}
},
Err(err) => match err.raw_os_error() {
Some(
ENOENT // Operation interrupted. Accordingly to FUSE, this is safe to retry
| EINTR // Interrupted system call, retry
| EAGAIN // Explicitly instructed to try again
) => continue,
Some(ENODEV) => break,
Some(ENODEV) => return Ok(None),
// Unhandled error
_ => return Err(err),
},
}
}
Ok(())
}

fn handshake(&mut self, buf: &mut [u8]) -> io::Result<()> {
Expand Down