Skip to content

Commit c551201

Browse files
authored
Update for Linux 6.16 (#350)
* Update sys for Linux 6.16 * Add Pipe op --------- Co-authored-by: silvanshade <[email protected]>
1 parent def1dda commit c551201

File tree

9 files changed

+433
-20
lines changed

9 files changed

+433
-20
lines changed

io-uring-test/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ fn test<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
171171
tests::poll::test_eventfd_poll_remove_failed(&mut ring, &test)?;
172172
tests::poll::test_eventfd_poll_multi(&mut ring, &test)?;
173173

174+
// pipe
175+
tests::pipe::test_pipe(&mut ring, &test)?;
176+
174177
// futex
175178
tests::futex::test_futex_wait(&mut ring, &test)?;
176179
tests::futex::test_futex_wake(&mut ring, &test)?;

io-uring-test/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod fs;
44
pub mod futex;
55
pub mod net;
66
pub mod os;
7+
pub mod pipe;
78
pub mod poll;
89
pub mod queue;
910
pub mod register;

io-uring-test/src/tests/pipe.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use crate::Test;
2+
use io_uring::{cqueue, opcode, squeue, IoUring};
3+
use std::{
4+
io::{PipeReader, PipeWriter, Read, Write},
5+
os::fd::FromRawFd,
6+
};
7+
8+
pub fn test_pipe<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
9+
ring: &mut IoUring<S, C>,
10+
test: &Test,
11+
) -> anyhow::Result<()> {
12+
require!(
13+
test;
14+
test.probe.is_supported(opcode::Pipe::CODE);
15+
);
16+
17+
println!("test pipe");
18+
19+
const REQ_TYPE_PIPE: u64 = 1;
20+
const DATA: &[u8] = b"foo";
21+
22+
// Setup placeholder fds to be assigned on op completion.
23+
let mut fds = [-1, -1];
24+
25+
// Submit pipe op.
26+
let sqe = opcode::Pipe::new(fds.as_mut_ptr())
27+
.build()
28+
.user_data(REQ_TYPE_PIPE)
29+
.into();
30+
unsafe { ring.submission().push(&sqe) }?;
31+
ring.submit_and_wait(1)?;
32+
33+
// Process pipe op.
34+
let cqe = ring
35+
.completion()
36+
.map(Into::<cqueue::Entry>::into)
37+
.next()
38+
.unwrap();
39+
assert!(cqe.result() >= 0);
40+
assert_eq!(cqe.user_data(), REQ_TYPE_PIPE);
41+
42+
// Ensure the fds were assigned.
43+
assert_ne!(fds[0], -1);
44+
assert_ne!(fds[1], -1);
45+
46+
// Wrap the raw fds.
47+
let mut rx = unsafe { PipeReader::from_raw_fd(fds[0]) };
48+
let mut tx = unsafe { PipeWriter::from_raw_fd(fds[1]) };
49+
50+
// Write data to the pipe.
51+
for _ in 0..1024 {
52+
tx.write_all(DATA).unwrap();
53+
}
54+
55+
// Read data from the pipe.
56+
let mut buf = [0u8; DATA.len() * 1024];
57+
rx.read_exact(&mut buf).unwrap();
58+
59+
// Check the read data matches what was sent.
60+
for chunk in buf.chunks(DATA.len()) {
61+
assert_eq!(chunk, DATA);
62+
}
63+
64+
Ok(())
65+
}

src/opcode.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,3 +2356,31 @@ opcode! {
23562356
Entry(sqe)
23572357
}
23582358
}
2359+
2360+
// === 6.16 ===
2361+
2362+
opcode! {
2363+
// Create a pipe, equivalent to `pipe(2)`.
2364+
pub struct Pipe {
2365+
fds: { *mut RawFd },
2366+
;;
2367+
flags: u32 = 0,
2368+
file_index: Option<types::DestinationSlot> = None,
2369+
}
2370+
2371+
pub const CODE = sys::IORING_OP_PIPE;
2372+
2373+
pub fn build(self) -> Entry {
2374+
let Self { fds, flags, file_index } = self;
2375+
2376+
let mut sqe = sqe_zeroed();
2377+
sqe.opcode = Self::CODE;
2378+
sqe.fd = 0;
2379+
sqe.__bindgen_anon_2.addr = fds as _;
2380+
sqe.__bindgen_anon_3.pipe_flags = flags;
2381+
if let Some(dest) = file_index {
2382+
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
2383+
}
2384+
Entry(sqe)
2385+
}
2386+
}

