feat(fast_io): add io_uring LINKAT wrapper and kernel probe#3738
Merged
Conversation
Closes #1921, #1923. Adds a typed wrapper around `IORING_OP_LINKAT` (Linux 5.15+) so the receiver can submit hardlink creation alongside disk writes on the same ring instead of issuing a synchronous `linkat(2)` syscall per hardlinked file. The new `linkat` submodule mirrors the conventions used by `shared_ring::probe_poll_add` and `splice::is_splice_available`: - `LINKAT_MIN_KERNEL = (5, 15)` and `IORING_OP_LINKAT = 39` constants. - `linkat_supported()` short-circuits on `is_io_uring_available()`, builds a throwaway ring, and asks the kernel via `IORING_REGISTER_PROBE` whether opcode 39 is supported. The result is cached in a process-wide `OnceLock`. - `LinkAtArgs<'a>` borrows source/destination `&CStr` paths plus dirfds and `flags` so the compiler enforces the kernel's path lifetime contract. - `build_linkat_sqe` returns `io::ErrorKind::Unsupported` when the probe is `false`; `build_linkat_sqe_unchecked` exposes the encoder for unit tests. - `submit_linkat_blocking` builds a private 2-entry ring, submits the SQE, and returns the kernel's CQE result. The non-Linux stub in `io_uring_stub.rs` provides the same names with `linkat_supported() -> false` and `Unsupported` round-trips. Public re-exports in `crates/fast_io/src/lib.rs` and the Linux `io_uring` module make the API available to consumer crates. Tests: - Unit tests verify `opcode::LinkAt::CODE == 39`, the cached probe is idempotent, the unchecked SQE encoder accepts user_data, and the stub consistently returns `Unsupported`. - `tests/io_uring_linkat.rs` (Linux+`io_uring` feature) submits a real LINKAT, verifies the destination hardlink, and unlinks it; skips when the kernel does not advertise the opcode.
38b037e to
cb8e533
Compare
oferchen
added a commit
that referenced
this pull request
May 18, 2026
* feat(fast_io): add io_uring LINKAT wrapper and kernel probe Closes #1921, #1923. Adds a typed wrapper around `IORING_OP_LINKAT` (Linux 5.15+) so the receiver can submit hardlink creation alongside disk writes on the same ring instead of issuing a synchronous `linkat(2)` syscall per hardlinked file. The new `linkat` submodule mirrors the conventions used by `shared_ring::probe_poll_add` and `splice::is_splice_available`: - `LINKAT_MIN_KERNEL = (5, 15)` and `IORING_OP_LINKAT = 39` constants. - `linkat_supported()` short-circuits on `is_io_uring_available()`, builds a throwaway ring, and asks the kernel via `IORING_REGISTER_PROBE` whether opcode 39 is supported. The result is cached in a process-wide `OnceLock`. - `LinkAtArgs<'a>` borrows source/destination `&CStr` paths plus dirfds and `flags` so the compiler enforces the kernel's path lifetime contract. - `build_linkat_sqe` returns `io::ErrorKind::Unsupported` when the probe is `false`; `build_linkat_sqe_unchecked` exposes the encoder for unit tests. - `submit_linkat_blocking` builds a private 2-entry ring, submits the SQE, and returns the kernel's CQE result. The non-Linux stub in `io_uring_stub.rs` provides the same names with `linkat_supported() -> false` and `Unsupported` round-trips. Public re-exports in `crates/fast_io/src/lib.rs` and the Linux `io_uring` module make the API available to consumer crates. Tests: - Unit tests verify `opcode::LinkAt::CODE == 39`, the cached probe is idempotent, the unchecked SQE encoder accepts user_data, and the stub consistently returns `Unsupported`. - `tests/io_uring_linkat.rs` (Linux+`io_uring` feature) submits a real LINKAT, verifies the destination hardlink, and unlinks it; skips when the kernel does not advertise the opcode. * fix(fast_io): use io::Error::other for clippy::io_other_error * fix(fast_io): use c"..." CStr literals to satisfy clippy manual_c_str_literals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IORING_OP_LINKAT(Linux 5.15+) wrapper in a newcrates/fast_io/src/io_uring/linkat.rssubmodule with anOnceLock-cached kernel probe (linkat_supported), a borrowed-arg struct (LinkAtArgs<'a>over&CStrpaths), the gated builder (build_linkat_sqe), an unchecked encoder for tests, and a blocking submitter (submit_linkat_blocking).io_uring_stub.rs) withlinkat_supported() -> falseandUnsupportedround-trips so cross-platform call sites compile unchanged.crates/fast_io/src/io_uring/mod.rsandcrates/fast_io/src/lib.rs.Implementation notes
LINKAT_MIN_KERNEL = (5, 15)andIORING_OP_LINKAT = 39follow the kernel UAPI ininclude/uapi/linux/io_uring.h.linkat_supportedshort-circuits onis_io_uring_available()before building a throwaway ring +Probe, matching the convention inshared_ring::probe_poll_addandsplice::is_splice_available.LinkAtArgs<'a>ties source/destinationCStrlifetimes to the SQE so the compiler enforces the kernel's path-lifetime contract.Test plan
fmt+clippy, nextest stable, Windows, macOS, Linux muslUnsupportedround-triptests/io_uring_linkat.rssubmits a real LINKAT, verifies the hardlink, then removes the destination and confirms the source survives; skips when the kernel does not advertise the opcodeCompatibility
crates/fast_io/src/io_uring/mod.rsandcrates/fast_io/src/lib.rswith the parallel RENAMEAT2 PR; the module list and re-exports rebase cleanly.