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

Merge pull request #901 from mrjana/bugs

Cleanup stale overlay sandboxes
This commit is contained in:
Madhu Venugopal 2016-01-26 11:17:16 -08:00
commit 8763b5981f

View file

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"path/filepath"
"strings"
"sync" "sync"
"syscall" "syscall"
@ -298,6 +300,26 @@ func (n *network) initSubnetSandbox(s *subnet) error {
return nil return nil
} }
func (n *network) cleanupStaleSandboxes() {
filepath.Walk(filepath.Dir(osl.GenerateKey("walk")),
func(path string, info os.FileInfo, err error) error {
_, fname := filepath.Split(path)
pList := strings.Split(fname, "-")
if len(pList) <= 1 {
return nil
}
pattern := pList[1]
if strings.Contains(n.id, pattern) {
syscall.Unmount(path, syscall.MNT_DETACH)
os.Remove(path)
}
return nil
})
}
func (n *network) initSandbox() error { func (n *network) initSandbox() error {
n.Lock() n.Lock()
n.initEpoch++ n.initEpoch++
@ -311,6 +333,10 @@ func (n *network) initSandbox() error {
} }
} }
// If there are any stale sandboxes related to this network
// from previous daemon life clean it up here
n.cleanupStaleSandboxes()
sbox, err := osl.NewSandbox( sbox, err := osl.NewSandbox(
osl.GenerateKey(fmt.Sprintf("%d-", n.initEpoch)+n.id), !hostMode) osl.GenerateKey(fmt.Sprintf("%d-", n.initEpoch)+n.id), !hostMode)
if err != nil { if err != nil {