mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 13:41:36 +00:00
Improvements to the original sharing implementation.
- Print the mount table as in /proc/self/mountinfo - Do not exit prematurely when one of the ipc mounts doesn't exist. - Do not exit prematurely when one of the ipc mounts cannot be unmounted. - Add a unit test to see if the cleanup really works. - Use syscall.MNT_DETACH to cleanup mounts after a crash. - Unmount IPC mounts when the daemon unregisters an old running container. Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
+18
-6
@@ -2,12 +2,13 @@ package daemon
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
)
|
||||
|
||||
// cleanupMounts umounts shm/mqueue mounts for old containers
|
||||
@@ -19,17 +20,24 @@ func (daemon *Daemon) cleanupMounts() error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
sc := bufio.NewScanner(f)
|
||||
return daemon.cleanupMountsFromReader(f, detachMounted)
|
||||
}
|
||||
|
||||
func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {
|
||||
sc := bufio.NewScanner(reader)
|
||||
var errors []string
|
||||
for sc.Scan() {
|
||||
line := sc.Text()
|
||||
fields := strings.Split(line, " ")
|
||||
fields := strings.Fields(line)
|
||||
if strings.HasPrefix(fields[4], daemon.repository) {
|
||||
logrus.Debugf("Mount base: %v, repository %s", fields[4], daemon.repository)
|
||||
mnt := fields[4]
|
||||
mountBase := filepath.Base(mnt)
|
||||
if mountBase == "mqueue" || mountBase == "shm" {
|
||||
logrus.Debugf("Unmounting %+v", mnt)
|
||||
if err := mount.Unmount(mnt); err != nil {
|
||||
return err
|
||||
logrus.Debugf("Unmounting %v", mnt)
|
||||
if err := unmount(mnt); err != nil {
|
||||
logrus.Error(err)
|
||||
errors = append(errors, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +47,10 @@ func (daemon *Daemon) cleanupMounts() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf("Error cleaningup mounts:\n%v", strings.Join(errors, "\n"))
|
||||
}
|
||||
|
||||
logrus.Debugf("Cleaning up old shm/mqueue mounts: done.")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user