Skip to content
Snippets Groups Projects
Commit 96ef6abc authored by Andy Pan's avatar Andy Pan Committed by Gopher Robot
Browse files

os: only employ sendfile(3ext) on illumos when target is regular file

Follows up CL 605355
Fixes #68863

Change-Id: I56e05822502e66eed610d5e924d110607ce146b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/606135


Reviewed-by: default avatarDamien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: default avatarIan Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
parent aa5d672a
No related branches found
No related tags found
No related merge requests found
...@@ -198,14 +198,16 @@ func TestCopyFile(t *testing.T) { ...@@ -198,14 +198,16 @@ func TestCopyFile(t *testing.T) {
} }
switch runtime.GOOS { switch runtime.GOOS {
case "illumos", "solaris": case "illumos", "solaris":
// On SunOS, We rely on File.Stat to get the size of the source file, // On solaris, We rely on File.Stat to get the size of the source file,
// which doesn't work for pipe. // which doesn't work for pipe.
// On illumos, We skip anything other than regular files conservatively
// for the target file, therefore the hook shouldn't have been called.
if hook.called { if hook.called {
t.Fatalf("%s: shouldn't have called the hook with a source of pipe", testName) t.Fatalf("%s: shouldn't have called the hook with a source or a destination of pipe", testName)
} }
default: default:
if !hook.called { if !hook.called {
t.Fatalf("%s: should have called the hook with a source of pipe", testName) t.Fatalf("%s: should have called the hook with both source and destination of pipe", testName)
} }
} }
pw2.Close() pw2.Close()
...@@ -231,8 +233,17 @@ func TestCopyFile(t *testing.T) { ...@@ -231,8 +233,17 @@ func TestCopyFile(t *testing.T) {
if n != int64(len(data)) { if n != int64(len(data)) {
t.Fatalf("%s: transferred %d, want %d", testName, n, len(data)) t.Fatalf("%s: transferred %d, want %d", testName, n, len(data))
} }
if !hook.called { switch runtime.GOOS {
t.Fatalf("%s: should have called the hook", testName) case "illumos":
// On illumos, We skip anything other than regular files conservatively
// for the target file, therefore the hook shouldn't have been called.
if hook.called {
t.Fatalf("%s: shouldn't have called the hook with a destination of pipe", testName)
}
default:
if !hook.called {
t.Fatalf("%s: should have called the hook with a destination of pipe", testName)
}
} }
pw.Close() pw.Close()
mustContainData(t, pr, data) mustContainData(t, pr, data)
......
...@@ -58,7 +58,7 @@ func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) { ...@@ -58,7 +58,7 @@ func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
// sendfile() on illumos seems to incur intermittent failures when the // sendfile() on illumos seems to incur intermittent failures when the
// target file is a standard stream (stdout/stderr), we hereby skip any // target file is a standard stream (stdout/stderr), we hereby skip any
// character devices conservatively and leave them to generic copy. // anything other than regular files conservatively and leave them to generic copy.
// Check out https://go.dev/issue/68863 for more details. // Check out https://go.dev/issue/68863 for more details.
if runtime.GOOS == "illumos" { if runtime.GOOS == "illumos" {
fi, err := f.Stat() fi, err := f.Stat()
...@@ -69,7 +69,7 @@ func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) { ...@@ -69,7 +69,7 @@ func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
if !ok { if !ok {
return 0, false, nil return 0, false, nil
} }
if typ := st.Mode & syscall.S_IFMT; typ == syscall.S_IFCHR || typ == syscall.S_IFBLK { if typ := st.Mode & syscall.S_IFMT; typ != syscall.S_IFREG {
return 0, false, nil return 0, false, nil
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment