Message:
Hello [email protected], [email protected] (cc:
[email protected]),
I'd like you to review this change to
https://code.google.com/p/go
Description:
net, os, syscall: don't hold ForkLock during blocked opens on Plan 9
If os.OpenFile holds ForkLock on files that block opens,
then threads that simultaneously try to do fork-exec will
get hung up (until the open succeeds).
This CL introduces a pseudo-open-flag O_CANBLOCK,
which os.OpenFile interprets as a trigger to *not* hold
ForkLock. Here, it is used by the Plan 9 implementation
of Accept() (which tries to open a network "listen" file)
to avoid the aforementioned problem.
Please review this at https://codereview.appspot.com/7235066/
Affected files:
M src/pkg/net/ipsock_plan9.go
M src/pkg/os/file_plan9.go
M src/pkg/syscall/zerrors_plan9_386.go
M src/pkg/syscall/zerrors_plan9_amd64.go
Index: src/pkg/net/ipsock_plan9.go
===================================================================
--- a/src/pkg/net/ipsock_plan9.go
+++ b/src/pkg/net/ipsock_plan9.go
@@ -9,6 +9,7 @@
import (
"errors"
"os"
+ "syscall"
)
// /sys/include/ape/sys/socket.h:/SOMAXCONN
@@ -150,7 +151,7 @@
}
func (l *netFD) acceptPlan9() (*netFD, error) {
- f, err := os.Open(l.dir + "/listen")
+ f, err := os.OpenFile(l.dir+"/listen", os.O_RDONLY|syscall.O_CANBLOCK, 0)
if err != nil {
return nil, err
}
Index: src/pkg/os/file_plan9.go
===================================================================
--- a/src/pkg/os/file_plan9.go
+++ b/src/pkg/os/file_plan9.go
@@ -86,6 +86,7 @@
excl bool
trunc bool
append bool
+ block bool
)
if flag&O_CREATE == O_CREATE {
@@ -103,8 +104,14 @@
flag = flag &^ O_APPEND
append = true
}
+ if flag&syscall.O_CANBLOCK == syscall.O_CANBLOCK {
+ flag = flag &^ syscall.O_CANBLOCK
+ block = true
+ }
- syscall.ForkLock.RLock()
+ if !block {
+ syscall.ForkLock.RLock()
+ }
if (create && trunc) || excl {
fd, e = syscall.Create(name, flag, syscallMode(perm))
} else {
@@ -117,7 +124,9 @@
}
}
}
- syscall.ForkLock.RUnlock()
+ if !block {
+ syscall.ForkLock.RUnlock()
+ }
if e != nil {
return nil, &PathError{"open", name, e}
Index: src/pkg/syscall/zerrors_plan9_386.go
===================================================================
--- a/src/pkg/syscall/zerrors_plan9_386.go
+++ b/src/pkg/syscall/zerrors_plan9_386.go
@@ -13,6 +13,7 @@
O_APPEND = 0x00400
O_NOCTTY = 0x00000
O_NONBLOCK = 0x00000
+ O_CANBLOCK = 0x00060
O_SYNC = 0x00000
O_ASYNC = 0x00000
Index: src/pkg/syscall/zerrors_plan9_amd64.go
===================================================================
--- a/src/pkg/syscall/zerrors_plan9_amd64.go
+++ b/src/pkg/syscall/zerrors_plan9_amd64.go
@@ -13,6 +13,7 @@
O_APPEND = 0x00400
O_NOCTTY = 0x00000
O_NONBLOCK = 0x00000
+ O_CANBLOCK = 0x00060
O_SYNC = 0x00000
O_ASYNC = 0x00000
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.