Skip to content

Commit

Permalink
Add register_buffers_* family of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fathyb committed Mar 14, 2023
1 parent 38d5905 commit b3b6f78
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,65 @@ impl<'a> Submitter<'a> {
.map(drop)
}

pub fn register_buffers_update_tag(
&self,
off: u32,
bufs: &[libc::iovec],
tags: &[u64],
) -> io::Result<()> {
use std::mem;
let rr = sys::io_uring_rsrc_update2 {
nr: bufs.len().min(tags.len()) as _,
data: bufs.as_ptr() as _,
tags: tags.as_ptr() as _,
offset: off,
..Default::default()
};
let rr = cast_ptr::<sys::io_uring_rsrc_update2>(&rr);
execute(
self.fd.as_raw_fd(),
sys::IORING_REGISTER_BUFFERS_UPDATE,
rr as *const _,
mem::size_of::<sys::io_uring_rsrc_update2>() as _,
)
.map(drop)
}

pub fn register_buffers_tags(&self, bufs: &[libc::iovec], tags: &[u64]) -> io::Result<()> {
use std::mem;
let rr = sys::io_uring_rsrc_register {
nr: bufs.len().min(tags.len()) as _,
data: bufs.as_ptr() as _,
tags: tags.as_ptr() as _,
..Default::default()
};
let rr = cast_ptr::<sys::io_uring_rsrc_register>(&rr);
execute(
self.fd.as_raw_fd(),
sys::IORING_REGISTER_BUFFERS2,
rr as *const _,
mem::size_of::<sys::io_uring_rsrc_register>() as _,
)
.map(drop)
}

pub fn register_buffers_sparse(&self, nr: u32) -> io::Result<()> {
use std::mem;
let rr = sys::io_uring_rsrc_register {
nr,
flags: sys::IORING_RSRC_REGISTER_SPARSE,
..Default::default()
};
let rr = cast_ptr::<sys::io_uring_rsrc_register>(&rr);
execute(
self.fd.as_raw_fd(),
sys::IORING_REGISTER_BUFFERS2,
rr as *const _,
mem::size_of::<sys::io_uring_rsrc_register>() as _,
)
.map(drop)
}

/// Registers an empty file table of nr_files number of file descriptors. The sparse variant is
/// available in kernels 5.19 and later.
///
Expand Down

0 comments on commit b3b6f78

Please sign in to comment.