pub fn is_uring_available() -> bool {
#[cfg(target_os = "linux")]
{
use std::sync::OnceLock;
static AVAILABLE: OnceLock<bool> = OnceLock::new();
*AVAILABLE.get_or_init(probe_uring_create_openat)
}
#[cfg(not(target_os = "linux"))]
{
false
}
}
#[cfg(target_os = "linux")]
fn probe_uring_create_openat() -> bool {
use io_uring::{opcode, types, IoUring};
use std::ffi::CString;
use std::path::PathBuf;
let mut ring = match IoUring::new(8) {
Ok(r) => r,
Err(e) => {
tracing::warn!(
error = %e,
"io_uring not available; falling back to tokio::fs backend"
);
return false;
}
};
let probe_path: PathBuf = std::env::temp_dir().join(format!(
"gfs_uring_probe_{}_{}",
std::process::id(),
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
.unwrap_or(0)
));
let path_cstr = match CString::new(probe_path.to_string_lossy().as_bytes()) {
Ok(p) => p,
Err(_) => return false,
};
let open_e = opcode::OpenAt::new(types::Fd(libc::AT_FDCWD), path_cstr.as_ptr())
.flags(libc::O_WRONLY | libc::O_CREAT | libc::O_TRUNC | libc::O_CLOEXEC)
.mode(0o644)
.build()
.user_data(1);
unsafe {
if ring.submission().push(&open_e).is_err() {
tracing::warn!("io_uring OPENAT(create) probe: submission queue full");
return false;
}
}
if let Err(e) = ring.submit_and_wait(1) {
tracing::warn!(
error = %e,
"io_uring OPENAT(create) probe: submit_and_wait failed; falling back"
);
let _ = std::fs::remove_file(&probe_path);
return false;
}
let result = {
let mut cq = ring.completion();
match cq.next() {
Some(cqe) => cqe.result(),
None => {
tracing::warn!("io_uring OPENAT(create) probe: no CQE");
let _ = std::fs::remove_file(&probe_path);
return false;
}
}
};
if result < 0 {
let err = std::io::Error::from_raw_os_error(-result);
tracing::warn!(
error = %err,
"io_uring OPENAT(create) probe failed (EPERM is common on GHA); \
falling back to tokio::fs backend"
);
let _ = std::fs::remove_file(&probe_path);
return false;
}
unsafe {
libc::close(result);
}
let _ = std::fs::remove_file(&probe_path);
tracing::info!("io_uring is available on this platform (OPENAT create probe ok)");
true
}