Skip to content

Commit 5541790

Browse files
authored
Merge pull request #447 from talex5/eio-main
eio_main: make EIO_BACKEND handling more uniform
2 parents e858a8c + 27cf787 commit 5541790

File tree

10 files changed

+37
-51
lines changed

10 files changed

+37
-51
lines changed

lib_eio_linux/eio_linux.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,15 +1318,18 @@ let with_uring ~queue_depth ?polling_timeout ?(fallback=no_fallback) fn =
13181318
match Uring.create ~queue_depth ?polling_timeout () with
13191319
| exception Unix.Unix_error(Unix.ENOSYS, _, _) -> fallback (`Msg "io_uring is not available on this system")
13201320
| uring ->
1321-
match fn uring with
1322-
| x -> Uring.exit uring; x
1323-
| exception ex ->
1324-
let bt = Printexc.get_raw_backtrace () in
1325-
begin
1326-
try Uring.exit uring
1327-
with ex2 -> Log.warn (fun f -> f "Uring.exit failed (%a) while handling another error" Fmt.exn ex2)
1328-
end;
1329-
Printexc.raise_with_backtrace ex bt
1321+
let probe = Uring.get_probe uring in
1322+
if not (Uring.op_supported probe Uring.Op.shutdown) then
1323+
fallback (`Msg "Linux >= 5.11 is required for io_uring support")
1324+
else match fn uring with
1325+
| x -> Uring.exit uring; x
1326+
| exception ex ->
1327+
let bt = Printexc.get_raw_backtrace () in
1328+
begin
1329+
try Uring.exit uring
1330+
with ex2 -> Log.warn (fun f -> f "Uring.exit failed (%a) while handling another error" Fmt.exn ex2)
1331+
end;
1332+
Printexc.raise_with_backtrace ex bt
13301333

13311334
let rec run : type a.
13321335
?queue_depth:int -> ?n_blocks:int -> ?block_size:int -> ?polling_timeout:int -> ?fallback:(_ -> a) -> (_ -> a) -> a =

lib_main/dune

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
(library
22
(name eio_main)
33
(public_name eio_main)
4-
(libraries eio_luv
5-
(select eio_main.ml from
6-
(eio_linux -> eio_main.linux.ml)
7-
( -> eio_main.default.ml))))
4+
(libraries
5+
(select linux_backend.ml from
6+
(eio_linux -> linux_backend.enabled.ml)
7+
( -> linux_backend.disabled.ml))
8+
(select luv_backend.ml from
9+
(eio_luv -> luv_backend.enabled.ml)
10+
( -> luv_backend.disabled.ml))
11+
))

lib_main/eio_main.default.ml

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib_main/eio_main.linux.ml

Lines changed: 0 additions & 36 deletions
This file was deleted.

lib_main/eio_main.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let force run fn =
2+
run ~fallback:(fun (`Msg msg) -> failwith msg) fn
3+
4+
let run fn =
5+
match Sys.getenv_opt "EIO_BACKEND" with
6+
| Some ("io-uring" | "linux") -> force Linux_backend.run fn
7+
| Some "luv" -> force Luv_backend.run fn
8+
| None | Some "" ->
9+
Linux_backend.run fn ~fallback:(fun _ ->
10+
force Luv_backend.run fn
11+
)
12+
| Some x -> Fmt.failwith "Unknown Eio backend %S (from $EIO_BACKEND)" x

lib_main/eio_main.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ val run : (Eio.Stdenv.t -> 'a) -> 'a
1919
2020
On recent-enough versions of Linux, it will use {!Eio_linux.run}.
2121
You can override this by setting the $EIO_BACKEND environment variable to
22-
either "io-uring" or "luv". *)
22+
either "linux" or "luv". *)

lib_main/linux_backend.disabled.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let run ~fallback _ = fallback (`Msg "The io_uring backend was disabled at compile-time")

lib_main/linux_backend.enabled.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let run ~fallback fn = Eio_linux.run ~fallback (fun env -> fn (env :> Eio.Stdenv.t))

lib_main/luv_backend.disabled.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let run ~fallback _ = fallback (`Msg "The Luv backend was disabled at compile-time")

lib_main/luv_backend.enabled.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let run ~fallback:_ fn = Eio_luv.run (fun env -> fn (env :> Eio.Stdenv.t))

0 commit comments

Comments
 (0)