Skip to content
Open
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
1 change: 0 additions & 1 deletion lib/uring/include/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ let toplevel_defs c =
"O_PATH", Int;
"O_TMPFILE", Int;

"AT_FDCWD", Int;
"IOV_MAX", Int;

"sizeof(struct iovec)", Int;
Expand Down
22 changes: 10 additions & 12 deletions lib/uring/uring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,17 @@ module Uring = struct
external submit_readv_fixed : t -> Unix.file_descr -> id -> Cstruct.buffer -> int -> int -> offset -> bool = "ocaml_uring_submit_readv_fixed_byte" "ocaml_uring_submit_readv_fixed_native" [@@noalloc]
external submit_writev_fixed : t -> Unix.file_descr -> id -> Cstruct.buffer -> int -> int -> offset -> bool = "ocaml_uring_submit_writev_fixed_byte" "ocaml_uring_submit_writev_fixed_native" [@@noalloc]
external submit_close : t -> Unix.file_descr -> id -> bool = "ocaml_uring_submit_close" [@@noalloc]
external submit_statx : t -> id -> Unix.file_descr -> Statx.t -> Sketch.ptr -> int -> int -> bool = "ocaml_uring_submit_statx_byte" "ocaml_uring_submit_statx_native" [@@noalloc]
external submit_statx : t -> id -> Unix.file_descr option -> Statx.t -> Sketch.ptr -> int -> int -> bool = "ocaml_uring_submit_statx_byte" "ocaml_uring_submit_statx_native" [@@noalloc]
external submit_splice : t -> id -> Unix.file_descr -> Unix.file_descr -> int -> bool = "ocaml_uring_submit_splice" [@@noalloc]
external submit_bind : t -> id -> Unix.file_descr -> Sockaddr.t -> bool = "ocaml_uring_submit_bind" [@@noalloc]
external submit_listen : t -> id -> Unix.file_descr -> int -> bool = "ocaml_uring_submit_listen" [@@noalloc]
external submit_connect : t -> id -> Unix.file_descr -> Sockaddr.t -> bool = "ocaml_uring_submit_connect" [@@noalloc]
external submit_accept : t -> id -> Unix.file_descr -> Sockaddr.t -> bool = "ocaml_uring_submit_accept" [@@noalloc]
external submit_cancel : t -> id -> id -> bool = "ocaml_uring_submit_cancel" [@@noalloc]
external submit_openat2 : t -> id -> Unix.file_descr -> Open_how.t -> bool = "ocaml_uring_submit_openat2" [@@noalloc]
external submit_linkat : t -> id -> Unix.file_descr -> Sketch.ptr -> Unix.file_descr -> Sketch.ptr -> int -> bool = "ocaml_uring_submit_linkat_byte" "ocaml_uring_submit_linkat_native" [@@noalloc]
external submit_unlinkat : t -> id -> Unix.file_descr -> Sketch.ptr -> bool -> bool = "ocaml_uring_submit_unlinkat" [@@noalloc]
external submit_mkdirat : t -> id -> Unix.file_descr -> Sketch.ptr -> int -> bool = "ocaml_uring_submit_mkdirat" [@@noalloc]
external submit_openat2 : t -> id -> Unix.file_descr option -> Open_how.t -> bool = "ocaml_uring_submit_openat2" [@@noalloc]
external submit_linkat : t -> id -> Unix.file_descr option -> Sketch.ptr -> Unix.file_descr option -> Sketch.ptr -> int -> bool = "ocaml_uring_submit_linkat_byte" "ocaml_uring_submit_linkat_native" [@@noalloc]
external submit_unlinkat : t -> id -> Unix.file_descr option -> Sketch.ptr -> bool -> bool = "ocaml_uring_submit_unlinkat" [@@noalloc]
external submit_mkdirat : t -> id -> Unix.file_descr option -> Sketch.ptr -> int -> bool = "ocaml_uring_submit_mkdirat" [@@noalloc]
external submit_send_msg : t -> id -> Unix.file_descr -> Msghdr.t -> Sketch.ptr -> bool = "ocaml_uring_submit_send_msg" [@@noalloc]
external submit_recv_msg : t -> id -> Unix.file_descr -> Msghdr.t -> Sketch.ptr -> bool = "ocaml_uring_submit_recv_msg" [@@noalloc]
external submit_fsync : t -> id -> Unix.file_descr -> int64 -> int -> bool = "ocaml_uring_submit_fsync" [@@noalloc]
Expand Down Expand Up @@ -465,9 +465,7 @@ let timeout ?(absolute = false) t clock timeout_ns user_data =
set_timespec timespec_ptr timeout_ns;
with_id t (fun id -> Uring.submit_timeout t.uring id timespec_ptr clock absolute) user_data

let at_fdcwd : Unix.file_descr = Obj.magic Config.at_fdcwd

let openat2 t ~access ~flags ~perm ~resolve ?(fd=at_fdcwd) path user_data =
let openat2 t ~access ~flags ~perm ~resolve ?fd path user_data =
let open_flags = flags lor match access with
| `R -> Open_flags.rdonly
| `W -> Open_flags.wronly
Expand All @@ -482,20 +480,20 @@ module Linkat_flags = struct
let symlink_follow = Config.At.symlink_follow
end

