I want to discuss this discrepancy as it currently exists in FreeBSD (all versions). cp(1) assumes that copy_file_range(2) is a one-shot. cp does not put a loop around the system call dealing with EINTR. However, this assumption is untrue at least on fuse filesystems. They can exit copy_file_range(2) with EINTR, e.g. when one copy operation is underway and a du(1) is executed simultaneously. This popped up at least twice on the FreeBSD forums. cp(1) basically doesn't work at all in that situation, the users need to use rsync instead. Which they don't know. I am soliciting opinions about "who is right" here. We need to either loop around copy_file_range=>EINTR or change fuse.
Sorry for the typo in the title.
CC rmacklem, who's done so much work on copy_file_range. copy_file_range is definitely not supposed to be one-shot. Its man page says "It is interruptible on most file systems" and "If it succeeds, the call returns the number of bytes copied, which can be fewer than len." And cp definitely does not assume that copy_file_range is one-shot. You can see that there's a loop in bin/cp/utils.c: 207. So I think there one of two things must be going on: * Either cp isn't handling an EINTR return value correctly, and is wrongly exiting from the loop, or * fusefs's VOP_COPY_FILE_RANGE implementation is returning EINTR when it really should be returning a short operation instead. I think the first problem is likelier. But a reproduction case would be helpful.
cp(1) does call copy_file_range() in a loop. The only issue, which is easily fixed, is that it expects copy_file_range() to always make _some_ progress.
Also, note that the same bug probably exists in install(1), and maybe other places too.
The reproducing case is timing dependent. I came up with the discrepancy when a user on the forums interrupted a cp operation with a du and cp bailed out. I will troll the base system for similar cases.
It's timing-dependent, but would be trivially reproducible if we had a fuse gadget designed specifically for that purpose. It would be extremely useful to be able to simulate I/O errors as well, cf. bug 292198.
(In reply to Dag-Erling Smørgrav from comment #6) We actually do have a fuse gadget designed for exactly that purpose. But it's not really meant to be used outside of the fusefs test suite. See tests/sys/fs/fusefs/interrupt.cc , and especially the in_kernel_nonrestartable test case. Another option might be to use gnop, which can be programmed to have delays.
(In reply to Alan Somers from comment #2) I would have said that a fuse specific vop_copy_file_range() should return EINTR if the copy is to be terminated. It should return the # of bytes copied, if it is meant to be continued. And, as others noted, it can only return to be continued after it has made some progress (return len > 0).
(In reply to Rick Macklem from comment #8) That's moot. As I reported in the linked code review (but not in Bugzilla), fuse isn't doing any copy_file_range. Instead, this bug involves the generic vn_copy_file_range. FUSE is just doing plain reads and writes.
(In reply to Alan Somers from comment #9) Ok, so you've confused me. What does fuse_vnop_copy_file_range() return for this case? Are you sure it is returning ENOSYS for this case, so that it falls back on vn_generic_copy_file_range()? (And it must not have changed any argument or what the argument points to, such as *lenp.) Looping on EINTR will mean that <ctrl>C cannot break out of a cp(1) that is taking too long, I think?
If the user presses Ctrl-C, cp will simply terminate, since it neither blocks nor catches SIGINT. It does catch SIGINFO, though, so spamming Ctrl-T can result in EINTR.
(In reply to Rick Macklem from comment #10) Correct. fuse_vnop_copy_file_range will return ENOSYS in this case.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=0fb940fd63dd9b6d6b848421c53b1e9ac8387265 commit 0fb940fd63dd9b6d6b848421c53b1e9ac8387265 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:50 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-11 16:24:50 +0000 install: Expect EINTR while copying Both copy_file_range() and read() / write() in our fallback loop can be interrupted before copying anything at all, in which case it returns -1 and sets errno to EINTR. If that happens, we should retry, not fail. While here, drop the size argument from copy() (we always want to copy the entire file anyway) and add test cases which exercise the metalog and digest functionality. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55168 usr.bin/xinstall/tests/install_test.sh | 38 +++++++++++++++++++++++++++++ usr.bin/xinstall/xinstall.c | 44 +++++++++++++++++----------------- 2 files changed, 60 insertions(+), 22 deletions(-)
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=7aa30669d6e04444b8ad1e4863a6e674fcac4afc commit 7aa30669d6e04444b8ad1e4863a6e674fcac4afc Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:46 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-11 16:24:46 +0000 cp: Expect EINTR while copying Both copy_file_range() and copy_fallback() can be interrupted before they have read anything at all, in which case they return -1 and set errno to EINTR. If that happens, we should retry, not fail. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55167 bin/cp/utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=9f1bff69b0b82accdaf056381bb86c5277236fd8 commit 9f1bff69b0b82accdaf056381bb86c5277236fd8 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:50 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-15 08:57:46 +0000 install: Expect EINTR while copying Both copy_file_range() and read() / write() in our fallback loop can be interrupted before copying anything at all, in which case it returns -1 and sets errno to EINTR. If that happens, we should retry, not fail. While here, drop the size argument from copy() (we always want to copy the entire file anyway) and add test cases which exercise the metalog and digest functionality. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55168 (cherry picked from commit 0fb940fd63dd9b6d6b848421c53b1e9ac8387265) usr.bin/xinstall/tests/install_test.sh | 38 +++++++++++++++++++++++++++++ usr.bin/xinstall/xinstall.c | 44 +++++++++++++++++----------------- 2 files changed, 60 insertions(+), 22 deletions(-)
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=77385e9fac1c34d7d3c1a778546ceb46c1b45796 commit 77385e9fac1c34d7d3c1a778546ceb46c1b45796 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:46 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-15 08:57:46 +0000 cp: Expect EINTR while copying Both copy_file_range() and copy_fallback() can be interrupted before they have read anything at all, in which case they return -1 and set errno to EINTR. If that happens, we should retry, not fail. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55167 (cherry picked from commit 7aa30669d6e04444b8ad1e4863a6e674fcac4afc) bin/cp/utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=cd24bdb92c1012760016a32cf5eb29143808a18f commit cd24bdb92c1012760016a32cf5eb29143808a18f Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:50 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-15 08:58:35 +0000 install: Expect EINTR while copying Both copy_file_range() and read() / write() in our fallback loop can be interrupted before copying anything at all, in which case it returns -1 and sets errno to EINTR. If that happens, we should retry, not fail. While here, drop the size argument from copy() (we always want to copy the entire file anyway) and add test cases which exercise the metalog and digest functionality. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55168 (cherry picked from commit 0fb940fd63dd9b6d6b848421c53b1e9ac8387265) usr.bin/xinstall/tests/install_test.sh | 38 +++++++++++++++++++++++++++++ usr.bin/xinstall/xinstall.c | 44 +++++++++++++++++----------------- 2 files changed, 60 insertions(+), 22 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=a9ac7da4c0c3907e21a5634a2338878eb9b33453 commit a9ac7da4c0c3907e21a5634a2338878eb9b33453 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:46 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-15 08:58:34 +0000 cp: Expect EINTR while copying Both copy_file_range() and copy_fallback() can be interrupted before they have read anything at all, in which case they return -1 and set errno to EINTR. If that happens, we should retry, not fail. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55167 (cherry picked from commit 7aa30669d6e04444b8ad1e4863a6e674fcac4afc) bin/cp/utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8e65c667475049f355fcff19d1f8647eb932a0c7 commit 8e65c667475049f355fcff19d1f8647eb932a0c7 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:50 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-15 08:58:47 +0000 install: Expect EINTR while copying Both copy_file_range() and read() / write() in our fallback loop can be interrupted before copying anything at all, in which case it returns -1 and sets errno to EINTR. If that happens, we should retry, not fail. While here, drop the size argument from copy() (we always want to copy the entire file anyway) and add test cases which exercise the metalog and digest functionality. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55168 (cherry picked from commit 0fb940fd63dd9b6d6b848421c53b1e9ac8387265) usr.bin/xinstall/tests/install_test.sh | 38 ++++++++++++++++++++++++++++++++ usr.bin/xinstall/xinstall.c | 40 +++++++++++++++++----------------- 2 files changed, 58 insertions(+), 20 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=f1a86b35dedba1b7dfa0ec8dae63b08a76cd395a commit f1a86b35dedba1b7dfa0ec8dae63b08a76cd395a Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-11 16:24:46 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-15 08:58:45 +0000 cp: Expect EINTR while copying Both copy_file_range() and copy_fallback() can be interrupted before they have read anything at all, in which case they return -1 and set errno to EINTR. If that happens, we should retry, not fail. PR: 293028 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55167 (cherry picked from commit 7aa30669d6e04444b8ad1e4863a6e674fcac4afc) bin/cp/utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)