Skip to content

Commit a0c90f2

Browse files
committed
[bridgeconfig] make mutex internal.
syncFlows only directly uses already protected GetBridgeName() method for bridgeConfig, and flow updates should be protected by the flowMutex. So hopefully I am not breaking anything... Signed-off-by: Nadia Pinaeva <[email protected]>
1 parent fa6076b commit a0c90f2

File tree

4 files changed

+41
-48
lines changed

4 files changed

+41
-48
lines changed

go-controller/pkg/node/bridgeconfig/bridgeconfig.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (netConfig *BridgeUDNConfiguration) setOfPatchPort() error {
6363
}
6464

6565
type BridgeConfiguration struct {
66-
Mutex sync.Mutex
66+
mutex sync.Mutex
6767

6868
// variables that are only set on creation and never changed
6969
// don't require mutex lock to read
@@ -234,8 +234,8 @@ func (b *BridgeConfiguration) GetGatewayIface() string {
234234

235235
// UpdateInterfaceIPAddresses sets and returns the bridge's current ips
236236
func (b *BridgeConfiguration) UpdateInterfaceIPAddresses(node *corev1.Node) ([]*net.IPNet, error) {
237-
b.Mutex.Lock()
238-
defer b.Mutex.Unlock()
237+
b.mutex.Lock()
238+
defer b.mutex.Unlock()
239239
ifAddrs, err := nodeutil.GetNetworkInterfaceIPAddresses(b.GetGatewayIface())
240240
if err != nil {
241241
return nil, err
@@ -265,8 +265,8 @@ func (b *BridgeConfiguration) UpdateInterfaceIPAddresses(node *corev1.Node) ([]*
265265
// GetPortConfigurations returns a slice of Network port configurations along with the
266266
// uplinkName and physical port's ofport value
267267
func (b *BridgeConfiguration) GetPortConfigurations() ([]*BridgeUDNConfiguration, string, string) {
268-
b.Mutex.Lock()
269-
defer b.Mutex.Unlock()
268+
b.mutex.Lock()
269+
defer b.mutex.Unlock()
270270
var netConfigs []*BridgeUDNConfiguration
271271
for _, netConfig := range b.netConfig {
272272
netConfigs = append(netConfigs, netConfig.ShallowCopy())
@@ -280,8 +280,8 @@ func (b *BridgeConfiguration) AddNetworkConfig(
280280
nodeSubnets []*net.IPNet,
281281
masqCTMark, pktMark uint,
282282
v6MasqIPs, v4MasqIPs *udn.MasqueradeIPs) error {
283-
b.Mutex.Lock()
284-
defer b.Mutex.Unlock()
283+
b.mutex.Lock()
284+
defer b.mutex.Unlock()
285285

286286
netName := nInfo.GetNetworkName()
287287
patchPort := nInfo.GetNetworkScopedPatchPortName(b.bridgeName, b.nodeName)
@@ -309,15 +309,15 @@ func (b *BridgeConfiguration) AddNetworkConfig(
309309

310310
// DelNetworkConfig deletes the provided netInfo from the bridge configuration cache
311311
func (b *BridgeConfiguration) DelNetworkConfig(nInfo util.NetInfo) {
312-
b.Mutex.Lock()
313-
defer b.Mutex.Unlock()
312+
b.mutex.Lock()
313+
defer b.mutex.Unlock()
314314

315315
delete(b.netConfig, nInfo.GetNetworkName())
316316
}
317317

318318
func (b *BridgeConfiguration) GetNetworkConfig(networkName string) *BridgeUDNConfiguration {
319-
b.Mutex.Lock()
320-
defer b.Mutex.Unlock()
319+
b.mutex.Lock()
320+
defer b.mutex.Unlock()
321321
return b.netConfig[networkName]
322322
}
323323

@@ -327,8 +327,8 @@ func (b *BridgeConfiguration) GetNetworkConfig(networkName string) *BridgeUDNCon
327327
// NOTE: if the network configuration can't be found or if the network is not patched by OVN
328328
// yet this returns nil.
329329
func (b *BridgeConfiguration) GetActiveNetworkBridgeConfigCopy(networkName string) *BridgeUDNConfiguration {
330-
b.Mutex.Lock()
331-
defer b.Mutex.Unlock()
330+
b.mutex.Lock()
331+
defer b.mutex.Unlock()
332332

333333
if netConfig, found := b.netConfig[networkName]; found && netConfig.OfPortPatch != "" {
334334
return netConfig.ShallowCopy()
@@ -337,8 +337,8 @@ func (b *BridgeConfiguration) GetActiveNetworkBridgeConfigCopy(networkName strin
337337
}
338338

339339
func (b *BridgeConfiguration) PatchedNetConfigs() []*BridgeUDNConfiguration {
340-
b.Mutex.Lock()
341-
defer b.Mutex.Unlock()
340+
b.mutex.Lock()
341+
defer b.mutex.Unlock()
342342
result := make([]*BridgeUDNConfiguration, 0, len(b.netConfig))
343343
for _, netConfig := range b.netConfig {
344344
if netConfig.OfPortPatch == "" {
@@ -352,8 +352,8 @@ func (b *BridgeConfiguration) PatchedNetConfigs() []*BridgeUDNConfiguration {
352352
// IsGatewayReady checks if patch ports of every netConfig are present.
353353
// used by gateway on newGateway readyFunc
354354
func (b *BridgeConfiguration) IsGatewayReady() bool {
355-
b.Mutex.Lock()
356-
defer b.Mutex.Unlock()
355+
b.mutex.Lock()
356+
defer b.mutex.Unlock()
357357
for _, netConfig := range b.netConfig {
358358
ready := gatewayReady(netConfig.PatchPort)
359359
if !ready {
@@ -364,8 +364,8 @@ func (b *BridgeConfiguration) IsGatewayReady() bool {
364364
}
365365

366366
func (b *BridgeConfiguration) SetOfPorts() error {
367-
b.Mutex.Lock()
368-
defer b.Mutex.Unlock()
367+
b.mutex.Lock()
368+
defer b.mutex.Unlock()
369369
// Get ofport of patchPort
370370
for _, netConfig := range b.netConfig {
371371
if err := netConfig.setOfPatchPort(); err != nil {
@@ -412,8 +412,8 @@ func (b *BridgeConfiguration) SetOfPorts() error {
412412
}
413413

414414
func (b *BridgeConfiguration) GetIPs() []*net.IPNet {
415-
b.Mutex.Lock()
416-
defer b.Mutex.Unlock()
415+
b.mutex.Lock()
416+
defer b.mutex.Unlock()
417417
return b.ips
418418
}
419419

@@ -426,20 +426,20 @@ func (b *BridgeConfiguration) GetUplinkName() string {
426426
}
427427

428428
func (b *BridgeConfiguration) GetMAC() net.HardwareAddr {
429-
b.Mutex.Lock()
430-
defer b.Mutex.Unlock()
429+
b.mutex.Lock()
430+
defer b.mutex.Unlock()
431431
return b.macAddress
432432
}
433433

434434
func (b *BridgeConfiguration) SetMAC(macAddr net.HardwareAddr) {
435-
b.Mutex.Lock()
436-
defer b.Mutex.Unlock()
435+
b.mutex.Lock()
436+
defer b.mutex.Unlock()
437437
b.macAddress = macAddr
438438
}
439439

440440
func (b *BridgeConfiguration) SetNetworkOfPatchPort(netName string) error {
441-
b.Mutex.Lock()
442-
defer b.Mutex.Unlock()
441+
b.mutex.Lock()
442+
defer b.mutex.Unlock()
443443

444444
netConfig, found := b.netConfig[netName]
445445
if !found {
@@ -453,20 +453,20 @@ func (b *BridgeConfiguration) GetInterfaceID() string {
453453
}
454454

455455
func (b *BridgeConfiguration) GetOfPortHost() string {
456-
b.Mutex.Lock()
457-
defer b.Mutex.Unlock()
456+
b.mutex.Lock()
457+
defer b.mutex.Unlock()
458458
return b.ofPortHost
459459
}
460460

461461
func (b *BridgeConfiguration) GetEIPMarkIPs() *egressip.MarkIPsCache {
462-
b.Mutex.Lock()
463-
defer b.Mutex.Unlock()
462+
b.mutex.Lock()
463+
defer b.mutex.Unlock()
464464
return b.eipMarkIPs
465465
}
466466

467467
func (b *BridgeConfiguration) SetEIPMarkIPs(eipMarkIPs *egressip.MarkIPsCache) {
468-
b.Mutex.Lock()
469-
defer b.Mutex.Unlock()
468+
b.mutex.Lock()
469+
defer b.mutex.Unlock()
470470
b.eipMarkIPs = eipMarkIPs
471471
}
472472

go-controller/pkg/node/bridgeconfig/bridgeconfig_testutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func TestBridgeConfig(brName string) *BridgeConfiguration {
3434
}
3535

3636
func (b *BridgeConfiguration) GetNetConfigLen() int {
37-
b.Mutex.Lock()
38-
defer b.Mutex.Unlock()
37+
b.mutex.Lock()
38+
defer b.mutex.Unlock()
3939
return len(b.netConfig)
4040
}
4141

go-controller/pkg/node/bridgeconfig/bridgeflows.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
)
1616

1717
func (b *BridgeConfiguration) DefaultBridgeFlows(hostSubnets []*net.IPNet, extraIPs []net.IP) ([]string, error) {
18-
b.Mutex.Lock()
19-
defer b.Mutex.Unlock()
18+
b.mutex.Lock()
19+
defer b.mutex.Unlock()
2020
dftFlows, err := b.flowsForDefaultBridge(extraIPs)
2121
if err != nil {
2222
return nil, err
@@ -29,8 +29,8 @@ func (b *BridgeConfiguration) DefaultBridgeFlows(hostSubnets []*net.IPNet, extra
2929
}
3030

3131
func (b *BridgeConfiguration) ExternalBridgeFlows(hostSubnets []*net.IPNet) ([]string, error) {
32-
b.Mutex.Lock()
33-
defer b.Mutex.Unlock()
32+
b.mutex.Lock()
33+
defer b.mutex.Unlock()
3434
return b.commonFlows(hostSubnets)
3535
}
3636

@@ -861,8 +861,8 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
861861
}
862862

863863
func (b *BridgeConfiguration) PMTUDDropFlows(ipAddrs []string) []string {
864-
b.Mutex.Lock()
865-
defer b.Mutex.Unlock()
864+
b.mutex.Lock()
865+
defer b.mutex.Unlock()
866866
var flows []string
867867
if config.Gateway.Mode != config.GatewayModeShared {
868868
return nil

go-controller/pkg/node/openflow_manager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ func (c *openflowManager) requestFlowSync() {
112112
}
113113

114114
func (c *openflowManager) syncFlows() {
115-
// protect gwBridge config from being updated by gw.nodeIPManager
116-
c.defaultBridge.Mutex.Lock()
117-
defer c.defaultBridge.Mutex.Unlock()
118-
119115
c.flowMutex.Lock()
120116
defer c.flowMutex.Unlock()
121117

@@ -130,9 +126,6 @@ func (c *openflowManager) syncFlows() {
130126
}
131127

132128
if c.externalGatewayBridge != nil {
133-
c.externalGatewayBridge.Mutex.Lock()
134-
defer c.externalGatewayBridge.Mutex.Unlock()
135-
136129
c.exGWFlowMutex.Lock()
137130
defer c.exGWFlowMutex.Unlock()
138131

0 commit comments

Comments
 (0)