Skip to content

Commit

Permalink
Add fixed buffer support to uring_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ollie-etl committed Feb 8, 2024
1 parent 4a11db4 commit b0b7ce2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,20 +1482,29 @@ opcode! {
fd: { impl sealed::UseFixed },
cmd_op: { u32 },
;;
/// The `buf_index` is an index into an array of fixed buffers,
/// and is only valid if fixed buffers were registered.
buf_index: Option<u16> = None,
/// Arbitrary command data.
cmd: [u8; 16] = [0u8; 16]
}

pub const CODE = sys::IORING_OP_URING_CMD;

pub fn build(self) -> Entry {
let UringCmd16 { fd, cmd_op, cmd } = self;
let UringCmd16 { fd, cmd_op, cmd, buf_index } = self;

let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd };
if let Some(buf_index) = buf_index {
sqe.__bindgen_anon_4.buf_index = buf_index;
unsafe {
sqe.__bindgen_anon_3.uring_cmd_flags |= sys::IORING_URING_CMD_FIXED;
}
}
Entry(sqe)
}
}
Expand All @@ -1506,14 +1515,17 @@ opcode! {
fd: { impl sealed::UseFixed },
cmd_op: { u32 },
;;
/// The `buf_index` is an index into an array of fixed buffers,
/// and is only valid if fixed buffers were registered.
buf_index: Option<u16> = None,
/// Arbitrary command data.
cmd: [u8; 80] = [0u8; 80]
}

pub const CODE = sys::IORING_OP_URING_CMD;

pub fn build(self) -> Entry128 {
let UringCmd80 { fd, cmd_op, cmd } = self;
let UringCmd80 { fd, cmd_op, cmd, buf_index } = self;

let cmd1 = cmd[..16].try_into().unwrap();
let cmd2 = cmd[16..].try_into().unwrap();
Expand All @@ -1523,6 +1535,12 @@ opcode! {
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd1 };
if let Some(buf_index) = buf_index {
sqe.__bindgen_anon_4.buf_index = buf_index;
unsafe {
sqe.__bindgen_anon_3.uring_cmd_flags |= sys::IORING_URING_CMD_FIXED;
}
}
Entry128(Entry(sqe), cmd2)
}
}
Expand Down

0 comments on commit b0b7ce2

Please sign in to comment.