diff options
author | Kevin Krakauer <krakauer@google.com> | 2021-10-07 17:37:50 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-10-07 17:41:20 -0700 |
commit | e44b100654ca639d11221e547384f699e461296d (patch) | |
tree | 950811fef6620dea99871f63e82a08cfa06849bf /pkg/tcpip/link/sharedmem/queuepair.go | |
parent | 487651ac46f302592ccffc9e5a4336a331010e42 (diff) |
add convenient wrapper for eventfd
The same create/write/read pattern is copied around several places. It's easier
to understand in a package with names and comments, and we can reuse the smart
blocking code in package rawfile.
PiperOrigin-RevId: 401647108
Diffstat (limited to 'pkg/tcpip/link/sharedmem/queuepair.go')
-rw-r--r-- | pkg/tcpip/link/sharedmem/queuepair.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/pkg/tcpip/link/sharedmem/queuepair.go b/pkg/tcpip/link/sharedmem/queuepair.go index 5fa6d91f0..b12647fdd 100644 --- a/pkg/tcpip/link/sharedmem/queuepair.go +++ b/pkg/tcpip/link/sharedmem/queuepair.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "golang.org/x/sys/unix" + "gvisor.dev/gvisor/pkg/eventfd" ) const ( @@ -116,25 +117,25 @@ type queueSizes struct { func createQueueFDs(s queueSizes) (QueueConfig, error) { success := false - var fd uintptr + var eventFD eventfd.Eventfd var dataFD, txPipeFD, rxPipeFD, sharedDataFD int defer func() { if success { return } closeFDs(QueueConfig{ - EventFD: int(fd), + EventFD: eventFD, DataFD: dataFD, TxPipeFD: txPipeFD, RxPipeFD: rxPipeFD, SharedDataFD: sharedDataFD, }) }() - eventFD, _, errno := unix.RawSyscall(unix.SYS_EVENTFD2, 0, 0, 0) - if errno != 0 { - return QueueConfig{}, fmt.Errorf("eventfd failed: %v", error(errno)) + eventFD, err := eventfd.Create() + if err != nil { + return QueueConfig{}, fmt.Errorf("eventfd failed: %v", err) } - dataFD, err := createFile(s.dataSize, false) + dataFD, err = createFile(s.dataSize, false) if err != nil { return QueueConfig{}, fmt.Errorf("failed to create dataFD: %s", err) } @@ -152,7 +153,7 @@ func createQueueFDs(s queueSizes) (QueueConfig, error) { } success = true return QueueConfig{ - EventFD: int(eventFD), + EventFD: eventFD, DataFD: dataFD, TxPipeFD: txPipeFD, RxPipeFD: rxPipeFD, @@ -191,7 +192,7 @@ func createFile(size int64, initQueue bool) (fd int, err error) { func closeFDs(c QueueConfig) { unix.Close(c.DataFD) - unix.Close(c.EventFD) + c.EventFD.Close() unix.Close(c.TxPipeFD) unix.Close(c.RxPipeFD) unix.Close(c.SharedDataFD) |