Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eio_linux: add fallback for statx on older kernels #624

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading