From 08ea9f69e1ee0db9df8bb8a590f7fe2b4c930b68 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 21 Feb 2025 17:06:49 +0100 Subject: [PATCH] Backwards-incompatibly introduce OnClose msg. --- src/lib.rs | 14 +++++++------- src/scheme.rs | 5 ----- src/scheme_block.rs | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e0c7763..bca9cc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,11 +13,11 @@ use syscall::{ StatVfs, TimeSpec, EBADF, EINTR, EINVAL, ENOENT, EOPNOTSUPP, }; -pub use self::scheme_block::SchemeBlock; pub use self::scheme::Scheme; +pub use self::scheme_block::SchemeBlock; -mod scheme_block; mod scheme; +mod scheme_block; pub struct CallerCtx { pub pid: usize, @@ -89,6 +89,7 @@ pub enum RequestKind { MsyncMsg, MunmapMsg, MmapMsg, + OnClose { id: usize }, } impl CallRequest { @@ -226,8 +227,6 @@ impl CallRequest { ) } - Opcode::Close => scheme.close(a), - Opcode::MmapPrep => scheme.mmap_prep(a, args[3], b, MapFlags::from_bits_retain(c)), Opcode::Munmap => scheme.munmap(a, args[3], b, MunmapFlags::from_bits_retain(c)), @@ -386,8 +385,6 @@ impl CallRequest { .transpose()? } - Opcode::Close => scheme.close(a).transpose()?, - Opcode::MmapPrep => scheme .mmap_prep(a, args[3], b, MapFlags::from_bits_retain(c)) .transpose()?, @@ -467,6 +464,9 @@ impl Request { Some(Opcode::Msync) => RequestKind::MsyncMsg, //Some(Opcode::Munmap) => RequestKind::MunmapMsg, Some(Opcode::RequestMmap) => RequestKind::MmapMsg, + Some(Opcode::CloseMsg) => RequestKind::OnClose { + id: self.sqe.args[0] as usize, + }, _ => RequestKind::Call(CallRequest { inner: Request { sqe: self.sqe }, @@ -481,7 +481,7 @@ pub struct Socket { impl Socket { fn create_inner(name: &str, nonblock: bool) -> Result<Self> { - let mut flags = flag::O_FSYNC; + let mut flags = flag::O_FSYNC | 0x0020_0000 /* O_EXLOCK */; if nonblock { flags |= flag::O_NONBLOCK; diff --git a/src/scheme.rs b/src/scheme.rs index 14e2e72..07542c4 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -121,11 +121,6 @@ pub trait Scheme { Err(Error::new(EBADF)) } - #[allow(unused_variables)] - fn close(&mut self, id: usize) -> Result<usize> { - Err(Error::new(EBADF)) - } - #[allow(unused_variables)] fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<usize> { Err(Error::new(EOPNOTSUPP)) diff --git a/src/scheme_block.rs b/src/scheme_block.rs index fa1e294..e365c36 100644 --- a/src/scheme_block.rs +++ b/src/scheme_block.rs @@ -38,7 +38,13 @@ pub trait SchemeBlock { Err(Error::new(EBADF)) } #[allow(unused_variables)] - fn read(&mut self, id: usize, buf: &mut [u8], offset: u64, fcntl_flags: u32) -> Result<Option<usize>> { + fn read( + &mut self, + id: usize, + buf: &mut [u8], + offset: u64, + fcntl_flags: u32, + ) -> Result<Option<usize>> { self.read_old(id, buf) } @@ -47,7 +53,13 @@ pub trait SchemeBlock { Err(Error::new(EBADF)) } #[allow(unused_variables)] - fn write(&mut self, id: usize, buf: &[u8], offset: u64, fcntl_flags: u32) -> Result<Option<usize>> { + fn write( + &mut self, + id: usize, + buf: &[u8], + offset: u64, + fcntl_flags: u32, + ) -> Result<Option<usize>> { self.write_old(id, buf) } @@ -122,17 +134,24 @@ pub trait SchemeBlock { } #[allow(unused_variables)] - fn close(&mut self, id: usize) -> Result<Option<usize>> { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<Option<usize>> { + fn mmap_prep( + &mut self, + id: usize, + offset: u64, + size: usize, + flags: MapFlags, + ) -> Result<Option<usize>> { Err(Error::new(EOPNOTSUPP)) } #[allow(unused_variables)] - fn munmap(&mut self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result<Option<usize>> { + fn munmap( + &mut self, + id: usize, + offset: u64, + size: usize, + flags: MunmapFlags, + ) -> Result<Option<usize>> { Err(Error::new(EOPNOTSUPP)) } } -- GitLab