diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-01-06 08:28:05 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-01-06 08:28:05 -0600 |
| commit | b9a99211a54d62f556fdf71d5eb91107f11398cf (patch) | |
| tree | 38131b1287e88b5f95137ac64cca41a55eaf54a5 /src | |
| parent | b3a9082a8b81c28ef81dbaaffe171f646b1f2777 (diff) | |
Move Forget and Getattr to new module ops::inode
Diffstat (limited to 'src')
| -rw-r--r-- | src/ops/entry.rs | 93 | ||||
| -rw-r--r-- | src/ops/inode.rs | 88 | ||||
| -rw-r--r-- | src/ops/mod.rs | 4 | ||||
| -rw-r--r-- | src/ops/traits.rs | 3 |
4 files changed, 95 insertions, 93 deletions
diff --git a/src/ops/entry.rs b/src/ops/entry.rs index 435188a..c174bc7 100644 --- a/src/ops/entry.rs +++ b/src/ops/entry.rs @@ -1,28 +1,17 @@ -use crate::{ - io::{Mode, Stat}, - private_trait::Sealed, - proto, Done, Ino, Operation, Reply, Request, -}; - use super::{ c_to_os, - traits::{ReplyKnown, ReplyOk, RequestHandle, RequestMode, RequestName}, + traits::{ReplyKnown, ReplyOk, RequestMode, RequestName}, }; +use crate::{io::Mode, private_trait::Sealed, proto, Ino, Operation, Request}; use std::ffi::{CStr, OsStr}; -pub enum Forget {} -pub enum Getattr {} pub enum Mkdir {} pub enum Unlink {} pub enum Rmdir {} pub enum Symlink {} pub enum Link {} -pub trait RequestForget<'o>: Operation<'o> { - fn forget_list<'a>(request: &'a Request<'o, Self>) -> ForgetList<'a>; -} - pub trait RequestTarget<'o>: Operation<'o> { fn target<'a>(request: &'a Request<'o, Self>) -> &'a OsStr; } @@ -31,38 +20,12 @@ pub trait RequestLink<'o>: Operation<'o> { fn source_ino(request: &Request<'o, Self>) -> Ino; } -pub trait ReplyStat<'o>: Operation<'o> { - fn stat(reply: Reply<'o, Self>, inode: &impl Stat) -> Done<'o>; -} - -pub enum ForgetList<'a> { - Single(Option<(Ino, u64)>), - Batch(std::slice::Iter<'a, proto::ForgetOne>), -} - -impl Sealed for Forget {} -impl Sealed for Getattr {} impl Sealed for Mkdir {} impl Sealed for Unlink {} impl Sealed for Rmdir {} impl Sealed for Symlink {} impl Sealed for Link {} -impl<'o> Operation<'o> for Forget { - type RequestBody = proto::OpcodeSelect< - (&'o proto::BatchForgetIn, &'o [proto::ForgetOne]), - &'o proto::ForgetIn, - { proto::Opcode::BatchForget as u32 }, - >; - - type ReplyState = (); -} - -impl<'o> Operation<'o> for Getattr { - type RequestBody = &'o proto::GetattrIn; - type ReplyState = (); -} - impl<'o> Operation<'o> for Mkdir { type RequestBody = (&'o proto::MkdirIn, &'o CStr); type ReplyState = (); @@ -88,58 +51,6 @@ impl<'o> Operation<'o> for Link { type ReplyState = (); } -impl<'o> RequestForget<'o> for Forget { - fn forget_list<'a>(request: &'a Request<'o, Self>) -> ForgetList<'a> { - use {proto::OpcodeSelect::*, ForgetList::*}; - - impl Iterator for ForgetList<'_> { - type Item = (Ino, u64); - - fn next(&mut self) -> Option<Self::Item> { - match self { - Single(single) => single.take(), - Batch(batch) => { - let forget = batch.next()?; - Some((Ino(forget.ino), forget.nlookup)) - } - } - } - } - - match request.body { - Match((_, slice)) => Batch(slice.iter()), - Alt(single) => Single(Some((request.ino(), single.nlookup))), - } - } -} - -impl<'o> ReplyOk<'o> for Forget { - fn ok(_reply: Reply<'o, Self>) -> Done<'o> { - // No reply for forget requests - Done::new() - } -} - -impl<'o> RequestHandle<'o> for Getattr { - fn handle(request: &Request<'o, Self>) -> u64 { - request.body.fh - } -} - -impl<'o> ReplyStat<'o> for Getattr { - fn stat(reply: Reply<'o, Self>, inode: &impl Stat) -> Done<'o> { - let (attrs, ttl) = inode.attrs(); - let attrs = attrs.finish(inode); - - reply.single(&proto::AttrOut { - attr_valid: ttl.seconds, - attr_valid_nsec: ttl.nanoseconds, - dummy: Default::default(), - attr: attrs, - }) - } -} - impl<'o> RequestName<'o> for Mkdir { fn name<'a>(request: &'a Request<'o, Self>) -> &'a OsStr { let (_header, name) = request.body; diff --git a/src/ops/inode.rs b/src/ops/inode.rs new file mode 100644 index 0000000..fa5d461 --- /dev/null +++ b/src/ops/inode.rs @@ -0,0 +1,88 @@ +use super::traits::{ReplyOk, RequestHandle}; +use crate::{io::Stat, private_trait::Sealed, proto, Done, Ino, Operation, Reply, Request}; + +pub enum Forget {} +pub enum Getattr {} + +pub trait RequestForget<'o>: Operation<'o> { + fn forget_list<'a>(request: &'a Request<'o, Self>) -> ForgetList<'a>; +} + +pub trait ReplyStat<'o>: Operation<'o> { + fn stat(reply: Reply<'o, Self>, inode: &impl Stat) -> Done<'o>; +} + +pub enum ForgetList<'a> { + Single(Option<(Ino, u64)>), + Batch(std::slice::Iter<'a, proto::ForgetOne>), +} + +impl Sealed for Forget {} +impl Sealed for Getattr {} + +impl<'o> Operation<'o> for Forget { + type RequestBody = proto::OpcodeSelect< + (&'o proto::BatchForgetIn, &'o [proto::ForgetOne]), + &'o proto::ForgetIn, + { proto::Opcode::BatchForget as u32 }, + >; + + type ReplyState = (); +} + +impl<'o> Operation<'o> for Getattr { + type RequestBody = &'o proto::GetattrIn; + type ReplyState = (); +} + +impl<'o> RequestForget<'o> for Forget { + fn forget_list<'a>(request: &'a Request<'o, Self>) -> ForgetList<'a> { + use {proto::OpcodeSelect::*, ForgetList::*}; + + impl Iterator for ForgetList<'_> { + type Item = (Ino, u64); + + fn next(&mut self) -> Option<Self::Item> { + match self { + Single(single) => single.take(), + Batch(batch) => { + let forget = batch.next()?; + Some((Ino(forget.ino), forget.nlookup)) + } + } + } + } + + match request.body { + Match((_, slice)) => Batch(slice.iter()), + Alt(single) => Single(Some((request.ino(), single.nlookup))), + } + } +} + +impl<'o> ReplyOk<'o> for Forget { + fn ok(_reply: Reply<'o, Self>) -> Done<'o> { + // No reply for forget requests + Done::new() + } +} + +impl<'o> RequestHandle<'o> for Getattr { + fn handle(request: &Request<'o, Self>) -> u64 { + request.body.fh + } +} + +impl<'o> ReplyStat<'o> for Getattr { + fn stat(reply: Reply<'o, Self>, inode: &impl Stat) -> Done<'o> { + let (attrs, ttl) = inode.attrs(); + let attrs = attrs.finish(inode); + + reply.single(&proto::AttrOut { + attr_valid: ttl.seconds, + attr_valid_nsec: ttl.nanoseconds, + dummy: Default::default(), + attr: attrs, + }) + } +} diff --git a/src/ops/mod.rs b/src/ops/mod.rs index de13ac6..4e5f052 100644 --- a/src/ops/mod.rs +++ b/src/ops/mod.rs @@ -12,8 +12,9 @@ use bytemuck::{bytes_of, Pod}; pub mod traits; pub use dir::{BufferedReaddir, Lookup, Readdir}; -pub use entry::{Forget, Getattr, Link, Mkdir, Rmdir, Symlink, Unlink}; +pub use entry::{Link, Mkdir, Rmdir, Symlink, Unlink}; pub use global::{Init, Statfs}; +pub use inode::{Forget, Getattr}; pub use open::{Access, Open, Opendir, Release, Releasedir}; pub use rw::{Flush, Fsync, Fsyncdir, Read, Readlink, Write}; pub use xattr::{Getxattr, Listxattr, Removexattr, Setxattr}; @@ -21,6 +22,7 @@ pub use xattr::{Getxattr, Listxattr, Removexattr, Setxattr}; mod dir; mod entry; mod global; +mod inode; mod open; mod rw; mod xattr; diff --git a/src/ops/traits.rs b/src/ops/traits.rs index 52aaed3..883f2f8 100644 --- a/src/ops/traits.rs +++ b/src/ops/traits.rs @@ -5,8 +5,9 @@ use crate::{ pub use super::{ dir::{ReplyEntries, ReplyFound}, - entry::{ReplyStat, RequestForget, RequestLink, RequestTarget}, + entry::{RequestLink, RequestTarget}, global::ReplyFsInfo, + inode::{ReplyStat, RequestForget}, open::{ReplyOpen, ReplyPermissionDenied}, rw::ReplyAll, xattr::ReplyXattrRead, |
