Expand description
Rust bindings for io_uring via a transliteration of Jens Axboe’s liburing.
Building this crate successfully may require the following in your .cargo/config.toml:
[env]
CLANG_PATH = "/usr/bin/clang-20"
LIBCLANG_PATH = "/usr/lib/llvm-20/lib"in order for bindgen to successfully generate the required struct definitions.
This crate implements an almost pure Rust version of Jens Axboe’s liburing.
All the good names were taken so the package’s name is axboe-liburing but the imported crate is liburing_rs.
liburing has tremendous value in that it’s a low-level unopinionated set of helpers that form a complete vocabulary for using io_uring. Originally designed as a set of test helpers, liburing is used to setup and teardown rings, register buffer groups, and create and manage SQEs and CQEs. liburing’s API offers users a comprehensive way of using io_uring in a simple manner.
axboe-liburing implements the entire header liburing.h in native Rust so that everything is as equally inlined as
if you were using the library from C or C++. This covers around 142 public functions.
Add the crate with:
cargo add axboe-liburingaxboe-liburing ships with the liburing source and builds liburing.a, statically linking it in via the build.rs. This means
that axboe-liburing requires a C toolchain be present on the system in order to build. Typical conventions are followed,
the environment variables CC, CXX are used to set the C and C++ compilers.
CC=clang-19 CXX=clang++-19 cargo build§Building Tests
axboe-liburing includes a few Rust-specific tests to verify the basic flow works but the lion’s share of the testing is
in recycling what already exists in liburing proper. To this end, we need objcopy in order to weaken the io_uring_get_sqe()
symbol present in liburing.a. When cross-compiling, it can be important to specify the objcopy being used. The objcopy
binary can be set via the OBJCOPY environment variable. objcopy ships with gcc toolchains.
Example building liburing tests with liburing-rs:
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
export OBJCOPY=aarch64-linux-gnu-objcopy
export CARGO_TOOLCHAIN=aarch64-unknown-linux-gnu
make -C test liburing_rs_tests -j$(nproc)axboe-liburing is also tested using sanitizers as well. To build the tests with sanitization enabled, one needs to enable
the sanitizers feature. This causes the crate to build liburing.a with sanitization enabled.
RUSTFLAGS='-Zsanitizer=address' cargo +nightly test --features sanitizers --target x86_64-unknown-linux-gnu -Zbuild-stdFor building the liburing_rs_tests target in test/Makefile, one needs to first configure the project to use sanitization.
# for liburing_rs_test.a, needed for the C test files to link against
./configure --enable-sanitizer
# builds everything, including C the default tests which are relied upon to exist by other tests
make all -j$(nproc)
# build a static library that exports everything from the Rust crate and use a shim header in the
# test files so that they link against the Rust-derived staticlib
make -C test liburing_rs_tests -j$(nproc)§Docs
For documentation, see the man pages for the liburing package itself. The Arch Linux pages have relatively up-to-date docs: https://man.archlinux.org/listing/extra/liburing/.
Examples can be found in the main repo: https://github.com/axboe/liburing/tree/master/examples
§Example
extern crate liburing_rs;
use std::{mem::zeroed, ptr, time::Duration};
use liburing_rs::*;
pub fn queue_init() {
// Setup the ring.
//
// We create a stack-local instance of `struct io_uring` and use
// the `io_uring_queue_init` function to initialize all of its
// fields, using a submission queue size of 64. liburing sets
// the size of the CQ to twice the SQ size by default.
//
let mut ring = unsafe { zeroed::<io_uring>() };
let ring = &raw mut ring;
let r = unsafe { io_uring_queue_init(64, ring, 0) };
assert_eq!(r, 0);
// Grab a pointer to an unused SQE from the SQ
let sqe = unsafe { io_uring_get_sqe(ring) };
assert!(!sqe.is_null());
// We're going to create an SQE that completes after a specified
// amount of time, in this case 250ms. We introduce a cast for `ts`
// because liburing expects a pointer to `__kernel_timespec` which
// is layout compatible.
//
let dur = Duration::from_millis(250);
let mut ts: timespec = dur.into();
let ts = (&raw mut ts).cast();
unsafe { io_uring_prep_timeout(sqe, ts, 0, 0) };
unsafe { io_uring_sqe_set_data64(sqe, 1234) };
// Submit the SQ to the kernel for processing. `io_uring_submit` returns
// the number of submitted entries that are going to be processed. In this case,
// we only have 1 work item.
//
let n = unsafe { io_uring_submit(ring) };
assert_eq!(n, 1);
// Grab the first CQE off the queue and make sure it has the same `user_data`
// field that we originally set.
//
let mut cqe = ptr::null_mut::<io_uring_cqe>();
unsafe { io_uring_wait_cqe(ring, &raw mut cqe) };
assert!(!cqe.is_null());
assert_eq!(unsafe { (*cqe).user_data }, 1234);
// Mark the CQE as seen so that its spot can be reused as more
// completions arrive.
//
unsafe { io_uring_cqe_seen(ring, cqe) };
// Teardown the ring.
//
unsafe { io_uring_queue_exit(ring) };
}Structs§
- io_
uring - Asynchronous I/O facility
- io_
uring_ clone_ buffers - Clones registered buffers between rings.
Constants§
- IOSQE_
ASYNC - IOSQE_
BUFFER_ SELECT - IOSQE_
CQE_ SKIP_ SUCCESS - IOSQE_
FIXED_ FILE - IOSQE_
IO_ DRAIN - IOSQE_
IO_ HARDLINK - IOSQE_
IO_ LINK
Functions§
- __
io_ ⚠uring_ buf_ ring_ cq_ advance - Advance index of provided buffer and CQ ring.
- __
io_ ⚠uring_ clone_ buffers - Clones registered buffers between rings.
- __
io_ ⚠uring_ clone_ buffers_ offset - Clones registered buffers between rings.
- io_
uring_ ⚠buf_ ring_ add - Add buffers to a shared buffer ring.
- io_
uring_ ⚠buf_ ring_ advance - Advance index of provided buffer in buffer ring.
- io_
uring_ ⚠buf_ ring_ available - Return number of unconsumed provided ring buffer entries.
- io_
uring_ ⚠buf_ ring_ cq_ advance - Advance index of provided buffer and CQ ring.
- io_
uring_ ⚠buf_ ring_ init - Initialise a buffer ring.
- io_
uring_ buf_ ring_ mask - Calculate buffer ring mask size.
- io_
uring_ ⚠check_ version - Functions and macros to check the liburing version.
- io_
uring_ ⚠clone_ buffers - Clones registered buffers between rings.
- io_
uring_ ⚠clone_ buffers_ offset - Clones registered buffers between rings.
- io_
uring_ ⚠close_ ring_ fd - Close a ring file descriptor and use it only via registered index.
- io_
uring_ ⚠cq_ advance - Mark one or more io_uring completion events as consumed.
- io_
uring_ ⚠cq_ eventfd_ enabled - Check if eventfd notifications are enabled.
- io_
uring_ ⚠cq_ eventfd_ toggle - Toggle eventfd notifications on or off.
- io_
uring_ ⚠cq_ has_ overflow - Returns if there are overflow entries waiting to move to the CQ ring.
- io_
uring_ ⚠cq_ ready - Returns number of unconsumed ready entries in the CQ ring.
- io_
uring_ ⚠cqe_ get_ data - Get user data for completion event.
- io_
uring_ ⚠cqe_ get_ data64 - Get user data for completion event.
- io_
uring_ ⚠cqe_ iter_ init - io_
uring_ ⚠cqe_ iter_ next - io_
uring_ ⚠cqe_ nr - Return the number of CQ ring slots consumed by a CQE.
- io_
uring_ ⚠cqe_ seen - Mark io_uring completion event as consumed.
- io_
uring_ ⚠cqe_ shift - io_
uring_ cqe_ shift_ from_ flags - io_
uring_ ⚠enable_ rings - Enable a disabled ring.
- io_
uring_ ⚠enter - Initiate and/or complete asynchronous I/O.
- io_
uring_ ⚠enter2 - Initiate and/or complete asynchronous I/O.
- io_
uring_ ⚠for_ each_ cqe - Iterate pending completion events.
- io_
uring_ ⚠free_ buf_ ring - Register and free a buffer ring for provided buffers.
- io_
uring_ ⚠free_ probe - Free probe instance.
- io_
uring_ ⚠get_ events - Flush outstanding requests to CQE ring.
- io_
uring_ ⚠get_ probe - Get probe instance.
- io_
uring_ ⚠get_ probe_ ring - Get probe information from an existing ring.
- io_
uring_ ⚠get_ sqe - Get the next available submission queue entry from the submission queue.
- io_
uring_ ⚠get_ sqe128 - Get the next available 128-byte submission queue entry from the submission queue.
- io_
uring_ ⚠initialize_ sqe - io_
uring_ ⚠load_ sq_ head - io_
uring_ ⚠major_ version - Functions and macros to check the liburing version.
- io_
uring_ ⚠minor_ version - Functions and macros to check the liburing version.
- io_
uring_ ⚠opcode_ supported - Is op code supported?.
- io_
uring_ ⚠peek_ batch_ cqe - Check if an io_uring completion event is available.
- io_
uring_ ⚠peek_ cqe - Check if an io_uring completion event is available.
- io_
uring_ ⚠prep_ accept - Prepare an accept request.
- io_
uring_ ⚠prep_ accept_ direct - Prepare an accept request.
- io_
uring_ ⚠prep_ bind - Prepare a bind request.
- io_
uring_ ⚠prep_ cancel - Prepare a cancelation request.
- io_
uring_ ⚠prep_ cancel64 - Prepare a cancelation request.
- io_
uring_ ⚠prep_ cancel_ fd - Prepare a cancelation request.
- io_
uring_ ⚠prep_ close - Prepare a file descriptor close request.
- io_
uring_ ⚠prep_ close_ direct - Prepare a file descriptor close request.
- io_
uring_ ⚠prep_ cmd_ discard - Prepare a discard command.
- io_
uring_ ⚠prep_ cmd_ getsockname - Prepare a getsockname or getpeername. request
- io_
uring_ ⚠prep_ cmd_ sock - Prepare a command request for a socket.
- io_
uring_ ⚠prep_ connect - Prepare a connect request.
- io_
uring_ ⚠prep_ epoll_ ctl - Prepare an epoll_ctl request.
- io_
uring_ ⚠prep_ epoll_ wait - Prepare an epoll wait request.
- io_
uring_ ⚠prep_ fadvise - Prepare a fadvise request.
- io_
uring_ ⚠prep_ fadvise64 - Prepare a fadvise request.
- io_
uring_ ⚠prep_ fallocate - Prepare a fallocate request.
- io_
uring_ ⚠prep_ fgetxattr - Prepare a request to. get an extended attribute value
- io_
uring_ ⚠prep_ files_ update - Prepare a registered file update request.
- io_
uring_ ⚠prep_ fixed_ fd_ install - Prepare fixed file fd installation. request
- io_
uring_ ⚠prep_ fsetxattr - Prepare a request to. set an extended attribute value
- io_
uring_ ⚠prep_ fsync - Prepare an fsync request.
- io_
uring_ ⚠prep_ ftruncate - Prepare an ftruncate request.
- io_
uring_ ⚠prep_ futex_ wait - Prepare a futex wait request.
- io_
uring_ ⚠prep_ futex_ waitv - Prepare a futex waitv request.
- io_
uring_ ⚠prep_ futex_ wake - Prepare a futex wake request.
- io_
uring_ ⚠prep_ getxattr - Prepare a request to. get an extended attribute value
- io_
uring_ ⚠prep_ link - Prepare a linkat request.
- io_
uring_ ⚠prep_ link_ timeout - A timeout request for linked sqes.
- io_
uring_ ⚠prep_ linkat - Prepare a linkat request.
- io_
uring_ ⚠prep_ listen - Prepare a listen request.
- io_
uring_ ⚠prep_ madvise - Prepare a madvise request.
- io_
uring_ ⚠prep_ madvise64 - Prepare a madvise request.
- io_
uring_ ⚠prep_ mkdir - Prepare an mkdirat request.
- io_
uring_ ⚠prep_ mkdirat - Prepare an mkdirat request.
- io_
uring_ ⚠prep_ msg_ ring - Send a message to another ring.
- io_
uring_ ⚠prep_ msg_ ring_ cqe_ flags - Send a message to another ring.
- io_
uring_ ⚠prep_ msg_ ring_ fd - Send a direct descriptor to another ring.
- io_
uring_ ⚠prep_ msg_ ring_ fd_ alloc - Send a direct descriptor to another ring.
- io_
uring_ ⚠prep_ multishot_ accept - Prepare an accept request.
- io_
uring_ ⚠prep_ multishot_ accept_ direct - Prepare an accept request.
- io_
uring_ ⚠prep_ nop - Prepare a nop request.
- io_
uring_ ⚠prep_ nop128 - Prepare a nop request.
- io_
uring_ ⚠prep_ open - Prepare an openat request.
- io_
uring_ ⚠prep_ open_ direct - Prepare an openat request.
- io_
uring_ ⚠prep_ openat - Prepare an openat request.
- io_
uring_ ⚠prep_ openat2 - Prepare an openat2 request.
- io_
uring_ ⚠prep_ openat2_ direct - Prepare an openat2 request.
- io_
uring_ ⚠prep_ openat_ direct - Prepare an openat request.
- io_
uring_ ⚠prep_ pipe - Prepare a pipe creation request.
- io_
uring_ ⚠prep_ pipe_ direct - Prepare a pipe creation request.
- io_
uring_ ⚠prep_ poll_ add - Prepare a poll request.
- io_
uring_ ⚠prep_ poll_ multishot - Prepare a poll request.
- io_
uring_ ⚠prep_ poll_ remove - Prepare a poll deletion request.
- io_
uring_ ⚠prep_ poll_ update - Update an existing poll request.
- io_
uring_ ⚠prep_ provide_ buffers - Prepare a provide buffers request.
- io_
uring_ ⚠prep_ read - Prepare I/O read request.
- io_
uring_ ⚠prep_ read_ fixed - Prepare I/O read request with registered. buffer
- io_
uring_ ⚠prep_ read_ multishot - Prepare I/O read multishot request.
- io_
uring_ ⚠prep_ readv - Prepare vector I/O read request.
- io_
uring_ ⚠prep_ readv2 - Prepare vector I/O read request with flags.
- io_
uring_ ⚠prep_ readv_ fixed - Prepare a vectored read using fixed buffers.
- io_
uring_ ⚠prep_ recv - Prepare a recv request.
- io_
uring_ ⚠prep_ recv_ multishot - Prepare a recv request.
- io_
uring_ ⚠prep_ recvmsg - Prepare a recvmsg request.
- io_
uring_ ⚠prep_ recvmsg_ multishot - Prepare a recvmsg request.
- io_
uring_ ⚠prep_ remove_ buffers - Prepare a remove buffers request.
- io_
uring_ ⚠prep_ rename - Prepare a renameat request.
- io_
uring_ ⚠prep_ renameat - Prepare a renameat request.
- io_
uring_ ⚠prep_ rw - io_
uring_ ⚠prep_ send - Prepare a send request.
- io_
uring_ ⚠prep_ send_ bundle - Prepare a send request.
- io_
uring_ ⚠prep_ send_ set_ addr - Set address details for send requests.
- io_
uring_ ⚠prep_ send_ zc - Prepare a zerocopy send request.
- io_
uring_ ⚠prep_ send_ zc_ fixed - Prepare a zerocopy send request.
- io_
uring_ ⚠prep_ sendmsg - Prepare a sendmsg request.
- io_
uring_ ⚠prep_ sendmsg_ zc - Prepare a sendmsg request.
- io_
uring_ ⚠prep_ sendmsg_ zc_ fixed - Prepare a zero-copy sendmsg using fixed. buffers
- io_
uring_ ⚠prep_ sendto - Prepare a send request.
- io_
uring_ ⚠prep_ setxattr - Prepare a request to. set an extended attribute value
- io_
uring_ ⚠prep_ shutdown - Prepare a shutdown request.
- io_
uring_ ⚠prep_ socket - Prepare a socket creation request.
- io_
uring_ ⚠prep_ socket_ direct - Prepare a socket creation request.
- io_
uring_ ⚠prep_ socket_ direct_ alloc - Prepare a socket creation request.
- io_
uring_ ⚠prep_ splice - Prepare an splice request.
- io_
uring_ ⚠prep_ statx - Prepare a statx request.
- io_
uring_ ⚠prep_ symlink - Prepare a symlinkat request.
- io_
uring_ ⚠prep_ symlinkat - Prepare a symlinkat request.
- io_
uring_ ⚠prep_ sync_ file_ range - Prepare a sync_file_range request.
- io_
uring_ ⚠prep_ tee - Prepare a tee request.
- io_
uring_ ⚠prep_ timeout - Prepare a timeout request.
- io_
uring_ ⚠prep_ timeout_ remove - Prepare a request to update an existing. timeout
- io_
uring_ ⚠prep_ timeout_ update - Prepare a request to update an existing. timeout
- io_
uring_ ⚠prep_ unlink - Prepare an unlinkat request.
- io_
uring_ ⚠prep_ unlinkat - Prepare an unlinkat request.
- io_
uring_ ⚠prep_ uring_ cmd - Prepare a uring_cmd request.
- io_
uring_ ⚠prep_ uring_ cmd128 - Prepare a uring_cmd request.
- io_
uring_ ⚠prep_ waitid - Prepare a waitid request.
- io_
uring_ ⚠prep_ write - Prepare I/O write request.
- io_
uring_ ⚠prep_ write_ fixed - Prepare I/O write request with registered. buffer
- io_
uring_ ⚠prep_ writev - Prepare vector I/O write request.
- io_
uring_ ⚠prep_ writev2 - Prepare vector I/O write request with flags.
- io_
uring_ ⚠prep_ writev_ fixed - Prepare a vectored write using fixed. buffers
- io_
uring_ ⚠queue_ exit - Tear down io_uring submission and completion. queues
- io_
uring_ ⚠queue_ init - Setup io_uring submission and completion queues.
- io_
uring_ ⚠queue_ init_ mem - Setup io_uring submission and completion queues.
- io_
uring_ ⚠queue_ init_ params - Setup io_uring submission and completion queues.
- io_
uring_ ⚠queue_ mmap - Mmap io_uring ring after setup.
- io_
uring_ ⚠recvmsg_ cmsg_ firsthdr - Access data from multishot recvmsg.
- io_
uring_ ⚠recvmsg_ cmsg_ nexthdr - Access data from multishot recvmsg.
- io_
uring_ ⚠recvmsg_ name - Access data from multishot recvmsg.
- io_
uring_ ⚠recvmsg_ payload - Access data from multishot recvmsg.
- io_
uring_ ⚠recvmsg_ payload_ length - Access data from multishot recvmsg.
- io_
uring_ ⚠recvmsg_ validate - Access data from multishot recvmsg.
- io_
uring_ ⚠register - Register files or user buffers for asynchronous I/O.
- io_
uring_ ⚠register_ bpf_ filter - Register classic BPF filters for io_uring operations.
- io_
uring_ ⚠register_ bpf_ filter_ task - io_uring_register_bpf_filter, io_uring_register_bpf_filter_task - register classic BPF filters for io_uring operations
- io_
uring_ ⚠register_ buf_ ring - Register buffer ring for provided buffers.
- io_
uring_ ⚠register_ buffers - Register buffers for fixed buffer operations.
- io_
uring_ ⚠register_ buffers_ sparse - Register buffers for fixed buffer operations.
- io_
uring_ ⚠register_ buffers_ tags - Register buffers for fixed buffer operations.
- io_
uring_ ⚠register_ buffers_ update_ tag - Register buffers for fixed buffer operations.
- io_
uring_ ⚠register_ clock - Set clock source for event waiting.
- io_
uring_ ⚠register_ eventfd - Register an eventfd with a ring.
- io_
uring_ ⚠register_ eventfd_ async - Register an eventfd with a ring.
- io_
uring_ ⚠register_ file_ alloc_ range - Set range for fixed file. allocations
- io_
uring_ ⚠register_ files - Register file descriptors.
- io_
uring_ ⚠register_ files_ sparse - Register file descriptors.
- io_
uring_ ⚠register_ files_ tags - Register file descriptors.
- io_
uring_ ⚠register_ files_ update - Register file descriptors.
- io_
uring_ ⚠register_ files_ update_ tag - Register file descriptors.
- io_
uring_ ⚠register_ ifq - Register a zero-copy receive interface queue.
- io_
uring_ ⚠register_ iowq_ max_ workers - Modify the maximum allowed async. workers
- io_
uring_ ⚠register_ napi - Register NAPI busy poll settings.
- io_
uring_ ⚠register_ personality - Register credentials with io_uring.
- io_
uring_ ⚠register_ probe - Register probe with io_uring.
- io_
uring_ ⚠register_ query - Query io_uring capabilities and feature. support
- io_
uring_ ⚠register_ region - Register a memory region.
- io_
uring_ ⚠register_ restrictions - Register restrictions with io_uring.
- io_
uring_ ⚠register_ ring_ fd - Register a ring file descriptor.
- io_
uring_ ⚠register_ sync_ cancel - Issue a synchronous cancelation request.
- io_
uring_ ⚠register_ sync_ msg - Send a synchronous message to another ring.
- io_
uring_ ⚠register_ wait_ reg - Register wait regions with io_uring.
- io_
uring_ ⚠register_ zcrx_ ctrl - Perform control operations on a zero-copy. receive context
- io_
uring_ ⚠resize_ rings - Resize the SQ and CQ rings.
- io_
uring_ ⚠ring_ dontfork - Prevent ring memory from being shared after fork.
- io_
uring_ ⚠setup - Setup a context for performing asynchronous I/O.
- io_
uring_ ⚠setup_ buf_ ring - Setup and register buffer ring for provided. buffers
- io_
uring_ ⚠sq_ ready - Number of unconsumed or unsubmitted entries in the. SQ ring
- io_
uring_ ⚠sq_ space_ left - Free space in the SQ ring.
- io_
uring_ ⚠sqe_ set_ buf_ group - Set buf group for submission queue event.
- io_
uring_ ⚠sqe_ set_ data - Set user data for submission queue event.
- io_
uring_ ⚠sqe_ set_ data64 - Set user data for submission queue event.
- io_
uring_ ⚠sqe_ set_ flags - Set flags for submission queue entry.
- io_
uring_ ⚠sqe_ shift - io_
uring_ sqe_ shift_ from_ flags - io_
uring_ ⚠sqring_ wait - Wait for free space in the SQ ring.
- io_
uring_ ⚠submit - Submit requests to the submission queue.
- io_
uring_ ⚠submit_ and_ get_ events - Submit requests to the submission queue. and flush completions
- io_
uring_ ⚠submit_ and_ wait - Submit requests to the submission queue and wait for completion.
- io_
uring_ ⚠submit_ and_ wait_ min_ timeout - Submit requests to the submission. queue and wait for the completion with both batch and normal timeout
- io_
uring_ ⚠submit_ and_ wait_ reg - Sets up and registers fixed wait regions.
- io_
uring_ ⚠submit_ and_ wait_ timeout - Submit requests to the submission. queue and wait for the completion with timeout
- io_
uring_ ⚠unregister_ buf_ ring - Unregister a previously registered buffer. ring
- io_
uring_ ⚠unregister_ buffers - Unregister buffers for fixed buffer. operations
- io_
uring_ ⚠unregister_ eventfd - Register an eventfd with a ring.
- io_
uring_ ⚠unregister_ files - Unregister file descriptors.
- io_
uring_ ⚠unregister_ iowq_ aff - Register async worker CPU affinities.
- io_
uring_ ⚠unregister_ napi - Unregister NAPI busy poll settings.
- io_
uring_ ⚠unregister_ personality - Unregister a personality from io_uring.
- io_
uring_ ⚠unregister_ ring_ fd - Unregister a ring file descriptor.
- io_
uring_ ⚠wait_ cqe - Wait for one io_uring completion event.
- io_
uring_ ⚠wait_ cqe_ nr - Wait for one or more io_uring completion events.
- io_
uring_ ⚠wait_ cqe_ timeout - Wait for one io_uring completion event with. timeout
- io_
uring_ ⚠wait_ cqes - Wait for one or more io_uring completion events.
- io_
uring_ ⚠wait_ cqes_ min_ timeout - Wait for completions with both batch. and normal timeout