]> Cypherpunks repositories - gostls13.git/commitdiff
os: skip zero-copy attempts with copy_file_range(2)/splice(2) for target files with...
authorAndy Pan <panjf2000@gmail.com>
Mon, 27 Feb 2023 04:47:39 +0000 (12:47 +0800)
committerGopher Robot <gobot@golang.org>
Mon, 27 Feb 2023 22:20:11 +0000 (22:20 +0000)
Change-Id: I6cccac9295ab4a9bf7f7a33382a34f31b1c4a000
Reviewed-on: https://go-review.googlesource.com/c/go/+/471496
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>

src/os/readfrom_linux.go

index 2a81b7abfed94b6a1e862ae2a5e8b78c7f609110..514d873ece7fd8d00c1aa01bbdc3f3a987ec7410 100644 (file)
@@ -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