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

Merge pull request #622 from mrjana/bugs

Move sandbox resources when container restarts
This commit is contained in:
Madhu Venugopal 2015-10-09 13:56:59 -07:00
commit 933190302f

View file

@ -307,15 +307,21 @@ func (sb *sandbox) SetKey(basePath string) error {
} }
sb.Lock() sb.Lock()
if sb.osSbox != nil { osSbox := sb.osSbox
sb.Unlock()
return types.ForbiddenErrorf("failed to set sandbox key : already assigned")
}
sb.Unlock() sb.Unlock()
osSbox, err := osl.GetSandboxForExternalKey(basePath, sb.Key())
if osSbox != nil {
// If we already have an OS sandbox, release the network resources from that
// and destroy the OS snab. We are moving into a new home further down. Note that none
// of the network resources gets destroyed during the move.
sb.releaseOSSbox()
}
osSbox, err = osl.GetSandboxForExternalKey(basePath, sb.Key())
if err != nil { if err != nil {
return err return err
} }
sb.Lock() sb.Lock()
sb.osSbox = osSbox sb.osSbox = osSbox
sb.Unlock() sb.Unlock()
@ -335,6 +341,45 @@ func (sb *sandbox) SetKey(basePath string) error {
return nil return nil
} }
func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) {
for _, i := range osSbox.Info().Interfaces() {
// Only remove the interfaces owned by this endpoint from the sandbox.
if ep.hasInterface(i.SrcName()) {
if err := i.Remove(); err != nil {
log.Debugf("Remove interface failed: %v", err)
}
}
}
ep.Lock()
joinInfo := ep.joinInfo
ep.Unlock()
// Remove non-interface routes.
for _, r := range joinInfo.StaticRoutes {
if err := osSbox.RemoveStaticRoute(r); err != nil {
log.Debugf("Remove route failed: %v", err)
}
}
}
func (sb *sandbox) releaseOSSbox() {
sb.Lock()
osSbox := sb.osSbox
sb.osSbox = nil
sb.Unlock()
if osSbox == nil {
return
}
for _, ep := range sb.getConnectedEndpoints() {
releaseOSSboxResources(osSbox, ep)
}
osSbox.Destroy()
}
func (sb *sandbox) populateNetworkResources(ep *endpoint) error { func (sb *sandbox) populateNetworkResources(ep *endpoint) error {
sb.Lock() sb.Lock()
if sb.osSbox == nil { if sb.osSbox == nil {
@ -394,25 +439,7 @@ func (sb *sandbox) clearNetworkResources(origEp *endpoint) error {
osSbox := sb.osSbox osSbox := sb.osSbox
sb.Unlock() sb.Unlock()
if osSbox != nil { if osSbox != nil {
for _, i := range osSbox.Info().Interfaces() { releaseOSSboxResources(osSbox, ep)
// Only remove the interfaces owned by this endpoint from the sandbox.
if ep.hasInterface(i.SrcName()) {
if err := i.Remove(); err != nil {
log.Debugf("Remove interface failed: %v", err)
}
}
}
ep.Lock()
joinInfo := ep.joinInfo
ep.Unlock()
// Remove non-interface routes.
for _, r := range joinInfo.StaticRoutes {
if err := osSbox.RemoveStaticRoute(r); err != nil {
log.Debugf("Remove route failed: %v", err)
}
}
} }
sb.Lock() sb.Lock()