Skip to content

Commit da39e71

Browse files
authored
fix(driver)!: full iour fallback (#656)
* fix(driver): full iour fallback * docs: add changelog entry
1 parent 82d35d6 commit da39e71

File tree

6 files changed

+195
-77
lines changed

6 files changed

+195
-77
lines changed

compio-driver/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14+
- *(driver)* [**breaking**] full iour fallback ([#656](https://github.com/compio-rs/compio/pull/656))
1415
- *(runtime)* future combinator ([#639](https://github.com/compio-rs/compio/pull/639))
1516
- *(fs)* splice ([#635](https://github.com/compio-rs/compio/pull/635))
1617
- *(driver)* fake splice test ([#638](https://github.com/compio-rs/compio/pull/638))

compio-driver/src/driver_type.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ impl DriverType {
2929
Send::CODE,
3030
RecvMsg::CODE,
3131
SendMsg::CODE,
32-
AsyncCancel::CODE,
33-
OpenAt::CODE,
34-
Close::CODE,
35-
Splice::CODE,
36-
Shutdown::CODE,
32+
PollAdd::CODE,
3733
];
3834

3935
if USED_OP.iter().all(|op| crate::sys::is_op_supported(*op)) {

compio-driver/src/sys/iour/mod.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,30 @@ impl Driver {
342342
trace!(?personality, "push RawOp");
343343
match entry {
344344
OpEntry::Submission(entry) => {
345-
#[allow(clippy::useless_conversion)]
346-
self.push_raw_with_key(entry.into(), key)?;
347-
Poll::Pending
345+
if is_op_supported(entry.get_opcode() as _) {
346+
#[allow(clippy::useless_conversion)]
347+
self.push_raw_with_key(entry.into(), key)?;
348+
Poll::Pending
349+
} else {
350+
self.push_blocking_loop(key)
351+
}
348352
}
349353
#[cfg(feature = "io-uring-sqe128")]
350354
OpEntry::Submission128(entry) => {
351355
self.push_raw_with_key(entry, key)?;
352356
Poll::Pending
353357
}
354-
OpEntry::Blocking => loop {
355-
if self.push_blocking(key.clone()) {
356-
break Poll::Pending;
357-
} else {
358-
self.poll_blocking();
359-
}
360-
},
358+
OpEntry::Blocking => self.push_blocking_loop(key),
359+
}
360+
}
361+
362+
fn push_blocking_loop(&mut self, key: ErasedKey) -> Poll<io::Result<usize>> {
363+
loop {
364+
if self.push_blocking(key.clone()) {
365+
break Poll::Pending;
366+
} else {
367+
self.poll_blocking();
368+
}
361369
}
362370
}
363371

compio-driver/src/sys/iour/op.rs

Lines changed: 98 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ unsafe impl OpCode for OpenFile {
6969
.build()
7070
.into()
7171
}
72+
73+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
74+
self.call()
75+
}
7276
}
7377

7478
unsafe impl OpCode for CloseFile {
@@ -77,21 +81,21 @@ unsafe impl OpCode for CloseFile {
7781
.build()
7882
.into()
7983
}
84+
85+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
86+
self.call()
87+
}
8088
}
8189

8290
unsafe impl<S: AsFd> OpCode for TruncateFile<S> {
8391
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
84-
if super::is_op_supported(opcode::Ftruncate::CODE) {
85-
return opcode::Ftruncate::new(Fd(self.fd.as_fd().as_raw_fd()), self.size)
86-
.build()
87-
.into();
88-
}
89-
90-
OpEntry::Blocking
92+
opcode::Ftruncate::new(Fd(self.fd.as_fd().as_raw_fd()), self.size)
93+
.build()
94+
.into()
9195
}
9296

9397
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
94-
self.truncate()
98+
self.call()
9599
}
96100
}
97101

@@ -127,6 +131,19 @@ unsafe impl<S: AsFd> OpCode for FileStat<S> {
127131
.build()
128132
.into()
129133
}
134+
135+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
136+
let this = self.project();
137+
static EMPTY_NAME: &[u8] = b"\0";
138+
let res = syscall!(libc::statx(
139+
this.fd.as_fd().as_raw_fd(),
140+
EMPTY_NAME.as_ptr().cast(),
141+
libc::AT_EMPTY_PATH,
142+
statx_mask(),
143+
this.stat as *mut _ as _
144+
))?;
145+
Ok(res as _)
146+
}
130147
}
131148

132149
impl<S> IntoInner for FileStat<S> {
@@ -171,6 +188,21 @@ unsafe impl OpCode for PathStat {
171188
.build()
172189
.into()
173190
}
191+
192+
fn call_blocking(mut self: Pin<&mut Self>) -> io::Result<usize> {
193+
let mut flags = libc::AT_EMPTY_PATH;
194+
if !self.follow_symlink {
195+
flags |= libc::AT_SYMLINK_NOFOLLOW;
196+
}
197+
let res = syscall!(libc::statx(
198+
libc::AT_FDCWD,
199+
self.path.as_ptr(),
200+
flags,
201+
statx_mask(),
202+
std::ptr::addr_of_mut!(self.stat).cast()
203+
))?;
204+
Ok(res as _)
205+
}
174206
}
175207

176208
impl IntoInner for PathStat {
@@ -316,6 +348,10 @@ unsafe impl OpCode for Unlink {
316348
.build()
317349
.into()
318350
}
351+
352+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
353+
self.call()
354+
}
319355
}
320356

321357
unsafe impl OpCode for CreateDir {
@@ -325,6 +361,10 @@ unsafe impl OpCode for CreateDir {
325361
.build()
326362
.into()
327363
}
364+
365+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
366+
self.call()
367+
}
328368
}
329369

330370
unsafe impl OpCode for Rename {
@@ -338,6 +378,10 @@ unsafe impl OpCode for Rename {
338378
.build()
339379
.into()
340380
}
381+
382+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
383+
self.call()
384+
}
341385
}
342386

