Selaa lähdekoodia

libn/d/o/ovmanager: drop mutex from network type

In the network.obtainVxlanID() method, the mutex only guards a local
variable and a function argument. Locking is therefore unnecessary.

The network.releaseVxlanID() method is only called in two contexts:
driver.NetworkAllocate(), where the network struct is a local variable
and network.releaseVxlanID() is only called in failure code-paths in
which the network does not escape; and driver.NetworkFree(), while the
driver mutex is held. Locking is therefore unnecessary.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 2 vuotta sitten
vanhempi
commit
e97492e579
1 muutettua tiedostoa jossa 3 lisäystä ja 21 poistoa
  1. 3 21
      libnetwork/drivers/overlay/ovmanager/ovmanager.go

+ 3 - 21
libnetwork/drivers/overlay/ovmanager/ovmanager.go

@@ -40,7 +40,6 @@ type subnet struct {
 type network struct {
 	id      string
 	driver  *driver
-	mu      sync.Mutex
 	subnets []*subnet
 }
 
@@ -160,24 +159,14 @@ func (d *driver) NetworkFree(id string) error {
 }
 
 func (n *network) obtainVxlanID(s *subnet) error {
-	var (
-		err error
-		vni uint64
-	)
-
-	n.mu.Lock()
-	vni = uint64(s.vni)
-	n.mu.Unlock()
-
+	vni := uint64(s.vni)
 	if vni == 0 {
-		vni, err = n.driver.vxlanIdm.GetIDInRange(vxlanIDStart, vxlanIDEnd, true)
+		vni, err := n.driver.vxlanIdm.GetIDInRange(vxlanIDStart, vxlanIDEnd, true)
 		if err != nil {
 			return err
 		}
 
-		n.mu.Lock()
 		s.vni = uint32(vni)
-		n.mu.Unlock()
 		return nil
 	}
 
@@ -185,17 +174,10 @@ func (n *network) obtainVxlanID(s *subnet) error {
 }
 
 func (n *network) releaseVxlanID() {
-	n.mu.Lock()
-	vnis := make([]uint32, 0, len(n.subnets))
 	for _, s := range n.subnets {
-		vnis = append(vnis, s.vni)
+		n.driver.vxlanIdm.Release(uint64(s.vni))
 		s.vni = 0
 	}
-	n.mu.Unlock()
-
-	for _, vni := range vnis {
-		n.driver.vxlanIdm.Release(uint64(vni))
-	}
 }
 
 func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {