1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #111 from aboch/lk

In bridge.go: Join(), Leave(), getnetwork() are not thread safe
This commit is contained in:
Madhu Venugopal 2015-05-06 09:29:56 -07:00
commit 1402220ec3

View file

@ -183,6 +183,8 @@ func (d *driver) Config(option map[string]interface{}) error {
func (d *driver) getNetwork(id types.UUID) (*bridgeNetwork, error) { func (d *driver) getNetwork(id types.UUID) (*bridgeNetwork, error) {
// Just a dummy function to return the only network managed by Bridge driver. // Just a dummy function to return the only network managed by Bridge driver.
// But this API makes the caller code unchanged when we move to support multiple networks. // But this API makes the caller code unchanged when we move to support multiple networks.
d.Lock()
defer d.Unlock()
return d.network, nil return d.network, nil
} }
@ -627,20 +629,24 @@ func (d *driver) EndpointInfo(nid, eid types.UUID) (map[string]interface{}, erro
// Join method is invoked when a Sandbox is attached to an endpoint. // Join method is invoked when a Sandbox is attached to an endpoint.
func (d *driver) Join(nid, eid types.UUID, sboxKey string, options map[string]interface{}) (*driverapi.JoinInfo, error) { func (d *driver) Join(nid, eid types.UUID, sboxKey string, options map[string]interface{}) (*driverapi.JoinInfo, error) {
var err error d.Lock()
if !d.config.EnableICC { config := d.config
err = d.link(nid, eid, options, true) d.Unlock()
if !config.EnableICC {
return nil, d.link(nid, eid, options, true)
} }
return nil, err return nil, nil
} }
// Leave method is invoked when a Sandbox detaches from an endpoint. // Leave method is invoked when a Sandbox detaches from an endpoint.
func (d *driver) Leave(nid, eid types.UUID, options map[string]interface{}) error { func (d *driver) Leave(nid, eid types.UUID, options map[string]interface{}) error {
var err error d.Lock()
if !d.config.EnableICC { config := d.config
err = d.link(nid, eid, options, false) d.Unlock()
if !config.EnableICC {
return d.link(nid, eid, options, false)
} }
return err return nil
} }
func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enable bool) error { func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enable bool) error {
@ -684,9 +690,11 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl
return err return err
} }
d.Lock()
l := newLink(parentEndpoint.intf.Address.IP.String(), l := newLink(parentEndpoint.intf.Address.IP.String(),
endpoint.intf.Address.IP.String(), endpoint.intf.Address.IP.String(),
endpoint.config.ExposedPorts, d.config.BridgeName) endpoint.config.ExposedPorts, d.config.BridgeName)
d.Unlock()
if enable { if enable {
err = l.Enable() err = l.Enable()
if err != nil { if err != nil {
@ -716,9 +724,11 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl
if childEndpoint.config == nil || childEndpoint.config.ExposedPorts == nil { if childEndpoint.config == nil || childEndpoint.config.ExposedPorts == nil {
continue continue
} }
d.Lock()
l := newLink(endpoint.intf.Address.IP.String(), l := newLink(endpoint.intf.Address.IP.String(),
childEndpoint.intf.Address.IP.String(), childEndpoint.intf.Address.IP.String(),
childEndpoint.config.ExposedPorts, d.config.BridgeName) childEndpoint.config.ExposedPorts, d.config.BridgeName)
d.Unlock()
if enable { if enable {
err = l.Enable() err = l.Enable()
if err != nil { if err != nil {