From 40ced0c00b04a5b9832bb5b47c995c82854f26ae Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 27 Aug 2022 10:44:25 +0800 Subject: [PATCH] internal/poll: drop redundant ENOSYS and EXDEV error checks in CopyFileRange() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Run-TryBot: hopehook Reviewed-by: Ian Lance Taylor Reviewed-by: Daniel Martí Reviewed-by: Heschi Kreinick --- src/internal/poll/copy_file_range_linux.go | 31 ++++++---------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/internal/poll/copy_file_range_linux.go b/src/internal/poll/copy_file_range_linux.go index ba33f5145d..4ac17d6a05 100644 --- a/src/internal/poll/copy_file_range_linux.go +++ b/src/internal/poll/copy_file_range_linux.go @@ -41,25 +41,9 @@ func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err } n, err := copyFileRange(dst, src, int(max)) switch err { - case syscall.ENOSYS: - // copy_file_range(2) was introduced in Linux 4.5. - // Go supports Linux >= 2.6.33, so the system call - // 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 + case syscall.EINVAL, syscall.EIO, syscall.EOPNOTSUPP, syscall.EPERM: + // EINVAL is what we see if, for example, + // dst or src refers to a pipe rather than a regular // file. This is another case where no data has been // 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. // // If the process is running inside a Docker container, - // we might see EPERM instead of ENOSYS. See issue - // #40893. Since EPERM might also be a legitimate error, - // don't mark copy_file_range(2) as unsupported. + // we might see EPERM instead of ENOSYS. See issue #40893. + // Since EPERM might also be a legitimate error: operation not permitted, + // 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 case nil: if n == 0 { @@ -83,7 +68,7 @@ func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err if written == 0 { return 0, false, nil } - // Otherwise src is at EOF, which means + // Otherwise, src is at EOF, which means // we are done. return written, true, nil }