summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorAndy Pan <panjf2000@gmail.com>2023-02-27 12:47:39 +0800
committerGopher Robot <gobot@golang.org>2023-02-27 22:20:11 +0000
commit08a68b73a4843dfe8c4896cace3242b895342511 (patch)
treed1b93d132fc423b080481e66a90727d6dff69066 /src/os
parent676794f73e6ca8fbd7ec14f4185625efda4e2ca8 (diff)
downloadgo-git-08a68b73a4843dfe8c4896cace3242b895342511.tar.gz
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 <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>
Diffstat (limited to 'src/os')
-rw-r--r--src/os/readfrom_linux.go15
1 files changed, 9 insertions, 6 deletions
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