Page MenuHomeFreeBSD

cp: fall back to read/write if copy_file_range fails
ClosedPublic

Authored by asomers on Sep 10 2020, 6:11 PM.
Tags
None
Referenced Files
F98813248: D26395.diff
Fri, Oct 4, 8:32 PM
F98600081: D26395.diff
Fri, Oct 4, 12:22 AM
Unknown Object (File)
Thu, Oct 3, 7:12 PM
Unknown Object (File)
Thu, Oct 3, 11:06 AM
Unknown Object (File)
Tue, Oct 1, 2:17 PM
Unknown Object (File)
Mon, Sep 30, 3:59 PM
Unknown Object (File)
Mon, Sep 30, 9:45 AM
Unknown Object (File)
Sun, Sep 29, 9:07 PM

Details

Summary

cp: fall back to read/write if copy_file_range fails

Even though copy_file_range has a file-system agnostic version, it still
fails on devfs (perhaps because the file descriptor is non-seekable?) In
that case, fallback to old-fashioned read/write. Fixes
"cp /dev/null /tmp/null"

Reported-by: Michael Butler

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 33496
Build 30769: arc lint + arc unit

Event Timeline

Minor nit, which could report a bad write total in some rare circumstances is the only issue I see.

bin/cp/utils.c
249

if rcount < 0, then this code will execute where before it would not.

bin/cp/utils.c
249

Yeah, I'm aware of that. But I didn't think inaccurate SIGINFO output in the event of an error was a problem. Do you want me to fix it?

mjg added a subscriber: mjg.

This is a serious regression, just please get this in. The SIGINFO nit can be sorted out later.

This revision is now accepted and ready to land.Sep 11 2020, 8:27 PM

I think it fails because vn_copy_file_range checks for v_type == VREG while /dev/null is VCHR. There may be other problems.

Might I suggest that you enable NetBSD's cp tests, and add necessary tests to prevent this breakage again?

allanjude added inline comments.
head/bin/cp/utils.c
245 ↗(On Diff #76932)

Is there a reason this isn't juse an else?

head/bin/cp/utils.c
245 ↗(On Diff #76932)

Think first time through