1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:38:33 -06:00

internal/poll: drop redundant ENOSYS and EXDEV error checks in CopyFileRange()

The initial CL 229101 didn't limit the kernel version, but relies on error checking to
ensure the kernel version >= 4.5 or >= 5.3 when it's calling copy_file_range(2) to copy data across file systems.

Since we have now put the kernel version checking at the beginning of the function, introduced by CL 268338,
which returns early instead of going forward to the code behind when the kernel verion is older than 5.3,
therefore, those subsequent related error checks are no longer needed.

Change-Id: Ifc4a530723e21f0bde91d6420cde9cb676081922
Reviewed-on: https://go-review.googlesource.com/c/go/+/425881
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Andy Pan 2022-08-27 10:44:25 +08:00 committed by Daniel Martí
parent af7f417665
commit 40ced0c00b

View File

@ -41,25 +41,9 @@ func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err
} }
n, err := copyFileRange(dst, src, int(max)) n, err := copyFileRange(dst, src, int(max))
switch err { switch err {
case syscall.ENOSYS: case syscall.EINVAL, syscall.EIO, syscall.EOPNOTSUPP, syscall.EPERM:
// copy_file_range(2) was introduced in Linux 4.5. // EINVAL is what we see if, for example,
// Go supports Linux >= 2.6.33, so the system call // dst or src refers to a pipe rather than a regular
// may not be present.
//
// If we see ENOSYS, we have certainly not transferred
// any data, so we can tell the caller that we
// couldn't handle the transfer and let them fall
// back to more generic code.
return 0, false, nil
case syscall.EXDEV, syscall.EINVAL, syscall.EIO, syscall.EOPNOTSUPP, syscall.EPERM:
// Prior to Linux 5.3, it was not possible to
// copy_file_range across file systems. Similarly to
// the ENOSYS case above, if we see EXDEV, we have
// not transferred any data, and we can let the caller
// fall back to generic code.
//
// As for EINVAL, that is what we see if, for example,
// dst or src refer to a pipe rather than a regular
// file. This is another case where no data has been // file. This is another case where no data has been
// transferred, so we consider it unhandled. // transferred, so we consider it unhandled.
// //
@ -70,9 +54,10 @@ func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err
// See issue #40731. // See issue #40731.
// //
// If the process is running inside a Docker container, // If the process is running inside a Docker container,
// we might see EPERM instead of ENOSYS. See issue // we might see EPERM instead of ENOSYS. See issue #40893.
// #40893. Since EPERM might also be a legitimate error, // Since EPERM might also be a legitimate error: operation not permitted,
// don't mark copy_file_range(2) as unsupported. // we should still keep this error even if we have the previous kernel version 5.3 check
// and don't mark copy_file_range(2) as unsupported.
return 0, false, nil return 0, false, nil
case nil: case nil:
if n == 0 { if n == 0 {
@ -83,7 +68,7 @@ func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err
if written == 0 { if written == 0 {
return 0, false, nil return 0, false, nil
} }
// Otherwise src is at EOF, which means // Otherwise, src is at EOF, which means
// we are done. // we are done.
return written, true, nil return written, true, nil
} }