tokio-uring icon indicating copy to clipboard operation
tokio-uring copied to clipboard

Switch from io_uring to rustix_uring for broad compatibility

Open Gelbpunkt opened this issue 11 months ago • 4 comments

rustix wraps syscalls without the libc crate, which does not expose a bunch of io-uring related APIs such as statx on musl targets.

With these changes, tokio-uring compiles fine when built for musl targets.

TODO: test and split the minvers fixes + maybe split the change for the listen syscall into their own commits, update docs, update tests

Gelbpunkt avatar Dec 14 '24 19:12 Gelbpunkt

Just out of curiosity, do you know what's the plan for io-uring crate (Do rustix replace it)? Looks like maintainer is same.

ileixe avatar Dec 16 '24 05:12 ileixe

Just out of curiosity, do you know what's the plan for io-uring crate (Do rustix replace it)? Looks like maintainer is same.

The maintainers aren't the same from what I can see, rustix-uring is a fork of the io-uring crate. I'm not involved with the project so I don't know more than that.

Gelbpunkt avatar Dec 16 '24 15:12 Gelbpunkt

Oh I did not aware it's fork of io-uring (so I saw same maintainer in github contributor view)

Anyway, here's the reason from io-uring side: https://github.com/tokio-rs/io-uring/pull/207

I think it makes sense.

ileixe avatar Dec 16 '24 23:12 ileixe

If you want musl compatibility, there is no need to switch to rustix_uring, just use linux-raw-sys (or any other linux headers library) with io_uring.

like

use io_uring::opcode;
use linux_raw_sys::general::statx;

let statx = Box::new(statx {
    // ...
});
let op = opcode::Statx::new(fd, path, Box::into_raw(statx).cast());

quininer avatar Dec 17 '24 02:12 quininer

Much thanks for this... I was trying to compile on riscv64 with musl and encountered statx missing in libc as well. First I was doing this kind of workarounds:

diff --git a/src/fs/statx.rs b/src/fs/statx.rs
index 5a3ccb1..7cbb13e 100644
--- a/src/fs/statx.rs
+++ b/src/fs/statx.rs
@@ -2,6 +2,9 @@ use super::File;
 use crate::io::{cstr, SharedFd};
 use crate::runtime::driver::op::Op;
 use std::{ffi::CString, io, path::Path};
+use io_uring::types::statx;
+use crate::fs::STATX_ALL;
+use crate::fs::STATX_TYPE;
 
 impl File {
     /// Returns statx(2) metadata for an open file via a uring call.
@@ -28,9 +31,9 @@ impl File {
     ///     f.close().await.unwrap();
     /// })
     /// ```
-    pub async fn statx(&self) -> io::Result<libc::statx> {
+    pub async fn statx(&self) -> io::Result<statx> {
         let flags = libc::AT_EMPTY_PATH;
-        let mask = libc::STATX_ALL;
+        let mask = STATX_ALL;
         Op::statx(Some(self.fd.clone()), None, flags, mask)?.await
     }
 
@@ -73,7 +76,7 @@ impl File {
             file: Some(self.fd.clone()),
             path: None,
             flags: libc::AT_EMPTY_PATH,
-            mask: libc::STATX_ALL,
+            mask: STATX_ALL,
         }
     }
 }

and then I encounter this PR so hopefully this is a proper fix btw: These changes was also necessary: https://github.com/tokio-rs/tokio-uring/pull/334

manio avatar Oct 27 '25 16:10 manio