let linkat t ?(old_dir_fd=at_fdcwd) ?(new_dir_fd=at_fdcwd) ~flags ~old_path ~new_path user_data =
let linkat t ?old_dir_fd ?new_dir_fd ~flags ~old_path ~new_path user_data =
with_id t (fun id ->
let old_path_buf = Sketch.String.alloc t.sketch old_path in
let new_path_buf = Sketch.String.alloc t.sketch new_path in
Uring.submit_linkat t.uring id old_dir_fd old_path_buf new_dir_fd new_path_buf flags
) user_data

let unlink t ~dir ?(fd=at_fdcwd) path user_data =
let unlink t ~dir ?fd path user_data =
with_id t (fun id ->
let buf = Sketch.String.alloc t.sketch path in
Uring.submit_unlinkat t.uring id fd buf dir
) user_data

let mkdirat t ~mode ?(fd=at_fdcwd) path user_data =
let mkdirat t ~mode ?fd path user_data =
with_id t (fun id ->
let buf = Sketch.String.alloc t.sketch path in
Uring.submit_mkdirat t.uring id fd buf mode
Expand Down Expand Up @@ -541,7 +539,7 @@ let poll_add t fd poll_mask user_data =
let close t fd user_data =
with_id t (fun id -> Uring.submit_close t.uring fd id) user_data

let statx t ?(fd=at_fdcwd) ~mask path statx flags user_data =
let statx t ?fd ~mask path statx flags user_data =
let spath = Sketch.String.alloc t.sketch path in
with_id_full t (fun id -> Uring.submit_statx t.uring id fd statx spath flags mask) user_data ~extra_data:statx

Expand Down
18 changes: 13 additions & 5 deletions lib/uring/uring_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,22 @@ ocaml_uring_make_open_how(value v_flags, value v_mode, value v_resolve, value v_
CAMLreturn(v);
}

static int with_at_fdcwd(value v_fd)
{
if (Is_none(v_fd))
return AT_FDCWD;
else
return Int_val(Some_val(v_fd));
}

// Caller must ensure v_open_how is not GC'd until the job is finished.
value /* noalloc */
ocaml_uring_submit_openat2(value v_uring, value v_id, value v_fd, value v_open_how) {
struct io_uring *ring = Ring_val(v_uring);
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
if (!sqe) return (Val_false);
struct open_how_data *data = Open_how_val(v_open_how);
io_uring_prep_openat2(sqe, Int_val(v_fd), data->path, &data->how);
io_uring_prep_openat2(sqe, with_at_fdcwd(v_fd), data->path, &data->how);
io_uring_sqe_set_data(sqe, (void *)Long_val(v_id));
return (Val_true);
}
Expand Down Expand Up @@ -483,7 +491,7 @@ ocaml_uring_submit_statx_native(value v_uring, value v_id, value v_fd, value v_s
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
if (!sqe) return (Val_false);
char *path = Sketch_ptr_val(v_sketch_ptr);
io_uring_prep_statx(sqe, Int_val(v_fd), path, Int_val(v_flags), Int_val(v_mask), Statx_val(v_statx));
io_uring_prep_statx(sqe, with_at_fdcwd(v_fd), path, Int_val(v_flags), Int_val(v_mask), Statx_val(v_statx));
io_uring_sqe_set_data(sqe, (void *)Long_val(v_id));
return (Val_true);
}
Expand Down Expand Up @@ -873,7 +881,7 @@ ocaml_uring_submit_unlinkat(value v_uring, value v_id, value v_fd, value v_sketc
int flags = Bool_val(v_rmdir) ? AT_REMOVEDIR : 0;
char *path = Sketch_ptr_val(v_sketch_ptr);
if (!sqe) return (Val_false);
io_uring_prep_unlinkat(sqe, Int_val(v_fd), path, flags);
io_uring_prep_unlinkat(sqe, with_at_fdcwd(v_fd), path, flags);
io_uring_sqe_set_data(sqe, (void *)Long_val(v_id));
return (Val_true);
}
Expand All @@ -884,7 +892,7 @@ ocaml_uring_submit_mkdirat(value v_uring, value v_id, value v_fd, value v_sketch
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
char *path = Sketch_ptr_val(v_sketch_ptr);
if (!sqe) return (Val_false);
io_uring_prep_mkdirat(sqe, Int_val(v_fd), path, Int_val(v_mode));
io_uring_prep_mkdirat(sqe, with_at_fdcwd(v_fd), path, Int_val(v_mode));
io_uring_sqe_set_data(sqe, (void *)Long_val(v_id));
return (Val_true);
}
Expand Down Expand Up @@ -1097,7 +1105,7 @@ ocaml_uring_submit_linkat_native(value v_uring, value v_id,
if (!sqe)
return Val_false;

io_uring_prep_linkat(sqe, Int_val(v_old_dir), old_path, Int_val(v_new_dir), new_path, Int_val(v_flags));
io_uring_prep_linkat(sqe, with_at_fdcwd(v_old_dir), old_path, with_at_fdcwd(v_new_dir), new_path, Int_val(v_flags));
io_uring_sqe_set_data(sqe, (void *)Long_val(v_id));

return Val_true;
Expand Down