Skip to content

Commit

Permalink
https://github.com/spacejam/rio/pull/46
Browse files Browse the repository at this point in the history
  • Loading branch information
CramBL committed Jul 19, 2024
1 parent b232303 commit 6c36e40
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/io_uring/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ pub const IORING_REGISTER_EVENTFD: u32 = 4;
pub const IORING_UNREGISTER_EVENTFD: u32 = 5;
pub const IORING_REGISTER_FILES_UPDATE: u32 = 6;
pub const IORING_REGISTER_EVENTFD_ASYNC: u32 = 7;
pub const IORING_REGISTER_PROBE: u32 = 8;
pub const IORING_REGISTER_PERSONALITY: u32 = 9;
pub const IORING_UNREGISTER_PERSONALITY: u32 = 10;
pub const IORING_REGISTER_RESTRICTIONS: u32 = 11;
pub const IORING_REGISTER_ENABLE_RINGS: u32 = 12;
42 changes: 36 additions & 6 deletions src/io_uring/kernel_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ impl io_uring_sqe {
fn apply_order(&mut self, ordering: Ordering) {
match ordering {
Ordering::None => {}
Ordering::Link => {
self.flags |= IOSQE_IO_LINK
}
Ordering::Drain => {
self.flags |= IOSQE_IO_DRAIN
}
Ordering::Link => self.flags |= IOSQE_IO_LINK,
Ordering::Drain => self.flags |= IOSQE_IO_DRAIN,
}
}
}
Expand Down Expand Up @@ -163,3 +159,37 @@ pub struct io_cqring_offsets {
pub cqes: u32,
pub resv: [u64; 2_usize],
}

#[repr(C)]
#[derive(Default, Debug, Copy, Clone)]
pub struct io_uring_probe_op {
pub op: u8,
pub resv: u8,
pub flags: u16, /* IO_URING_OP_* flags */
pub resv2: u32,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct io_uring_probe {
pub last_op: u8, /* last opcode supported */
pub ops_len: u8, /* length of ops[] array below */
pub resv: u16,
pub resv2: [u32; 3_usize],

// This is a variable length field in C, but the usual call
// to get all available ops would always use 256
pub ops: [io_uring_probe_op; 256],
}

impl Default for io_uring_probe {
fn default() -> Self {
Self {
last_op: 0,
ops_len: 0,
resv: 0,
resv2: [0; 3],
ops: [io_uring_probe_op::default(); 256],
}
}
}
27 changes: 27 additions & 0 deletions src/io_uring/uring.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::*;
use crate::io_uring::kernel_types::{
io_uring_probe, io_uring_probe_op,
};
use crate::io_uring::syscall::register;

/// Nice bindings for the shiny new linux IO system
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -77,6 +81,29 @@ impl Uring {
}
}

/// Gets a list of io_uring opcodes supported by the
/// running kernel.
///
/// # Warning
///
/// This only becomes usable on linux kernels
/// 5.6 and up.
pub fn probe_ops(
&self,
) -> io::Result<Vec<io_uring_probe_op>> {
let probe = io_uring_probe::default();
let probe_ptr: *const io_uring_probe = &probe;

register(
self.ring_fd.as_raw_fd(),
IORING_REGISTER_PROBE,
probe_ptr as *const libc::c_void,
256,
)?;

Ok(probe.ops[0..probe.last_op as usize + 1].into())
}

pub(crate) fn ensure_submitted(
&self,
sqe_id: u64,
Expand Down

0 comments on commit 6c36e40

Please sign in to comment.