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

[3.8] Backport #8049 (sendfile fix on Linux) #8055

Merged
merged 2 commits into from
Jun 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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

- Fix deadlock on Windows (#8044, @nojb)

- When using `sendfile` to copy files on Linux, fall back to the portable
version if it fails at runtime for some reason (NFS, etc).
(#8049, fixes #8041, @emillon)

3.8.2 (2023-06-16)
------------------

Expand Down
7 changes: 6 additions & 1 deletion otherlibs/stdune/src/io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ module Copyfile = struct
Exn.protectx (setup_copy ?chmod ~src ~dst ()) ~finally:close_both
~f:(fun (ic, oc) -> copy_channels ic oc)

let sendfile_with_fallback ?chmod ~src ~dst () =
try sendfile ?chmod ~src ~dst ()
with Unix.Unix_error (EINVAL, "sendfile", _) ->
copy_file_portable ?chmod ~src ~dst ()

let copy_file_best =
match available with
| `Sendfile -> sendfile
| `Sendfile -> sendfile_with_fallback
| `Copyfile -> copyfile
| `Nothing -> copy_file_portable

Expand Down
6 changes: 6 additions & 0 deletions test/blackbox-tests/test-cases/dune
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,9 @@
(cram
(applies_to version-corruption)
(deps %{bin:od} %{bin:git} %{bin:cmp} %{bin:sed} %{bin:chmod}))

(cram
(applies_to github8041)
(enabled_if
(= %{system} linux))
(deps %{bin:strace}))
17 changes: 17 additions & 0 deletions test/blackbox-tests/test-cases/github8041.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$ cat > dune-project << EOF
> (lang dune 1.0)
> (package
> (name p))
> EOF

$ cat > dune << EOF
> (install
> (files data.txt)
> (section share))
> EOF

$ echo contents > data.txt

If sendfile fails, we should fallback to the portable implementation.

$ strace -e inject=sendfile:error=EINVAL -o /dev/null dune build @install