Skip to content

Commit 1ef8ad4

Browse files
authored
Merge pull request #624 from talex5/statx-fallback
eio_linux: add fallback for statx on older kernels
2 parents f169082 + 7c94ccb commit 1ef8ad4

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

lib_eio_linux/eio_linux.ml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -536,23 +536,34 @@ end = struct
536536
else Float.pred f
537537

538538
let stat t ~follow path =
539-
let module X = Uring.Statx in
540-
let x = X.create () in
541-
Low_level.statx_confined ~follow ~mask:X.Mask.basic_stats t.fd path x;
542-
{ Eio.File.Stat.
543-
dev = X.dev x;
544-
ino = X.ino x;
545-
kind = X.kind x;
546-
perm = X.perm x;
547-
nlink = X.nlink x;
548-
uid = X.uid x;
549-
gid = X.gid x;
550-
rdev = X.rdev x;
551-
size = X.size x |> Optint.Int63.of_int64;
552-
atime = float_of_time (X.atime_sec x) (X.atime_nsec x);
553-
mtime = float_of_time (X.mtime_sec x) (X.mtime_nsec x);
554-
ctime = float_of_time (X.ctime_sec x) (X.ctime_nsec x);
555-
}
539+
if !Sched.statx_works then (
540+
let module X = Uring.Statx in
541+
let x = X.create () in
542+
Low_level.statx_confined ~follow ~mask:X.Mask.basic_stats t.fd path x;
543+
{ Eio.File.Stat.
544+
dev = X.dev x;
545+
ino = X.ino x;
546+
kind = X.kind x;
547+
perm = X.perm x;
548+
nlink = X.nlink x;
549+
uid = X.uid x;
550+
gid = X.gid x;
551+
rdev = X.rdev x;
552+
size = X.size x |> Optint.Int63.of_int64;
553+
atime = float_of_time (X.atime_sec x) (X.atime_nsec x);
554+
mtime = float_of_time (X.mtime_sec x) (X.mtime_nsec x);
555+
ctime = float_of_time (X.ctime_sec x) (X.ctime_nsec x);
556+
}
557+
) else (
558+
(* Linux < 5.18 *)
559+
Switch.run @@ fun sw ->
560+
let fd = Low_level.openat ~sw ~seekable:false t.fd (if path = "" then "." else path)
561+
~access:`R
562+
~flags:Uring.Open_flags.(cloexec + path + (if follow then empty else nofollow))
563+
~perm:0
564+
in
565+
Flow.stat fd
566+
)
556567

557568
let rename t old_path t2 new_path =
558569
match get_dir_fd_opt t2 with

lib_eio_linux/sched.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module Lf_queue = Eio_utils.Lf_queue
1111

1212
let system_thread = Ctf.mint_id ()
1313

14+
let statx_works = ref false (* Before Linux 5.18, statx is unreliable *)
15+
1416
type exit = [`Exit_scheduler]
1517

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

0 commit comments

Comments
 (0)