Skip to content

Update for Linux 6.16 #350

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions io-uring-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ fn test<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
tests::poll::test_eventfd_poll_remove_failed(&mut ring, &test)?;
tests::poll::test_eventfd_poll_multi(&mut ring, &test)?;

// pipe
tests::pipe::test_pipe(&mut ring, &test)?;

// futex
tests::futex::test_futex_wait(&mut ring, &test)?;
tests::futex::test_futex_wake(&mut ring, &test)?;
Expand Down
1 change: 1 addition & 0 deletions io-uring-test/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod fs;
pub mod futex;
pub mod net;
pub mod os;
pub mod pipe;
pub mod poll;
pub mod queue;
pub mod register;
Expand Down
65 changes: 65 additions & 0 deletions io-uring-test/src/tests/pipe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::Test;
use io_uring::{cqueue, opcode, squeue, IoUring};
use std::{
io::{PipeReader, PipeWriter, Read, Write},
os::fd::FromRawFd,
};

pub fn test_pipe<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
) -> anyhow::Result<()> {
require!(
test;
test.probe.is_supported(opcode::Pipe::CODE);
);

println!("test pipe");

const REQ_TYPE_PIPE: u64 = 1;
const DATA: &[u8] = b"foo";

// Setup placeholder fds to be assigned on op completion.
let mut fds = [-1, -1];

// Submit pipe op.
let sqe = opcode::Pipe::new(fds.as_mut_ptr())
.build()
.user_data(REQ_TYPE_PIPE)
.into();
unsafe { ring.submission().push(&sqe) }?;
ring.submit_and_wait(1)?;

// Process pipe op.
let cqe = ring
.completion()
.map(Into::<cqueue::Entry>::into)
.next()
.unwrap();
assert!(cqe.result() >= 0);
assert_eq!(cqe.user_data(), REQ_TYPE_PIPE);

// Ensure the fds were assigned.
assert_ne!(fds[0], -1);
assert_ne!(fds[1], -1);

// Wrap the raw fds.
let mut rx = unsafe { PipeReader::from_raw_fd(fds[0]) };
let mut tx = unsafe { PipeWriter::from_raw_fd(fds[1]) };

// Write data to the pipe.
for _ in 0..1024 {
tx.write_all(DATA).unwrap();
}

// Read data from the pipe.
let mut buf = [0u8; DATA.len() * 1024];
rx.read_exact(&mut buf).unwrap();

// Check the read data matches what was sent.
for chunk in buf.chunks(DATA.len()) {
assert_eq!(chunk, DATA);
}

Ok(())
}
28 changes: 28 additions & 0 deletions src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2356,3 +2356,31 @@ opcode! {
Entry(sqe)
}
}

// === 6.16 ===

