Skip to content

Commit

Permalink
eio_linux: add fallback for statx on older kernels
Browse files Browse the repository at this point in the history
If statx isn't available, open the path and use fstat instead.

See: io-uring: Make statx API stable
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1b6fe6e0dfecf8c82a64fb87148ad9333fa2f62e
  • Loading branch information
talex5 committed Sep 27, 2023
1 parent 9256754 commit 590df4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
45 changes: 28 additions & 17 deletions lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -536,23 +536,34 @@ end = struct
else Float.pred f

let stat t ~follow path =
let module X = Uring.Statx in
let x = X.create () in
Low_level.statx_confined ~follow ~mask:X.Mask.basic_stats t.fd path x;
{ Eio.File.Stat.
dev = X.dev x;
ino = X.ino x;
kind = X.kind x;
perm = X.perm x;
nlink = X.nlink x;
uid = X.uid x;
gid = X.gid x;
rdev = X.rdev x;
size = X.size x |> Optint.Int63.of_int64;
atime = float_of_time (X.atime_sec x) (X.atime_nsec x);
mtime = float_of_time (X.mtime_sec x) (X.mtime_nsec x);
ctime = float_of_time (X.ctime_sec x) (X.ctime_nsec x);
}
if !Sched.statx_works then (
let module X = Uring.Statx in
let x = X.create () in
Low_level.statx_confined ~follow ~mask:X.Mask.basic_stats t.fd path x;
{ Eio.File.Stat.
dev = X.dev x;
ino = X.ino x;
kind = X.kind x;
perm = X.perm x;
nlink = X.nlink x;
uid = X.uid x;
gid = X.gid x;
rdev = X.rdev x;
size = X.size x |> Optint.Int63.of_int64;
atime = float_of_time (X.atime_sec x) (X.atime_nsec x);
mtime = float_of_time (X.mtime_sec x) (X.mtime_nsec x);
ctime = float_of_time (X.ctime_sec x) (X.ctime_nsec x);
}
) else (
(* Linux < 5.18 *)
Switch.run @@ fun sw ->
let fd = Low_level.openat ~sw ~seekable:false t.fd (if path = "" then "." else path)
~access:`R
~flags:Uring.Open_flags.(cloexec + path + (if follow then empty else nofollow))
~perm:0
in
Flow.stat fd
)

let rename t old_path t2 new_path =
match get_dir_fd_opt t2 with
Expand Down
3 changes: 3 additions & 0 deletions lib_eio_linux/sched.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module Lf_queue = Eio_utils.Lf_queue

let system_thread = Ctf.mint_id ()

let statx_works = ref false (* Before Linux 5.18, statx is unreliable *)

type exit = [`Exit_scheduler]

type file_offset = [
Expand Down Expand Up @@ -526,6 +528,7 @@ let with_sched ?(fallback=no_fallback) config fn =
Uring.exit uring;
fallback (`Msg "Linux >= 5.11 is required for io_uring support")
) else (
statx_works := Uring.op_supported probe Uring.Op.msg_ring;
match
let mem =
let fixed_buf_len = block_size * n_blocks in
Expand Down

0 comments on commit 590df4c

Please sign in to comment.