Skip to content

Commit d2ddce1

Browse files
authored
async cancel flags and msgring types (#547)
Additionally: * updates other union flag fields names for consistency. Sticks to kernel header naming but may use additional unions for better type checking. * fixes open_flags to use `OFLAGS`async cancel flags and msgring types
1 parent 59f7b71 commit d2ddce1

File tree

1 file changed

+71
-10
lines changed

1 file changed

+71
-10
lines changed

src/io_uring.rs

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
//!
1515
//! # References
1616
//! - [Linux]
17+
//! - [io_uring header]
1718
//!
1819
//! [Linux]: https://man.archlinux.org/man/io_uring.7.en
1920
//! [io_uring]: https://en.wikipedia.org/wiki/Io_uring
21+
//! [io_uring header]: https://github.com/torvalds/linux/blob/master/include/uapi/linux/io_uring.h
2022
#![allow(unsafe_code)]
2123

2224
use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd};
@@ -383,6 +385,18 @@ impl Default for IoringRestrictionOp {
383385
}
384386
}
385387

388+
/// `IORING_MSG_*` constants which represent commands for use with [`IoringOp::Msgring`], (`seq.addr`)
389+
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
390+
#[repr(u64)]
391+
#[non_exhaustive]
392+
pub enum IoringMsgringCmds {
393+
/// `IORING_MSG_DATA`
394+
Data = sys::IORING_MSG_DATA as _,
395+
396+
/// `IORING_MSG_SEND_FD`
397+
SendFd = sys::IORING_MSG_SEND_FD as _,
398+
}
399+
386400
bitflags::bitflags! {
387401
/// `IORING_SETUP_*` flags for use with [`io_uring_params`].
388402
#[derive(Default)]
@@ -525,6 +539,33 @@ bitflags::bitflags! {
525539
}
526540
}
527541