opcode! {
// Create a pipe, equivalent to `pipe(2)`.
pub struct Pipe {
fds: { *mut RawFd },
;;
flags: u32 = 0,
file_index: Option<types::DestinationSlot> = None,
}

pub const CODE = sys::IORING_OP_PIPE;

pub fn build(self) -> Entry {
let Self { fds, flags, file_index } = self;

let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = 0;
sqe.__bindgen_anon_2.addr = fds as _;
sqe.__bindgen_anon_3.pipe_flags = flags;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
}
71 changes: 67 additions & 4 deletions src/sys/sys_aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ pub union io_uring_sqe__bindgen_ty_3 {
pub futex_flags: __u32,
pub install_fd_flags: __u32,
pub nop_flags: __u32,
pub pipe_flags: __u32,
}
#[test]
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
Expand Down Expand Up @@ -769,6 +770,16 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
stringify!(nop_flags)
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).pipe_flags) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(io_uring_sqe__bindgen_ty_3),
"::",
stringify!(pipe_flags)
)
);
}
impl Default for io_uring_sqe__bindgen_ty_3 {
fn default() -> Self {
Expand Down Expand Up @@ -838,6 +849,7 @@ pub union io_uring_sqe__bindgen_ty_5 {
pub zcrx_ifq_idx: __u32,
pub optlen: __u32,
pub __bindgen_anon_1: io_uring_sqe__bindgen_ty_5__bindgen_ty_1,
pub __bindgen_anon_2: io_uring_sqe__bindgen_ty_5__bindgen_ty_2,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
Expand Down Expand Up @@ -887,6 +899,54 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_1() {
)
);
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct io_uring_sqe__bindgen_ty_5__bindgen_ty_2 {
pub write_stream: __u8,
pub __pad4: [__u8; 3usize],
}
#[test]
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_2() {
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5__bindgen_ty_2> =
::core::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::core::mem::size_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
4usize,
concat!(
"Size of: ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
)
);
assert_eq!(
::core::mem::align_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
1usize,
concat!(
"Alignment of ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).write_stream) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
"::",
stringify!(write_stream)
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).__pad4) as usize - ptr as usize },
1usize,
concat!(
"Offset of field: ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
"::",
stringify!(__pad4)
)
);
}
#[test]
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5() {
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5> =
Expand Down Expand Up @@ -1350,7 +1410,8 @@ pub const IORING_OP_RECV_ZC: io_uring_op = 58;
pub const IORING_OP_EPOLL_WAIT: io_uring_op = 59;
pub const IORING_OP_READV_FIXED: io_uring_op = 60;
pub const IORING_OP_WRITEV_FIXED: io_uring_op = 61;
pub const IORING_OP_LAST: io_uring_op = 62;
pub const IORING_OP_PIPE: io_uring_op = 62;
pub const IORING_OP_LAST: io_uring_op = 63;
pub type io_uring_op = libc::c_uint;
pub const IORING_MSG_DATA: io_uring_msg_ring_flags = 0;
pub const IORING_MSG_SEND_FD: io_uring_msg_ring_flags = 1;
Expand Down Expand Up @@ -3662,14 +3723,16 @@ fn bindgen_test_layout_io_uring_zcrx_offsets() {
)
);
}
pub const IORING_ZCRX_AREA_DMABUF: io_uring_zcrx_area_flags = 1;
pub type io_uring_zcrx_area_flags = libc::c_uint;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct io_uring_zcrx_area_reg {
pub addr: __u64,
pub len: __u64,
pub rq_area_token: __u64,
pub flags: __u32,
pub __resv1: __u32,
pub dmabuf_fd: __u32,
pub __resv2: [__u64; 2usize],
}
#[test]
Expand Down Expand Up @@ -3728,13 +3791,13 @@ fn bindgen_test_layout_io_uring_zcrx_area_reg() {
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).__resv1) as usize - ptr as usize },
unsafe { ::core::ptr::addr_of!((*ptr).dmabuf_fd) as usize - ptr as usize },
28usize,
concat!(
"Offset of field: ",
stringify!(io_uring_zcrx_area_reg),
"::",
stringify!(__resv1)
stringify!(dmabuf_fd)
)
);
assert_eq!(
Expand Down
72 changes: 68 additions & 4 deletions src/sys/sys_loongarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ pub union io_uring_sqe__bindgen_ty_3 {
pub futex_flags: __u32,
pub install_fd_flags: __u32,
pub nop_flags: __u32,
pub pipe_flags: __u32,
}
#[test]
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
Expand Down Expand Up @@ -769,6 +770,16 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
stringify!(nop_flags)
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).pipe_flags) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(io_uring_sqe__bindgen_ty_3),
"::",
stringify!(pipe_flags)
)
);
}
impl Default for io_uring_sqe__bindgen_ty_3 {
fn default() -> Self {
Expand Down Expand Up @@ -838,6 +849,7 @@ pub union io_uring_sqe__bindgen_ty_5 {
pub zcrx_ifq_idx: __u32,
pub optlen: __u32,
pub __bindgen_anon_1: io_uring_sqe__bindgen_ty_5__bindgen_ty_1,
pub __bindgen_anon_2: io_uring_sqe__bindgen_ty_5__bindgen_ty_2,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
Expand Down Expand Up @@ -887,6 +899,54 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_1() {
)
);
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct io_uring_sqe__bindgen_ty_5__bindgen_ty_2 {
pub write_stream: __u8,
pub __pad4: [__u8; 3usize],
}
#[test]
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_2() {
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5__bindgen_ty_2> =
::core::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::core::mem::size_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
4usize,
concat!(
"Size of: ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
)
);
assert_eq!(
::core::mem::align_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
1usize,
concat!(
"Alignment of ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).write_stream) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
"::",
stringify!(write_stream)
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).__pad4) as usize - ptr as usize },
1usize,
concat!(
"Offset of field: ",
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
"::",
stringify!(__pad4)
)
);
}
#[test]
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5() {
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5> =
Expand Down Expand Up @@ -1350,7 +1410,8 @@ pub const IORING_OP_RECV_ZC: io_uring_op = 58;
pub const IORING_OP_EPOLL_WAIT: io_uring_op = 59;
pub const IORING_OP_READV_FIXED: io_uring_op = 60;
pub const IORING_OP_WRITEV_FIXED: io_uring_op = 61;
pub const IORING_OP_LAST: io_uring_op = 62;
pub const IORING_OP_PIPE: io_uring_op = 62;
pub const IORING_OP_LAST: io_uring_op = 63;
pub type io_uring_op = libc::c_uint;
pub const IORING_MSG_DATA: io_uring_msg_ring_flags = 0;
pub const IORING_MSG_SEND_FD: io_uring_msg_ring_flags = 1;
Expand Down Expand Up @@ -3662,14 +3723,16 @@ fn bindgen_test_layout_io_uring_zcrx_offsets() {
)
);
}
pub const IORING_ZCRX_AREA_DMABUF: io_uring_zcrx_area_flags = 1;
pub type io_uring_zcrx_area_flags = libc::c_uint;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct io_uring_zcrx_area_reg {
pub addr: __u64,
pub len: __u64,
pub rq_area_token: __u64,
pub flags: __u32,
pub __resv1: __u32,
pub dmabuf_fd: __u32,
pub __resv2: [__u64; 2usize],
}
#[test]
Expand Down Expand Up @@ -3728,13 +3791,13 @@ fn bindgen_test_layout_io_uring_zcrx_area_reg() {
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).__resv1) as usize - ptr as usize },
unsafe { ::core::ptr::addr_of!((*ptr).dmabuf_fd) as usize - ptr as usize },
28usize,
concat!(
"Offset of field: ",
stringify!(io_uring_zcrx_area_reg),
"::",
stringify!(__resv1)
stringify!(dmabuf_fd)
)
);
assert_eq!(
Expand Down Expand Up @@ -3878,6 +3941,7 @@ fn bindgen_test_layout_io_uring_zcrx_ifq_reg() {
)
);
}
#[doc = " struct futex_waitv - A waiter for vectorized wait\n @val:\tExpected value at uaddr\n @uaddr:\tUser address to wait on\n @flags:\tFlags for this waiter\n @__reserved:\tReserved member to preserve data alignment. Should be 0."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct futex_waitv {
Expand Down
Loading
Loading