diff options
Diffstat (limited to 'src/fuse')
| -rw-r--r-- | src/fuse/fs.rs | 55 | ||||
| -rw-r--r-- | src/fuse/io.rs | 4 | ||||
| -rw-r--r-- | src/fuse/ops.rs | 11 | ||||
| -rw-r--r-- | src/fuse/session.rs | 52 |
4 files changed, 28 insertions, 94 deletions
diff --git a/src/fuse/fs.rs b/src/fuse/fs.rs index 4cf3282..0c39ea7 100644 --- a/src/fuse/fs.rs +++ b/src/fuse/fs.rs @@ -1,13 +1,6 @@ -use async_trait::async_trait; -use nix::errno::Errno; - -use std::{ - num::NonZeroUsize, - ops::{Deref, DerefMut}, - sync::Arc, -}; - use crate::{Ino, TimeToLive}; +use async_trait::async_trait; +use std::{num::NonZeroUsize, ops::Deref, sync::Arc}; use super::{ io::{Attrs, EntryType}, @@ -43,7 +36,7 @@ pub trait Inode: Send + Sync { fn attrs(self: &FarcTo<Self>) -> (Attrs, TimeToLive); fn inode_type(self: &FarcTo<Self>) -> EntryType; - fn direct_io<'o>(self: &FarcTo<Self>) -> bool { + fn direct_io(self: &FarcTo<Self>) -> bool { false } @@ -82,46 +75,4 @@ pub trait Inode: Send + Sync { } } -#[async_trait] -pub trait Tape: Send + Sync { - type Fuse: Fuse; - - async fn seek(self: &mut Head<Self>, offset: u64) -> Result<(), Errno>; - - async fn rewind(self: &mut Head<Self>) -> Result<(), Errno> { - self.seek(0).await - } - - async fn read<'o>(self: &mut Head<Self>, (_, reply, _): Op<'o, Self::Fuse, Read>) -> Done<'o> { - reply.not_implemented() - } - - async fn write<'o>( - self: &mut Head<Self>, - (_, reply, _): Op<'o, Self::Fuse, Write>, - ) -> Done<'o> { - reply.not_implemented() - } -} - pub type FarcTo<I> = <<I as Inode>::Fuse as Fuse>::Farc; - -pub struct Head<T: Tape + ?Sized> { - offset: u64, - inode: <T::Fuse as Fuse>::Farc, - tape: T, -} - -impl<T: Tape + ?Sized> Deref for Head<T> { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.tape - } -} - -impl<T: Tape + ?Sized> DerefMut for Head<T> { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.tape - } -} diff --git a/src/fuse/io.rs b/src/fuse/io.rs index 450d9f7..305f0ef 100644 --- a/src/fuse/io.rs +++ b/src/fuse/io.rs @@ -68,7 +68,7 @@ impl<'o, Fs: Fuse, O: Operation<'o, Fs>> Reply<'o, Fs, O> { F: Future<Output = T>, { tokio::pin!(f); - let mut rx = session::interrupt_rx(&self.session); + let mut rx = session::interrupt_rx(self.session); use Interruptible::*; loop { @@ -97,7 +97,7 @@ impl<'o, Fs: Fuse, O: Operation<'o, Fs>> Reply<'o, Fs, O> { let errno = errno as i32; O::consume_errno(errno, &mut self.tail); - Done::from_result(session::fail(&self.session, self.unique, errno)) + Done::from_result(session::fail(self.session, self.unique, errno)) } pub fn not_implemented(self) -> Done<'o> { diff --git a/src/fuse/ops.rs b/src/fuse/ops.rs index bfbc70a..bbd49fe 100644 --- a/src/fuse/ops.rs +++ b/src/fuse/ops.rs @@ -55,7 +55,7 @@ op! { /// be cached by the client for up to the given TTL. pub fn found(self, entry: &Fs::Farc, ttl: TimeToLive) -> Done<'o> { let (attrs, attrs_ttl) = <Fs as Fuse>::Inode::attrs(entry); - session::unveil(&self.session, entry); + session::unveil(self.session, entry); self.single(&make_entry( (<Fs as Fuse>::Inode::ino(entry), ttl), @@ -103,16 +103,11 @@ op! { }, Reply { - /// The iinode may now be accessed. + /// The inode may now be accessed. pub fn ok(self) -> Done<'o> { self.ok_with_handle(0) } - /*pub fn tape<R: Tape<Fuse = Fs>>(self, reel: R) -> Done<'o> { - let (ino, _) = self.tail; - self.ok_with_handle(session::allocate_handle(&self.session, ino, reel)) - }*/ - fn ok_with_handle(self, handle: u64) -> Done<'o> { let (_, flags) = self.tail; self.single(&proto::OpenOut { @@ -342,7 +337,7 @@ impl<'o, Fs: Fuse, O: Operation<'o, Fs>> Reply<'o, Fs, O> { } fn chain(self, chain: OutputChain<'_>) -> Done<'o> { - Done::from_result(session::ok(&self.session, self.unique, chain)) + Done::from_result(session::ok(self.session, self.unique, chain)) } } diff --git a/src/fuse/session.rs b/src/fuse/session.rs index 4a34aae..8975c57 100644 --- a/src/fuse/session.rs +++ b/src/fuse/session.rs @@ -35,14 +35,6 @@ pub fn ok<Fs: Fuse>(session: &Session<Fs>, unique: u64, output: OutputChain<'_>) session.send(unique, 0, output) } -pub fn notify<Fs: Fuse>( - session: &Session<Fs>, - op: proto::NotifyCode, - output: OutputChain<'_>, -) -> FuseResult<()> { - session.send(0, op as i32, output) -} - pub fn fail<Fs: Fuse>(session: &Session<Fs>, unique: u64, mut errno: i32) -> FuseResult<()> { if errno <= 0 { log::warn!( @@ -164,7 +156,7 @@ impl<Fs: Fuse> Session<Fs> { Ordering::Greater => { let tail = [bytes_of(&proto::MAJOR_VERSION)]; - ok(&self, unique, OutputChain::tail(&tail))?; + ok(self, unique, OutputChain::tail(&tail))?; return Ok(Handshake::Restart); } @@ -183,14 +175,14 @@ impl<Fs: Fuse> Session<Fs> { major = proto::MAJOR_VERSION ); - fail(&self, unique, Errno::EPROTONOSUPPORT as i32)?; + fail(self, unique, Errno::EPROTONOSUPPORT as i32)?; return Err(ProtocolInit); } let root = { let mut init_result = Err(0); let reply = Reply { - session: &self, + session: self, unique, tail: &mut init_result, }; @@ -232,12 +224,12 @@ impl<Fs: Fuse> Session<Fs> { }; let tail = [bytes_of(&init_out)]; - ok(&self, unique, OutputChain::tail(&tail))?; + ok(self, unique, OutputChain::tail(&tail))?; Ok(Handshake::Done) } - async fn dispatch(self: &Arc<Self>, request: &mut Incoming<Fs>) -> FuseResult<()> { + async fn dispatch(self: &Arc<Self>, request: &mut Incoming) -> FuseResult<()> { let request: proto::Request<'_> = request.buffer.data().try_into()?; let header = request.header(); let InHeader { unique, ino, .. } = *header; @@ -281,7 +273,7 @@ impl<Fs: Fuse> Session<Fs> { Interrupt(body) => { //TODO: Don't reply with EAGAIN if the interrupt is successful let _ = self.interrupt_tx.send(body.unique); - return fail(&self, unique, Errno::EAGAIN as i32); + return fail(self, unique, Errno::EAGAIN as i32); } Destroy => { @@ -313,7 +305,7 @@ impl<Fs: Fuse> Session<Fs> { ino ); - return fail(&self, unique, Errno::ENOANO as i32); + return fail(self, unique, Errno::ENOANO as i32); } }; @@ -331,7 +323,7 @@ impl<Fs: Fuse> Session<Fs> { attr: attrs, }; - return ok(&self, unique, OutputChain::tail(&[bytes_of(&out)])); + return ok(self, unique, OutputChain::tail(&[bytes_of(&out)])); } Access(body) => { @@ -363,7 +355,7 @@ impl<Fs: Fuse> Session<Fs> { Opendir(body) => inode_op!(opendir, *body), Readdir(body) => inode_op!(readdir, *body), - _ => return fail(&self, unique, Errno::ENOSYS as i32), + _ => return fail(self, unique, Errno::ENOSYS as i32), }; done.into_result() @@ -398,7 +390,7 @@ impl<Fs: Fuse> Session<Fs> { } } - async fn receive(self: &Arc<Self>) -> std::io::Result<Incoming<Fs>> { + async fn receive(self: &Arc<Self>) -> std::io::Result<Incoming> { use InputBufferStorage::*; let permit = Arc::clone(&self.input_semaphore) @@ -407,7 +399,6 @@ impl<Fs: Fuse> Session<Fs> { .unwrap(); let mut incoming = Incoming { - session: Arc::clone(self), buffer: InputBuffer { bytes: 0, data: Sbo(SboStorage([0; SBO_SIZE])), @@ -452,17 +443,15 @@ impl<Fs: Fuse> Session<Fs> { } fn send(&self, unique: u64, error: i32, output: OutputChain<'_>) -> FuseResult<()> { - let length = std::mem::size_of::<proto::OutHeader>(); - let length = length - + output - .iter() - .map(<[_]>::iter) - .flatten() - .copied() - .map(<[_]>::len) - .sum::<usize>(); - - let length = length.try_into().unwrap(); + let after_header: usize = output + .iter() + .map(<[_]>::iter) + .flatten() + .copied() + .map(<[_]>::len) + .sum(); + + let length = (std::mem::size_of::<proto::OutHeader>() + after_header) as _; let header = proto::OutHeader { len: length, error, @@ -537,8 +526,7 @@ enum Handshake { Restart, } -struct Incoming<Fs: Fuse> { - session: Arc<Session<Fs>>, +struct Incoming { buffer: InputBuffer, } |
