Skip to content

Commit 82252ef

Browse files
committed
Merge pull request #901 from mrjana/bugs
Cleanup stale overlay sandboxes
2 parents 014fb9c + 4dc6808 commit 82252ef

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

drivers/overlay/ov_network.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"net"
77
"os"
8+
"path/filepath"
9+
"strings"
810
"sync"
911
"syscall"
1012

@@ -298,6 +300,26 @@ func (n *network) initSubnetSandbox(s *subnet) error {
298300
return nil
299301
}
300302

303+
func (n *network) cleanupStaleSandboxes() {
304+
filepath.Walk(filepath.Dir(osl.GenerateKey("walk")),
305+
func(path string, info os.FileInfo, err error) error {
306+
_, fname := filepath.Split(path)
307+
308+
pList := strings.Split(fname, "-")
309+
if len(pList) <= 1 {
310+
return nil
311+
}
312+
313+
pattern := pList[1]
314+
if strings.Contains(n.id, pattern) {
315+
syscall.Unmount(path, syscall.MNT_DETACH)
316+
os.Remove(path)
317+
}
318+
319+
return nil
320+
})
321+
}
322+
301323
func (n *network) initSandbox() error {
302324
n.Lock()
303325
n.initEpoch++
@@ -311,6 +333,10 @@ func (n *network) initSandbox() error {
311333
}
312334
}
313335

336+
// If there are any stale sandboxes related to this network
337+
// from previous daemon life clean it up here
338+
n.cleanupStaleSandboxes()
339+
314340
sbox, err := osl.NewSandbox(
315341
osl.GenerateKey(fmt.Sprintf("%d-", n.initEpoch)+n.id), !hostMode)
316342
if err != nil {

0 commit comments

Comments
 (0)