src/sys/sys_aarch64.rs

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ pub union io_uring_sqe__bindgen_ty_3 {
523523
pub futex_flags: __u32,
524524
pub install_fd_flags: __u32,
525525
pub nop_flags: __u32,
526+
pub pipe_flags: __u32,
526527
}
527528
#[test]
528529
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
@@ -769,6 +770,16 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
769770
stringify!(nop_flags)
770771
)
771772
);
773+
assert_eq!(
774+
unsafe { ::core::ptr::addr_of!((*ptr).pipe_flags) as usize - ptr as usize },
775+
0usize,
776+
concat!(
777+
"Offset of field: ",
778+
stringify!(io_uring_sqe__bindgen_ty_3),
779+
"::",
780+
stringify!(pipe_flags)
781+
)
782+
);
772783
}
773784
impl Default for io_uring_sqe__bindgen_ty_3 {
774785
fn default() -> Self {
@@ -838,6 +849,7 @@ pub union io_uring_sqe__bindgen_ty_5 {
838849
pub zcrx_ifq_idx: __u32,
839850
pub optlen: __u32,
840851
pub __bindgen_anon_1: io_uring_sqe__bindgen_ty_5__bindgen_ty_1,
852+
pub __bindgen_anon_2: io_uring_sqe__bindgen_ty_5__bindgen_ty_2,
841853
}
842854
#[repr(C)]
843855
#[derive(Debug, Default, Copy, Clone)]
@@ -887,6 +899,54 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_1() {
887899
)
888900
);
889901
}
902+
#[repr(C)]
903+
#[derive(Debug, Default, Copy, Clone)]
904+
pub struct io_uring_sqe__bindgen_ty_5__bindgen_ty_2 {
905+
pub write_stream: __u8,
906+
pub __pad4: [__u8; 3usize],
907+
}
908+
#[test]
909+
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_2() {
910+
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5__bindgen_ty_2> =
911+
::core::mem::MaybeUninit::uninit();
912+
let ptr = UNINIT.as_ptr();
913+
assert_eq!(
914+
::core::mem::size_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
915+
4usize,
916+
concat!(
917+
"Size of: ",
918+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
919+
)
920+
);
921+
assert_eq!(
922+
::core::mem::align_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
923+
1usize,
924+
concat!(
925+
"Alignment of ",
926+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
927+
)
928+
);
929+
assert_eq!(
930+
unsafe { ::core::ptr::addr_of!((*ptr).write_stream) as usize - ptr as usize },
931+
0usize,
932+
concat!(
933+
"Offset of field: ",
934+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
935+
"::",
936+
stringify!(write_stream)
937+
)
938+
);
939+
assert_eq!(
940+
unsafe { ::core::ptr::addr_of!((*ptr).__pad4) as usize - ptr as usize },
941+
1usize,
942+
concat!(
943+
"Offset of field: ",
944+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
945+
"::",
946+
stringify!(__pad4)
947+
)
948+
);
949+
}
890950
#[test]
891951
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5() {
892952
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5> =
@@ -1350,7 +1410,8 @@ pub const IORING_OP_RECV_ZC: io_uring_op = 58;
13501410
pub const IORING_OP_EPOLL_WAIT: io_uring_op = 59;
13511411
pub const IORING_OP_READV_FIXED: io_uring_op = 60;
13521412
pub const IORING_OP_WRITEV_FIXED: io_uring_op = 61;
1353-
pub const IORING_OP_LAST: io_uring_op = 62;
1413+
pub const IORING_OP_PIPE: io_uring_op = 62;
1414+
pub const IORING_OP_LAST: io_uring_op = 63;
13541415
pub type io_uring_op = libc::c_uint;
13551416
pub const IORING_MSG_DATA: io_uring_msg_ring_flags = 0;
13561417
pub const IORING_MSG_SEND_FD: io_uring_msg_ring_flags = 1;
@@ -3662,14 +3723,16 @@ fn bindgen_test_layout_io_uring_zcrx_offsets() {
36623723
)
36633724
);
36643725
}
3726+
pub const IORING_ZCRX_AREA_DMABUF: io_uring_zcrx_area_flags = 1;
3727+
pub type io_uring_zcrx_area_flags = libc::c_uint;
36653728
#[repr(C)]
36663729
#[derive(Debug, Default, Copy, Clone)]
36673730
pub struct io_uring_zcrx_area_reg {
36683731
pub addr: __u64,
36693732
pub len: __u64,
36703733
pub rq_area_token: __u64,
36713734
pub flags: __u32,
3672-
pub __resv1: __u32,
3735+
pub dmabuf_fd: __u32,
36733736
pub __resv2: [__u64; 2usize],
36743737
}
36753738
#[test]
@@ -3728,13 +3791,13 @@ fn bindgen_test_layout_io_uring_zcrx_area_reg() {
37283791
)
37293792
);
37303793
assert_eq!(
3731-
unsafe { ::core::ptr::addr_of!((*ptr).__resv1) as usize - ptr as usize },
3794+
unsafe { ::core::ptr::addr_of!((*ptr).dmabuf_fd) as usize - ptr as usize },
37323795
28usize,
37333796
concat!(
37343797
"Offset of field: ",
37353798
stringify!(io_uring_zcrx_area_reg),
37363799
"::",
3737-
stringify!(__resv1)
3800+
stringify!(dmabuf_fd)
37383801
)
37393802
);
37403803
assert_eq!(

src/sys/sys_loongarch64.rs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ pub union io_uring_sqe__bindgen_ty_3 {
523523
pub futex_flags: __u32,
524524
pub install_fd_flags: __u32,
525525
pub nop_flags: __u32,
526+
pub pipe_flags: __u32,
526527
}
527528
#[test]
528529
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
@@ -769,6 +770,16 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_3() {
769770
stringify!(nop_flags)
770771
)
771772
);
773+
assert_eq!(
774+
unsafe { ::core::ptr::addr_of!((*ptr).pipe_flags) as usize - ptr as usize },
775+
0usize,
776+
concat!(
777+
"Offset of field: ",
778+
stringify!(io_uring_sqe__bindgen_ty_3),
779+
"::",
780+
stringify!(pipe_flags)
781+
)
782+
);
772783
}
773784
impl Default for io_uring_sqe__bindgen_ty_3 {
774785
fn default() -> Self {
@@ -838,6 +849,7 @@ pub union io_uring_sqe__bindgen_ty_5 {
838849
pub zcrx_ifq_idx: __u32,
839850
pub optlen: __u32,
840851
pub __bindgen_anon_1: io_uring_sqe__bindgen_ty_5__bindgen_ty_1,
852+
pub __bindgen_anon_2: io_uring_sqe__bindgen_ty_5__bindgen_ty_2,
841853
}
842854
#[repr(C)]
843855
#[derive(Debug, Default, Copy, Clone)]
@@ -887,6 +899,54 @@ fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_1() {
887899
)
888900
);
889901
}
902+
#[repr(C)]
903+
#[derive(Debug, Default, Copy, Clone)]
904+
pub struct io_uring_sqe__bindgen_ty_5__bindgen_ty_2 {
905+
pub write_stream: __u8,
906+
pub __pad4: [__u8; 3usize],
907+
}
908+
#[test]
909+
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5__bindgen_ty_2() {
910+
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5__bindgen_ty_2> =
911+
::core::mem::MaybeUninit::uninit();
912+
let ptr = UNINIT.as_ptr();
913+
assert_eq!(
914+
::core::mem::size_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
915+
4usize,
916+
concat!(
917+
"Size of: ",
918+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
919+
)
920+
);
921+
assert_eq!(
922+
::core::mem::align_of::<io_uring_sqe__bindgen_ty_5__bindgen_ty_2>(),
923+
1usize,
924+
concat!(
925+
"Alignment of ",
926+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2)
927+
)
928+
);
929+
assert_eq!(
930+
unsafe { ::core::ptr::addr_of!((*ptr).write_stream) as usize - ptr as usize },
931+
0usize,
932+
concat!(
933+
"Offset of field: ",
934+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
935+
"::",
936+
stringify!(write_stream)
937+
)
938+
);
939+
assert_eq!(
940+
unsafe { ::core::ptr::addr_of!((*ptr).__pad4) as usize - ptr as usize },
941+
1usize,
942+
concat!(
943+
"Offset of field: ",
944+
stringify!(io_uring_sqe__bindgen_ty_5__bindgen_ty_2),
945+
"::",
946+
stringify!(__pad4)
947+
)
948+
);
949+
}
890950
#[test]
891951
fn bindgen_test_layout_io_uring_sqe__bindgen_ty_5() {
892952
const UNINIT: ::core::mem::MaybeUninit<io_uring_sqe__bindgen_ty_5> =
@@ -1350,7 +1410,8 @@ pub const IORING_OP_RECV_ZC: io_uring_op = 58;
13501410
pub const IORING_OP_EPOLL_WAIT: io_uring_op = 59;
13511411
pub const IORING_OP_READV_FIXED: io_uring_op = 60;
13521412
pub const IORING_OP_WRITEV_FIXED: io_uring_op = 61;
1353-
pub const IORING_OP_LAST: io_uring_op = 62;
1413+
pub const IORING_OP_PIPE: io_uring_op = 62;
1414+
pub const IORING_OP_LAST: io_uring_op = 63;
13541415
pub type io_uring_op = libc::c_uint;
13551416
pub const IORING_MSG_DATA: io_uring_msg_ring_flags = 0;
13561417
pub const IORING_MSG_SEND_FD: io_uring_msg_ring_flags = 1;
@@ -3662,14 +3723,16 @@ fn bindgen_test_layout_io_uring_zcrx_offsets() {
36623723
)
36633724
);
36643725
}
3726+
pub const IORING_ZCRX_AREA_DMABUF: io_uring_zcrx_area_flags = 1;
3727+
pub type io_uring_zcrx_area_flags = libc::c_uint;
36653728
#[repr(C)]
36663729
#[derive(Debug, Default, Copy, Clone)]
36673730
pub struct io_uring_zcrx_area_reg {
36683731
pub addr: __u64,
36693732
pub len: __u64,
36703733
pub rq_area_token: __u64,
36713734
pub flags: __u32,
3672-
pub __resv1: __u32,
3735+
pub dmabuf_fd: __u32,
36733736
pub __resv2: [__u64; 2usize],
36743737
}
36753738
#[test]
@@ -3728,13 +3791,13 @@ fn bindgen_test_layout_io_uring_zcrx_area_reg() {
37283791
)
37293792
);
37303793
assert_eq!(
3731-
unsafe { ::core::ptr::addr_of!((*ptr).__resv1) as usize - ptr as usize },
3794+
unsafe { ::core::ptr::addr_of!((*ptr).dmabuf_fd) as usize - ptr as usize },
37323795
28usize,
37333796
concat!(
37343797
"Offset of field: ",
37353798
stringify!(io_uring_zcrx_area_reg),
37363799
"::",
3737-
stringify!(__resv1)
3800+
stringify!(dmabuf_fd)
37383801
)
37393802
);
37403803
assert_eq!(
@@ -3878,6 +3941,7 @@ fn bindgen_test_layout_io_uring_zcrx_ifq_reg() {
38783941
)
38793942
);
38803943
}
3944+
#[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."]
38813945
#[repr(C)]
38823946
#[derive(Debug, Default, Copy, Clone)]
38833947
pub struct futex_waitv {

0 commit comments

Comments
 (0)