-
Notifications
You must be signed in to change notification settings - Fork 11
Add missing ops up to Linux 6.15 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aa8599f
Fix test_tcp_send_bundle
silvanshade 68d0d38
tmp: Override deps from upstream PRs
silvanshade 4f1c603
Add ops {ReadMulti}
silvanshade 6175387
Add ops {Waitid}
silvanshade a57b1b1
Add ops {Bind, Listen}
silvanshade d5d251d
Add ops {GetXattr, SetXattr}
silvanshade 4c64879
Add ops {FGetXattr, FSetXattr}
silvanshade 5e66e60
Add ops {SetSockOpt}
silvanshade a9b99bf
Add ops {RecvZc}
silvanshade 05ca293
Add ops {EpollWait}
silvanshade e839343
Add ops {ReadvFixed, WritevFixed}
silvanshade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,16 @@ members = [ "io-uring-test", "io-uring-bench" ] | |
|
|
||
| [dependencies] | ||
| bitflags = { version = "2.4.0", default-features = false } | ||
| rustix = { version = "1.0.2", default-features = false, features = ["io_uring", "mm", "thread"] } | ||
| linux-raw-sys = { version = "0.10.0", default-features = false } | ||
| rustix = { version = "1.0.2", default-features = false, features = ["io_uring", "mm", "process", "thread"] } | ||
|
|
||
| [dev-dependencies] | ||
| libc = "0.2.98" | ||
| anyhow = "1" | ||
| rustix = "1.0.2" | ||
| socket2 = "0.5" | ||
| slab = "0.4" | ||
|
|
||
| [patch.crates-io] | ||
| linux-raw-sys = { git = "https://github.com/silvanshade/linux-raw-sys", branch = "io_uring-zcrx" } | ||
| rustix = { git = "https://github.com/silvanshade/rustix", branch = "linux-6.15-io_uring" } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also lets only land this when there is a release we can point to. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,291 @@ | ||
| use crate::Test; | ||
| use ::core::{mem::MaybeUninit, time::Duration}; | ||
| use ::rustix::{event::epoll, fd::OwnedFd, io}; | ||
| use ::std::{ | ||
| io::{PipeReader, PipeWriter}, | ||
| os::{ | ||
| fd::{AsFd, BorrowedFd}, | ||
| unix::io::AsRawFd, | ||
| }, | ||
| thread, | ||
| }; | ||
| use io_uring::{cqueue, opcode, squeue, types, IoUring}; | ||
|
|
||
| // Tests translated from liburing/test/epwait.c. | ||
|
|
||
| #[derive(Debug)] | ||
| struct RxTxPipe { | ||
| rx: PipeReader, | ||
| tx: PipeWriter, | ||
| } | ||
|
|
||
| pub fn test_ready<S: squeue::EntryMarker, C: cqueue::EntryMarker>( | ||
| ring: &mut IoUring<S, C>, | ||
| test: &Test, | ||
| ) -> anyhow::Result<()> { | ||
| require!( | ||
| test; | ||
| test.probe.is_supported(opcode::EpollWait::CODE); | ||
| ); | ||
|
|
||
| println!("test ready"); | ||
|
|
||
| const REQ_TYPE_EPOLL_WAIT: u64 = 1; | ||
|
|
||
| const NPIPES: usize = 2; | ||
| let (efd, pipes, mut events) = init::<NPIPES>()?; | ||
|
|
||
| for pipe in &pipes { | ||
| let tx = pipe.tx.as_fd(); | ||
| io::write(tx, b"foo")?; | ||
| } | ||
|
|
||
| let sqe = opcode::EpollWait::new(types::Fd(efd.as_raw_fd()), events.as_mut_ptr(), NPIPES as _) | ||
| .build() | ||
| .user_data(REQ_TYPE_EPOLL_WAIT) | ||
| .into(); | ||
| unsafe { ring.submission().push(&sqe) }?; | ||
|
|
||
| ring.submit_and_wait(1)?; | ||
| for cqe in ring.completion().map(Into::<cqueue::Entry>::into).take(1) { | ||
| assert_eq!(cqe.user_data_u64(), REQ_TYPE_EPOLL_WAIT); | ||
| cqe.result()?; | ||
| } | ||
|
|
||
| let mut tmp = [0u8; 16]; | ||
|
|
||
| for event in &events { | ||
| let fd = unsafe { BorrowedFd::borrow_raw(event.data.u64() as _) }; | ||
| io::read(fd, &mut tmp)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn test_not_ready<S: squeue::EntryMarker, C: cqueue::EntryMarker>( | ||
| ring: &mut IoUring<S, C>, | ||
| test: &Test, | ||
| ) -> anyhow::Result<()> { | ||
| require!( | ||
| test; | ||
| test.probe.is_supported(opcode::EpollWait::CODE); | ||
| ); | ||
|
|
||
| println!("test not ready"); | ||
|
|
||
| const REQ_TYPE_EPOLL_WAIT: u64 = 1; | ||
|
|
||
| const NPIPES: usize = 2; | ||
| let (efd, pipes, mut events) = init::<NPIPES>()?; | ||
|
|
||
| let sqe = opcode::EpollWait::new(types::Fd(efd.as_raw_fd()), events.as_mut_ptr(), NPIPES as _) | ||
| .build() | ||
| .user_data(REQ_TYPE_EPOLL_WAIT) | ||
| .into(); | ||
| unsafe { ring.submission().push(&sqe) }?; | ||
|
|
||
| for pipe in &pipes { | ||
| thread::sleep(Duration::from_micros(10000)); | ||
| let tx = pipe.tx.as_fd(); | ||
| io::write(tx, b"foo")?; | ||
| } | ||
|
|
||
| let mut nr = 0; | ||
| ring.submit_and_wait(1)?; | ||
| for cqe in ring.completion().map(Into::<cqueue::Entry>::into).take(1) { | ||
| assert_eq!(cqe.user_data_u64(), REQ_TYPE_EPOLL_WAIT); | ||
| nr = cqe.result()?; | ||
| assert!(nr.cast_signed() >= 0); | ||
| } | ||
|
|
||
| let mut tmp = [0u8; 16]; | ||
|
|
||
| for event in events.iter().take(nr as _) { | ||
| let fd = unsafe { BorrowedFd::borrow_raw(event.data.u64() as _) }; | ||
| io::read(fd, &mut tmp)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn test_delete<S: squeue::EntryMarker, C: cqueue::EntryMarker>( | ||
| ring: &mut IoUring<S, C>, | ||
| test: &Test, | ||
| ) -> anyhow::Result<()> { | ||
| require!( | ||
| test; | ||
| test.probe.is_supported(opcode::EpollWait::CODE); | ||
| ); | ||
|
|
||
| println!("test delete"); | ||
|
|
||
| const REQ_TYPE_EPOLL_WAIT: u64 = 1; | ||
|
|
||
| const NPIPES: usize = 2; | ||
| let (efd, pipes, mut events) = init::<NPIPES>()?; | ||
|
|
||
| let sqe = opcode::EpollWait::new(types::Fd(efd.as_raw_fd()), events.as_mut_ptr(), NPIPES as _) | ||
| .build() | ||
| .user_data(REQ_TYPE_EPOLL_WAIT) | ||
| .into(); | ||
| unsafe { ring.submission().push(&sqe) }?; | ||
|
|
||
| epoll::delete(efd.as_fd(), pipes[0].rx.as_fd())?; | ||
|
|
||
| let mut tmp = [0u8; 16]; | ||
|
|
||
| for pipe in &pipes { | ||
| io::write(pipe.tx.as_fd(), &tmp)?; | ||
| } | ||
|
|
||
| ring.submit_and_wait(1)?; | ||
| for cqe in ring.completion().map(Into::<cqueue::Entry>::into).take(1) { | ||
| assert_eq!(cqe.user_data_u64(), REQ_TYPE_EPOLL_WAIT); | ||
| cqe.result()?; | ||
| } | ||
|
|
||
| for pipe in &pipes { | ||
| io::read(pipe.rx.as_fd(), &mut tmp)?; | ||
| } | ||
|
|
||
| let data = epoll::EventData::new_u64(pipes[0].rx.as_raw_fd().cast_unsigned().into()); | ||
| let flags = epoll::EventFlags::IN; | ||
| epoll::add(efd, pipes[0].rx.as_fd(), data, flags)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn test_remove<S: squeue::EntryMarker, C: cqueue::EntryMarker>( | ||
| ring: &mut IoUring<S, C>, | ||
| test: &Test, | ||
| ) -> anyhow::Result<()> { | ||
| require!( | ||
| test; | ||
| test.probe.is_supported(opcode::EpollWait::CODE); | ||
| ); | ||
|
|
||
| println!("test remove"); | ||
|
|
||
| const REQ_TYPE_EPOLL_WAIT: u64 = 1; | ||
|
|
||
| const NPIPES: usize = 2; | ||
| let (efd, pipes, mut events) = init::<NPIPES>()?; | ||
|
|
||
| let sqe = opcode::EpollWait::new(types::Fd(efd.as_raw_fd()), events.as_mut_ptr(), NPIPES as _) | ||
| .build() | ||
| .user_data(REQ_TYPE_EPOLL_WAIT) | ||
| .into(); | ||
| unsafe { ring.submission().push(&sqe) }?; | ||
|
|
||
| drop(efd); | ||
|
|
||
| thread::sleep(Duration::from_micros(10000)); | ||
| for pipe in &pipes { | ||
| io::write(pipe.tx.as_fd(), b"foo")?; | ||
| } | ||
|
|
||
| ring.submit_and_wait(1)?; | ||
| for cqe in ring.completion().map(Into::<cqueue::Entry>::into).take(1) { | ||
| assert_eq!(cqe.user_data_u64(), REQ_TYPE_EPOLL_WAIT); | ||
| let err = cqe.result().unwrap_err(); | ||
| assert!([io::Errno::AGAIN, io::Errno::BADF].contains(&err)); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn test_race<S: squeue::EntryMarker, C: cqueue::EntryMarker>( | ||
| ring: &mut IoUring<S, C>, | ||
| test: &Test, | ||
| ) -> anyhow::Result<()> { | ||
| require!( | ||
| test; | ||
| test.probe.is_supported(opcode::EpollWait::CODE); | ||
| ); | ||
|
|
||
| println!("test race"); | ||
|
|
||
| const REQ_TYPE_EPOLL_WAIT: u64 = 1; | ||
|
|
||
| const LOOPS: usize = 500; | ||
| const NPIPES: usize = 8; | ||
|
|
||
| fn prune(events: &[epoll::Event], nr: usize) -> anyhow::Result<()> { | ||
| let mut tmp = [0u8; 32]; | ||
|
|
||
| for event in events.iter().take(nr) { | ||
| let fd = unsafe { BorrowedFd::borrow_raw(event.data.u64() as _) }; | ||
| io::read(fd, &mut tmp)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| thread::scope(|scope| -> anyhow::Result<()> { | ||
| let (efd, pipes, mut events) = init::<NPIPES>()?; | ||
|
|
||
| let handle = scope.spawn(move || -> anyhow::Result<()> { | ||
| for _ in 0..LOOPS { | ||
| thread::sleep(Duration::from_micros(150)); | ||
| for pipe in &pipes { | ||
| io::write(pipe.tx.as_fd(), b"foo")?; | ||
| } | ||
| } | ||
| Ok(()) | ||
| }); | ||
|
|
||
| for _ in 0..LOOPS { | ||
| let sqe = opcode::EpollWait::new( | ||
| types::Fd(efd.as_raw_fd()), | ||
| events.as_mut_ptr(), | ||
| NPIPES as _, | ||
| ) | ||
| .build() | ||
| .user_data(REQ_TYPE_EPOLL_WAIT) | ||
| .into(); | ||
| unsafe { ring.submission().push(&sqe) }?; | ||
| ring.submit_and_wait(1)?; | ||
| let cqe = ring | ||
| .completion() | ||
| .next() | ||
| .map(Into::<cqueue::Entry>::into) | ||
| .unwrap(); | ||
| assert_eq!(cqe.user_data_u64(), REQ_TYPE_EPOLL_WAIT); | ||
| let nr = cqe.result()?; | ||
| prune(&events, nr as _)?; | ||
| thread::sleep(Duration::from_micros(100)); | ||
| } | ||
|
|
||
| handle.join().unwrap()?; | ||
|
|
||
| Ok(()) | ||
| })?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn init<const NPIPES: usize>( | ||
| ) -> anyhow::Result<(OwnedFd, [RxTxPipe; NPIPES], [epoll::Event; NPIPES])>{ | ||
| let pipes: [RxTxPipe; NPIPES] = { | ||
| let mut pipes: [MaybeUninit<RxTxPipe>; NPIPES] = [const { MaybeUninit::uninit() }; NPIPES]; | ||
| for pipe in &mut pipes { | ||
| let (rx, tx) = ::std::io::pipe()?; | ||
| pipe.write(RxTxPipe { rx, tx }); | ||
| } | ||
| unsafe { ::core::mem::transmute_copy(&pipes) } | ||
| }; | ||
|
|
||
| let efd = epoll::create(epoll::CreateFlags::empty())?; | ||
|
|
||
| for pipe in &pipes { | ||
| let efd = efd.as_fd(); | ||
| let rx = pipe.rx.as_fd(); | ||
| let data = epoll::EventData::new_u64(rx.as_raw_fd().cast_unsigned().into()); | ||
| let flags = epoll::EventFlags::IN; | ||
| epoll::add(efd, rx, data, flags)?; | ||
| } | ||
|
|
||
| let events: [epoll::Event; NPIPES] = unsafe { ::core::mem::zeroed() }; | ||
|
|
||
| Ok((efd, pipes, events)) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets try and avoid adding any dependencies. This should really just be rustix + any supporting helpers.