542+
bitflags::bitflags! {
543+
/// `IORING_MSG_RING_*` flags for use with [`io_uring_sqe`].
544+
#[derive(Default)]
545+
pub struct IoringMsgringFlags: u32 {
546+
/// `IORING_MSG_RING_CQE_SKIP`
547+
const CQE_SKIP = sys::IORING_MSG_RING_CQE_SKIP;
548+
}
549+
}
550+
551+
bitflags::bitflags! {
552+
/// `IORING_ASYNC_CANCEL_*` flags for use with [`io_uring_sqe`].
553+
#[derive(Default)]
554+
pub struct IoringAsyncCancelFlags: u32 {
555+
/// `IORING_ASYNC_CANCEL_ALL`
556+
const ALL = sys::IORING_ASYNC_CANCEL_ALL;
557+
558+
/// `IORING_ASYNC_CANCEL_FD`
559+
const FD = sys::IORING_ASYNC_CANCEL_FD;
560+
561+
/// `IORING_ASYNC_CANCEL_FD`
562+
const ANY = sys::IORING_ASYNC_CANCEL_ANY;
563+
564+
/// `IORING_ASYNC_CANCEL_FD`
565+
const FD_FIXED = sys::IORING_ASYNC_CANCEL_FD_FIXED;
566+
}
567+
}
568+
528569
bitflags::bitflags! {
529570
/// `IORING_FEAT_*` flags for use with [`io_uring_params`].
530571
#[derive(Default)]
@@ -633,7 +674,7 @@ bitflags::bitflags! {
633674
bitflags::bitflags! {
634675
/// send/sendmsg & recv/recvmsg flags (`sqe.ioprio`)
635676
#[derive(Default)]
636-
pub struct IoringRecvSendFlags: u16 {
677+
pub struct IoringRecvsendFlags: u16 {
637678
/// `IORING_RECVSEND_POLL_FIRST`
638679
const POLL_FIRST = sys::IORING_RECVSEND_POLL_FIRST as _;
639680

@@ -819,11 +860,11 @@ impl core::fmt::Debug for io_uring_user_data {
819860
pub struct io_uring_sqe {
820861
pub opcode: IoringOp,
821862
pub flags: IoringSqeFlags,
822-
pub ioprio_or_flags: ioprio_or_flags_union,
863+
pub ioprio: ioprio_union,
823864
pub fd: RawFd,
824865
pub off_or_addr2: off_or_addr2_union,
825866
pub addr_or_splice_off_in: addr_or_splice_off_in_union,
826-
pub len: u32,
867+
pub len: len_union,
827868
pub op_flags: op_flags_union,
828869
pub user_data: io_uring_user_data,
829870
pub buf: buf_union,
@@ -835,12 +876,20 @@ pub struct io_uring_sqe {
835876
#[allow(missing_docs)]
836877
#[repr(C)]
837878
#[derive(Copy, Clone)]
838-
pub union ioprio_or_flags_union {
839-
pub recvsend: IoringRecvSendFlags,
840-
pub accept: IoringAcceptFlags,
879+
pub union ioprio_union {
880+
pub recvsend_flags: IoringRecvsendFlags,
881+
pub accept_flags: IoringAcceptFlags,
841882
pub ioprio: u16,
842883
}
843884

885+
#[allow(missing_docs)]
886+
#[repr(C)]
887+
#[derive(Copy, Clone)]
888+
pub union len_union {
889+
pub poll_flags: IoringPollFlags,
890+
pub len: u32,
891+
}
892+
844893
#[allow(missing_docs)]
845894
#[repr(C)]
846895
#[derive(Copy, Clone)]
@@ -864,6 +913,7 @@ pub union off_or_addr2_union {
864913
pub off: u64,
865914
pub addr2: io_uring_ptr,
866915
pub cmd_op: cmd_op_struct,
916+
pub user_data: io_uring_user_data,
867917
}
868918

869919
#[allow(missing_docs)]
@@ -880,6 +930,8 @@ pub struct cmd_op_struct {
880930
pub union addr_or_splice_off_in_union {
881931
pub addr: io_uring_ptr,
882932
pub splice_off_in: u64,
933+
pub msgring_cmd: IoringMsgringCmds,
934+
pub user_data: io_uring_user_data,
883935
}
884936

885937
#[allow(missing_docs)]
@@ -899,14 +951,15 @@ pub union op_flags_union {
899951
pub recv_flags: crate::net::RecvFlags,
900952
pub timeout_flags: IoringTimeoutFlags,
901953
pub accept_flags: crate::net::AcceptFlags,
902-
pub cancel_flags: u32,
903-
pub open_flags: crate::fs::AtFlags,
954+
pub cancel_flags: IoringAsyncCancelFlags,
955+
pub open_flags: crate::fs::OFlags,
904956
pub statx_flags: crate::fs::AtFlags,
905957
pub fadvise_advice: crate::fs::Advice,
906958
pub splice_flags: SpliceFlags,
907959
pub rename_flags: crate::fs::RenameFlags,
908960
pub unlink_flags: crate::fs::AtFlags,
909961
pub hardlink_flags: crate::fs::AtFlags,
962+
pub msg_ring_flags: IoringMsgringFlags,
910963
}
911964

912965
#[allow(missing_docs)]
@@ -1128,7 +1181,15 @@ pub struct io_uring_buf {
11281181
pub resv: u16,
11291182
}
11301183

1131-
impl Default for ioprio_or_flags_union {
1184+
impl Default for ioprio_union {
1185+
#[inline]
1186+
fn default() -> Self {
1187+
// Safety: All of Linux's io_uring structs may be zero-initialized.
1188+
unsafe { ::core::mem::zeroed::<Self>() }
1189+
}
1190+
}
1191+
1192+
impl Default for len_union {
11321193
#[inline]
11331194
fn default() -> Self {
11341195
// Safety: All of Linux's io_uring structs may be zero-initialized.
@@ -1275,7 +1336,7 @@ fn io_uring_layouts() {
12751336
check_type!(io_uring_sqe);
12761337
check_struct_field!(io_uring_sqe, opcode);
12771338
check_struct_field!(io_uring_sqe, flags);
1278-
check_struct_renamed_field!(io_uring_sqe, ioprio_or_flags, ioprio);
1339+
check_struct_field!(io_uring_sqe, ioprio);
12791340
check_struct_field!(io_uring_sqe, fd);
12801341
check_struct_renamed_field!(io_uring_sqe, off_or_addr2, __bindgen_anon_1);
12811342
check_struct_renamed_field!(io_uring_sqe, addr_or_splice_off_in, __bindgen_anon_2);

0 commit comments

Comments
 (0)