Skip to content

Commit

Permalink
release 0.6.0 (tokio-rs#229)
Browse files Browse the repository at this point in the history
* Some api changes

* test: show test count

* test: Update deps

* No bitflags 2

* Fix fmt

* test: Fix read unaligned

* Remove deprecated fn

* move Sealed trait

* Some style

* probe no alloc

* Fix style

* Enable more test for ci

* opcode: remove result from MsgRingSendFd

The kernel now does not allow non-zero values.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/io_uring/msg_ring.c?h=v6.3-rc5#n232

* Fix ci

* Fix fmt

* Use Probe::COUNT for size

* some change
  • Loading branch information
quininer authored Apr 9, 2023
1 parent 9febb08 commit e3fa23a
Show file tree
Hide file tree
Showing 18 changed files with 350 additions and 438 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
command: run
use-cross: true
# Only run the test package on x86 until we find an ergonomic way
# Only run the test package on x86 until we find an ergonomic way
# to virtualize aarch64
args: --package io-uring-test --features io-uring-test/ci --target x86_64-unknown-linux-gnu

Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "io-uring"
version = "0.6.0-pre"
version = "0.6.0"
authors = ["quininer <[email protected]>"]
edition = "2018"
license = "MIT/Apache-2.0"
Expand All @@ -17,13 +17,14 @@ exclude = []
members = [ "io-uring-test", "io-uring-bench" ]

[features]
unstable = []
overwrite = [ "bindgen" ]
direct-syscall = [ "sc" ]
io_safety = []

[dependencies]
# Since we need to work on rustc 1.48, we cannot use 2021 edition.
bitflags = "1"

libc = { version = "0.2.98", default-features = false }
sc = { version = "0.2", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion io-uring-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
io-uring = { path = ".." }
iou = "0.3"
uring-sys = "0.7"
criterion = "0.3"
criterion = "0.4"
iai = "0.1"
tempfile = "3"

Expand Down
2 changes: 1 addition & 1 deletion io-uring-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ libc = { version = "0.2", features = [ "extra_traits" ] }
anyhow = "1"
tempfile = "3"
once_cell = "1"
socket2 = "0.4"
socket2 = "0.5"

[features]
direct-syscall = [ "io-uring/direct-syscall" ]
Expand Down
23 changes: 8 additions & 15 deletions io-uring-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ mod utils;
mod tests;

use io_uring::{cqueue, squeue, IoUring, Probe};
use std::cell::Cell;

pub struct Test {
probe: Probe,
target: Option<String>,
count: Cell<usize>,
}

fn main() -> anyhow::Result<()> {
Expand All @@ -16,7 +18,7 @@ fn main() -> anyhow::Result<()> {

#[cfg(not(feature = "ci"))]
{
match IoUring::<squeue::Entry128, cqueue::Entry>::generic_new(entries) {
match IoUring::<squeue::Entry128, cqueue::Entry>::builder().build(entries) {
Ok(r) => test(r)?,
Err(e) => {
println!(
Expand All @@ -27,12 +29,8 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}
};
test(IoUring::<squeue::Entry, cqueue::Entry32>::generic_new(
entries,
)?)?;
test(IoUring::<squeue::Entry128, cqueue::Entry32>::generic_new(
entries,
)?)?;
test(IoUring::<squeue::Entry, cqueue::Entry32>::builder().build(entries)?)?;
test(IoUring::<squeue::Entry128, cqueue::Entry32>::builder().build(entries)?)?;
}

Ok(())
Expand Down Expand Up @@ -64,6 +62,7 @@ fn test<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
let test = Test {
probe,
target: std::env::args().nth(1),
count: Cell::new(0),
};

tests::queue::test_nop(&mut ring, &test)?;
Expand All @@ -87,12 +86,10 @@ fn test<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
tests::fs::test_file_fsync(&mut ring, &test)?;
tests::fs::test_file_fsync_file_range(&mut ring, &test)?;
tests::fs::test_file_fallocate(&mut ring, &test)?;
tests::fs::test_file_fallocate64(&mut ring, &test)?;
tests::fs::test_file_openat2(&mut ring, &test)?;
tests::fs::test_file_openat2_close_file_index(&mut ring, &test)?;
tests::fs::test_file_openat_close_file_index(&mut ring, &test)?;
tests::fs::test_file_close(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::fs::test_file_direct_write_read(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::fs::test_statx(&mut ring, &test)?;
Expand All @@ -117,17 +114,12 @@ fn test<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
tests::net::test_tcp_zero_copy_sendmsg_recvmsg(&mut ring, &test)?;
tests::net::test_tcp_accept(&mut ring, &test)?;
tests::net::test_tcp_accept_file_index(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::net::test_tcp_accept_multi(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::net::test_tcp_accept_multi_file_index(&mut ring, &test)?;
tests::net::test_tcp_connect(&mut ring, &test)?;
tests::net::test_tcp_buffer_select(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::net::test_tcp_buffer_select_recvmsg(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::net::test_tcp_buffer_select_readv(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::net::test_tcp_recv_multi(&mut ring, &test)?;
tests::net::test_shutdown(&mut ring, &test)?;
tests::net::test_socket(&mut ring, &test)?;
Expand All @@ -138,11 +130,12 @@ fn test<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
tests::poll::test_eventfd_poll(&mut ring, &test)?;
tests::poll::test_eventfd_poll_remove(&mut ring, &test)?;
tests::poll::test_eventfd_poll_remove_failed(&mut ring, &test)?;
#[cfg(not(feature = "ci"))]
tests::poll::test_eventfd_poll_multi(&mut ring, &test)?;

// regression test
tests::regression::test_issue154(&mut ring, &test)?;

println!("Test count: {}", test.count.get());

Ok(())
}
42 changes: 3 additions & 39 deletions io-uring-test/src/tests/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub fn test_file_fsync_file_range<S: squeue::EntryMarker, C: cqueue::EntryMarker
Ok(())
}

#[allow(deprecated)]
pub fn test_file_fallocate<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
Expand Down Expand Up @@ -155,39 +154,6 @@ pub fn test_file_fallocate<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
Ok(())
}

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

println!("test file_fallocate64");

let fd = tempfile::tempfile()?;
let fd = types::Fd(fd.as_raw_fd());

let falloc_e = opcode::Fallocate64::new(fd, 1024);

unsafe {
ring.submission()
.push(&falloc_e.build().user_data(0x20).into())
.expect("queue is full");
}

ring.submit_and_wait(1)?;

let cqes: Vec<cqueue::Entry> = ring.completion().map(Into::into).collect();

assert_eq!(cqes.len(), 1);
assert_eq!(cqes[0].user_data(), 0x20);
assert_eq!(cqes[0].result(), 0);

Ok(())
}

pub fn test_file_openat2<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
Expand Down Expand Up @@ -609,7 +575,6 @@ pub fn test_file_cur_pos<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
Ok(())
}

/// Skip ci, because statx does not exist in old release.
#[cfg(not(feature = "ci"))]
pub fn test_statx<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
Expand Down Expand Up @@ -698,8 +663,6 @@ pub fn test_statx<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
Ok(())
}

/// Skip ci, because direct IO does not work on qemu.
#[cfg(not(feature = "ci"))]
pub fn test_file_direct_write_read<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
Expand Down Expand Up @@ -764,7 +727,8 @@ pub fn test_file_direct_write_read<S: squeue::EntryMarker, C: cqueue::EntryMarke

// fail

let mut buf = vec![0; 4097];
let mut buf = Box::new(AlignedBuffer([0; 4096]));
let buf = &mut buf.0;

let read_e = opcode::Read::new(fd, buf[1..].as_mut_ptr(), buf[1..].len() as _);

Expand All @@ -780,7 +744,7 @@ pub fn test_file_direct_write_read<S: squeue::EntryMarker, C: cqueue::EntryMarke

assert_eq!(cqes.len(), 1);
assert_eq!(cqes[0].user_data(), 0x03);
assert_eq!(cqes[0].result(), -libc::EINVAL);
assert_eq_warn!(cqes[0].result(), -libc::EINVAL);

Ok(())
}
Expand Down
57 changes: 26 additions & 31 deletions io-uring-test/src/tests/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use io_uring::squeue::Flags;
use io_uring::types::Fd;
use io_uring::{cqueue, opcode, squeue, types, IoUring};
use once_cell::sync::OnceCell;
use std::convert::TryInto;
use std::net::{TcpListener, TcpStream};
use std::os::fd::FromRawFd;
use std::os::unix::io::AsRawFd;
Expand Down Expand Up @@ -549,15 +550,14 @@ pub fn test_tcp_accept_file_index<S: squeue::EntryMarker, C: cqueue::EntryMarker
Ok(())
}

/// Skip ci, because multi accept does not exist in old release.
#[cfg(not(feature = "ci"))]
pub fn test_tcp_accept_multi<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
) -> anyhow::Result<()> {
require!(
test;
test.probe.is_supported(opcode::Accept::CODE);
test.probe.is_supported(opcode::Socket::CODE); // check 5.19 kernel
);

println!("test tcp_accept_multi");
Expand All @@ -584,12 +584,12 @@ pub fn test_tcp_accept_multi<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
let cqes: Vec<cqueue::Entry> = ring.completion().map(Into::into).collect();

assert_eq!(cqes.len(), 2);
#[allow(clippy::needless_range_loop)]
for round in 0..=1 {
assert_eq!(cqes[round].user_data(), 2002);
assert!(cqes[round].result() >= 0);

let fd = cqes[round].result();
for cqe in cqes {
assert_eq!(cqe.user_data(), 2002);
assert!(cqe.result() >= 0);

let fd = cqe.result();

unsafe {
libc::close(fd);
Expand Down Expand Up @@ -627,15 +627,14 @@ pub fn test_tcp_accept_multi<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
Ok(())
}

/// Skip ci, because multi accept does not exist in old release.
#[cfg(not(feature = "ci"))]
pub fn test_tcp_accept_multi_file_index<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
) -> anyhow::Result<()> {
require!(
test;
test.probe.is_supported(opcode::Accept::CODE);
test.probe.is_supported(opcode::Socket::CODE); // check 5.19 kernel
);

println!("test tcp_accept_multi_file_index");
Expand Down Expand Up @@ -912,8 +911,6 @@ pub fn test_tcp_buffer_select<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
Ok(())
}

/// Skip ci, because buf group does not exist in old release.
#[cfg(not(feature = "ci"))]
pub fn test_tcp_buffer_select_recvmsg<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
Expand Down Expand Up @@ -1004,8 +1001,6 @@ pub fn test_tcp_buffer_select_recvmsg<S: squeue::EntryMarker, C: cqueue::EntryMa
Ok(())
}

/// Skip ci, because buf group does not exist in old release.
#[cfg(not(feature = "ci"))]
pub fn test_tcp_buffer_select_readv<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
Expand Down Expand Up @@ -1081,8 +1076,6 @@ pub fn test_tcp_buffer_select_readv<S: squeue::EntryMarker, C: cqueue::EntryMark
Ok(())
}

/// Skip ci, because recv multi feature does not exist in old release, requires 6.0.
#[cfg(not(feature = "ci"))]
pub fn test_tcp_recv_multi<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
Expand Down Expand Up @@ -1394,14 +1387,15 @@ pub fn test_udp_recvmsg_multishot<S: squeue::EntryMarker, C: cqueue::EntryMarker
assert!(!msg0.is_control_data_truncated());
assert_eq!(msg0.control_data(), &[]);
assert!(!msg0.is_name_data_truncated());
let (_, addr) = unsafe {
socket2::SockAddr::init(|storage, len| {
*len = msg0.name_data().len() as u32;
std::ptr::copy_nonoverlapping(msg0.name_data().as_ptr() as _, storage, 1);
Ok(())
})
}
.unwrap();
let addr = unsafe {
let storage = msg0
.name_data()
.as_ptr()
.cast::<libc::sockaddr_storage>()
.read_unaligned();
let len = msg0.name_data().len().try_into().unwrap();
socket2::SockAddr::new(storage, len)
};
let addr = addr.as_socket_ipv4().unwrap();
assert_eq!(addr.ip(), client_addr.ip());
assert_eq!(addr.port(), client_addr.port());
Expand All @@ -1412,14 +1406,15 @@ pub fn test_udp_recvmsg_multishot<S: squeue::EntryMarker, C: cqueue::EntryMarker
assert!(!msg1.is_control_data_truncated());
assert_eq!(msg1.control_data(), &[]);
assert!(!msg1.is_name_data_truncated());
let (_, addr) = unsafe {
socket2::SockAddr::init(|storage, len| {
*len = msg1.name_data().len() as u32;
std::ptr::copy_nonoverlapping(msg1.name_data().as_ptr() as _, storage, 1);
Ok(())
})
}
.unwrap();
let addr = unsafe {
let storage = msg1
.name_data()
.as_ptr()
.cast::<libc::sockaddr_storage>()
.read_unaligned();
let len = msg1.name_data().len().try_into().unwrap();
socket2::SockAddr::new(storage, len)
};
let addr = addr.as_socket_ipv4().unwrap();
assert_eq!(addr.ip(), client_addr.ip());
assert_eq!(addr.port(), client_addr.port());
Expand Down
2 changes: 0 additions & 2 deletions io-uring-test/src/tests/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ pub fn test_eventfd_poll_remove_failed<S: squeue::EntryMarker, C: cqueue::EntryM
Ok(())
}

// Multi-shot only available since 5.13.
#[cfg(not(feature = "ci"))]
pub fn test_eventfd_poll_multi<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
ring: &mut IoUring<S, C>,
test: &Test,
Expand Down
Loading

0 comments on commit e3fa23a

Please sign in to comment.