From: Andy Pan Date: Mon, 27 Feb 2023 04:47:39 +0000 (+0800) Subject: os: skip zero-copy attempts with copy_file_range(2)/splice(2) for target files with... X-Git-Tag: go1.21rc1~1446 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=08a68b73a4843dfe8c4896cace3242b895342511;p=gostls13.git os: skip zero-copy attempts with copy_file_range(2)/splice(2) for target files with O_APPEND flag Change-Id: I6cccac9295ab4a9bf7f7a33382a34f31b1c4a000 Reviewed-on: https://go-review.googlesource.com/c/go/+/471496 Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Reviewed-by: Than McIntosh Reviewed-by: Bryan Mills Run-TryBot: Andy Pan --- diff --git a/src/os/readfrom_linux.go b/src/os/readfrom_linux.go index 2a81b7abfe..514d873ece 100644 --- a/src/os/readfrom_linux.go +++ b/src/os/readfrom_linux.go @@ -16,6 +16,15 @@ var ( ) func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) { + // Neither copy_file_range(2) nor splice(2) supports destinations opened with + // O_APPEND, so don't bother to try zero-copy with these system calls. + // + // Visit https://man7.org/linux/man-pages/man2/copy_file_range.2.html#ERRORS and + // https://man7.org/linux/man-pages/man2/splice.2.html#ERRORS for details. + if f.appendMode { + return 0, false, nil + } + written, handled, err = f.copyFileRange(r) if handled { return @@ -74,12 +83,6 @@ func getPollFD(r io.Reader) *poll.FD { } func (f *File) copyFileRange(r io.Reader) (written int64, handled bool, err error) { - // copy_file_range(2) does not support destinations opened with - // O_APPEND, so don't even try. - if f.appendMode { - return 0, false, nil - } - var ( remain int64 lr *io.LimitedReader