From e4b395db49e9e90659bd3d366f62aa258a3c7157 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 24 May 2019 12:28:15 -0700 Subject: Remove unused wakers These wakers are uselessly allocated and passed around; nothing ever listens for notifications on them. The code here appears to be vestigial, so removing it and allowing a nil waker to be passed seems appropriate. PiperOrigin-RevId: 249879320 Change-Id: Icd209fb77cc0dd4e5c49d7a9f2adc32bf88b4b71 --- pkg/tcpip/stack/linkaddrcache.go | 10 ++++++---- pkg/tcpip/transport/icmp/endpoint.go | 8 +------- pkg/tcpip/transport/raw/endpoint.go | 8 +------- pkg/tcpip/transport/udp/endpoint.go | 7 +------ 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/pkg/tcpip/stack/linkaddrcache.go b/pkg/tcpip/stack/linkaddrcache.go index 42b9768ae..b952ad20f 100644 --- a/pkg/tcpip/stack/linkaddrcache.go +++ b/pkg/tcpip/stack/linkaddrcache.go @@ -138,8 +138,10 @@ func (e *linkAddrEntry) changeState(ns entryState) { e.s = ns } -func (e *linkAddrEntry) addWaker(w *sleep.Waker) { - e.wakers[w] = struct{}{} +func (e *linkAddrEntry) maybeAddWaker(w *sleep.Waker) { + if w != nil { + e.wakers[w] = struct{}{} + } } func (e *linkAddrEntry) removeWaker(w *sleep.Waker) { @@ -217,7 +219,7 @@ func (c *linkAddrCache) get(k tcpip.FullAddress, linkRes LinkAddressResolver, lo return "", nil, tcpip.ErrNoLinkAddress case incomplete: // Address resolution is still in progress. - entry.addWaker(waker) + entry.maybeAddWaker(waker) return "", entry.done, tcpip.ErrWouldBlock default: panic(fmt.Sprintf("invalid cache entry state: %s", s)) @@ -230,7 +232,7 @@ func (c *linkAddrCache) get(k tcpip.FullAddress, linkRes LinkAddressResolver, lo // Add 'incomplete' entry in the cache to mark that resolution is in progress. e := c.makeAndAddEntry(k, "") - e.addWaker(waker) + e.maybeAddWaker(waker) go c.startAddressResolution(k, linkRes, localAddr, linkEP, e.done) // S/R-SAFE: link non-savable; wakers dropped synchronously. diff --git a/pkg/tcpip/transport/icmp/endpoint.go b/pkg/tcpip/transport/icmp/endpoint.go index cc384dd3d..e2b90ef10 100644 --- a/pkg/tcpip/transport/icmp/endpoint.go +++ b/pkg/tcpip/transport/icmp/endpoint.go @@ -18,7 +18,6 @@ import ( "encoding/binary" "sync" - "gvisor.googlesource.com/gvisor/pkg/sleep" "gvisor.googlesource.com/gvisor/pkg/tcpip" "gvisor.googlesource.com/gvisor/pkg/tcpip/buffer" "gvisor.googlesource.com/gvisor/pkg/tcpip/header" @@ -274,13 +273,8 @@ func (e *endpoint) Write(p tcpip.Payload, opts tcpip.WriteOptions) (uintptr, <-c } if route.IsResolutionRequired() { - waker := &sleep.Waker{} - if ch, err := route.Resolve(waker); err != nil { + if ch, err := route.Resolve(nil); err != nil { if err == tcpip.ErrWouldBlock { - // Link address needs to be resolved. - // Resolution was triggered the background. - // Better luck next time. - route.RemoveWaker(waker) return 0, ch, tcpip.ErrNoLinkAddress } return 0, nil, err diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index e7b383ad5..1daf5823f 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -29,7 +29,6 @@ package raw import ( "sync" - "gvisor.googlesource.com/gvisor/pkg/sleep" "gvisor.googlesource.com/gvisor/pkg/tcpip" "gvisor.googlesource.com/gvisor/pkg/tcpip/buffer" "gvisor.googlesource.com/gvisor/pkg/tcpip/header" @@ -259,13 +258,8 @@ func (ep *endpoint) finishWrite(payload tcpip.Payload, route *stack.Route) (uint // network address). If that requires blocking (e.g. to use ARP), // return a channel on which the caller can wait. if route.IsResolutionRequired() { - waker := &sleep.Waker{} - if ch, err := route.Resolve(waker); err != nil { + if ch, err := route.Resolve(nil); err != nil { if err == tcpip.ErrWouldBlock { - // Link address needs to be resolved. - // Resolution was triggered the background. - // Better luck next time. - route.RemoveWaker(waker) return 0, ch, tcpip.ErrNoLinkAddress } return 0, nil, err diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index d9ca097c9..3d52a4f31 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -18,7 +18,6 @@ import ( "math" "sync" - "gvisor.googlesource.com/gvisor/pkg/sleep" "gvisor.googlesource.com/gvisor/pkg/tcpip" "gvisor.googlesource.com/gvisor/pkg/tcpip/buffer" "gvisor.googlesource.com/gvisor/pkg/tcpip/header" @@ -346,12 +345,8 @@ func (e *endpoint) Write(p tcpip.Payload, opts tcpip.WriteOptions) (uintptr, <-c } if route.IsResolutionRequired() { - waker := &sleep.Waker{} - if ch, err := route.Resolve(waker); err != nil { + if ch, err := route.Resolve(nil); err != nil { if err == tcpip.ErrWouldBlock { - // Link address needs to be resolved. Resolution was triggered the background. - // Better luck next time. - route.RemoveWaker(waker) return 0, ch, tcpip.ErrNoLinkAddress } return 0, nil, err -- cgit v1.2.3