Skip to content

Commit 96ef6ab

Browse files
panjf2000gopherbot
authored andcommitted
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: Damien Neil <[email protected]> TryBot-Result: Gopher Robot <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Andy Pan <[email protected]>
1 parent aa5d672 commit 96ef6ab

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/os/readfrom_unix_test.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,16 @@ func TestCopyFile(t *testing.T) {
198198
}
199199
switch runtime.GOOS {
200200
case "illumos", "solaris":
201-
// On SunOS, We rely on File.Stat to get the size of the source file,
201+
// On solaris, We rely on File.Stat to get the size of the source file,
202202
// which doesn't work for pipe.
203+
// On illumos, We skip anything other than regular files conservatively
204+
// for the target file, therefore the hook shouldn't have been called.
203205
if hook.called {
204-
t.Fatalf("%s: shouldn't have called the hook with a source of pipe", testName)
206+
t.Fatalf("%s: shouldn't have called the hook with a source or a destination of pipe", testName)
205207
}
206208
default:
207209
if !hook.called {
208-
t.Fatalf("%s: should have called the hook with a source of pipe", testName)
210+
t.Fatalf("%s: should have called the hook with both source and destination of pipe", testName)
209211
}
210212
}
211213
pw2.Close()
@@ -231,8 +233,17 @@ func TestCopyFile(t *testing.T) {
231233
if n != int64(len(data)) {
232234
t.Fatalf("%s: transferred %d, want %d", testName, n, len(data))
233235
}
234-
if !hook.called {
235-
t.Fatalf("%s: should have called the hook", testName)
236+
switch runtime.GOOS {
237+
case "illumos":
238+
// On illumos, We skip anything other than regular files conservatively
239+
// for the target file, therefore the hook shouldn't have been called.
240+
if hook.called {
241+
t.Fatalf("%s: shouldn't have called the hook with a destination of pipe", testName)
242+
}
243+
default:
244+
if !hook.called {
245+
t.Fatalf("%s: should have called the hook with a destination of pipe", testName)
246+
}
236247
}
237248
pw.Close()
238249
mustContainData(t, pr, data)

src/os/zero_copy_solaris.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
5858

5959
// sendfile() on illumos seems to incur intermittent failures when the
6060
// target file is a standard stream (stdout/stderr), we hereby skip any
61-
// character devices conservatively and leave them to generic copy.
61+
// anything other than regular files conservatively and leave them to generic copy.
6262
// Check out https://go.dev/issue/68863 for more details.
6363
if runtime.GOOS == "illumos" {
6464
fi, err := f.Stat()
@@ -69,7 +69,7 @@ func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
6969
if !ok {
7070
return 0, false, nil
7171
}
72-
if typ := st.Mode & syscall.S_IFMT; typ == syscall.S_IFCHR || typ == syscall.S_IFBLK {
72+
if typ := st.Mode & syscall.S_IFMT; typ != syscall.S_IFREG {
7373
return 0, false, nil
7474
}
7575
}

0 commit comments

Comments
 (0)