343387
unsafe impl OpCode for Symlink {
@@ -350,6 +394,10 @@ unsafe impl OpCode for Symlink {
350394
.build()
351395
.into()
352396
}
397+
398+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
399+
self.call()
400+
}
353401
}
354402

355403
unsafe impl OpCode for HardLink {
@@ -363,21 +411,21 @@ unsafe impl OpCode for HardLink {
363411
.build()
364412
.into()
365413
}
414+
415+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
416+
self.call()
417+
}
366418
}
367419

368420
unsafe impl OpCode for CreateSocket {
369421
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
370-
if super::is_op_supported(opcode::Socket::CODE) {
371-
opcode::Socket::new(
372-
self.domain,
373-
self.socket_type | libc::SOCK_CLOEXEC,
374-
self.protocol,
375-
)
376-
.build()
377-
.into()
378-
} else {
379-
OpEntry::Blocking
380-
}
422+
opcode::Socket::new(
423+
self.domain,
424+
self.socket_type | libc::SOCK_CLOEXEC,
425+
self.protocol,
426+
)
427+
.build()
428+
.into()
381429
}
382430

383431
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
@@ -395,6 +443,10 @@ unsafe impl<S: AsFd> OpCode for ShutdownSocket<S> {
395443
.build()
396444
.into()
397445
}
446+
447+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
448+
self.call()
449+
}
398450
}
399451

400452
unsafe impl OpCode for CloseSocket {
@@ -403,6 +455,10 @@ unsafe impl OpCode for CloseSocket {
403455
.build()
404456
.into()
405457
}
458+
459+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
460+
self.call()
461+
}
406462
}
407463

408464
unsafe impl<S: AsFd> OpCode for Accept<S> {
@@ -756,6 +812,29 @@ unsafe impl<S1: AsFd, S2: AsFd> OpCode for Splice<S1, S2> {
756812
.build()
757813
.into()
758814
}
815+
816+
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
817+
let mut offset_in = self.offset_in;
818+
let mut offset_out = self.offset_out;
819+
let offset_in_ptr = if offset_in < 0 {
820+
std::ptr::null_mut()
821+
} else {
822+
&mut offset_in
823+
};
824+
let offset_out_ptr = if offset_out < 0 {
825+
std::ptr::null_mut()
826+
} else {
827+
&mut offset_out
828+
};
829+
Ok(syscall!(libc::splice(
830+
self.fd_in.as_fd().as_raw_fd(),
831+
offset_in_ptr,
832+
self.fd_out.as_fd().as_raw_fd(),
833+
offset_out_ptr,
834+
self.len,
835+
self.flags,
836+
))? as _)
837+
}
759838
}
760839

761840
mod buf_ring {

0 commit comments

Comments
 (0)