Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #764 from markdryan/fix-763
Browse files Browse the repository at this point in the history
ciao-launcher: Fix docker network locks
  • Loading branch information
mcastelino authored Nov 2, 2016
2 parents 581f0b6 + 54d8e50 commit f44a9cd
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions ciao-launcher/docker_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,24 @@ type dockerNetworkState struct {
err error
}

var dockerNetworkMap struct {
sync.Mutex
networks map[string]*dockerNetworkState
}

func init() {
dockerNetworkMap.networks = make(map[string]*dockerNetworkState)
}
var dockerNetworkLock sync.Mutex

func createDockerVnic(vnicCfg *libsnnet.VnicConfig) (*libsnnet.Vnic, *libsnnet.SsntpEventInfo, *libsnnet.ContainerInfo, error) {
dockerNetworkMap.Lock()
state := dockerNetworkMap.networks[vnicCfg.SubnetID]
if state != nil {
dockerNetworkMap.Unlock()
glog.Info("Waiting for Docker network creation")
<-state.done
if state.err != nil {
return nil, nil, nil, state.err
}

return cnNet.CreateVnic(vnicCfg)
}
ch := make(chan struct{})
defer close(ch)
state = &dockerNetworkState{done: ch}
dockerNetworkMap.networks[vnicCfg.SubnetID] = state
dockerNetworkMap.Unlock()
dockerNetworkLock.Lock()
defer dockerNetworkLock.Unlock()
vnic, event, info, err := cnNet.CreateVnic(vnicCfg)
state.err = err
if err != nil {
return vnic, event, info, err
}

if info == nil {
glog.Warning("VNIC information expected")
return vnic, event, info, err
}

// We are going to ignore the error here. Docker network
// might fail as it could already have been created. We
// would not know this if it was created in a previous invocation
// of launcher. Should the network really fail to be created
// the container will not launch.

_ = createDockerNetwork(context.Background(), info)
return vnic, event, info, state.err
return vnic, event, info, nil
}

func destroyDockerVnic(vnicCfg *libsnnet.VnicConfig) (*libsnnet.SsntpEventInfo, error) {
Expand All @@ -96,9 +68,6 @@ func destroyDockerVnic(vnicCfg *libsnnet.VnicConfig) (*libsnnet.SsntpEventInfo,
// these inconsistencies and cleans up:
// https://github.com/01org/ciao/issues/4
_ = destroyDockerNetwork(context.Background(), info.SubnetID)
dockerNetworkMap.Lock()
delete(dockerNetworkMap.networks, vnicCfg.SubnetID)
dockerNetworkMap.Unlock()
}

return event, err
Expand Down

0 comments on commit f44a9cd

Please sign in to comment.