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
1 change: 1 addition & 0 deletions compio-driver/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- *(driver)* [**breaking**] full iour fallback ([#656](https://github.com/compio-rs/compio/pull/656))
- *(runtime)* future combinator ([#639](https://github.com/compio-rs/compio/pull/639))
- *(fs)* splice ([#635](https://github.com/compio-rs/compio/pull/635))
- *(driver)* fake splice test ([#638](https://github.com/compio-rs/compio/pull/638))
Expand Down
6 changes: 1 addition & 5 deletions compio-driver/src/driver_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ impl DriverType {
Send::CODE,
RecvMsg::CODE,
SendMsg::CODE,
AsyncCancel::CODE,
OpenAt::CODE,
Close::CODE,
Splice::CODE,
Shutdown::CODE,
PollAdd::CODE,
];

if USED_OP.iter().all(|op| crate::sys::is_op_supported(*op)) {
Expand Down
28 changes: 18 additions & 10 deletions compio-driver/src/sys/iour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,30 @@ impl Driver {
trace!(?personality, "push RawOp");
match entry {
OpEntry::Submission(entry) => {
#[allow(clippy::useless_conversion)]
self.push_raw_with_key(entry.into(), key)?;
Poll::Pending
if is_op_supported(entry.get_opcode() as _) {
#[allow(clippy::useless_conversion)]
self.push_raw_with_key(entry.into(), key)?;
Poll::Pending
} else {
self.push_blocking_loop(key)
}
}
#[cfg(feature = "io-uring-sqe128")]
OpEntry::Submission128(entry) => {
self.push_raw_with_key(entry, key)?;
Poll::Pending
}
OpEntry::Blocking => loop {
if self.push_blocking(key.clone()) {
break Poll::Pending;
} else {
self.poll_blocking();
}
},
OpEntry::Blocking => self.push_blocking_loop(key),
}
}

fn push_blocking_loop(&mut self, key: ErasedKey) -> Poll<io::Result<usize>> {
loop {
if self.push_blocking(key.clone()) {
break Poll::Pending;
} else {
self.poll_blocking();
}
}
}

Expand Down
117 changes: 98 additions & 19 deletions compio-driver/src/sys/iour/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ unsafe impl OpCode for OpenFile {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl OpCode for CloseFile {
Expand All @@ -77,21 +81,21 @@ unsafe impl OpCode for CloseFile {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl<S: AsFd> OpCode for TruncateFile<S> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
if super::is_op_supported(opcode::Ftruncate::CODE) {
return opcode::Ftruncate::new(Fd(self.fd.as_fd().as_raw_fd()), self.size)
.build()
.into();
}

OpEntry::Blocking
opcode::Ftruncate::new(Fd(self.fd.as_fd().as_raw_fd()), self.size)
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.truncate()
self.call()
}
}

Expand Down Expand Up @@ -127,6 +131,19 @@ unsafe impl<S: AsFd> OpCode for FileStat<S> {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
let this = self.project();
static EMPTY_NAME: &[u8] = b"\0";
let res = syscall!(libc::statx(
this.fd.as_fd().as_raw_fd(),
EMPTY_NAME.as_ptr().cast(),
libc::AT_EMPTY_PATH,
statx_mask(),
this.stat as *mut _ as _
))?;
Ok(res as _)
}
}

impl<S> IntoInner for FileStat<S> {
Expand Down Expand Up @@ -171,6 +188,21 @@ unsafe impl OpCode for PathStat {
.build()
.into()
}

fn call_blocking(mut self: Pin<&mut Self>) -> io::Result<usize> {
let mut flags = libc::AT_EMPTY_PATH;
if !self.follow_symlink {
flags |= libc::AT_SYMLINK_NOFOLLOW;
}
let res = syscall!(libc::statx(
libc::AT_FDCWD,
self.path.as_ptr(),
flags,
statx_mask(),
std::ptr::addr_of_mut!(self.stat).cast()
))?;
Ok(res as _)
}
}

impl IntoInner for PathStat {
Expand Down Expand Up @@ -316,6 +348,10 @@ unsafe impl OpCode for Unlink {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl OpCode for CreateDir {
Expand All @@ -325,6 +361,10 @@ unsafe impl OpCode for CreateDir {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl OpCode for Rename {
Expand All @@ -338,6 +378,10 @@ unsafe impl OpCode for Rename {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl OpCode for Symlink {
Expand All @@ -350,6 +394,10 @@ unsafe impl OpCode for Symlink {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl OpCode for HardLink {
Expand All @@ -363,21 +411,21 @@ unsafe impl OpCode for HardLink {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl OpCode for CreateSocket {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
if super::is_op_supported(opcode::Socket::CODE) {
opcode::Socket::new(
self.domain,
self.socket_type | libc::SOCK_CLOEXEC,
self.protocol,
)
.build()
.into()
} else {
OpEntry::Blocking
}
opcode::Socket::new(
self.domain,
self.socket_type | libc::SOCK_CLOEXEC,
self.protocol,
)
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
Expand All @@ -395,6 +443,10 @@ unsafe impl<S: AsFd> OpCode for ShutdownSocket<S> {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl OpCode for CloseSocket {
Expand All @@ -403,6 +455,10 @@ unsafe impl OpCode for CloseSocket {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
self.call()
}
}

unsafe impl<S: AsFd> OpCode for Accept<S> {
Expand Down Expand Up @@ -756,6 +812,29 @@ unsafe impl<S1: AsFd, S2: AsFd> OpCode for Splice<S1, S2> {
.build()
.into()
}

fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
let mut offset_in = self.offset_in;
let mut offset_out = self.offset_out;
let offset_in_ptr = if offset_in < 0 {
std::ptr::null_mut()
} else {
&mut offset_in
};
let offset_out_ptr = if offset_out < 0 {
std::ptr::null_mut()
} else {
&mut offset_out
};
Ok(syscall!(libc::splice(
self.fd_in.as_fd().as_raw_fd(),
offset_in_ptr,
self.fd_out.as_fd().as_raw_fd(),
offset_out_ptr,
self.len,
self.flags,
))? as _)
}
}

mod buf_ring {
Expand Down
Loading